From: Niki Roo Date: Sun, 30 Jun 2024 11:37:43 +0000 (+0200) Subject: makefile X-Git-Url: http://git.nikiroo.be/?a=commitdiff_plain;h=2a4094582fff08e3624110e6c041ea76fec54976;p=nsub.git makefile --- diff --git a/Makefile b/Makefile index c542c07..6f6ce65 100644 --- a/Makefile +++ b/Makefile @@ -8,6 +8,7 @@ NAME = nsub NAMES = $(NAME) cutils TESTS = +# You may override these when calling make PREFIX = /usr/local dstdir = bin @@ -24,7 +25,8 @@ build: mess-build $(NAMES) test: mess-test $(TESTS) # Main buildables -M_OPTS=$(MAKECMDGOALS) --no-print-directory PREFIX=$(PREFIX) DEBUG=$(DEBUG) +M_OPTS=$(MAKECMDGOALS) --no-print-directory \ + PREFIX=$(PREFIX) DEBUG=$(DEBUG) dstdir=$(abspath $(dstdir)) $(NAMES) $(TESTS): $(MAKE) -C src/$@ $(M_OPTS) @@ -61,7 +63,7 @@ uninstall: mess-uninstall $(NAMES) man # Messages mess-build: @echo - @echo ">>>>>>>>>> Building $(NAMES)..." + @echo ">>>>>>>>>> Building $(NAMES) in $(dstdir)..." mess-run: @echo @echo ">>>>>>>>>> Running $(NAME)..." @@ -79,7 +81,7 @@ mess-man: @echo ">>>>>>>>>> Manual of $(NAME): $(MAKECMDGOALS)..." mess-test: @echo - @echo ">>>>>>>>>> Building all tests: $(TESTS)..." + @echo ">>>>>>>>>> Building all tests in $(dstdir): $(TESTS)..." mess-run-test: @echo @echo ">>>>>>>>>> Running tests: $(TESTS)..." diff --git a/src/cutils b/src/cutils index 9e29e2f..780c8d0 160000 --- a/src/cutils +++ b/src/cutils @@ -1 +1 @@ -Subproject commit 9e29e2f55d36a2e05a3420825b8ecc33006a45eb +Subproject commit 780c8d0590a2f34e68ff896058b3b1a89539dcd8 diff --git a/src/nsub/makefile.d b/src/nsub/makefile.d index 5218164..5ea5c95 100644 --- a/src/nsub/makefile.d +++ b/src/nsub/makefile.d @@ -1,12 +1,14 @@ # Note: 99+ required for for-loop initial declaration (CentOS 6) -# Note: gnu99 (instead of c99) required for libcutils-net NAME = nsub NAMES = $(NAME) srcdir = $(NAME) -dstdir = ../bin -CFLAGS += -Wall -pedantic -I./ -std=gnu99 +ifeq ($(dstdir),) +dstdir = $(srcdir)/bin +endif + +CFLAGS += -Wall -pedantic -I./ -std=c99 CXXFLAGS += -Wall -pedantic -I./ # LDFLAGS += -lcheck PREFIX = /usr/local @@ -17,10 +19,9 @@ CXXFLAGS += -ggdb -O0 endif .PHONY: all build install uninstall clean mrpropre mrpropre \ - $(NAMES) + $(NAMES) deps test run run-test run-test-more SOURCES=$(wildcard $(srcdir)/*.c) -HEADERS=$(wildcard $(srcdir)/*.h) OBJECTS=$(SOURCES:%.c=%.o) # Main targets @@ -29,40 +30,53 @@ all: build build: $(NAMES) -nsub: $(dstdir)/nsub +$(NAME): deps $(dstdir)/$(NAME) +# Program, so no test run: - $(dstdir)/nsub --help + @echo + $(dstdir)/$(NAME) --help +test run-test run-test-more: + @echo you are in the sources of the program, look at the tests instead ################ # Dependencies # ################ -OBJECTS+=$(dstdir)/libcutils.o -$(dstdir)/libcutils.o: +## Libs (if needed) +deps: $(MAKE) --no-print-directory -C cutils/ cutils +DEPS=$(dstdir)/libcutils.o + +## Headers +DEPENDS=$(SOURCES:%.c=%.d) +-include $(DEPENDS) +%.o: %.c + $(CC) $(CFLAGS) -MMD -MP -c $< -o $@ ################ -$(dstdir)/nsub: $(OBJECTS) +$(dstdir)/$(NAME): $(DEPS) $(OBJECTS) mkdir -p $(dstdir) - $(CC) $(OBJECTS) -o $@ + # note: -r = --relocatable, but former also works with Clang + $(CC) $(CFLAGS) $(LDFLAGS) $(DEPS) $(OBJECTS) -o $@ debug: $(MAKE) -f $(srcdir)/makefile.d DEBUG=1 clean: - rm -f $(srcdir)/*.o + rm -f $(OBJECTS) + rm -f $(DEPENDS) + rm -f $(DEPS) mrproper: mrpropre - mrpropre: clean - rm -f $(dstdir)/nsub + rm -f $(dstdir)/$(NAME) rmdir $(dstdir) 2>/dev/null || true -install: +install: build mkdir -p "$(PREFIX)/bin" - cp $(dstdir)/nsub "$(PREFIX)/bin/" + cp "$(dstdir)/$(NAME)" "$(PREFIX)/bin/" -uninstall: - rm "$(PREFIX)/bin/nsub" +uninstall: build + rm "$(PREFIX)/bin/$(NAME)" rmdir "$(PREFIX)/bin" 2>/dev/null