From ab0c27611be891841f5d7f250ae95c3a9895c145 Mon Sep 17 00:00:00 2001 From: "Dmitrij D. Czarkoff" Date: Fri, 25 Dec 2015 15:07:03 +0100 Subject: Use "PREFIX" instead of "prefix" Most package management systems already expect "PREFIX" macro to control installation path. --- Makefile | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 861a237..f07141f 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ .PHONY: clean check install uninstall -prefix = /usr +PREFIX ?= /usr CFLAGS = -W -Wall -Wpedantic -std=gnu11 `sdl2-config --cflags` LDFLAGS = `sdl2-config --libs` -lfreeimage -lSDL2_ttf -lfontconfig -lpthread @@ -40,11 +40,11 @@ clean: @$(RM) $(TARGET) $(OBJECTS) $(TESTS) install: $(TARGET) - install -D -m 0755 $(TARGET) $(DESTDIR)$(prefix)/bin/imv - install -D -m 0644 doc/imv.1 $(DESTDIR)$(prefix)/share/man/man1/imv.1 - install -D -m 0644 files/imv.desktop $(DESTDIR)$(prefix)/share/applications/imv.desktop + install -D -m 0755 $(TARGET) $(DESTDIR)$(PREFIX)/bin/imv + install -D -m 0644 doc/imv.1 $(DESTDIR)$(PREFIX)/share/man/man1/imv.1 + install -D -m 0644 files/imv.desktop $(DESTDIR)$(PREFIX)/share/applications/imv.desktop uninstall: - $(RM) $(DESTDIR)$(prefix)/bin/imv - $(RM) $(DESTDIR)$(prefix)/share/man/man1/imv.1 - $(RM) $(DESTDIR)$(prefix)/share/applications/imv.desktop + $(RM) $(DESTDIR)$(PREFIX)/bin/imv + $(RM) $(DESTDIR)$(PREFIX)/share/man/man1/imv.1 + $(RM) $(DESTDIR)$(PREFIX)/share/applications/imv.desktop -- cgit v1.2.3 From 57d83b7b376a71726c148d9b82a43285c70fe0b8 Mon Sep 17 00:00:00 2001 From: "Dmitrij D. Czarkoff" Date: Fri, 25 Dec 2015 15:11:32 +0100 Subject: Respect default CFLAGS and LDFLAGS if set in environment Some package management systems allow users to set default CFLAGS and LDFLAGS and then supply them to the make via environment. This change makes build infrastructure respect such settings. Also, don't force non-essential flags. --- Makefile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index f07141f..a0614fe 100644 --- a/Makefile +++ b/Makefile @@ -2,8 +2,9 @@ PREFIX ?= /usr -CFLAGS = -W -Wall -Wpedantic -std=gnu11 `sdl2-config --cflags` -LDFLAGS = `sdl2-config --libs` -lfreeimage -lSDL2_ttf -lfontconfig -lpthread +CFLAGS ?= -W -Wall -Wpedantic +CFLAGS += -std=gnu11 `sdl2-config --cflags` +LDFLAGS += `sdl2-config --libs` -lfreeimage -lSDL2_ttf -lfontconfig -lpthread TARGET = imv BUILDDIR = build -- cgit v1.2.3 From 6de6b358e81251bcf9c978b04452d2390d46a388 Mon Sep 17 00:00:00 2001 From: "Dmitrij D. Czarkoff" Date: Fri, 25 Dec 2015 15:27:00 +0100 Subject: Use "shell" macro in CFLAGS When CFLAGS contain "`cmd`" construct, the "cmd" command is executed every time when make issues shell command with expanded CFLAGS. Using "$(shell cmd)" instead forces make to expand output of "cmd" into CFLAGS. --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index a0614fe..f002847 100644 --- a/Makefile +++ b/Makefile @@ -3,8 +3,8 @@ PREFIX ?= /usr CFLAGS ?= -W -Wall -Wpedantic -CFLAGS += -std=gnu11 `sdl2-config --cflags` -LDFLAGS += `sdl2-config --libs` -lfreeimage -lSDL2_ttf -lfontconfig -lpthread +CFLAGS += -std=gnu11 $(shell sdl2-config --cflags) +LDFLAGS += $(shell sdl2-config --libs) -lfreeimage -lSDL2_ttf -lfontconfig -lpthread TARGET = imv BUILDDIR = build -- cgit v1.2.3 From 77827c838e36e39471f2f23338f76e5ace2404c4 Mon Sep 17 00:00:00 2001 From: "Dmitrij D. Czarkoff" Date: Fri, 25 Dec 2015 15:29:12 +0100 Subject: Make installation locations more configurable This might be desired when platform has its own, custom layout (eg. OpenBSD or Solaris), or when user wants to install the program to his home directory. --- Makefile | 9 ++++++--- README.md | 6 ++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index f002847..fb3d07e 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,9 @@ .PHONY: clean check install uninstall PREFIX ?= /usr +BINPREFIX ?= $(PREFIX)/bin +MANPREFIX ?= $(PREFIX)/share/man +DATAPREFIX ?= $(PREFIX)/share CFLAGS ?= -W -Wall -Wpedantic CFLAGS += -std=gnu11 $(shell sdl2-config --cflags) @@ -41,9 +44,9 @@ clean: @$(RM) $(TARGET) $(OBJECTS) $(TESTS) install: $(TARGET) - install -D -m 0755 $(TARGET) $(DESTDIR)$(PREFIX)/bin/imv - install -D -m 0644 doc/imv.1 $(DESTDIR)$(PREFIX)/share/man/man1/imv.1 - install -D -m 0644 files/imv.desktop $(DESTDIR)$(PREFIX)/share/applications/imv.desktop + install -D -m 0755 $(TARGET) $(DESTDIR)$(BINPREFIX)/imv + install -D -m 0644 doc/imv.1 $(DESTDIR)$(MANPREFIX)/man1/imv.1 + install -D -m 0644 files/imv.desktop $(DESTDIR)$(DATAPREFIX)/applications/imv.desktop uninstall: $(RM) $(DESTDIR)$(PREFIX)/bin/imv diff --git a/README.md b/README.md index 2a08f31..5c9c87b 100644 --- a/README.md +++ b/README.md @@ -64,6 +64,12 @@ Installation $ make # make install +Macro `PREFIX` controls installation prefix. If more control over installation +paths is required, macros `BINPREFIX`, `MANPREFIX` and `DATAPREFIX` are +available. Eg. to install `imv` to home directory, run: + + $ BINPREFIX=~/bin PREFIX=~/.local make install + Tests ----- -- cgit v1.2.3 From c42ab088191d5dd8a2d856dc96cb5b3f90687fc4 Mon Sep 17 00:00:00 2001 From: "Dmitrij D. Czarkoff" Date: Fri, 25 Dec 2015 17:52:01 +0100 Subject: Add verbose mode If V variable is set to any value, commands will be echoed to standard output. --- Makefile | 14 ++++++++------ README.md | 5 +++++ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index fb3d07e..6ffa5c5 100644 --- a/Makefile +++ b/Makefile @@ -5,6 +5,8 @@ BINPREFIX ?= $(PREFIX)/bin MANPREFIX ?= $(PREFIX)/share/man DATAPREFIX ?= $(PREFIX)/share +V ?= + CFLAGS ?= -W -Wall -Wpedantic CFLAGS += -std=gnu11 $(shell sdl2-config --cflags) LDFLAGS += $(shell sdl2-config --libs) -lfreeimage -lSDL2_ttf -lfontconfig -lpthread @@ -22,26 +24,26 @@ CFLAGS += -DIMV_VERSION=\"$(VERSION)\" $(TARGET): $(OBJECTS) @echo "LINKING $@" - @$(CC) -o $@ $^ $(LDLIBS) $(LDFLAGS) + $(V:%=@)$(CC) -o $@ $^ $(LDLIBS) $(LDFLAGS) debug: CFLAGS += -DDEBUG -g -pg debug: $(TARGET) $(BUILDDIR)/%.o: src/%.c - @mkdir -p $(BUILDDIR) + $(V:%=@)mkdir -p $(BUILDDIR) @echo "COMPILING $@" - @$(CC) -c $(CFLAGS) -o $@ $< + $(V:%=@)$(CC) -c $(CFLAGS) -o $@ $< test_%: test/%.c src/%.c @echo "BUILDING $@" - @$(CC) -o $@ -Isrc -W -Wall -std=gnu11 -lcmocka $^ + $(V:%=@)$(CC) -o $@ -Isrc -W -Wall -std=gnu11 -lcmocka $^ check: $(TESTS) @echo "RUNNING TESTS" - @for t in "$(TESTS)"; do ./$$t; done + $(V:%=@)for t in "$(TESTS)"; do ./$$t; done clean: - @$(RM) $(TARGET) $(OBJECTS) $(TESTS) + $(V:%=@)$(RM) $(TARGET) $(OBJECTS) $(TESTS) install: $(TARGET) install -D -m 0755 $(TARGET) $(DESTDIR)$(BINPREFIX)/imv diff --git a/README.md b/README.md index 5c9c87b..7ed1ff3 100644 --- a/README.md +++ b/README.md @@ -70,6 +70,11 @@ available. Eg. to install `imv` to home directory, run: $ BINPREFIX=~/bin PREFIX=~/.local make install +In case something goes wrong during installation process you may use verbose +mode to inspect commands issued by make: + + $ V=1 make + Tests ----- -- cgit v1.2.3 From 447e86d35d4a0a4aed50056a08c4361c7f903dd8 Mon Sep 17 00:00:00 2001 From: "Dmitrij D. Czarkoff" Date: Fri, 25 Dec 2015 23:27:11 +0100 Subject: Fix verbose build --- Makefile | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 6ffa5c5..ca917af 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,9 @@ BINPREFIX ?= $(PREFIX)/bin MANPREFIX ?= $(PREFIX)/share/man DATAPREFIX ?= $(PREFIX)/share -V ?= +ifeq ($(V),) +MUTE := @ +endif CFLAGS ?= -W -Wall -Wpedantic CFLAGS += -std=gnu11 $(shell sdl2-config --cflags) @@ -24,26 +26,26 @@ CFLAGS += -DIMV_VERSION=\"$(VERSION)\" $(TARGET): $(OBJECTS) @echo "LINKING $@" - $(V:%=@)$(CC) -o $@ $^ $(LDLIBS) $(LDFLAGS) + $(MUTE)$(CC) -o $@ $^ $(LDLIBS) $(LDFLAGS) debug: CFLAGS += -DDEBUG -g -pg debug: $(TARGET) $(BUILDDIR)/%.o: src/%.c - $(V:%=@)mkdir -p $(BUILDDIR) + $(MUTE)mkdir -p $(BUILDDIR) @echo "COMPILING $@" - $(V:%=@)$(CC) -c $(CFLAGS) -o $@ $< + $(MUTE)$(CC) -c $(CFLAGS) -o $@ $< test_%: test/%.c src/%.c @echo "BUILDING $@" - $(V:%=@)$(CC) -o $@ -Isrc -W -Wall -std=gnu11 -lcmocka $^ + $(MUTE)$(CC) -o $@ -Isrc -W -Wall -std=gnu11 -lcmocka $^ check: $(TESTS) @echo "RUNNING TESTS" - $(V:%=@)for t in "$(TESTS)"; do ./$$t; done + $(MUTE)for t in "$(TESTS)"; do ./$$t; done clean: - $(V:%=@)$(RM) $(TARGET) $(OBJECTS) $(TESTS) + $(MUTE)$(RM) $(TARGET) $(OBJECTS) $(TESTS) install: $(TARGET) install -D -m 0755 $(TARGET) $(DESTDIR)$(BINPREFIX)/imv -- cgit v1.2.3