Krolyxon
Commit a2339e7

Branches

Refs →

nsxivMakefile

133 lines · 3.2 KB · Makefile

1# Include configure options
2ifneq (clean,$(filter clean,$(MAKECMDGOALS)))
3-include config.mk
4endif
5
6# nsxiv version
7VERSION = 27.1
8
9# PREFIX for install
10PREFIX ?= /usr/local
11MANPREFIX = $(PREFIX)/share/man
12DOCPREFIX = $(PREFIX)/share/doc/nsxiv
13
14# autoreload backend: inotify/nop
15AUTORELOAD = inotify
16
17# CFLAGS, any optimization flags goes here
18CFLAGS ?= -std=c99 -Wall -pedantic
19
20# icons that will be installed via `make icon`
21ICONS = 16x16.png 32x32.png 48x48.png 64x64.png 128x128.png
22
23ifeq ($(HAVE_LIBEXIF), 1)
24 OPTIONAL_LIBS += -lexif
25else
26 HAVE_LIBEXIF = 0
27endif
28ifeq ($(HAVE_LIBGIF), 1)
29 OPTIONAL_LIBS += -lgif
30else
31 HAVE_LIBGIF = 0
32endif
33ifeq ($(HAVE_LIBWEBP), 1)
34 OPTIONAL_LIBS += -lwebpdemux -lwebp
35else
36 HAVE_LIBWEBP = 0
37endif
38
39CPPFLAGS = -D_XOPEN_SOURCE=700 \
40 -DHAVE_LIBGIF=$(HAVE_LIBGIF) -DHAVE_LIBEXIF=$(HAVE_LIBEXIF) \
41 -DHAVE_LIBWEBP=$(HAVE_LIBWEBP) \
42 -I/usr/include/freetype2 -I$(PREFIX)/include/freetype2
43
44LDLIBS = -lImlib2 -lX11 -lXft -lfontconfig $(OPTIONAL_LIBS)
45
46OBJS = autoreload_$(AUTORELOAD).o commands.o image.o main.o options.o \
47 thumbs.o util.o window.o
48
49.PHONY: all clean install uninstall install-all install-icon uninstall-icon install-desktop
50.SUFFIXES:
51.SUFFIXES: .c .o
52
53all: nsxiv
54
55nsxiv: $(OBJS)
56 @echo "LINK $@"
57 $(CC) $(LDFLAGS) -o $@ $^ $(LDLIBS)
58
59.c.o:
60 @echo "CC $@"
61 $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $<
62
63$(OBJS): Makefile nsxiv.h commands.lst config.h config.mk
64options.o: version.h
65window.o: icon/data.h
66
67config.mk:
68 @echo "GEN $@"
69 @echo "# 0 = disable, 1 = enable" > config.mk
70 @for lib in exif gif webp; do \
71 if echo "int main(){}" | $(CC) "-l$$lib" -o /dev/null -x c - 2>/dev/null ; then \
72 echo "HAVE_LIB$$lib=1" | tr '[:lower:]' '[:upper:]' >> config.mk ; \
73 fi \
74 done
75
76config.h:
77 @echo "GEN $@"
78 cp config.def.h $@
79
80version.h: Makefile .git/index
81 @echo "GEN $@"
82 v="$$(git describe 2>/dev/null)"; \
83 echo "#define VERSION \"$${v:-$(VERSION)}\"" >$@
84
85.git/index:
86
87clean:
88 $(RM) *.o nsxiv
89
90install-all: install install-desktop install-icon
91
92install-desktop:
93 @echo "INSTALL nsxiv.desktop"
94 mkdir -p $(DESTDIR)$(PREFIX)/share/applications
95 cp nsxiv.desktop $(DESTDIR)$(PREFIX)/share/applications
96
97install-icon:
98 @echo "INSTALL icon"
99 for f in $(ICONS); do \
100 dir="$(DESTDIR)$(PREFIX)/share/icons/hicolor/$${f%.png}/apps"; \
101 mkdir -p "$$dir"; \
102 cp "icon/$$f" "$$dir/nsxiv.png"; \
103 chmod 644 "$$dir/nsxiv.png"; \
104 done
105
106uninstall-icon:
107 @echo "REMOVE icon"
108 for f in $(ICONS); do \
109 dir="$(DESTDIR)$(PREFIX)/share/icons/hicolor/$${f%.png}/apps"; \
110 rm -f "$$dir/nsxiv.png"; \
111 done
112
113install: all
114 @echo "INSTALL bin/nsxiv"
115 install -Dt $(DESTDIR)$(PREFIX)/bin nsxiv
116 @echo "INSTALL nsxiv.1"
117 mkdir -p $(DESTDIR)$(MANPREFIX)/man1
118 sed "s!DOCPREFIX!$(DOCPREFIX)!g; s!PREFIX!$(PREFIX)!g; s!VERSION!$(VERSION)!g" nsxiv.1 \
119 >$(DESTDIR)$(MANPREFIX)/man1/nsxiv.1
120 chmod 644 $(DESTDIR)$(MANPREFIX)/man1/nsxiv.1
121 @echo "INSTALL share/nsxiv/"
122 install -Dt $(DESTDIR)$(DOCPREFIX)/examples examples/*
123
124uninstall: uninstall-icon
125 @echo "REMOVE bin/nsxiv"
126 rm -f $(DESTDIR)$(PREFIX)/bin/nsxiv
127 @echo "REMOVE nsxiv.1"
128 rm -f $(DESTDIR)$(MANPREFIX)/man1/nsxiv.1
129 @echo "REMOVE nsxiv.desktop"
130 rm -f $(DESTDIR)$(PREFIX)/share/applications/nsxiv.desktop
131 @echo "REMOVE share/nsxiv/"
132 rm -rf $(DESTDIR)$(DOCPREFIX)
133