From 81cfbf171dfd11c6f8a4d277159ee077b5ca0255 Mon Sep 17 00:00:00 2001 From: Bert Date: Tue, 13 Sep 2011 10:08:35 +0200 Subject: [PATCH] Renamed XLIBS to config, added -D/-l options --- .gitignore | 2 +- Makefile | 12 ++++++------ XLIBS.c | 23 ----------------------- config.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 52 insertions(+), 30 deletions(-) delete mode 100644 XLIBS.c create mode 100644 config.c diff --git a/.gitignore b/.gitignore index cfb39e4..4fa5841 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ -XLIBS +config config.h *.o sxiv diff --git a/Makefile b/Makefile index dd1c87b..590c391 100644 --- a/Makefile +++ b/Makefile @@ -24,27 +24,27 @@ options: @echo "CC $<" @$(CC) $(CFLAGS) -DVERSION=\"$(VERSION)\" -c -o $@ $< -$(OBJ) XLIBS: Makefile config.h +$(OBJ) config: Makefile config.h -XLIBS: XLIBS.c +config: config.c @$(CC) $(CFLAGS) -o $@ $@.c config.h: @echo "creating $@ from config.def.h" @cp config.def.h $@ -sxiv: $(OBJ) XLIBS +sxiv: $(OBJ) config @echo "CC -o $@" - @$(CC) $(LDFLAGS) -o $@ $(OBJ) $(LIBS) $$(./XLIBS) + @$(CC) $(LDFLAGS) -o $@ $(OBJ) $(LIBS) $$(./config -l) clean: @echo "cleaning" - @rm -f $(OBJ) XLIBS sxiv sxiv-$(VERSION).tar.gz + @rm -f $(OBJ) config sxiv sxiv-$(VERSION).tar.gz dist: clean @echo "creating dist tarball" @mkdir -p sxiv-$(VERSION) - @cp LICENSE Makefile README.md config.def.h sxiv.1 $(SRC) XLIBS.c \ + @cp LICENSE Makefile README.md config.def.h sxiv.1 $(SRC) config.c \ sxiv-$(VERSION) @tar -cf sxiv-$(VERSION).tar sxiv-$(VERSION) @gzip sxiv-$(VERSION).tar diff --git a/XLIBS.c b/XLIBS.c deleted file mode 100644 index 14dc1e1..0000000 --- a/XLIBS.c +++ /dev/null @@ -1,23 +0,0 @@ -#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.c b/config.c new file mode 100644 index 0000000..51da7db --- /dev/null +++ b/config.c @@ -0,0 +1,45 @@ +#define _POSIX_C_SOURCE 200112L +#define _FEATURE_CONFIG + +#include +#include + +#include "config.h" + +#define QUOTE(m) #m +#define PUT_MACRO(m) \ + printf("%s-D%s=%s", n++ ? " " : "", #m, QUOTE(m)) + +int n = 0; + +inline void puts_if(const char *s, int c) { + if (c) + printf("%s%s", n++ ? " " : "", s); +} + +inline void endl() { + if (n) { + printf("\n"); + n = 0; + } +} + +int main(int argc, char **argv) { + int i; + + for (i = 1; i < argc; i++) { + if (!strcmp(argv[i], "-D")) { + PUT_MACRO(EXIF_SUPPORT); + PUT_MACRO(GIF_SUPPORT); + endl(); + } else if (!strcmp(argv[i], "-l")) { + puts_if("-lexif", EXIF_SUPPORT); + puts_if("-lgif", GIF_SUPPORT); + endl(); + } else { + fprintf(stderr, "%s: invalid argument: %s\n", argv[0], argv[i]); + return 1; + } + } + return 0; +}