diff options
-rw-r--r-- | Makefile | 30 |
1 files changed, 18 insertions, 12 deletions
@@ -1,4 +1,4 @@ -.PHONY: clean check install uninstall +.PHONY: imv obj clean check install uninstall PREFIX ?= /usr BINPREFIX ?= $(PREFIX)/bin @@ -13,39 +13,45 @@ CFLAGS ?= -W -Wall -Wpedantic CFLAGS += -std=gnu11 $(shell sdl2-config --cflags) LDFLAGS += $(shell sdl2-config --libs) -lfreeimage -lSDL2_ttf -lfontconfig -lpthread -TARGET = imv -BUILDDIR = build +TARGET = $(BUILDDIR)/imv +BUILDDIR ?= build SOURCES = $(wildcard src/*.c) OBJECTS = $(patsubst src/%.c,$(BUILDDIR)/%.o,$(SOURCES)) -TESTS = $(patsubst test/%.c,test_%,$(wildcard test/*.c)) +TESTS = $(patsubst test/%.c,$(BUILDDIR)/test_%,$(wildcard test/*.c)) VERSION = "v1.2.0" CFLAGS += -DIMV_VERSION=\"$(VERSION)\" -$(TARGET): $(OBJECTS) +imv: $(TARGET) + +$(TARGET): obj @echo "LINKING $@" - $(MUTE)$(CC) -o $@ $^ $(LDLIBS) $(LDFLAGS) + $(MUTE)$(CC) -o $@ $(OBJECTS) $(LDLIBS) $(LDFLAGS) debug: CFLAGS += -DDEBUG -g -pg debug: $(TARGET) -$(BUILDDIR)/%.o: src/%.c +obj: $(BUILDDIR) $(OBJECTS) + +$(BUILDDIR): $(MUTE)mkdir -p $(BUILDDIR) + +$(BUILDDIR)/%.o: src/%.c @echo "COMPILING $@" $(MUTE)$(CC) -c $(CFLAGS) -o $@ $< -test_%: test/%.c src/%.c +$(BUILDDIR)/test_%: test/%.c src/%.c @echo "BUILDING $@" - $(MUTE)$(CC) -o $@ -Isrc -W -Wall -std=gnu11 -lcmocka $^ + $(MUTE)$(CC) -o $@ -Isrc -W -Wall $(CFLAGS) $(LDFLAGS) -std=gnu11 -lcmocka $^ -check: $(TESTS) +check: $(BUILDDIR) $(TESTS) @echo "RUNNING TESTS" - $(MUTE)for t in "$(TESTS)"; do ./$$t; done + $(MUTE)for t in "$(TESTS)"; do $$t; done clean: - $(MUTE)$(RM) $(TARGET) $(OBJECTS) $(TESTS) + $(MUTE)$(RM) -Rf $(BUILDDIR) install: $(TARGET) install -D -m 0755 $(TARGET) $(DESTDIR)$(BINPREFIX)/imv |