From 1836cfa85068c1b32d441423895371bcc323510e Mon Sep 17 00:00:00 2001 From: Lukas Krickl Date: Tue, 29 Oct 2024 09:56:14 +0100 Subject: [PATCH] Updated makefile to be more portable --- .gitignore | 3 ++ makefile | 75 ++++++++++++++++++++------------------------- {doc => man}/ulas.1 | 0 3 files changed, 36 insertions(+), 42 deletions(-) rename {doc => man}/ulas.1 (100%) diff --git a/.gitignore b/.gitignore index c7e8574..2571b19 100644 --- a/.gitignore +++ b/.gitignore @@ -62,3 +62,6 @@ compile_commands.json .clang_complete # .clangd .session + +ulas +testulas diff --git a/makefile b/makefile index 501f9f2..b923c19 100644 --- a/makefile +++ b/makefile @@ -1,76 +1,67 @@ NAME=ulas -IDIR=./src -SDIR=./src -CC=gcc +TEST_NAME=test$(NAME) DBGCFLAGS=-g -fsanitize=address DBGLDFLAGS=-fsanitize=address -CFLAGS=-I$(IDIR) -Wall -pedantic $(DBGCFLAGS) -std=gnu99 +CFLAGS=-Wall -pedantic $(DBGCFLAGS) -std=gnu99 LIBS= -TEST_LIBS= LDFLAGS=$(DBGLDFLAGS) $(LIBS) -TAG_LIBS=/usr/include/unistd.h /usr/include/stdio.h /usr/include/stdlib.h /usr/include/assert.h /usr/include/errno.h /usr/include/ctype.h +INSTALL_DIR=/usr/local +OBJS:=ulas.o archs.o uldas.o -ODIR=obj -TEST_ODIR=obj/test -BDIR=bin -BNAME=$(NAME) -MAIN=main.o -TEST_MAIN=test.o -TEST_BNAME=testulas - -BIN_INSTALL_DIR=/usr/local/bin -MAN_INSTALL_DIR=/usr/local/man - -OBJ = $(ODIR)/$(MAIN) $(ODIR)/ulas.o $(ODIR)/archs.o $(ODIR)/uldas.o +CCOBJ=$(CC) -c -o $@ $< $(CFLAGS) $(LDFLAGS) all: bin test release: make DBGCFLAGS="" DBGLDFLAGS="" -$(ODIR)/%.o: src/%.c src/*.h - mkdir -p $(@D) - $(CC) -c -o $@ $< $(CFLAGS) $(LDFLAGS) -bin: $(OBJ) - mkdir -p $(BDIR) - $(CC) -o $(BDIR)/$(BNAME) $^ $(CFLAGS) $(LDFLAGS) +main.o: src/main.c + $(CCOBJ) +test.o: src/test.c + $(CCOBJ) +ulas.o: src/ulas.c + $(CCOBJ) +uldas.o: src/uldas.c + $(CCOBJ) +archs.o: src/archs.c + $(CCOBJ) + -test: - echo "building tests" - make bin MAIN=$(TEST_MAIN) BNAME=$(TEST_BNAME) ODIR=$(TEST_ODIR) LIBS=$(TEST_LIBS) +bin: main.o $(OBJS) + $(CC) -o $(NAME) main.o $(OBJS) $(CFLAGS) $(LDFLAGS) -.PHONY: clean +test: test.o $(OBJS) + $(CC) -o $(TEST_NAME) test.o $(OBJS) $(CFLAGS) $(LDFLAGS) +.PHONY: clean clean: - rm -f ./$(ODIR)/*.o - rm -f ./$(TEST_ODIR)/*.o - rm -f ./$(BDIR)/$(BNAME) - rm -f ./$(BDIR)/$(TEST_BNAME) + rm -f ./*.o + rm -f ./$(NAME) + rm -f ./$(TEST_NAME) .PHONY: install - install: - cp ./$(BDIR)/$(BNAME) $(BIN_INSTALL_DIR) - cp ./doc/$(BNAME).1 $(MAN_INSTALL_DIR) + cp ./$(NAME) $(INSTALL_DIR)/bin + cp ./man/$(NAME).1 $(INSTALL_DIR)/man .PHONY: tags tags: - ctags --recurse=yes --exclude=.git --exclude=bin --exclude=obj --extras=* --fields=* --c-kinds=* --language-force=C $(TAG_LIBS) . + ctags --recurse=yes --exclude=.git --exclude=bin --exclude=obj --extras=* --fields=* --c-kinds=* --language-force=C . -.PHONY: +.PHONY: ccmds ccmds: bear -- make SHELL="sh -x -e" --always-make .PHONY: format format: - clang-format -i ./src/*.c ./src/*.h + clang-format -i src/*.c src/*.h .PHONY: lint lint: - clang-tidy ./src/*.h ./src/*.c + clang-tidy src/*.h src/*.c -buildtests: - ./$(BDIR)/$(BNAME) tests/t0.s -l - -o tests/t0.bin - ./$(BDIR)/$(BNAME) tests/t0.bin -d - -o tests/t0_dasm.s +buildtests: $(NAME) + ./$(NAME) tests/t0.s -l - -o tests/t0.bin + ./$(NAME) tests/t0.bin -d - -o tests/t0_dasm.s diff --git a/doc/ulas.1 b/man/ulas.1 similarity index 100% rename from doc/ulas.1 rename to man/ulas.1 -- 2.30.2