diff --git a/Makefile b/Makefile index 08ce4e1..bd383a2 100644 --- a/Makefile +++ b/Makefile @@ -5,6 +5,10 @@ SUBDIRS = src examples +include config.mk + +CONFIG_VARS= INCLUDE_TESTS + .DEFAULT_GOAL := all %: @@ -25,3 +29,6 @@ $(foreach dir,$(SUBDIRS),$(eval $(call SUBDIR_TEMPLATE,$(dir)))) TAGS: $(shell find * -name "*.c") etags $^ + +config: + @printf "%30s %s\n" $(foreach var,$(CONFIG_VARS),$(var) $($(var)) ) diff --git a/common.mk b/common.mk index 4f70745..972466e 100644 --- a/common.mk +++ b/common.mk @@ -1,17 +1,29 @@ -CFLAGS := $(shell pkg-config --cflags glib-2.0) -std=gnu99 -Wall -Wextra -Werror -Wno-unused-parameter -Wno-attributes -LDFLAGS := $(shell pkg-config --libs glib-2.0) -CC ?= gcc -$(info CC=$(CC)) -# Set V=1 for verbose mode... -V ?= 0 -CFLAGS += -DINCLUDE_TESTS $(EXTRA_CFLAGS) -HUSH = $(TOPLEVEL)/lib/hush - # Check to make sure variables are properly set ifeq ($(TOPLEVEL),) $(error $$TOPLEVEL is unset) endif +include $(TOPLEVEL)/config.mk + +TEST_CFLAGS := $(shell pkg-config --cflags glib-2.0) -DINCLUDE_TESTS +TEST_LDFLAGS := $(shell pkg-config --libs glib-2.0) + +CFLAGS := -std=gnu99 -Wall -Wextra -Werror -Wno-unused-parameter -Wno-attributes +LDFLAGS := + +ifneq ($(INCLUDE_TESTS),0) +CFLAGS += $(TEST_CFLAGS) +LDFLAGS += $(TEST_LDFLAGS) +endif + +CC ?= gcc +$(info CC=$(CC)) +# Set V=1 for verbose mode... +V ?= 0 +CFLAGS += $(EXTRA_CFLAGS) +HUSH = $(TOPLEVEL)/lib/hush + + ifsilent = $(if $(findstring 0, $(V)),$(1),) hush = $(call ifsilent,$(HUSH) $(1)) #.SUFFIXES: diff --git a/config.mk b/config.mk new file mode 100644 index 0000000..54248f9 --- /dev/null +++ b/config.mk @@ -0,0 +1 @@ +INCLUDE_TESTS = 1 diff --git a/examples/Makefile b/examples/Makefile index d2c76cf..6a054ca 100644 --- a/examples/Makefile +++ b/examples/Makefile @@ -7,6 +7,9 @@ OUTPUTS := dns.o \ TOPLEVEL := ../ include ../common.mk +CFLAGS += $(pkg-config --cflags glib-2.0) +LDFLAGS += $(pkg-config --libs glib-2.0) + all: dns base64 diff --git a/src/Makefile b/src/Makefile index e4d70d1..de340e7 100644 --- a/src/Makefile +++ b/src/Makefile @@ -42,10 +42,7 @@ TOPLEVEL := ../ include ../common.mk -all: libhammer.a test_suite - -test_suite: test_suite.o libhammer.a - $(call hush, "Linking $@") $(CC) -o $@ $^ $(LDFLAGS) +all: libhammer.a libhammer.a: bitreader.o hammer.o pprint.o allocator.o datastructures.o bitwriter.o system_allocator.o \ $(PARSERS:%=parsers/%.o) @@ -53,5 +50,12 @@ libhammer.a: bitreader.o hammer.o pprint.o allocator.o datastructures.o bitwrite bitreader.o: test_suite.h hammer.o: hammer.h +ifneq ($(INCLUDE_TESTS),0) +all: test_suite + test: test_suite ./test_suite -v + +test_suite: test_suite.o libhammer.a + $(call hush, "Linking $@") $(CC) -o $@ $^ $(LDFLAGS) +endif