| 1 | # Include configure options |
| 2 | ifneq (clean,$(filter clean,$(MAKECMDGOALS))) |
| 3 | -include config.mk |
| 4 | endif |
| 5 | |
| 6 | # nsxiv version |
| 7 | VERSION = 27.1 |
| 8 | |
| 9 | # PREFIX for install |
| 10 | PREFIX ?= /usr/local |
| 11 | MANPREFIX = $(PREFIX)/share/man |
| 12 | DOCPREFIX = $(PREFIX)/share/doc/nsxiv |
| 13 | |
| 14 | # autoreload backend: inotify/nop |
| 15 | AUTORELOAD = inotify |
| 16 | |
| 17 | # CFLAGS, any optimization flags goes here |
| 18 | CFLAGS ?= -std=c99 -Wall -pedantic |
| 19 | |
| 20 | # icons that will be installed via `make icon` |
| 21 | ICONS = 16x16.png 32x32.png 48x48.png 64x64.png 128x128.png |
| 22 | |
| 23 | ifeq ($(HAVE_LIBEXIF), 1) |
| 24 | OPTIONAL_LIBS += -lexif |
| 25 | else |
| 26 | HAVE_LIBEXIF = 0 |
| 27 | endif |
| 28 | ifeq ($(HAVE_LIBGIF), 1) |
| 29 | OPTIONAL_LIBS += -lgif |
| 30 | else |
| 31 | HAVE_LIBGIF = 0 |
| 32 | endif |
| 33 | ifeq ($(HAVE_LIBWEBP), 1) |
| 34 | OPTIONAL_LIBS += -lwebpdemux -lwebp |
| 35 | else |
| 36 | HAVE_LIBWEBP = 0 |
| 37 | endif |
| 38 | |
| 39 | CPPFLAGS = -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 | |
| 44 | LDLIBS = -lImlib2 -lX11 -lXft -lfontconfig $(OPTIONAL_LIBS) |
| 45 | |
| 46 | OBJS = 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 | |
| 53 | all: nsxiv |
| 54 | |
| 55 | nsxiv: $(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 |
| 64 | options.o: version.h |
| 65 | window.o: icon/data.h |
| 66 | |
| 67 | config.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 | |
| 76 | config.h: |
| 77 | @echo "GEN $@" |
| 78 | cp config.def.h $@ |
| 79 | |
| 80 | version.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 | |
| 87 | clean: |
| 88 | $(RM) *.o nsxiv |
| 89 | |
| 90 | install-all: install install-desktop install-icon |
| 91 | |
| 92 | install-desktop: |
| 93 | @echo "INSTALL nsxiv.desktop" |
| 94 | mkdir -p $(DESTDIR)$(PREFIX)/share/applications |
| 95 | cp nsxiv.desktop $(DESTDIR)$(PREFIX)/share/applications |
| 96 | |
| 97 | install-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 | |
| 106 | uninstall-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 | |
| 113 | install: 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 | |
| 124 | uninstall: 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 | |