aboutsummaryrefslogtreecommitdiff
path: root/Makefile
diff options
context:
space:
mode:
authorDmitrij D. Czarkoff <czarkoff@gmail.com>2015-12-26 12:27:03 +0100
committerDmitrij D. Czarkoff <czarkoff@gmail.com>2015-12-26 14:09:41 +0100
commit5f3ebdd39e7cb7cc71b1816c2885bd4c60bc9978 (patch)
tree59541790b3970418215918182608f82504fadc09 /Makefile
parent4263e95ae080dee60844c861f674473f64e73f7e (diff)
downloadimv-5f3ebdd39e7cb7cc71b1816c2885bd4c60bc9978.tar.gz
Generate all files in build directory
* Allow building off read-only source tree. * Allow setting build directory from environment. These changes allow parallel building of imv for multiple architectures, which is used by package management systems of some operating systems.
Diffstat (limited to 'Makefile')
-rw-r--r--Makefile30
1 files changed, 18 insertions, 12 deletions
diff --git a/Makefile b/Makefile
index 244c384..f80e64c 100644
--- a/Makefile
+++ b/Makefile
@@ -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