Krolyxon
Commit 5155d52

Branches

Refs →

nsxiv5155d52

Much more portable Makefile

The config.mk file is now optional and only needs to be created if one wants to
persistently overwrite default macro values.

Features used in the Makefile that are not yet in the POSIX standard:

  - Advanced macro assignment operators '+=' and '?=' [1]
  - Special target .PHONY [2]
  - Pattern rules [3]; only needed when $srcdir != '.'. For every pattern rule
    there is an inference rule with the same effect. Hopefully, the inference
    rules get picked up by make programs not supporting pattern rules.
  - Silently including multiple possibly not exisiting files [4] [5]

[1] http://austingroupbugs.net/view.php?id=330
[2] http://austingroupbugs.net/view.php?id=523
[3] http://austingroupbugs.net/view.php?id=513
[4] http://austingroupbugs.net/view.php?id=333
[5] http://austingroupbugs.net/view.php?id=518
Author
Bert Münnich
Date
2017-10-12 10:56 +0200
Committer
Bert Münnich · 2017-10-12 11:00 +0200
Parent
6beb8b4
Commit
5155d52ab18c06925046e2f56a87f2765bb515ba

+57 −48

2 files changed

  1. M Makefile +57 −30
  2. D config.mk +0 −18
M Makefile View
@@ -1,42 +1,72 @@
1−# Requires GNU make 3.80 or later
1+# Works best with GNU make 3.80 or later
22
3−VERSION := git-20171006
3+VERSION = git-20171012
44
5−all: sxiv
5+srcdir = .
66
7−include config.mk
7+PREFIX = /usr/local
8+MANPREFIX = $(PREFIX)/share/man
89
9−override CPPFLAGS += -I. -DVERSION=\"$(VERSION)\" -DHAVE_GIFLIB=$(HAVE_GIFLIB) -DHAVE_LIBEXIF=$(HAVE_LIBEXIF)
10+CC ?= gcc
11+CFLAGS += -std=c99 -Wall -pedantic
12+CPPFLAGS += -I/usr/include/freetype2 -D_XOPEN_SOURCE=700
13+DEPFLAGS = -MMD -MP
14+LDFLAGS +=
1015
11−LDLIBS := -lImlib2 -lX11 -lXft
16+# autoreload backend: inotify/nop
17+AUTORELOAD = inotify
1218
13−ifneq ($(HAVE_GIFLIB),0)
14− LDLIBS += -lgif
15−endif
16−ifneq ($(HAVE_LIBEXIF),0)
17− LDLIBS += -lexif
18−endif
19+# enable features requiring giflib (-lgif)
20+HAVE_GIFLIB = 1
1921
20−SRC := autoreload_$(AUTORELOAD).c commands.c image.c main.c options.c thumbs.c util.c window.c
21−DEP := $(SRC:.c=.d)
22−OBJ := $(SRC:.c=.o)
22+# enable features requiring libexif (-lexif)
23+HAVE_LIBEXIF = 1
2324
24−$(OBJ): config.h Makefile
25+REQ_CPPFLAGS = -I. -DVERSION=\"$(VERSION)\" \
26+ -DHAVE_GIFLIB=$(HAVE_GIFLIB) -DHAVE_LIBEXIF=$(HAVE_LIBEXIF)
27+ALL_CPPFLAGS = $(REQ_CPPFLAGS) $(CPPFLAGS)
2528
26−%.o: %.c
27− @echo "CC $@"
28− $(CC) $(CFLAGS) $(CPPFLAGS) $(DEPFLAGS) -c -o $@ $<
29+LIB_EXIF_0 =
30+LIB_EXIF_1 = -lexif
31+LIB_GIF_0 =
32+LIB_GIF_1 = -lgif
33+LDLIBS = -lImlib2 -lX11 -lXft \
34+ $(LIB_EXIF_$(HAVE_LIBEXIF)) $(LIB_GIF_$(HAVE_GIFLIB))
2935
30−config.h: | config.def.h
31− @echo "GEN $@"
32− cp $| $@
36+-include config.mk
37+
38+SRCS = autoreload_$(AUTORELOAD).c commands.c image.c main.c options.c \
39+ thumbs.c util.c window.c
40+OBJS = $(SRCS:.c=.o)
41+DEPS = $(SRCS:.c=.d)
42+
43+all: sxiv
3344
34−sxiv: $(OBJ)
45+.PHONY: all clean install uninstall
46+.SUFFIXES:
47+.SUFFIXES: .c .o
48+$(V).SILENT:
49+
50+sxiv: $(OBJS)
3551 @echo "LINK $@"
36− $(CC) $(LDFLAGS) -o $@ $^ $(LDLIBS)
52+ $(CC) $(LDFLAGS) -o $@ $(OBJS) $(LDLIBS)
53+
54+$(OBJS): config.h $(srcdir)/Makefile
55+
56+.c.o:
57+ @echo "CC $@"
58+ $(CC) $(ALL_CPPFLAGS) $(DEPFLAGS) $(CFLAGS) -c -o $@ $<
59+
60+%.o: $(srcdir)/%.c
61+ @echo "CC $@"
62+ $(CC) $(ALL_CPPFLAGS) $(DEPFLAGS) $(CFLAGS) -c -o $@ $(srcdir)/$(@:.o=.c)
63+
64+config.h:
65+ @echo "GEN $@"
66+ cp $(srcdir)/config.def.h $@
3767
3868 clean:
39− rm -f $(OBJ) $(DEP) sxiv
69+ rm -f $(OBJS) $(DEPS) sxiv
4070
4171 install: all
4272 @echo "INSTALL bin/sxiv"
@@ -45,7 +75,8 @@ install: all
4575 chmod 755 $(DESTDIR)$(PREFIX)/bin/sxiv
4676 @echo "INSTALL sxiv.1"
4777 mkdir -p $(DESTDIR)$(MANPREFIX)/man1
48− sed "s!PREFIX!$(PREFIX)!g; s!VERSION!$(VERSION)!g" sxiv.1 > $(DESTDIR)$(MANPREFIX)/man1/sxiv.1
78+ sed "s!PREFIX!$(PREFIX)!g; s!VERSION!$(VERSION)!g" sxiv.1 \
79+ >$(DESTDIR)$(MANPREFIX)/man1/sxiv.1
4980 chmod 644 $(DESTDIR)$(MANPREFIX)/man1/sxiv.1
5081 @echo "INSTALL share/sxiv/"
5182 mkdir -p $(DESTDIR)$(PREFIX)/share/sxiv/exec
@@ -60,9 +91,5 @@ uninstall:
6091 @echo "REMOVE share/sxiv/"
6192 rm -rf $(DESTDIR)$(PREFIX)/share/sxiv
6293
63−.PHONY: all clean install uninstall
64−.SUFFIXES:
65−$(V).SILENT:
66−
6794 -include $(DEP)
6895
D config.mk View
@@ -1,18 +0,0 @@
1−PREFIX := /usr/local
2−MANPREFIX := $(PREFIX)/share/man
3−
4−CC ?= gcc
5−CFLAGS += -std=c99 -Wall -pedantic
6−CPPFLAGS += -I/usr/include/freetype2 -D_XOPEN_SOURCE=700
7−DEPFLAGS := -MMD -MP
8−LDFLAGS +=
9−
10−# autoreload backend: inotify/nop
11−AUTORELOAD := inotify
12−
13−# enable features requiring giflib (-lgif)
14−HAVE_GIFLIB := 1
15−
16−# enable features requiring libexif (-lexif)
17−HAVE_LIBEXIF := 1
18−