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.
This commit is contained in:
N-R-K 2021-10-03 22:52:12 +06:00 committed by GitHub
parent 1dc936d0ee
commit e8d08ba67e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 51 additions and 54 deletions

1
.gitignore vendored
View File

@ -3,4 +3,3 @@ version.h
*.d *.d
*.o *.o
nsxiv nsxiv
config.mk

View File

@ -1,18 +1,21 @@
# Include configure options
ifneq (clean,$(filter clean,$(MAKECMDGOALS)))
-include config.mk
endif
# nsxiv version # nsxiv version
VERSION = 27.1 VERSION = 27.1
# PREFIX for install # PREFIX for install
PREFIX ?= /usr/local PREFIX ?= /usr/local
MANPREFIX = $(PREFIX)/share/man MANPREFIX ?= $(PREFIX)/share/man
DOCPREFIX = $(PREFIX)/share/doc/nsxiv EGPREFIX ?= $(PREFIX)/share/doc/nsxiv/examples
# autoreload backend: inotify/nop # default value for optional dependencies. 1 = enabled, 0 = disabled
AUTORELOAD = inotify OPT_DEP_DEFAULT ?= 1
# autoreload backend: 1 = inotify, 0 = none
HAVE_INOTIFY ?= $(OPT_DEP_DEFAULT)
# optional dependencies, see README for more info
HAVE_LIBGIF ?= $(OPT_DEP_DEFAULT)
HAVE_LIBEXIF ?= $(OPT_DEP_DEFAULT)
HAVE_LIBWEBP ?= $(OPT_DEP_DEFAULT)
# CFLAGS, any optimization flags goes here # CFLAGS, any optimization flags goes here
CFLAGS ?= -std=c99 -Wall -pedantic CFLAGS ?= -std=c99 -Wall -pedantic
@ -20,30 +23,25 @@ CFLAGS ?= -std=c99 -Wall -pedantic
# icons that will be installed via `make icon` # icons that will be installed via `make icon`
ICONS = 16x16.png 32x32.png 48x48.png 64x64.png 128x128.png ICONS = 16x16.png 32x32.png 48x48.png 64x64.png 128x128.png
ifeq ($(HAVE_LIBEXIF), 1)
OPTIONAL_LIBS += -lexif
else
HAVE_LIBEXIF = 0
endif
ifeq ($(HAVE_LIBGIF), 1)
OPTIONAL_LIBS += -lgif
else
HAVE_LIBGIF = 0
endif
ifeq ($(HAVE_LIBWEBP), 1)
OPTIONAL_LIBS += -lwebpdemux -lwebp
else
HAVE_LIBWEBP = 0
endif
CPPFLAGS = -D_XOPEN_SOURCE=700 \ CPPFLAGS = -D_XOPEN_SOURCE=700 \
-DHAVE_LIBGIF=$(HAVE_LIBGIF) -DHAVE_LIBEXIF=$(HAVE_LIBEXIF) \ -DHAVE_LIBGIF=$(HAVE_LIBGIF) -DHAVE_LIBEXIF=$(HAVE_LIBEXIF) \
-DHAVE_LIBWEBP=$(HAVE_LIBWEBP) \ -DHAVE_LIBWEBP=$(HAVE_LIBWEBP) \
-I/usr/include/freetype2 -I$(PREFIX)/include/freetype2 -I/usr/include/freetype2 -I$(PREFIX)/include/freetype2
LDLIBS = -lImlib2 -lX11 -lXft -lfontconfig $(OPTIONAL_LIBS) lib_exif_0 =
lib_exif_1 = -lexif
lib_gif_0 =
lib_gif_1 = -lgif
lib_webp_0 =
lib_webp_1 = -lwebpdemux -lwebp
autoreload_0 = nop
autoreload_1 = inotify
# using += because certain *BSD distros may need to add additional flags
LDLIBS += -lImlib2 -lX11 -lXft -lfontconfig \
$(lib_exif_$(HAVE_LIBEXIF)) $(lib_gif_$(HAVE_LIBGIF)) \
$(lib_webp_$(HAVE_LIBWEBP))
OBJS = autoreload_$(AUTORELOAD).o commands.o image.o main.o options.o \ OBJS = autoreload_$(autoreload_$(HAVE_INOTIFY)).o commands.o image.o main.o options.o \
thumbs.o util.o window.o thumbs.o util.o window.o
.PHONY: all clean install uninstall install-all install-icon uninstall-icon install-desktop .PHONY: all clean install uninstall install-all install-icon uninstall-icon install-desktop
@ -60,19 +58,10 @@ nsxiv: $(OBJS)
@echo "CC $@" @echo "CC $@"
$(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $< $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $<
$(OBJS): Makefile nsxiv.h commands.lst config.h config.mk $(OBJS): Makefile nsxiv.h commands.lst config.h
options.o: version.h options.o: version.h
window.o: icon/data.h window.o: icon/data.h
config.mk:
@echo "GEN $@"
@echo "# 0 = disable, 1 = enable" > config.mk
@for lib in exif gif webp; do \
if echo "int main(){}" | $(CC) "-l$$lib" -o /dev/null -x c - 2>/dev/null ; then \
echo "HAVE_LIB$$lib=1" | tr '[:lower:]' '[:upper:]' >> config.mk ; \
fi \
done
config.h: config.h:
@echo "GEN $@" @echo "GEN $@"
cp config.def.h $@ cp config.def.h $@
@ -85,7 +74,7 @@ version.h: Makefile .git/index
.git/index: .git/index:
clean: clean:
$(RM) *.o nsxiv rm -f *.o nsxiv version.h
install-all: install install-desktop install-icon install-all: install install-desktop install-icon
@ -112,14 +101,18 @@ uninstall-icon:
install: all install: all
@echo "INSTALL bin/nsxiv" @echo "INSTALL bin/nsxiv"
install -Dt $(DESTDIR)$(PREFIX)/bin nsxiv mkdir -p $(DESTDIR)$(PREFIX)/bin
cp nsxiv $(DESTDIR)$(PREFIX)/bin/
chmod 755 $(DESTDIR)$(PREFIX)/bin/nsxiv
@echo "INSTALL nsxiv.1" @echo "INSTALL nsxiv.1"
mkdir -p $(DESTDIR)$(MANPREFIX)/man1 mkdir -p $(DESTDIR)$(MANPREFIX)/man1
sed "s!DOCPREFIX!$(DOCPREFIX)!g; s!PREFIX!$(PREFIX)!g; s!VERSION!$(VERSION)!g" nsxiv.1 \ sed "s!EGPREFIX!$(EGPREFIX)!g; s!PREFIX!$(PREFIX)!g; s!VERSION!$(VERSION)!g" nsxiv.1 \
>$(DESTDIR)$(MANPREFIX)/man1/nsxiv.1 >$(DESTDIR)$(MANPREFIX)/man1/nsxiv.1
chmod 644 $(DESTDIR)$(MANPREFIX)/man1/nsxiv.1 chmod 644 $(DESTDIR)$(MANPREFIX)/man1/nsxiv.1
@echo "INSTALL share/nsxiv/" @echo "INSTALL share/nsxiv/"
install -Dt $(DESTDIR)$(DOCPREFIX)/examples examples/* mkdir -p $(DESTDIR)$(EGPREFIX)
cp examples/* $(DESTDIR)$(EGPREFIX)
chmod 755 $(DESTDIR)$(EGPREFIX)/*
uninstall: uninstall-icon uninstall: uninstall-icon
@echo "REMOVE bin/nsxiv" @echo "REMOVE bin/nsxiv"
@ -129,5 +122,5 @@ uninstall: uninstall-icon
@echo "REMOVE nsxiv.desktop" @echo "REMOVE nsxiv.desktop"
rm -f $(DESTDIR)$(PREFIX)/share/applications/nsxiv.desktop rm -f $(DESTDIR)$(PREFIX)/share/applications/nsxiv.desktop
@echo "REMOVE share/nsxiv/" @echo "REMOVE share/nsxiv/"
rm -rf $(DESTDIR)$(DOCPREFIX) rm -rf $(DESTDIR)$(EGPREFIX)

View File

@ -49,11 +49,16 @@ nsxiv requires the following software to be installed:
* freetype2 * freetype2
* fontconfig * fontconfig
The following libraries are optional. They are automatically enabled if installed. The following dependencies are optional.
* inotify : Used for auto-reloading images on change.
Disabled via `HAVE_INOTIFY=0`
* giflib : Used for animated gif playback. * giflib : Used for animated gif playback.
Disabled via `HAVE_LIBGIF=0`.
* libexif : Used for auto-orientation and exif thumbnails. * libexif : Used for auto-orientation and exif thumbnails.
Disable via `HAVE_LIBEXIF=0`
* libwebp : Used for animated webp playback. * libwebp : Used for animated webp playback.
Disabled via `HAVE_LIBWEBP=0`.
Please make sure to install the corresponding development packages in case that Please make sure to install the corresponding development packages in case that
you want to build nsxiv on a distribution with separate runtime and development you want to build nsxiv on a distribution with separate runtime and development
@ -67,14 +72,14 @@ nsxiv is built using the commands:
$ make $ make
Running make will automatically detect if libexif and libgif are available and You can pass `HAVE_X=0` to `make` to disable an optional dependency.
enable them if so. CLI arguments will override any automatic detection.
For example: For example:
$ make HAVE_LIBGIF=0 $ make HAVE_LIBEXIF=0
will always disable libgif. will disable `libexif` support. Alternatively they can be disabled via editing
Alternatively, they can be disabled via editing `config.mk`. the `Makefile` directly. `OPT_DEP_DEFAULT=0` can be used to disable all
optional dependencies.
Installing nsxiv: Installing nsxiv:
@ -102,9 +107,9 @@ You can install nsxiv into a directory of your choice by changing this command t
$ make PREFIX="/your/dir" install $ make PREFIX="/your/dir" install
Example scripts are installed using `DOCPREFIX` which defaults to Example scripts are installed using `EGPREFIX` which defaults to
`/usr/local/share/doc/nsxiv`. You can change `DOCPREFIX` the same way you can `/usr/local/share/doc/nsxiv/examples`. You can change `EGPREFIX` the same way
change `PREFIX` shown above. you can change `PREFIX` shown above.
The build-time specific settings of nsxiv can be found in the file *config.h*. The build-time specific settings of nsxiv can be found in the file *config.h*.
Please check and change them, so that they fit your needs. Please check and change them, so that they fit your needs.

View File

@ -428,7 +428,7 @@ and the arguments given to it are: 1) path to image file, 2) image width,
3) image height. 3) image height.
.P .P
There is also an example script installed together with nsxiv as There is also an example script installed together with nsxiv as
.IR DOCPREFIX/examples/image-info . .IR EGPREFIX/image-info .
.SH EXTERNAL KEY HANDLER .SH EXTERNAL KEY HANDLER
Additional external keyboard commands can be defined using a handler program Additional external keyboard commands can be defined using a handler program
located in located in
@ -446,7 +446,7 @@ where C/M/S indicate Ctrl/Meta(Alt)/Shift modifier states and KEY is the X
keysym as listed in /usr/include/X11/keysymdef.h without the "XK_" prefix. keysym as listed in /usr/include/X11/keysymdef.h without the "XK_" prefix.
There is also an example script installed together with nsxiv as There is also an example script installed together with nsxiv as
.IR DOCPREFIX/examples/key-handler . .IR EGPREFIX/key-handler .
.SH THUMBNAIL CACHING .SH THUMBNAIL CACHING
nsxiv stores all thumbnails under nsxiv stores all thumbnails under
.IR $XDG_CACHE_HOME/nsxiv/ . .IR $XDG_CACHE_HOME/nsxiv/ .