nsxivdad06c7
Much nicer handling of compile-time features
- *_SUPPORT enabled in config.h - XLIBS helper app prints lib flags needed for current settings
+73 −57
8 files changed
- M .gitignore +1 −0
- M Makefile +10 −13
- M README.md +9 −29
- A XLIBS.c +23 −0
- M config.def.h +12 −0
- M image.c +12 −11
- M options.c +3 −2
- M thumbs.c +3 −2
| @@ -1,3 +1,4 @@ | |||
| 1 | + | XLIBS | |
| 1 | 2 | config.h | |
| 2 | 3 | *.o | |
| 3 | 4 | sxiv | |
| @@ -5,10 +5,6 @@ CFLAGS = -Wall -pedantic -O2 | |||
| 5 | 5 | LDFLAGS = | |
| 6 | 6 | LIBS = -lX11 -lImlib2 | |
| 7 | 7 | ||
| 8 | − | XFLAGS = | |
| 9 | − | XLIBS = | |
| 10 | − | ||
| 11 | − | DESTDIR = | |
| 12 | 8 | PREFIX = /usr/local | |
| 13 | 9 | MANPREFIX = $(PREFIX)/share/man | |
| 14 | 10 | ||
| @@ -22,33 +18,34 @@ options: | |||
| 22 | 18 | @echo "CC = $(CC)" | |
| 23 | 19 | @echo "CFLAGS = $(CFLAGS)" | |
| 24 | 20 | @echo "LDFLAGS = $(LDFLAGS)" | |
| 25 | − | @echo "XFLAGS = $(XFLAGS)" | |
| 26 | − | @echo "XLIBS = $(XLIBS)" | |
| 27 | 21 | @echo "PREFIX = $(PREFIX)" | |
| 28 | 22 | ||
| 29 | 23 | .c.o: | |
| 30 | 24 | @echo "CC $<" | |
| 31 | − | @$(CC) $(CFLAGS) $(XFLAGS) -DVERSION=\"$(VERSION)\" -c -o $@ $< | |
| 25 | + | @$(CC) $(CFLAGS) -DVERSION=\"$(VERSION)\" -c -o $@ $< | |
| 26 | + | ||
| 27 | + | $(OBJ) XLIBS: Makefile config.h | |
| 32 | 28 | ||
| 33 | − | $(OBJ): Makefile config.h | |
| 29 | + | XLIBS: XLIBS.c | |
| 30 | + | @$(CC) $(CFLAGS) -o $@ $@.c | |
| 34 | 31 | ||
| 35 | 32 | config.h: | |
| 36 | 33 | @echo "creating $@ from config.def.h" | |
| 37 | 34 | @cp config.def.h $@ | |
| 38 | 35 | ||
| 39 | − | sxiv: $(OBJ) | |
| 36 | + | sxiv: $(OBJ) XLIBS | |
| 40 | 37 | @echo "CC -o $@" | |
| 41 | − | @$(CC) $(LDFLAGS) -o $@ $(OBJ) $(LIBS) $(XLIBS) | |
| 38 | + | @$(CC) $(LDFLAGS) -o $@ $(OBJ) $(LIBS) $$(./XLIBS) | |
| 42 | 39 | ||
| 43 | 40 | clean: | |
| 44 | 41 | @echo "cleaning" | |
| 45 | − | @rm -f $(OBJ) sxiv sxiv-$(VERSION).tar.gz | |
| 42 | + | @rm -f $(OBJ) XLIBS sxiv sxiv-$(VERSION).tar.gz | |
| 46 | 43 | ||
| 47 | 44 | dist: clean | |
| 48 | 45 | @echo "creating dist tarball" | |
| 49 | 46 | @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) | |
| 52 | 49 | @tar -cf sxiv-$(VERSION).tar sxiv-$(VERSION) | |
| 53 | 50 | @gzip sxiv-$(VERSION).tar | |
| 54 | 51 | @rm -rf sxiv-$(VERSION) | |
| @@ -8,7 +8,7 @@ Its code base should be kept small and clean to make it easy for you to dig | |||
| 8 | 8 | into it and customize it for your needs. | |
| 9 | 9 | ||
| 10 | 10 | Features | |
| 11 | − | ======== | |
| 11 | + | -------- | |
| 12 | 12 | ||
| 13 | 13 | * Basic image operations, e.g. zooming, panning, rotating | |
| 14 | 14 | * Customizable key and mouse button mappings (in *config.h*) | |
| @@ -17,14 +17,13 @@ Features | |||
| 17 | 17 | * Basic support for multi-frame images | |
| 18 | 18 | * Display image information in window title | |
| 19 | 19 | ||
| 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*): | |
| 22 | 21 | ||
| 23 | − | * Play GIF animations | |
| 22 | + | * Load all frames from GIF files and play GIF animations | |
| 24 | 23 | * Auto-orientate JPEG images according to their EXIF tags | |
| 25 | 24 | ||
| 26 | 25 | Screenshots | |
| 27 | − | =========== | |
| 26 | + | ----------- | |
| 28 | 27 | ||
| 29 | 28 | Image mode: | |
| 30 | 29 | ||
| @@ -35,7 +34,7 @@ Thumbnail mode: | |||
| 35 | 34 | <img src="http://github.com/muennich/sxiv/raw/master/sample/thumb.png"> | |
| 36 | 35 | ||
| 37 | 36 | Installation | |
| 38 | − | ============ | |
| 37 | + | ------------ | |
| 39 | 38 | sxiv is built using the commands: | |
| 40 | 39 | ||
| 41 | 40 | $ make | |
| @@ -45,35 +44,16 @@ Please note, that the latter one requires root privileges. | |||
| 45 | 44 | By default, sxiv is installed using the prefix "/usr/local", so the full path | |
| 46 | 45 | of the executable will be "/usr/local/bin/sxiv". | |
| 47 | 46 | ||
| 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 | |
| 49 | 48 | command to: | |
| 50 | 49 | ||
| 51 | 50 | # make PREFIX="/your/dir" install | |
| 52 | 51 | ||
| 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. | |
| 74 | 54 | ||
| 75 | 55 | Usage | |
| 76 | − | ===== | |
| 56 | + | ----- | |
| 77 | 57 | sxiv has two modes of operation: image and thumbnail mode. The default is | |
| 78 | 58 | image mode, in which only the current image is shown. In thumbnail mode a grid | |
| 79 | 59 | of small previews is displayed, making it easy to choose an image to open. | |
| @@ -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 | + | } | |
| @@ -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 | |
| 1 | 13 | #ifdef _WINDOW_CONFIG | |
| 2 | 14 | ||
| 3 | 15 | /* default window dimensions (overwritten via -g option): */ | |
| @@ -17,26 +17,27 @@ | |||
| 17 | 17 | */ | |
| 18 | 18 | ||
| 19 | 19 | #define _POSIX_C_SOURCE 200112L | |
| 20 | + | #define _FEATURE_CONFIG | |
| 20 | 21 | #define _IMAGE_CONFIG | |
| 21 | 22 | ||
| 22 | 23 | #include <string.h> | |
| 23 | 24 | #include <unistd.h> | |
| 24 | 25 | ||
| 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 | |
| 26 | 32 | #include <libexif/exif-data.h> | |
| 27 | 33 | #endif | |
| 28 | 34 | ||
| 29 | − | #ifdef GIF_SUPPORT | |
| 35 | + | #if GIF_SUPPORT | |
| 30 | 36 | #include <stdlib.h> | |
| 31 | 37 | #include <sys/types.h> | |
| 32 | 38 | #include <gif_lib.h> | |
| 33 | 39 | #endif | |
| 34 | 40 | ||
| 35 | − | #include "image.h" | |
| 36 | − | #include "options.h" | |
| 37 | − | #include "util.h" | |
| 38 | − | #include "config.h" | |
| 39 | − | ||
| 40 | 41 | #define ZOOMDIFF(z1,z2) ((z1) - (z2) > 0.001 || (z1) - (z2) < -0.001) | |
| 41 | 42 | ||
| 42 | 43 | enum { MIN_GIF_DELAY = 50 }; | |
| @@ -70,7 +71,7 @@ void img_init(img_t *img, win_t *win) { | |||
| 70 | 71 | } | |
| 71 | 72 | } | |
| 72 | 73 | ||
| 73 | − | #ifdef EXIF_SUPPORT | |
| 74 | + | #if EXIF_SUPPORT | |
| 74 | 75 | void exif_auto_orientate(const fileinfo_t *file) { | |
| 75 | 76 | ExifData *ed; | |
| 76 | 77 | ExifEntry *entry; | |
| @@ -115,7 +116,7 @@ void exif_auto_orientate(const fileinfo_t *file) { | |||
| 115 | 116 | } | |
| 116 | 117 | #endif /* EXIF_SUPPORT */ | |
| 117 | 118 | ||
| 118 | − | #ifdef GIF_SUPPORT | |
| 119 | + | #if GIF_SUPPORT | |
| 119 | 120 | /* Originally based on, but in its current form merely inspired by Imlib2's | |
| 120 | 121 | * src/modules/loaders/loader_gif.c:load(), written by Carsten Haitzler. | |
| 121 | 122 | */ | |
| @@ -301,11 +302,11 @@ bool img_load(img_t *img, const fileinfo_t *file) { | |||
| 301 | 302 | /* avoid unused-but-set-variable warning */ | |
| 302 | 303 | (void) fmt; | |
| 303 | 304 | ||
| 304 | − | #ifdef EXIF_SUPPORT | |
| 305 | + | #if EXIF_SUPPORT | |
| 305 | 306 | if (!strcmp(fmt, "jpeg")) | |
| 306 | 307 | exif_auto_orientate(file); | |
| 307 | 308 | #endif | |
| 308 | − | #ifdef GIF_SUPPORT | |
| 309 | + | #if GIF_SUPPORT | |
| 309 | 310 | if (!strcmp(fmt, "gif")) | |
| 310 | 311 | img_load_gif(img, file); | |
| 311 | 312 | #endif | |
| @@ -17,6 +17,7 @@ | |||
| 17 | 17 | */ | |
| 18 | 18 | ||
| 19 | 19 | #define _POSIX_C_SOURCE 200112L | |
| 20 | + | #define _FEATURE_CONFIG | |
| 20 | 21 | #define _IMAGE_CONFIG | |
| 21 | 22 | ||
| 22 | 23 | #include <stdlib.h> | |
| @@ -39,12 +40,12 @@ void print_usage() { | |||
| 39 | 40 | void print_version() { | |
| 40 | 41 | printf("sxiv %s - Simple X Image Viewer\n", VERSION); | |
| 41 | 42 | printf("Additional features included (+) or not (-): %s, %s\n", | |
| 42 | − | #ifdef EXIF_SUPPORT | |
| 43 | + | #if EXIF_SUPPORT | |
| 43 | 44 | "+exif", | |
| 44 | 45 | #else | |
| 45 | 46 | "-exif", | |
| 46 | 47 | #endif | |
| 47 | − | #ifdef GIF_SUPPORT | |
| 48 | + | #if GIF_SUPPORT | |
| 48 | 49 | "+gif" | |
| 49 | 50 | #else | |
| 50 | 51 | "-gif" | |
| @@ -17,6 +17,7 @@ | |||
| 17 | 17 | */ | |
| 18 | 18 | ||
| 19 | 19 | #define _POSIX_C_SOURCE 200112L | |
| 20 | + | #define _FEATURE_CONFIG | |
| 20 | 21 | #define _THUMBS_CONFIG | |
| 21 | 22 | ||
| 22 | 23 | #include <stdlib.h> | |
| @@ -30,7 +31,7 @@ | |||
| 30 | 31 | #include "util.h" | |
| 31 | 32 | #include "config.h" | |
| 32 | 33 | ||
| 33 | − | #ifdef EXIF_SUPPORT | |
| 34 | + | #if EXIF_SUPPORT | |
| 34 | 35 | void exif_auto_orientate(const fileinfo_t*); | |
| 35 | 36 | #endif | |
| 36 | 37 | ||
| @@ -252,7 +253,7 @@ bool tns_load(tns_t *tns, int n, const fileinfo_t *file, | |||
| 252 | 253 | /* avoid unused-but-set-variable warning */ | |
| 253 | 254 | (void) fmt; | |
| 254 | 255 | ||
| 255 | − | #ifdef EXIF_SUPPORT | |
| 256 | + | #if EXIF_SUPPORT | |
| 256 | 257 | if (!cache_hit && !strcmp(fmt, "jpeg")) | |
| 257 | 258 | exif_auto_orientate(file); | |
| 258 | 259 | #endif | |