diff options
Diffstat (limited to 'Makefile')
-rw-r--r-- | Makefile | 46 |
1 files changed, 34 insertions, 12 deletions
@@ -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' >$@ |