aboutsummaryrefslogtreecommitdiff
path: root/Makefile
diff options
context:
space:
mode:
authorTom Smeding <tom.smeding@gmail.com>2020-08-07 22:47:46 +0200
committerTom Smeding <tom.smeding@gmail.com>2020-08-07 22:47:46 +0200
commit8f17684810718973c8ea0f1150e46d6c1b8c0ef1 (patch)
treed03b30c0a14e75e6c3374af3744cf7d7b1789f39 /Makefile
parenta260f02eac411171a827c9e0aeb31b8de397a5b5 (diff)
server: Add basic unit test framework
Diffstat (limited to 'Makefile')
-rw-r--r--Makefile46
1 files changed, 34 insertions, 12 deletions
diff --git a/Makefile b/Makefile
index 41621f9..fe01fb6 100644
--- a/Makefile
+++ b/Makefile
@@ -1,16 +1,24 @@
-CC = gcc
-CFLAGS = -Wall -Wextra -std=c11 -g -O2 -fwrapv -D_DEFAULT_SOURCE
-LDFLAGS = -ldl
+CC := gcc
+CFLAGS := -Wall -Wextra -std=c11 -g -O2 -fwrapv -D_DEFAULT_SOURCE
+LDFLAGS := -ldl
CFLAGS += $(shell pkg-config --cflags sqlite3 libsodium)
LDFLAGS += $(shell pkg-config --libs sqlite3 libsodium)
-TARGETS = tomsg_server
+TARGETS := tomsg_server
+TEST_TARGET := test/main
-PLUGINDIR = plugins
+PLUGINDIR := plugins
-PLUGINS = $(filter-out _%,$(patsubst $(PLUGINDIR)/%,%,$(shell find $(PLUGINDIR)/ -maxdepth 1 -type d)))
+PLUGINS := $(filter-out _%,$(patsubst $(PLUGINDIR)/%,%,$(shell find $(PLUGINDIR)/ -maxdepth 1 -type d)))
-.PHONY: all clean
+SOURCES := $(wildcard *.c)
+OBJECTS := $(SOURCES:.c=.o)
+TEST_ONLY_SOURCES := $(wildcard test/*.c)
+TEST_ONLY_OBJECTS := $(TEST_ONLY_SOURCES:.c=.o)
+TEST_SOURCES := $(TEST_ONLY_SOURCES) $(filter-out main.c,$(SOURCES))
+TEST_OBJECTS := $(TEST_SOURCES:.c=.o)
+
+.PHONY: all clean test_build test
# Clear all implicit suffix rules
.SUFFIXES:
@@ -19,18 +27,32 @@ PLUGINS = $(filter-out _%,$(patsubst $(PLUGINDIR)/%,%,$(shell find $(PLUGINDIR)/
.SECONDARY:
all: $(TARGETS)
- for pl in $(PLUGINS); do make --no-print-directory -C $(PLUGINDIR) $@ PLUGINNAME=$$pl; done
+ for pl in $(PLUGINS); do $(MAKE) --no-print-directory -C $(PLUGINDIR) $@ PLUGINNAME=$$pl; done
clean:
- rm -f $(TARGETS) *.o *.sql.h
- for pl in $(PLUGINS); do make --no-print-directory -C $(PLUGINDIR) $@ PLUGINNAME=$$pl; done
+ rm -f $(TARGETS) $(TEST_TARGET) *.o *.sql.h test/test_declarations.h
+ for pl in $(PLUGINS); do $(MAKE) --no-print-directory -C $(PLUGINDIR) $@ PLUGINNAME=$$pl; done
+
+test_build: $(TEST_TARGET)
+
+test: test_build
+ $(TEST_TARGET)
-$(TARGETS): $(patsubst %.c,%.o,$(wildcard *.c))
+$(TARGETS): $(OBJECTS)
$(CC) -o $@ $^ $(LDFLAGS)
-%.o: %.c $(wildcard *.h) $(patsubst %.sql,%.sql.h,$(wildcard *.sql))
+$(OBJECTS) $(TEST_ONLY_OBJECTS): $(wildcard *.h) $(patsubst %.sql,%.sql.h,$(wildcard *.sql))
+$(TEST_ONLY_OBJECTS): test/test_declarations.h
+%.o: %.c
$(CC) $(CFLAGS) -c -o $@ $<
%.sql.h: %.sql
xxd -i $^ $@
+
+
+$(TEST_TARGET): $(TEST_OBJECTS) $(wildcard *.h test/*.h)
+ $(CC) -o $@ $(filter %.o,$^) $(LDFLAGS)
+
+test/test_declarations.h: $(wildcard test/*.c)
+ $(CC) -E -D TEST_HEADER_GENERATION=1 test/*.c | sed -n 's/^XXTEST_DECLARATION(\([^)]*\)).*/int \1(void);/p' >$@