Skip to content

Commit

Permalink
Rework build system v2
Browse files Browse the repository at this point in the history
* Remove non-POSIX extensions and commands
* Drop autodetection in favor of HAVE_LIB_DEFAULT
* Use += for LDLIBS as some BSD distros need to add extra flags
  • Loading branch information
N-R-K committed Oct 2, 2021
1 parent 1dc936d commit 7e29bdc
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 43 deletions.
1 change: 0 additions & 1 deletion .gitignore
Expand Up @@ -3,4 +3,3 @@ version.h
*.d
*.o
nsxiv
config.mk
63 changes: 27 additions & 36 deletions Makefile
@@ -1,8 +1,3 @@
# Include configure options
ifneq (clean,$(filter clean,$(MAKECMDGOALS)))
-include config.mk
endif

# nsxiv version
VERSION = 27.1

Expand All @@ -12,36 +7,37 @@ MANPREFIX = $(PREFIX)/share/man
DOCPREFIX = $(PREFIX)/share/doc/nsxiv

# autoreload backend: inotify/nop
AUTORELOAD = inotify
AUTORELOAD ?= inotify

# default value for optional dependencies. 1 = enabled, 0 = disabled
HAVE_LIB_DEFAULT ?= 1

# optional dependencies, see README for more info
HAVE_LIBGIF ?= $(HAVE_LIB_DEFAULT)
HAVE_LIBEXIF ?= $(HAVE_LIB_DEFAULT)
HAVE_LIBWEBP ?= $(HAVE_LIB_DEFAULT)

# CFLAGS, any optimization flags goes here
CFLAGS ?= -std=c99 -Wall -pedantic

# icons that will be installed via `make icon`
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 \
-DHAVE_LIBGIF=$(HAVE_LIBGIF) -DHAVE_LIBEXIF=$(HAVE_LIBEXIF) \
-DHAVE_LIBWEBP=$(HAVE_LIBWEBP) \
-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
# 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 \
thumbs.o util.o window.o
Expand All @@ -60,19 +56,10 @@ nsxiv: $(OBJS)
@echo "CC $@"
$(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
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:
@echo "GEN $@"
cp config.def.h $@
Expand All @@ -85,7 +72,7 @@ version.h: Makefile .git/index
.git/index:

clean:
$(RM) *.o nsxiv
rm -f *.o nsxiv version.h

install-all: install install-desktop install-icon

Expand All @@ -112,14 +99,18 @@ uninstall-icon:

install: all
@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"
mkdir -p $(DESTDIR)$(MANPREFIX)/man1
sed "s!DOCPREFIX!$(DOCPREFIX)!g; s!PREFIX!$(PREFIX)!g; s!VERSION!$(VERSION)!g" nsxiv.1 \
>$(DESTDIR)$(MANPREFIX)/man1/nsxiv.1
chmod 644 $(DESTDIR)$(MANPREFIX)/man1/nsxiv.1
@echo "INSTALL share/nsxiv/"
install -Dt $(DESTDIR)$(DOCPREFIX)/examples examples/*
mkdir -p $(DESTDIR)$(DOCPREFIX)/examples
cp examples/* $(DESTDIR)$(DOCPREFIX)/examples
chmod 755 $(DESTDIR)$(DOCPREFIX)/examples/*

uninstall: uninstall-icon
@echo "REMOVE bin/nsxiv"
Expand Down
14 changes: 8 additions & 6 deletions README.md
Expand Up @@ -49,11 +49,14 @@ nsxiv requires the following software to be installed:
* freetype2
* fontconfig

The following libraries are optional. They are automatically enabled if installed.
The following libraries are optional.

* giflib : Used for animated gif playback.
Disabled via `HAVE_LIBGIF=0`.
* libexif : Used for auto-orientation and exif thumbnails.
Disable via `HAVE_LIBEXIF=0`
* libwebp : Used for animated webp playback.
Disabled via `HAVE_LIBWEBP=0`.

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
Expand All @@ -67,14 +70,13 @@ nsxiv is built using the commands:

$ make

Running make will automatically detect if libexif and libgif are available and
enable them if so. CLI arguments will override any automatic detection.
You can pass `HAVE_LIBX=0` to `make` to disable an optional dependency.
For example:

$ make HAVE_LIBGIF=0
$ make HAVE_LIBEXIF=0

will always disable libgif.
Alternatively, they can be disabled via editing `config.mk`.
will disable `libexif` support. Alternatively they can be disabled via editing
the `Makefile` directly.

Installing nsxiv:

Expand Down

0 comments on commit 7e29bdc

Please sign in to comment.