makefile
authorNiki Roo <niki@nikiroo.be>
Sun, 30 Jun 2024 10:13:27 +0000 (12:13 +0200)
committerNiki Roo <niki@nikiroo.be>
Sun, 30 Jun 2024 10:13:27 +0000 (12:13 +0200)
Makefile
src/cbook/makefile.d
src/cutils
src/tests-cbook/Makefile [moved from src/tests/Makefile with 100% similarity]
src/tests-cbook/main.c [new file with mode: 0644]
src/tests-cbook/makefile.d [new file with mode: 0644]
src/tests/makefile.d [deleted file]
src/tests/tests.c [deleted file]

index eaf5f24b16bb5759a753427ba039a6d9af453f80..51e897c0d687549a447616204f2bd3fd93ee9b50 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,7 @@
 NAME   = cbook
 NAMES  = $(NAME) cutils
-TEST   =
-TESTS  =
+TEST   = tests-cbook
+TESTS  = $(TEST)
 
 PREFIX = /usr/local
 
index 4747a79e629de1bef3df3f643461e1b761c8d564..54085c1f74461ee8ef3cf68c334c735d9e1d7c2b 100644 (file)
@@ -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
 
index 7f42ed22b8dab3f7bd1d9e675e2217797cdc29cc..70e6676e68300c59384ffb1127fd1330e1d644e7 160000 (submodule)
@@ -1 +1 @@
-Subproject commit 7f42ed22b8dab3f7bd1d9e675e2217797cdc29cc
+Subproject commit 70e6676e68300c59384ffb1127fd1330e1d644e7
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 (file)
index 0000000..3527333
--- /dev/null
@@ -0,0 +1,21 @@
+#include <check.h>
+#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 (file)
index 0000000..82682db
--- /dev/null
@@ -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 (file)
index f4c61f3..0000000
+++ /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 (executable)
index 15c2b61..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-#include <check.h>
-#include <stdio.h>
-
-#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);
-       }
-}
-