Krolyxon
Commit dad06c7

Branches

Refs →

nsxivdad06c7

Much nicer handling of compile-time features

- *_SUPPORT enabled in config.h
- XLIBS helper app prints lib flags needed for current settings
Author
Bert
Date
2011-09-12 19:28 +0200
Parent
32a6520
Commit
dad06c7561d6f0ca0ea8d7f104ade04ab0e051fd

+73 −57

8 files changed

  1. M .gitignore +1 −0
  2. M Makefile +10 −13
  3. M README.md +9 −29
  4. A XLIBS.c +23 −0
  5. M config.def.h +12 −0
  6. M image.c +12 −11
  7. M options.c +3 −2
  8. M thumbs.c +3 −2
M .gitignore View
@@ -1,3 +1,4 @@
1+XLIBS
12 config.h
23 *.o
34 sxiv
M Makefile View
@@ -5,10 +5,6 @@ CFLAGS = -Wall -pedantic -O2
55 LDFLAGS =
66 LIBS = -lX11 -lImlib2
77
8−XFLAGS =
9−XLIBS =
10−
11−DESTDIR =
128 PREFIX = /usr/local
139 MANPREFIX = $(PREFIX)/share/man
1410
@@ -22,33 +18,34 @@ options:
2218 @echo "CC = $(CC)"
2319 @echo "CFLAGS = $(CFLAGS)"
2420 @echo "LDFLAGS = $(LDFLAGS)"
25− @echo "XFLAGS = $(XFLAGS)"
26− @echo "XLIBS = $(XLIBS)"
2721 @echo "PREFIX = $(PREFIX)"
2822
2923 .c.o:
3024 @echo "CC $<"
31− @$(CC) $(CFLAGS) $(XFLAGS) -DVERSION=\"$(VERSION)\" -c -o $@ $<
25+ @$(CC) $(CFLAGS) -DVERSION=\"$(VERSION)\" -c -o $@ $<
26+
27+$(OBJ) XLIBS: Makefile config.h
3228
33−$(OBJ): Makefile config.h
29+XLIBS: XLIBS.c
30+ @$(CC) $(CFLAGS) -o $@ $@.c
3431
3532 config.h:
3633 @echo "creating $@ from config.def.h"
3734 @cp config.def.h $@
3835
39−sxiv: $(OBJ)
36+sxiv: $(OBJ) XLIBS
4037 @echo "CC -o $@"
41− @$(CC) $(LDFLAGS) -o $@ $(OBJ) $(LIBS) $(XLIBS)
38+ @$(CC) $(LDFLAGS) -o $@ $(OBJ) $(LIBS) $$(./XLIBS)
4239
4340 clean:
4441 @echo "cleaning"
45− @rm -f $(OBJ) sxiv sxiv-$(VERSION).tar.gz
42+ @rm -f $(OBJ) XLIBS sxiv sxiv-$(VERSION).tar.gz
4643
4744 dist: clean
4845 @echo "creating dist tarball"
4946 @mkdir -p sxiv-$(VERSION)
50− @cp LICENSE Makefile Makefile.netbsd README.md config.def.h \
51− sxiv.1 $(SRC) sxiv-$(VERSION)
47+ @cp LICENSE Makefile README.md config.def.h sxiv.1 $(SRC) XLIBS.c \
48+ sxiv-$(VERSION)
5249 @tar -cf sxiv-$(VERSION).tar sxiv-$(VERSION)
5350 @gzip sxiv-$(VERSION).tar
5451 @rm -rf sxiv-$(VERSION)
M README.md View
@@ -8,7 +8,7 @@ Its code base should be kept small and clean to make it easy for you to dig
88 into it and customize it for your needs.
99
1010 Features
11−========
11+--------
1212
1313 * Basic image operations, e.g. zooming, panning, rotating
1414 * Customizable key and mouse button mappings (in *config.h*)
@@ -17,14 +17,13 @@ Features
1717 * Basic support for multi-frame images
1818 * Display image information in window title
1919
20−Additional features, that need to be included at compile-time--see section
21−*Installation* on how to enable them:
20+Additional features, that need to be enabled at compile-time (in *config.h*):
2221
23−* Play GIF animations
22+* Load all frames from GIF files and play GIF animations
2423 * Auto-orientate JPEG images according to their EXIF tags
2524
2625 Screenshots
27−===========
26+-----------
2827
2928 Image mode:
3029
@@ -35,7 +34,7 @@ Thumbnail mode:
3534 <img src="http://github.com/muennich/sxiv/raw/master/sample/thumb.png">
3635
3736 Installation
38−============
37+------------
3938 sxiv is built using the commands:
4039
4140 $ make
@@ -45,35 +44,16 @@ Please note, that the latter one requires root privileges.
4544 By default, sxiv is installed using the prefix "/usr/local", so the full path
4645 of the executable will be "/usr/local/bin/sxiv".
4746
48−You can install it into a directory of your choice by changing the second
47+You can install sxiv into a directory of your choice by changing the second
4948 command to:
5049
5150 # make PREFIX="/your/dir" install
5251
53−All build-time specific settings can be found in the file *config.h*. Please
54−check and change them, so that they fit your needs.
55−
56−Additional features
57−-------------------
58−
59−The XFLAGS and XLIBS macros control which additional features (non-default
60−compile-time features) should be enabled and included during compilation.
61−
62−* GIF support:
63−
64− XFLAGS=-DGIF_SUPPORT, XLIBS=-lgif, requires: giflib
65−
66−* EXIF support:
67−
68− XFLAGS=-DEXIF_SUPPORT, XLIBS=-lexif, requires: libexif
69−
70−To enable GIF and EXIF support, the giflib and libexif libraries need to be
71−installed on your system and you need to change the first build command to:
72−
73− $ make XFLAGS="-DGIF_SUPPORT -DEXIF_SUPPORT" XLIBS="-lgif -lexif"
52+The build-time specific settings of sxiv can be found in the file *config.h*.
53+Please check and change them, so that they fit your needs.
7454
7555 Usage
76−=====
56+-----
7757 sxiv has two modes of operation: image and thumbnail mode. The default is
7858 image mode, in which only the current image is shown. In thumbnail mode a grid
7959 of small previews is displayed, making it easy to choose an image to open.
A XLIBS.c View
@@ -0,0 +1,23 @@
1+#define _POSIX_C_SOURCE 200112L
2+#define _FEATURE_CONFIG
3+
4+#include <stdio.h>
5+
6+#include "config.h"
7+
8+int n = 0;
9+
10+inline void put_lib_flag(const char *flag, int needed) {
11+ if (needed)
12+ printf("%s%s", n++ ? " " : "", flag);
13+}
14+
15+int main(int argc, char **argv) {
16+ put_lib_flag("-lexif", EXIF_SUPPORT);
17+ put_lib_flag("-lgif", GIF_SUPPORT);
18+
19+ if (n)
20+ printf("\n");
21+
22+ return 0;
23+}
M config.def.h View
@@ -1,3 +1,15 @@
1+#ifdef _FEATURE_CONFIG
2+
3+/* auto-orientate jpeg files according to their exif tags?
4+ * (requires libexif [-lexif] to be installed)
5+ */
6+#define EXIF_SUPPORT 0
7+/* load all frames from gif files and support gif animations?
8+ * (requires giflib [-lgif] to be installed)
9+ */
10+#define GIF_SUPPORT 0
11+
12+#endif
113 #ifdef _WINDOW_CONFIG
214
315 /* default window dimensions (overwritten via -g option): */
M image.c View
@@ -17,26 +17,27 @@
1717 */
1818
1919 #define _POSIX_C_SOURCE 200112L
20+#define _FEATURE_CONFIG
2021 #define _IMAGE_CONFIG
2122
2223 #include <string.h>
2324 #include <unistd.h>
2425
25−#ifdef EXIF_SUPPORT
26+#include "image.h"
27+#include "options.h"
28+#include "util.h"
29+#include "config.h"
30+
31+#if EXIF_SUPPORT
2632 #include <libexif/exif-data.h>
2733 #endif
2834
29−#ifdef GIF_SUPPORT
35+#if GIF_SUPPORT
3036 #include <stdlib.h>
3137 #include <sys/types.h>
3238 #include <gif_lib.h>
3339 #endif
3440
35−#include "image.h"
36−#include "options.h"
37−#include "util.h"
38−#include "config.h"
39−
4041 #define ZOOMDIFF(z1,z2) ((z1) - (z2) > 0.001 || (z1) - (z2) < -0.001)
4142
4243 enum { MIN_GIF_DELAY = 50 };
@@ -70,7 +71,7 @@ void img_init(img_t *img, win_t *win) {
7071 }
7172 }
7273
73−#ifdef EXIF_SUPPORT
74+#if EXIF_SUPPORT
7475 void exif_auto_orientate(const fileinfo_t *file) {
7576 ExifData *ed;
7677 ExifEntry *entry;
@@ -115,7 +116,7 @@ void exif_auto_orientate(const fileinfo_t *file) {
115116 }
116117 #endif /* EXIF_SUPPORT */
117118
118−#ifdef GIF_SUPPORT
119+#if GIF_SUPPORT
119120 /* Originally based on, but in its current form merely inspired by Imlib2's
120121 * src/modules/loaders/loader_gif.c:load(), written by Carsten Haitzler.
121122 */
@@ -301,11 +302,11 @@ bool img_load(img_t *img, const fileinfo_t *file) {
301302 /* avoid unused-but-set-variable warning */
302303 (void) fmt;
303304
304−#ifdef EXIF_SUPPORT
305+#if EXIF_SUPPORT
305306 if (!strcmp(fmt, "jpeg"))
306307 exif_auto_orientate(file);
307308 #endif
308−#ifdef GIF_SUPPORT
309+#if GIF_SUPPORT
309310 if (!strcmp(fmt, "gif"))
310311 img_load_gif(img, file);
311312 #endif
M options.c View
@@ -17,6 +17,7 @@
1717 */
1818
1919 #define _POSIX_C_SOURCE 200112L
20+#define _FEATURE_CONFIG
2021 #define _IMAGE_CONFIG
2122
2223 #include <stdlib.h>
@@ -39,12 +40,12 @@ void print_usage() {
3940 void print_version() {
4041 printf("sxiv %s - Simple X Image Viewer\n", VERSION);
4142 printf("Additional features included (+) or not (-): %s, %s\n",
42−#ifdef EXIF_SUPPORT
43+#if EXIF_SUPPORT
4344 "+exif",
4445 #else
4546 "-exif",
4647 #endif
47−#ifdef GIF_SUPPORT
48+#if GIF_SUPPORT
4849 "+gif"
4950 #else
5051 "-gif"
M thumbs.c View
@@ -17,6 +17,7 @@
1717 */
1818
1919 #define _POSIX_C_SOURCE 200112L
20+#define _FEATURE_CONFIG
2021 #define _THUMBS_CONFIG
2122
2223 #include <stdlib.h>
@@ -30,7 +31,7 @@
3031 #include "util.h"
3132 #include "config.h"
3233
33−#ifdef EXIF_SUPPORT
34+#if EXIF_SUPPORT
3435 void exif_auto_orientate(const fileinfo_t*);
3536 #endif
3637
@@ -252,7 +253,7 @@ bool tns_load(tns_t *tns, int n, const fileinfo_t *file,
252253 /* avoid unused-but-set-variable warning */
253254 (void) fmt;
254255
255−#ifdef EXIF_SUPPORT
256+#if EXIF_SUPPORT
256257 if (!cache_hit && !strcmp(fmt, "jpeg"))
257258 exif_auto_orientate(file);
258259 #endif