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
*.o
sxiv

View File

@ -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): Makefile config.h
$(OBJ) XLIBS: 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)

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.
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.

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

29
image.c
View File

@ -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 <libexif/exif-data.h>
#endif
#ifdef 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"
#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)
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

View File

@ -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"

View File

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