From 8eececcac8ee2f2b076b240f32c926af9c07cfd3 Mon Sep 17 00:00:00 2001 From: Dan Hirsch <thequux@thequux.com> Date: Wed, 10 Oct 2012 16:45:10 +0200 Subject: [PATCH] Now builds without glib --- Makefile | 7 +++++++ common.mk | 26 +++++++++++++++++++------- config.mk | 1 + examples/Makefile | 3 +++ src/Makefile | 12 ++++++++---- 5 files changed, 38 insertions(+), 11 deletions(-) create mode 100644 config.mk diff --git a/Makefile b/Makefile index 08ce4e1e..bd383a22 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 4f70745e..972466ef 100644 --- a/common.mk +++ b/common.mk @@ -1,16 +1,28 @@ -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) +# 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 += -DINCLUDE_TESTS $(EXTRA_CFLAGS) +CFLAGS += $(EXTRA_CFLAGS) HUSH = $(TOPLEVEL)/lib/hush -# Check to make sure variables are properly set -ifeq ($(TOPLEVEL),) -$(error $$TOPLEVEL is unset) -endif ifsilent = $(if $(findstring 0, $(V)),$(1),) hush = $(call ifsilent,$(HUSH) $(1)) diff --git a/config.mk b/config.mk new file mode 100644 index 00000000..54248f98 --- /dev/null +++ b/config.mk @@ -0,0 +1 @@ +INCLUDE_TESTS = 1 diff --git a/examples/Makefile b/examples/Makefile index d2c76cf4..6a054cad 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 e4d70d12..de340e7b 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 -- GitLab