From: Niki Roo Date: Sun, 30 Jun 2024 11:36:29 +0000 (+0200) Subject: makefile X-Git-Url: https://git.nikiroo.be/?a=commitdiff_plain;h=f4ff782c40e87b41cca285e2e8811e16f73d5e88;p=cbook.git makefile --- diff --git a/Makefile b/Makefile index 51e897c..51306d4 100644 --- a/Makefile +++ b/Makefile @@ -1,15 +1,19 @@ +# +# Simple makefile that will forward all commands to src/xxx +# > NAME: main program (for 'man' and 'run') +# > NAMES: list of all the programs to compile +# > TESTS: list of all test programs to compile and run +# NAME = cbook NAMES = $(NAME) cutils -TEST = tests-cbook -TESTS = $(TEST) +TESTS = tests-cbook +# You may override these when calling make PREFIX = /usr/local - dstdir = bin - -.PHONY: all run clean mrpropre mrpropre love debug doc man \ - test tests run-test run-tests run-test-more run-tests-more \ +.PHONY: all build run clean mrpropre mrpropre love debug doc man \ + test run-test run-test-more \ mess-build mess-run mess-clean mess-propre mess-doc mess-man \ mess-test mess-run-test mess-run-test-more \ $(NAMES) $(TESTS) @@ -21,21 +25,21 @@ 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) + $(MAKE) -C src/$@ $(M_OPTS) # Manual man: mess-man - @$(MAKE) -f man.d $(M_OPTS) NAME=$(NAME) + @$(MAKE) -f man.d $(MAKECMDGOALS) NAME=$(NAME) # Run -run: mess-run - $(dstdir)/$(NAME) +run: mess-run $(NAME) # Run main test -run-test: mess-run-test $(TEST) -run-test-more: mess-run-test-more $(TEST) +run-test: mess-run-test $(TESTS) +run-test-more: mess-run-test-more $(TESTS) # Doc/man/misc doc: mess-doc @@ -43,29 +47,29 @@ doc: mess-doc love: @echo " ...not war." debug: - $(MAKE) DEBUG=1 + $(MAKE) $(MAKECMDGOALS) PREFIX=$(PREFIX) NAME=$(NAME) DEBUG=1 # Clean -clean: mess-clean $(NAMES) $(TESTS) +clean: mess-clean $(TESTS) $(NAMES) mrproper: mrpropre -mrpropre: mess-propre $(NAMES) $(TESTS) man +mrpropre: mess-propre $(TESTS) $(NAMES) man rm -rf doc/html doc/latex doc/man rmdir doc 2>/dev/null || true # Install/uninstall -install: mess-install $(NAME) man -uninstall: mess-uninstall $(NAME) man +install: mess-install $(NAMES) man +uninstall: mess-uninstall $(NAMES) man # Messages mess-build: @echo - @echo ">>>>>>>>>> Running $(NAME)..." + @echo ">>>>>>>>>> Building $(NAMES) in $(dstdir)..." mess-run: @echo @echo ">>>>>>>>>> Running $(NAME)..." mess-clean: @echo - @echo ">>>>>>>>>> Cleaning $(NAME)..." + @echo ">>>>>>>>>> Cleaning $(NAMES) $(TESTS)..." mess-propre: @echo @echo ">>>>>>>>>> Calling Mr Propre..." @@ -74,16 +78,16 @@ mess-doc: @echo ">>>>>>>>>> Generating documentation for $(NAME)..." mess-man: @echo - @echo ">>>>>>>>>> Generating the manual of $(NAME)..." + @echo ">>>>>>>>>> Manual of $(NAME): $(MAKECMDGOALS)..." mess-test: @echo - @echo ">>>>>>>>>> Building tests for $(NAME)..." + @echo ">>>>>>>>>> Building all tests in $(dstdir): $(TESTS)..." mess-run-test: @echo - @echo ">>>>>>>>>> Running tests on $(NAME)..." + @echo ">>>>>>>>>> Running tests: $(TESTS)..." mess-run-test-more: @echo - @echo ">>>>>>>>>> Running more tests on $(NAME)..." + @echo ">>>>>>>>>> Running more tests: $(TESTS)..." mess-install: @echo @echo ">>>>>>>>>> Installing $(NAME) into $(PREFIX)..." diff --git a/src/cbook/Makefile b/src/cbook/Makefile index dba54eb..699e560 100644 --- a/src/cbook/Makefile +++ b/src/cbook/Makefile @@ -1,9 +1,10 @@ # Simply pass everything to makefile.d, but calling from "../" -.PHONY: MK all install uninstall clean mrpropre mrpropre +.PHONY: all build install uninstall clean mrpropre mrpropre \ + run test run-test run-test-more default \ + cbook -$(MAKECMDGOALS): MK -MK: +default $(MAKECMDGOALS): @$(MAKE) --no-print-directory -C ../ -f $(CURDIR)/makefile.d \ $(MAKECMDGOALS) diff --git a/src/cbook/makefile.d b/src/cbook/makefile.d index 87654a0..88fbb17 100644 --- a/src/cbook/makefile.d +++ b/src/cbook/makefile.d @@ -3,7 +3,10 @@ NAME = cbook NAMES = $(NAME) srcdir = $(NAME) -dstdir = ../bin + +ifeq ($(dstdir),) +dstdir = $(srcdir)/bin +endif CFLAGS += -Wall -pedantic -I./ -std=c99 CXXFLAGS += -Wall -pedantic -I./ @@ -16,7 +19,7 @@ CXXFLAGS += -ggdb -O0 endif .PHONY: all build install uninstall clean mrpropre mrpropre \ - $(NAMES) deps run + $(NAMES) deps test run run-test run-test-more SOURCES=$(wildcard $(srcdir)/*.c) OBJECTS=$(SOURCES:%.c=%.o) @@ -29,6 +32,13 @@ build: $(NAMES) $(NAME): deps $(dstdir)/$(NAME) +# Program, so no test +run: + @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 # ################ @@ -46,25 +56,27 @@ DEPENDS=$(SOURCES:%.c=%.d) $(dstdir)/$(NAME): $(DEPS) $(OBJECTS) mkdir -p $(dstdir) + # note: -r = --relocatable, but former also works with Clang $(CC) $(CFLAGS) $(LDFLAGS) $(DEPS) $(OBJECTS) -o $@ -run: - @echo - $(dstdir)/$(NAME) +debug: + $(MAKE) -f $(srcdir)/makefile.d DEBUG=1 clean: - rm -f $(OBJECTS) $(DEPENDS) + rm -f $(OBJECTS) + rm -f $(DEPENDS) + rm -f $(DEPS) mrproper: mrpropre mrpropre: clean rm -f $(dstdir)/$(NAME) rmdir $(dstdir) 2>/dev/null || true -install: +install: build mkdir -p "$(PREFIX)/bin" - cp $(dstdir)/$(NAME) "$(PREFIX)/bin/" + cp "$(dstdir)/$(NAME)" "$(PREFIX)/bin/" -uninstall: +uninstall: build rm "$(PREFIX)/bin/$(NAME)" rmdir "$(PREFIX)/bin" 2>/dev/null diff --git a/src/cutils b/src/cutils index 70e6676..780c8d0 160000 --- a/src/cutils +++ b/src/cutils @@ -1 +1 @@ -Subproject commit 70e6676e68300c59384ffb1127fd1330e1d644e7 +Subproject commit 780c8d0590a2f34e68ff896058b3b1a89539dcd8 diff --git a/src/tests-cbook/makefile.d b/src/tests-cbook/makefile.d index 82682db..2d5a0d7 100644 --- a/src/tests-cbook/makefile.d +++ b/src/tests-cbook/makefile.d @@ -3,7 +3,10 @@ NAME = tests-cbook NAMES = $(NAME) srcdir = $(NAME) -dstdir = ../bin + +ifeq ($(dstdir),) +dstdir = $(srcdir)/bin +endif CFLAGS += -Wall -pedantic -I./ -std=c99 CXXFLAGS += -Wall -pedantic -I./ @@ -29,13 +32,24 @@ build: $(NAMES) $(NAME): deps $(dstdir)/$(NAME) +# Test program, so running = running tests +run: run-test +test: build +run-test: test + @echo + $(dstdir)/$(NAME) +run-test-more: test + @echo + $(dstdir)/$(NAME) --more + ################ # Dependencies # ################ ## Libs (if needed) deps: - $(MAKE) --no-print-directory -C cutils/ check -DEPS=$(dstdir)/libcutils-check.o + $(MAKE) dstdir=$(dstdir) --no-print-directory -C cutils/ cutils + $(MAKE) dstdir=$(dstdir) --no-print-directory -C cutils/ check +DEPS=$(dstdir)/libcutils.o $(dstdir)/libcutils-check.o ## Headers DEPENDS=$(SOURCES:%.c=%.d) @@ -48,22 +62,16 @@ $(dstdir)/$(NAME): $(DEPS) $(OBJECTS) mkdir -p $(dstdir) $(CC) $(CFLAGS) $(LDFLAGS) $(DEPS) $(OBJECTS) -o $@ -# Test program, so running = running tests -run: run-test -test: build - -run-test: test - @echo - $(dstdir)/$(NAME) -run-test-more: test - @echo - $(dstdir)/$(NAME) --more - clean: - rm -f $(OBJECTS) $(DEPENDS) + rm -f $(OBJECTS) + rm -f $(DEPENDS) + rm -f $(DEPS) mrproper: mrpropre mrpropre: clean rm -f $(dstdir)/$(NAME) rmdir $(dstdir) 2>/dev/null || true +install uninstall: + @echo Those are tests, nothing to install/uninstall +