aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBert <ber.t@gmx.com>2011-09-12 19:28:02 +0200
committerBert <ber.t@gmx.com>2011-09-12 19:28:02 +0200
commitdad06c7561d6f0ca0ea8d7f104ade04ab0e051fd (patch)
treed2dd7b45aa80c926cc9b895c776c403b2366ea13
parent32a65201bb2114790d98a73427fab80f41d94b97 (diff)
downloadnsxiv-dad06c7561d6f0ca0ea8d7f104ade04ab0e051fd.tar.zst
Much nicer handling of compile-time features
- *_SUPPORT enabled in config.h - XLIBS helper app prints lib flags needed for current settings
-rw-r--r--.gitignore1
-rw-r--r--Makefile23
-rw-r--r--README.md38
-rw-r--r--XLIBS.c23
-rw-r--r--config.def.h12
-rw-r--r--image.c23
-rw-r--r--options.c5
-rw-r--r--thumbs.c5
8 files changed, 73 insertions, 57 deletions
diff --git a/.gitignore b/.gitignore
index bb71929..cfb39e4 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,4 @@
+XLIBS
config.h
*.o
sxiv
diff --git a/Makefile b/Makefile
index f1337b4..dd1c87b 100644
--- a/Makefile
+++ b/Makefile
@@ -5,10 +5,6 @@ CFLAGS = -Wall -pedantic -O2
LDFLAGS =
LIBS = -lX11 -lImlib2
-XFLAGS =
-XLIBS =
-
-DESTDIR =
PREFIX = /usr/local
MANPREFIX = $(PREFIX)/share/man
@@ -22,33 +18,34 @@ options:
@echo "CC = $(CC)"
@echo "CFLAGS = $(CFLAGS)"
@echo "LDFLAGS = $(LDFLAGS)"
- @echo "XFLAGS = $(XFLAGS)"
- @echo "XLIBS = $(XLIBS)"
@echo "PREFIX = $(PREFIX)"
.c.o:
@echo "CC $<"
- @$(CC) $(CFLAGS) $(XFLAGS) -DVERSION=\"$(VERSION)\" -c -o $@ $<
+ @$(CC) $(CFLAGS) -DVERSION=\"$(VERSION)\" -c -o $@ $<
+
+$(OBJ) XLIBS: Makefile config.h
-$(OBJ): Makefile config.h
+XLIBS: XLIBS.c
+ @$(CC) $(CFLAGS) -o $@ $@.c
config.h:
@echo "creating $@ from config.def.h"
@cp config.def.h $@
-sxiv: $(OBJ)
+sxiv: $(OBJ) XLIBS
@echo "CC -o $@"
- @$(CC) $(LDFLAGS) -o $@ $(OBJ) $(LIBS) $(XLIBS)
+ @$(CC) $(LDFLAGS) -o $@ $(OBJ) $(LIBS) $$(./XLIBS)
clean:
@echo "cleaning"
- @rm -f $(OBJ) sxiv sxiv-$(VERSION).tar.gz
+ @rm -f $(OBJ) XLIBS sxiv sxiv-$(VERSION).tar.gz
dist: clean
@echo "creating dist tarball"
@mkdir -p sxiv-$(VERSION)
- @cp LICENSE Makefile Makefile.netbsd README.md config.def.h \
- sxiv.1 $(SRC) sxiv-$(VERSION)
+ @cp LICENSE Makefile README.md config.def.h sxiv.1 $(SRC) XLIBS.c \
+ sxiv-$(VERSION)
@tar -cf sxiv-$(VERSION).tar sxiv-$(VERSION)
@gzip sxiv-$(VERSION).tar
@rm -rf sxiv-$(VERSION)
diff --git a/README.md b/README.md
index 0037f87..828093e 100644
--- a/README.md
+++ b/README.md
@@ -8,7 +8,7 @@ Its code base should be kept small and clean to make it easy for you to dig
into it and customize it for your needs.
Features
-========
+--------
* Basic image operations, e.g. zooming, panning, rotating
* Customizable key and mouse button mappings (in *config.h*)
@@ -17,14 +17,13 @@ Features
* Basic support for multi-frame images
* Display image information in window title
-Additional features, that need to be included at compile-time--see section
-*Installation* on how to enable them:
+Additional features, that need to be enabled at compile-time (in *config.h*):
-* Play GIF animations
+* Load all frames from GIF files and play GIF animations
* Auto-orientate JPEG images according to their EXIF tags
Screenshots
-===========
+-----------
Image mode:
@@ -35,7 +34,7 @@ Thumbnail mode:
<img src="http://github.com/muennich/sxiv/raw/master/sample/thumb.png">
Installation
-============
+------------
sxiv is built using the commands:
$ make
@@ -45,35 +44,16 @@ Please note, that the latter one requires root privileges.
By default, sxiv is installed using the prefix "/usr/local", so the full path
of the executable will be "/usr/local/bin/sxiv".
-You can install it into a directory of your choice by changing the second
+You can install sxiv into a directory of your choice by changing the second
command to:
# make PREFIX="/your/dir" install
-All build-time specific settings can be found in the file *config.h*. Please
-check and change them, so that they fit your needs.
-
-Additional features
--------------------
-
-The XFLAGS and XLIBS macros control which additional features (non-default
-compile-time features) should be enabled and included during compilation.
-
-* GIF support:
-
- XFLAGS=-DGIF_SUPPORT, XLIBS=-lgif, requires: giflib
-
-* EXIF support:
-
- XFLAGS=-DEXIF_SUPPORT, XLIBS=-lexif, requires: libexif
-
-To enable GIF and EXIF support, the giflib and libexif libraries need to be
-installed on your system and you need to change the first build command to:
-
- $ make XFLAGS="-DGIF_SUPPORT -DEXIF_SUPPORT" XLIBS="-lgif -lexif"
+The build-time specific settings of sxiv can be found in the file *config.h*.
+Please check and change them, so that they fit your needs.
Usage
-=====
+-----
sxiv has two modes of operation: image and thumbnail mode. The default is
image mode, in which only the current image is shown. In thumbnail mode a grid
of small previews is displayed, making it easy to choose an image to open.
diff --git a/XLIBS.c b/XLIBS.c
new file mode 100644
index 0000000..14dc1e1
--- /dev/null
+++ b/XLIBS.c
@@ -0,0 +1,23 @@
+#define _POSIX_C_SOURCE 200112L
+#define _FEATURE_CONFIG
+
+#include <stdio.h>
+
+#include "config.h"
+
+int n = 0;
+
+inline void put_lib_flag(const char *flag, int needed) {
+ if (needed)
+ printf("%s%s", n++ ? " " : "", flag);
+}
+
+int main(int argc, char **argv) {
+ put_lib_flag("-lexif", EXIF_SUPPORT);
+ put_lib_flag("-lgif", GIF_SUPPORT);
+
+ if (n)
+ printf("\n");
+
+ return 0;
+}
diff --git a/config.def.h b/config.def.h
index 022bf9a..b3e1826 100644
--- a/config.def.h
+++ b/config.def.h
@@ -1,3 +1,15 @@
+#ifdef _FEATURE_CONFIG
+
+/* auto-orientate jpeg files according to their exif tags?
+ * (requires libexif [-lexif] to be installed)
+ */
+#define EXIF_SUPPORT 0
+/* load all frames from gif files and support gif animations?
+ * (requires giflib [-lgif] to be installed)
+ */
+#define GIF_SUPPORT 0
+
+#endif
#ifdef _WINDOW_CONFIG
/* default window dimensions (overwritten via -g option): */
diff --git a/image.c b/image.c
index 8b4ff49..ea0e272 100644
--- a/image.c
+++ b/image.c
@@ -17,26 +17,27 @@
*/
#define _POSIX_C_SOURCE 200112L
+#define _FEATURE_CONFIG
#define _IMAGE_CONFIG
#include <string.h>
#include <unistd.h>
-#ifdef EXIF_SUPPORT
+#include "image.h"
+#include "options.h"
+#include "util.h"
+#include "config.h"
+
+#if EXIF_SUPPORT
#include <libexif/exif-data.h>
#endif
-#ifdef GIF_SUPPORT
+#if GIF_SUPPORT
#include <stdlib.h>
#include <sys/types.h>
#include <gif_lib.h>
#endif
-#include "image.h"
-#include "options.h"
-#include "util.h"
-#include "config.h"
-
#define ZOOMDIFF(z1,z2) ((z1) - (z2) > 0.001 || (z1) - (z2) < -0.001)
enum { MIN_GIF_DELAY = 50 };
@@ -70,7 +71,7 @@ void img_init(img_t *img, win_t *win) {
}
}
-#ifdef EXIF_SUPPORT
+#if EXIF_SUPPORT
void exif_auto_orientate(const fileinfo_t *file) {
ExifData *ed;
ExifEntry *entry;
@@ -115,7 +116,7 @@ void exif_auto_orientate(const fileinfo_t *file) {
}
#endif /* EXIF_SUPPORT */
-#ifdef GIF_SUPPORT
+#if GIF_SUPPORT
/* Originally based on, but in its current form merely inspired by Imlib2's
* src/modules/loaders/loader_gif.c:load(), written by Carsten Haitzler.
*/
@@ -301,11 +302,11 @@ bool img_load(img_t *img, const fileinfo_t *file) {
/* avoid unused-but-set-variable warning */
(void) fmt;
-#ifdef EXIF_SUPPORT
+#if EXIF_SUPPORT
if (!strcmp(fmt, "jpeg"))
exif_auto_orientate(file);
#endif
-#ifdef GIF_SUPPORT
+#if GIF_SUPPORT
if (!strcmp(fmt, "gif"))
img_load_gif(img, file);
#endif
diff --git a/options.c b/options.c
index 13e1174..2a04071 100644
--- a/options.c
+++ b/options.c
@@ -17,6 +17,7 @@
*/
#define _POSIX_C_SOURCE 200112L
+#define _FEATURE_CONFIG
#define _IMAGE_CONFIG
#include <stdlib.h>
@@ -39,12 +40,12 @@ void print_usage() {
void print_version() {
printf("sxiv %s - Simple X Image Viewer\n", VERSION);
printf("Additional features included (+) or not (-): %s, %s\n",
-#ifdef EXIF_SUPPORT
+#if EXIF_SUPPORT
"+exif",
#else
"-exif",
#endif
-#ifdef GIF_SUPPORT
+#if GIF_SUPPORT
"+gif"
#else
"-gif"
diff --git a/thumbs.c b/thumbs.c
index fa54576..85dd34f 100644
--- a/thumbs.c
+++ b/thumbs.c
@@ -17,6 +17,7 @@
*/
#define _POSIX_C_SOURCE 200112L
+#define _FEATURE_CONFIG
#define _THUMBS_CONFIG
#include <stdlib.h>
@@ -30,7 +31,7 @@
#include "util.h"
#include "config.h"
-#ifdef EXIF_SUPPORT
+#if EXIF_SUPPORT
void exif_auto_orientate(const fileinfo_t*);
#endif
@@ -252,7 +253,7 @@ bool tns_load(tns_t *tns, int n, const fileinfo_t *file,
/* avoid unused-but-set-variable warning */
(void) fmt;
-#ifdef EXIF_SUPPORT
+#if EXIF_SUPPORT
if (!cache_hit && !strcmp(fmt, "jpeg"))
exif_auto_orientate(file);
#endif