From 9aea3f0ddad87cc97f246161075d249177aeae46 Mon Sep 17 00:00:00 2001 From: "Dmitrij D. Czarkoff" Date: Tue, 22 Nov 2016 15:48:04 +0100 Subject: Separate preprocessor flags from compiler flags, libs from linker flags PR #98 hints that we were venturing into downstream's territory: compiler and linker flags may be OS-specific, while preprocessor flags and libraries are our responsibility. Provide clean separation between these categories. Downstreams may still need to provide "--std=c99" in CFLAGS though. --- Makefile | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index 642eaa9..3feb11c 100644 --- a/Makefile +++ b/Makefile @@ -10,8 +10,9 @@ MUTE := @ endif CFLAGS ?= -W -Wall -pedantic -Wmissing-prototypes -CFLAGS += -std=c99 $(shell sdl2-config --cflags) -D_XOPEN_SOURCE=700 -LDFLAGS += $(shell sdl2-config --libs) -lfreeimage -lSDL2_ttf -lfontconfig -lpthread +CFLAGS += -std=c99 +CPPFLAGS += $(shell sdl2-config --cflags) -D_XOPEN_SOURCE=700 +LIBS := $(shell sdl2-config --libs) -lfreeimage -lSDL2_ttf -lfontconfig -lpthread BUILDDIR ?= build TARGET := $(BUILDDIR)/imv @@ -19,7 +20,8 @@ TARGET := $(BUILDDIR)/imv SOURCES := $(wildcard src/*.c) OBJECTS := $(patsubst src/%.c,$(BUILDDIR)/%.o,$(SOURCES)) TESTS := $(patsubst test/%.c,$(BUILDDIR)/test_%,$(wildcard test/*.c)) -TFLAGS ?= -g ${CFLAGS} +TFLAGS ?= -g $(CFLAGS) $(CPPFLAGS) $(shell pkg-config --cflags cmocka) +TLIBS := $(LIBS) $(shell pkg-config --libs cmocka) VERSION := $(shell git describe --abbrev=8 --dirty --always --tags 2> /dev/null) ifeq ($(VERSION),) @@ -32,7 +34,7 @@ imv: $(TARGET) $(TARGET): $(OBJECTS) @echo "LINKING $@" - $(MUTE)$(CC) -o $@ $^ $(LDLIBS) $(LDFLAGS) + $(MUTE)$(CC) -o $@ $^ $(LIBS) $(LDFLAGS) debug: CFLAGS += -DDEBUG -g -pg debug: $(TARGET) @@ -44,11 +46,11 @@ $(BUILDDIR): $(BUILDDIR)/%.o: src/%.c @echo "COMPILING $@" - $(MUTE)$(CC) -c $(CFLAGS) -o $@ $< + $(MUTE)$(CC) -c $(CFLAGS) $(CPPFLAGS) -o $@ $< $(BUILDDIR)/test_%: test/%.c src/%.c @echo "BUILDING $@" - $(MUTE)$(CC) -o $@ -Isrc $(TFLAGS) $^ $(LDFLAGS) -lcmocka + $(MUTE)$(CC) -o $@ -Isrc $(TFLAGS) $^ $(LDFLAGS) $(TLIBS) check: $(BUILDDIR) $(TESTS) @echo "RUNNING TESTS" -- cgit v1.2.3