From: Niki Roo Date: Sun, 30 Jun 2024 10:13:27 +0000 (+0200) Subject: makefile X-Git-Url: https://git.nikiroo.be/?a=commitdiff_plain;h=886f61523f0ec0d510957def220fd499bd1d61bd;p=cbook.git makefile --- diff --git a/Makefile b/Makefile index eaf5f24..51e897c 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ NAME = cbook NAMES = $(NAME) cutils -TEST = -TESTS = +TEST = tests-cbook +TESTS = $(TEST) PREFIX = /usr/local diff --git a/src/cbook/makefile.d b/src/cbook/makefile.d index 4747a79..54085c1 100644 --- a/src/cbook/makefile.d +++ b/src/cbook/makefile.d @@ -16,10 +16,9 @@ CXXFLAGS += -ggdb -O0 endif .PHONY: all build install uninstall clean mrpropre mrpropre \ - $(NAMES) + $(NAMES) deps run SOURCES=$(wildcard $(srcdir)/*.c) -HEADERS=$(wildcard $(srcdir)/*.h) OBJECTS=$(SOURCES:%.c=%.o) # Main targets @@ -28,25 +27,36 @@ all: build build: $(NAMES) -cbook: $(dstdir)/cbook +$(NAME): deps $(dstdir)/$(NAME) ################ # 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)/cbook: $(OBJECTS) +$(dstdir)/$(NAME): $(DEPS) $(OBJECTS) mkdir -p $(dstdir) - $(CC) $(CFLAGS) $(LDFLAGS) $(OBJECTS) -o $@ + $(CC) $(CFLAGS) $(LDFLAGS) $(DEPS) $(OBJECTS) -o $@ + +run: + @echo + $(dstdir)/$(NAME) clean: - rm -f $(srcdir)/*.o + rm -f $(OBJECTS) $(DEPENDS) mrproper: mrpropre mrpropre: clean - rm -f $(dstdir)/cbook + rm -f $(dstdir)/$(NAME) rmdir $(dstdir) 2>/dev/null || true diff --git a/src/cutils b/src/cutils index 7f42ed2..70e6676 160000 --- a/src/cutils +++ b/src/cutils @@ -1 +1 @@ -Subproject commit 7f42ed22b8dab3f7bd1d9e675e2217797cdc29cc +Subproject commit 70e6676e68300c59384ffb1127fd1330e1d644e7 diff --git a/src/tests/Makefile b/src/tests-cbook/Makefile similarity index 100% rename from src/tests/Makefile rename to src/tests-cbook/Makefile diff --git a/src/tests-cbook/main.c b/src/tests-cbook/main.c new file mode 100644 index 0000000..3527333 --- /dev/null +++ b/src/tests-cbook/main.c @@ -0,0 +1,21 @@ +#include +#include "cutils/check/launcher.h" + +// The tests we intend to run: + +// SRunner *test_XXX(SRunner *runner, int more); +// ... + +SRunner *get_tests(int more) { + SRunner *runner = NULL; + + // runner = test_XXX(runner, more); + // ... + + return runner; +} + +int main(int argc, char **argv) { + return launch_tests(argc, argv); +} + diff --git a/src/tests-cbook/makefile.d b/src/tests-cbook/makefile.d new file mode 100644 index 0000000..82682db --- /dev/null +++ b/src/tests-cbook/makefile.d @@ -0,0 +1,69 @@ +# Note: 99+ required for for-loop initial declaration (CentOS 6) + +NAME = tests-cbook +NAMES = $(NAME) +srcdir = $(NAME) +dstdir = ../bin + +CFLAGS += -Wall -pedantic -I./ -std=c99 +CXXFLAGS += -Wall -pedantic -I./ +LDFLAGS += -lcheck +PREFIX = /usr/local + +ifdef DEBUG +CFLAGS += -ggdb -O0 +CXXFLAGS += -ggdb -O0 +endif + +.PHONY: all build install uninstall clean mrpropre mrpropre \ + $(NAME) deps test run run-test run-test-more + +SOURCES=$(wildcard $(srcdir)/*.c) +OBJECTS=$(SOURCES:%.c=%.o) + +# Main target + +all: build + +build: $(NAMES) + +$(NAME): deps $(dstdir)/$(NAME) + +################ +# Dependencies # +################ +## Libs (if needed) +deps: + $(MAKE) --no-print-directory -C cutils/ check +DEPS=$(dstdir)/libcutils-check.o + +## Headers +DEPENDS=$(SOURCES:%.c=%.d) +-include $(DEPENDS) +%.o: %.c + $(CC) $(CFLAGS) -MMD -MP -c $< -o $@ +################ + +$(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) + +mrproper: mrpropre +mrpropre: clean + rm -f $(dstdir)/$(NAME) + rmdir $(dstdir) 2>/dev/null || true + diff --git a/src/tests/makefile.d b/src/tests/makefile.d deleted file mode 100644 index f4c61f3..0000000 --- a/src/tests/makefile.d +++ /dev/null @@ -1,44 +0,0 @@ -# Note: 99+ required for for-loop initial declaration (CentOS 6) - -srcdir = tests -dstdir = ../bin - -CFLAGS += -Wall -pedantic -I./ -std=c99 -CXXFLAGS += -Wall -pedantic -I./ -LDFLAGS += -lcheck $(dstdir)/libcutils.o - -ifdef DEBUG -CFLAGS += -ggdb -O0 -CXXFLAGS += -ggdb -O0 -endif - -.PHONY: all install uninstall clean mrpropre mrpropre \ - test run run-test run-test-more - -all: test - -test: $(dstdir)/tests - -run: run-test -run-test: test - $(dstdir)/tests - -run-test-more: test - $(dstdir)/tests --more - -SOURCES=$(wildcard $(srcdir)/*.c) -HEADERS=$(wildcard $(srcdir)/*.h) -OBJECTS=$(SOURCES:%.c=%.o) - -$(dstdir)/tests: $(OBJECTS) $(dstdir)/libcutils-check.o - mkdir -p $(dstdir) - $(CC) $(CFLAGS) $(LDFLAGS) $(OBJECTS) $(dstdir)/libcutils-check.o -o $@ - -clean: - rm -f $(srcdir)/*.o - -mrproper: mrpropre -mrpropre: clean - rm -f $(dstdir)/tests - rmdir $(dstdir) 2>/dev/null || true - diff --git a/src/tests/tests.c b/src/tests/tests.c deleted file mode 100755 index 15c2b61..0000000 --- a/src/tests/tests.c +++ /dev/null @@ -1,21 +0,0 @@ -#include -#include - -#include "cutils/cutils.h" -#include "cutils/check/launcher.h" - -SRunner *runner = NULL; -void add_test(Suite *test); - -SRunner *get_tests(int more) { - return runner; -} - -void add_test(Suite *test) { - if (!runner) { - runner = srunner_create(test); - } else { - srunner_add_suite(runner, test); - } -} -