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): 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)
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:
    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 
+
+#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 
 #include 
 
-#ifdef EXIF_SUPPORT
-#include 
-#endif
-
-#ifdef GIF_SUPPORT
-#include 
-#include 
-#include 
-#endif
-
 #include "image.h"
 #include "options.h"
 #include "util.h"
 #include "config.h"
 
+#if EXIF_SUPPORT
+#include 
+#endif
+
+#if GIF_SUPPORT
+#include 
+#include 
+#include 
+#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
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 
@@ -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 
@@ -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
 
 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 
+
+#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 
 #include 
 
-#ifdef EXIF_SUPPORT
-#include 
-#endif
-
-#ifdef GIF_SUPPORT
-#include 
-#include 
-#include 
-#endif
-
 #include "image.h"
 #include "options.h"
 #include "util.h"
 #include "config.h"
 
+#if EXIF_SUPPORT
+#include 
+#endif
+
+#if GIF_SUPPORT
+#include 
+#include 
+#include 
+#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
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 
@@ -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 
@@ -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