Krolyxon
Commit e8d08ba

Branches

Refs →

nsxive8d08ba

Rework build system v2 (#71)

* Remove non-POSIX extensions and commands
* Drop autodetection in favor of OPT_DEP_DEFAULT
* Use += for LDLIBS as some BSD distros need to add extra flags
* Change DOCPREFIX -> EGPREFIX
* Use ?= for MANPREFIX and EGPREFIX
* Update docs

With this, we should have a stable build system. No further significant
changes should be needed.
Author
N-R-K
Date
2021-10-03 22:52 +0600
Committer
GitHub · 2021-10-03 16:52 +0000
Parent
1dc936d
Commit
e8d08ba67edf407884fa36f11c027cd7c0d4e46d

+52 −55

4 files changed

  1. M .gitignore +0 −1
  2. M Makefile +36 −43
  3. M README.md +14 −9
  4. M nsxiv.1 +2 −2
M .gitignore View
@@ -3,4 +3,3 @@ version.h
33 *.d
44 *.o
55 nsxiv
6−config.mk
M Makefile View
@@ -1,18 +1,21 @@
1−# Include configure options
2−ifneq (clean,$(filter clean,$(MAKECMDGOALS)))
3−-include config.mk
4−endif
5−
61 # nsxiv version
72 VERSION = 27.1
83
94 # PREFIX for install
105 PREFIX ?= /usr/local
11−MANPREFIX = $(PREFIX)/share/man
12−DOCPREFIX = $(PREFIX)/share/doc/nsxiv
6+MANPREFIX ?= $(PREFIX)/share/man
7+EGPREFIX ?= $(PREFIX)/share/doc/nsxiv/examples
8+
9+# default value for optional dependencies. 1 = enabled, 0 = disabled
10+OPT_DEP_DEFAULT ?= 1
1311
14−# autoreload backend: inotify/nop
15−AUTORELOAD = inotify
12+# autoreload backend: 1 = inotify, 0 = none
13+HAVE_INOTIFY ?= $(OPT_DEP_DEFAULT)
14+
15+# optional dependencies, see README for more info
16+HAVE_LIBGIF ?= $(OPT_DEP_DEFAULT)
17+HAVE_LIBEXIF ?= $(OPT_DEP_DEFAULT)
18+HAVE_LIBWEBP ?= $(OPT_DEP_DEFAULT)
1619
1720 # CFLAGS, any optimization flags goes here
1821 CFLAGS ?= -std=c99 -Wall -pedantic
@@ -20,30 +23,25 @@ CFLAGS ?= -std=c99 -Wall -pedantic
2023 # icons that will be installed via `make icon`
2124 ICONS = 16x16.png 32x32.png 48x48.png 64x64.png 128x128.png
2225
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−
3926 CPPFLAGS = -D_XOPEN_SOURCE=700 \
4027 -DHAVE_LIBGIF=$(HAVE_LIBGIF) -DHAVE_LIBEXIF=$(HAVE_LIBEXIF) \
4128 -DHAVE_LIBWEBP=$(HAVE_LIBWEBP) \
4229 -I/usr/include/freetype2 -I$(PREFIX)/include/freetype2
4330
44−LDLIBS = -lImlib2 -lX11 -lXft -lfontconfig $(OPTIONAL_LIBS)
45−
46−OBJS = autoreload_$(AUTORELOAD).o commands.o image.o main.o options.o \
31+lib_exif_0 =
32+lib_exif_1 = -lexif
33+lib_gif_0 =
34+lib_gif_1 = -lgif
35+lib_webp_0 =
36+lib_webp_1 = -lwebpdemux -lwebp
37+autoreload_0 = nop
38+autoreload_1 = inotify
39+# using += because certain *BSD distros may need to add additional flags
40+LDLIBS += -lImlib2 -lX11 -lXft -lfontconfig \
41+ $(lib_exif_$(HAVE_LIBEXIF)) $(lib_gif_$(HAVE_LIBGIF)) \
42+ $(lib_webp_$(HAVE_LIBWEBP))
43+
44+OBJS = autoreload_$(autoreload_$(HAVE_INOTIFY)).o commands.o image.o main.o options.o \
4745 thumbs.o util.o window.o
4846
4947 .PHONY: all clean install uninstall install-all install-icon uninstall-icon install-desktop
@@ -60,19 +58,10 @@ nsxiv: $(OBJS)
6058 @echo "CC $@"
6159 $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $<
6260
63−$(OBJS): Makefile nsxiv.h commands.lst config.h config.mk
61+$(OBJS): Makefile nsxiv.h commands.lst config.h
6462 options.o: version.h
6563 window.o: icon/data.h
6664
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−
7665 config.h:
7766 @echo "GEN $@"
7867 cp config.def.h $@
@@ -85,7 +74,7 @@ version.h: Makefile .git/index
8574 .git/index:
8675
8776 clean:
88− $(RM) *.o nsxiv
77+ rm -f *.o nsxiv version.h
8978
9079 install-all: install install-desktop install-icon
9180
@@ -112,14 +101,18 @@ uninstall-icon:
112101
113102 install: all
114103 @echo "INSTALL bin/nsxiv"
115− install -Dt $(DESTDIR)$(PREFIX)/bin nsxiv
104+ mkdir -p $(DESTDIR)$(PREFIX)/bin
105+ cp nsxiv $(DESTDIR)$(PREFIX)/bin/
106+ chmod 755 $(DESTDIR)$(PREFIX)/bin/nsxiv
116107 @echo "INSTALL nsxiv.1"
117108 mkdir -p $(DESTDIR)$(MANPREFIX)/man1
118− sed "s!DOCPREFIX!$(DOCPREFIX)!g; s!PREFIX!$(PREFIX)!g; s!VERSION!$(VERSION)!g" nsxiv.1 \
109+ sed "s!EGPREFIX!$(EGPREFIX)!g; s!PREFIX!$(PREFIX)!g; s!VERSION!$(VERSION)!g" nsxiv.1 \
119110 >$(DESTDIR)$(MANPREFIX)/man1/nsxiv.1
120111 chmod 644 $(DESTDIR)$(MANPREFIX)/man1/nsxiv.1
121112 @echo "INSTALL share/nsxiv/"
122− install -Dt $(DESTDIR)$(DOCPREFIX)/examples examples/*
113+ mkdir -p $(DESTDIR)$(EGPREFIX)
114+ cp examples/* $(DESTDIR)$(EGPREFIX)
115+ chmod 755 $(DESTDIR)$(EGPREFIX)/*
123116
124117 uninstall: uninstall-icon
125118 @echo "REMOVE bin/nsxiv"
@@ -129,5 +122,5 @@ uninstall: uninstall-icon
129122 @echo "REMOVE nsxiv.desktop"
130123 rm -f $(DESTDIR)$(PREFIX)/share/applications/nsxiv.desktop
131124 @echo "REMOVE share/nsxiv/"
132− rm -rf $(DESTDIR)$(DOCPREFIX)
125+ rm -rf $(DESTDIR)$(EGPREFIX)
133126
M README.md View
@@ -49,11 +49,16 @@ nsxiv requires the following software to be installed:
4949 * freetype2
5050 * fontconfig
5151
52−The following libraries are optional. They are automatically enabled if installed.
52+The following dependencies are optional.
5353
54+ * inotify : Used for auto-reloading images on change.
55+ Disabled via `HAVE_INOTIFY=0`
5456 * giflib : Used for animated gif playback.
57+ Disabled via `HAVE_LIBGIF=0`.
5558 * libexif : Used for auto-orientation and exif thumbnails.
59+ Disable via `HAVE_LIBEXIF=0`
5660 * libwebp : Used for animated webp playback.
61+ Disabled via `HAVE_LIBWEBP=0`.
5762
5863 Please make sure to install the corresponding development packages in case that
5964 you want to build nsxiv on a distribution with separate runtime and development
@@ -67,14 +72,14 @@ nsxiv is built using the commands:
6772
6873 $ make
6974
70−Running make will automatically detect if libexif and libgif are available and
71−enable them if so. CLI arguments will override any automatic detection.
75+You can pass `HAVE_X=0` to `make` to disable an optional dependency.
7276 For example:
7377
74− $ make HAVE_LIBGIF=0
78+ $ make HAVE_LIBEXIF=0
7579
76−will always disable libgif.
77−Alternatively, they can be disabled via editing `config.mk`.
80+will disable `libexif` support. Alternatively they can be disabled via editing
81+the `Makefile` directly. `OPT_DEP_DEFAULT=0` can be used to disable all
82+optional dependencies.
7883
7984 Installing nsxiv:
8085
@@ -102,9 +107,9 @@ You can install nsxiv into a directory of your choice by changing this command t
102107
103108 $ make PREFIX="/your/dir" install
104109
105−Example scripts are installed using `DOCPREFIX` which defaults to
106−`/usr/local/share/doc/nsxiv`. You can change `DOCPREFIX` the same way you can
107−change `PREFIX` shown above.
110+Example scripts are installed using `EGPREFIX` which defaults to
111+`/usr/local/share/doc/nsxiv/examples`. You can change `EGPREFIX` the same way
112+you can change `PREFIX` shown above.
108113
109114 The build-time specific settings of nsxiv can be found in the file *config.h*.
110115 Please check and change them, so that they fit your needs.
M nsxiv.1 View
@@ -428,7 +428,7 @@ and the arguments given to it are: 1) path to image file, 2) image width,
428428 3) image height.
429429 .P
430430 There is also an example script installed together with nsxiv as
431−.IR DOCPREFIX/examples/image-info .
431+.IR EGPREFIX/image-info .
432432 .SH EXTERNAL KEY HANDLER
433433 Additional external keyboard commands can be defined using a handler program
434434 located in
@@ -446,7 +446,7 @@ where C/M/S indicate Ctrl/Meta(Alt)/Shift modifier states and KEY is the X
446446 keysym as listed in /usr/include/X11/keysymdef.h without the "XK_" prefix.
447447
448448 There is also an example script installed together with nsxiv as
449−.IR DOCPREFIX/examples/key-handler .
449+.IR EGPREFIX/key-handler .
450450 .SH THUMBNAIL CACHING
451451 nsxiv stores all thumbnails under
452452 .IR $XDG_CACHE_HOME/nsxiv/ .