Much nicer handling of compile-time features

- *_SUPPORT enabled in config.h
- XLIBS helper app prints lib flags needed for current settings
This commit is contained in:
Bert 2011-09-12 19:28:02 +02:00
parent 32a65201bb
commit dad06c7561
8 changed files with 76 additions and 60 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
XLIBS
config.h config.h
*.o *.o
sxiv sxiv

View File

@ -5,10 +5,6 @@ CFLAGS = -Wall -pedantic -O2
LDFLAGS = LDFLAGS =
LIBS = -lX11 -lImlib2 LIBS = -lX11 -lImlib2
XFLAGS =
XLIBS =
DESTDIR =
PREFIX = /usr/local PREFIX = /usr/local
MANPREFIX = $(PREFIX)/share/man MANPREFIX = $(PREFIX)/share/man
@ -22,33 +18,34 @@ options:
@echo "CC = $(CC)" @echo "CC = $(CC)"
@echo "CFLAGS = $(CFLAGS)" @echo "CFLAGS = $(CFLAGS)"
@echo "LDFLAGS = $(LDFLAGS)" @echo "LDFLAGS = $(LDFLAGS)"
@echo "XFLAGS = $(XFLAGS)"
@echo "XLIBS = $(XLIBS)"
@echo "PREFIX = $(PREFIX)" @echo "PREFIX = $(PREFIX)"
.c.o: .c.o:
@echo "CC $<" @echo "CC $<"
@$(CC) $(CFLAGS) $(XFLAGS) -DVERSION=\"$(VERSION)\" -c -o $@ $< @$(CC) $(CFLAGS) -DVERSION=\"$(VERSION)\" -c -o $@ $<
$(OBJ): Makefile config.h $(OBJ) XLIBS: Makefile config.h
XLIBS: XLIBS.c
@$(CC) $(CFLAGS) -o $@ $@.c
config.h: config.h:
@echo "creating $@ from config.def.h" @echo "creating $@ from config.def.h"
@cp config.def.h $@ @cp config.def.h $@
sxiv: $(OBJ) sxiv: $(OBJ) XLIBS
@echo "CC -o $@" @echo "CC -o $@"
@$(CC) $(LDFLAGS) -o $@ $(OBJ) $(LIBS) $(XLIBS) @$(CC) $(LDFLAGS) -o $@ $(OBJ) $(LIBS) $$(./XLIBS)
clean: clean:
@echo "cleaning" @echo "cleaning"
@rm -f $(OBJ) sxiv sxiv-$(VERSION).tar.gz @rm -f $(OBJ) XLIBS sxiv sxiv-$(VERSION).tar.gz
dist: clean dist: clean
@echo "creating dist tarball" @echo "creating dist tarball"
@mkdir -p sxiv-$(VERSION) @mkdir -p sxiv-$(VERSION)
@cp LICENSE Makefile Makefile.netbsd README.md config.def.h \ @cp LICENSE Makefile README.md config.def.h sxiv.1 $(SRC) XLIBS.c \
sxiv.1 $(SRC) sxiv-$(VERSION) sxiv-$(VERSION)
@tar -cf sxiv-$(VERSION).tar sxiv-$(VERSION) @tar -cf sxiv-$(VERSION).tar sxiv-$(VERSION)
@gzip sxiv-$(VERSION).tar @gzip sxiv-$(VERSION).tar
@rm -rf sxiv-$(VERSION) @rm -rf sxiv-$(VERSION)

View File

@ -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. into it and customize it for your needs.
Features Features
======== --------
* Basic image operations, e.g. zooming, panning, rotating * Basic image operations, e.g. zooming, panning, rotating
* Customizable key and mouse button mappings (in *config.h*) * Customizable key and mouse button mappings (in *config.h*)
@ -17,14 +17,13 @@ Features
* Basic support for multi-frame images * Basic support for multi-frame images
* Display image information in window title * Display image information in window title
Additional features, that need to be included at compile-time--see section Additional features, that need to be enabled at compile-time (in *config.h*):
*Installation* on how to enable them:
* Play GIF animations * Load all frames from GIF files and play GIF animations
* Auto-orientate JPEG images according to their EXIF tags * Auto-orientate JPEG images according to their EXIF tags
Screenshots Screenshots
=========== -----------
Image mode: Image mode:
@ -35,7 +34,7 @@ Thumbnail mode:
<img src="http://github.com/muennich/sxiv/raw/master/sample/thumb.png"> <img src="http://github.com/muennich/sxiv/raw/master/sample/thumb.png">
Installation Installation
============ ------------
sxiv is built using the commands: sxiv is built using the commands:
$ make $ 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 By default, sxiv is installed using the prefix "/usr/local", so the full path
of the executable will be "/usr/local/bin/sxiv". 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: command to:
# make PREFIX="/your/dir" install # make PREFIX="/your/dir" install
All build-time specific settings can be found in the file *config.h*. Please The build-time specific settings of sxiv can be found in the file *config.h*.
check and change them, so that they fit your needs. 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"
Usage Usage
===== -----
sxiv has two modes of operation: image and thumbnail mode. The default is 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 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. of small previews is displayed, making it easy to choose an image to open.

23
XLIBS.c Normal file
View File

@ -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;
}

View File

@ -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 #ifdef _WINDOW_CONFIG
/* default window dimensions (overwritten via -g option): */ /* default window dimensions (overwritten via -g option): */

29
image.c
View File

@ -17,26 +17,27 @@
*/ */
#define _POSIX_C_SOURCE 200112L #define _POSIX_C_SOURCE 200112L
#define _FEATURE_CONFIG
#define _IMAGE_CONFIG #define _IMAGE_CONFIG
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#ifdef EXIF_SUPPORT
#include <libexif/exif-data.h>
#endif
#ifdef GIF_SUPPORT
#include <stdlib.h>
#include <sys/types.h>
#include <gif_lib.h>
#endif
#include "image.h" #include "image.h"
#include "options.h" #include "options.h"
#include "util.h" #include "util.h"
#include "config.h" #include "config.h"
#if EXIF_SUPPORT
#include <libexif/exif-data.h>
#endif
#if GIF_SUPPORT
#include <stdlib.h>
#include <sys/types.h>
#include <gif_lib.h>
#endif
#define ZOOMDIFF(z1,z2) ((z1) - (z2) > 0.001 || (z1) - (z2) < -0.001) #define ZOOMDIFF(z1,z2) ((z1) - (z2) > 0.001 || (z1) - (z2) < -0.001)
enum { MIN_GIF_DELAY = 50 }; 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) { void exif_auto_orientate(const fileinfo_t *file) {
ExifData *ed; ExifData *ed;
ExifEntry *entry; ExifEntry *entry;
@ -115,7 +116,7 @@ void exif_auto_orientate(const fileinfo_t *file) {
} }
#endif /* EXIF_SUPPORT */ #endif /* EXIF_SUPPORT */
#ifdef GIF_SUPPORT #if GIF_SUPPORT
/* Originally based on, but in its current form merely inspired by Imlib2's /* Originally based on, but in its current form merely inspired by Imlib2's
* src/modules/loaders/loader_gif.c:load(), written by Carsten Haitzler. * 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 */ /* avoid unused-but-set-variable warning */
(void) fmt; (void) fmt;
#ifdef EXIF_SUPPORT #if EXIF_SUPPORT
if (!strcmp(fmt, "jpeg")) if (!strcmp(fmt, "jpeg"))
exif_auto_orientate(file); exif_auto_orientate(file);
#endif #endif
#ifdef GIF_SUPPORT #if GIF_SUPPORT
if (!strcmp(fmt, "gif")) if (!strcmp(fmt, "gif"))
img_load_gif(img, file); img_load_gif(img, file);
#endif #endif

View File

@ -17,6 +17,7 @@
*/ */
#define _POSIX_C_SOURCE 200112L #define _POSIX_C_SOURCE 200112L
#define _FEATURE_CONFIG
#define _IMAGE_CONFIG #define _IMAGE_CONFIG
#include <stdlib.h> #include <stdlib.h>
@ -39,12 +40,12 @@ void print_usage() {
void print_version() { void print_version() {
printf("sxiv %s - Simple X Image Viewer\n", VERSION); printf("sxiv %s - Simple X Image Viewer\n", VERSION);
printf("Additional features included (+) or not (-): %s, %s\n", printf("Additional features included (+) or not (-): %s, %s\n",
#ifdef EXIF_SUPPORT #if EXIF_SUPPORT
"+exif", "+exif",
#else #else
"-exif", "-exif",
#endif #endif
#ifdef GIF_SUPPORT #if GIF_SUPPORT
"+gif" "+gif"
#else #else
"-gif" "-gif"

View File

@ -17,6 +17,7 @@
*/ */
#define _POSIX_C_SOURCE 200112L #define _POSIX_C_SOURCE 200112L
#define _FEATURE_CONFIG
#define _THUMBS_CONFIG #define _THUMBS_CONFIG
#include <stdlib.h> #include <stdlib.h>
@ -30,7 +31,7 @@
#include "util.h" #include "util.h"
#include "config.h" #include "config.h"
#ifdef EXIF_SUPPORT #if EXIF_SUPPORT
void exif_auto_orientate(const fileinfo_t*); void exif_auto_orientate(const fileinfo_t*);
#endif #endif
@ -252,7 +253,7 @@ bool tns_load(tns_t *tns, int n, const fileinfo_t *file,
/* avoid unused-but-set-variable warning */ /* avoid unused-but-set-variable warning */
(void) fmt; (void) fmt;
#ifdef EXIF_SUPPORT #if EXIF_SUPPORT
if (!cache_hit && !strcmp(fmt, "jpeg")) if (!cache_hit && !strcmp(fmt, "jpeg"))
exif_auto_orientate(file); exif_auto_orientate(file);
#endif #endif