Commits

Anonymous committed a127bf4

Support 'make configure'.

Comments (0)

Files changed (4)

 
 2. CONFIGURATION
 
-mirage2iso doesn't come with any configure script. Basically,
-Makefile directly gathers information about libmirage from pkg-config.
-
 If you don't have pkg-config or libmirage < 1.2 installed, expect
 standard compilation failure with some less or more readable output.
 
-By default, mirage2iso uses GNU & POSIX C extensions. You can disable
-them by either defining NO_GNU, NO_BSD or NO_POSIX (each next implies
-previous one). You can disable only specific features too using
-following defines:
-	-DNO_GETOPT_LONG (GNU)
+You can either let mirage2iso's Makefile shortly determine few
+capabilites of your system by calling:
+	$ make configure
+or directly provide correct defines as CPPFLAGS to make. You can use
+following defines to disable particular features:
+	-DNO_GETOPT_LONG (GNU extension)
 		disable use of getopt_long() in favor of internal parser
 	-DNO_SYSEXITS (BSD)
 		disable use of <sysexits.h> header in favor of hardcoded values
 	-DNO_MMAPIO (POSIX)
 		disable use of ftruncate() and mmap() to get mmaped I/O
 
+You can use -DNO_GNU, -DNO_BSD and -DNO_POSIX too, to disable all
+functions which require given standard. Note that disabling POSIX
+implies disabling BSD&GNU extensions too, and diabling BSD implies
+disabling GNU.
+
 
 3. COMPILATION
 
 It's all just plain make. It uses following variables either provided
 in command-line or gathered from environment:
-	CC, CFLAGS, CPPFLAGS, LDFLAGS
+	CC, CFLAGS, LDFLAGS
 
 If your environment is set right, you may compile it by calling:
 	$ make
 
-As CPPFLAGS mostly isn't rather defined globally, you should use it
-to define compile options, like:
+If you didn't use 'make configure', you should use CPPFLAGS to define
+compile options like:
 	$ make CPPFLAGS='-DNO_POSIX'
-to compile on non-POSIX systems.
+to compile on non-POSIX systems. Note that if you want to use
+'configure' results, you have to either leave CPPFLAGS undefined
+or specify '-DUSE_CONFIG' within.
 
 
 4. INSTALLATION
 MIRAGE_CPPFLAGS = $$(pkg-config --cflags libmirage)
 MIRAGE_LDFLAGS = $$(pkg-config --libs-only-L --libs-only-other libmirage)
 MIRAGE_LIBS = $$(pkg-config --libs-only-l libmirage)
+CPPFLAGS = $$([ -f mirage-config.h ] && echo -DUSE_CONFIG)
 
 PROG = mirage2iso
 OBJS = mirage-getopt.o mirage-wrapper.o
 
+CONFIGOUT = mirage-config.h
+CONFIGTESTS = check-getopt.o check-sysexits.o check-mmapio.o
+CONFIGIN = check-getopt.c check-sysexits.c check-mmapio.c
+
 DESTDIR = 
 PREFIX = /usr/local
 BINDIR = $(PREFIX)/bin
 
-.SUFFIXES = .o .c
+.SUFFIXES: .o .c
 
 all: $(PROG)
+configure: $(CONFIGOUT)
 
 $(PROG): $(PROG).c $(OBJS)
 	$(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $(MIRAGE_LDFLAGS) -o $@ $< $(OBJS) $(MIRAGE_LIBS)
 .c.o:
 	$(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $<
 
+$(CONFIGOUT):
+	make $(MAKEOPTS) -k $(CONFIGTESTS) || true
+	[ -f check-getopt.o ] || echo '#define NO_GETOPT_LONG 1' >> $@
+	[ -f check-sysexits.o ] || echo '#define NO_SYSEXITS 1' >> $@
+	[ -f check-mmapio.o ] || echo '#define NO_MMAPIO 1' >> $@
+	touch $@
+	rm -f $(CONFIGTESTS) $(CONFIGIN)
+
+check-getopt.c:
+	printf '#define _GNU_SOURCE 1\n#include <getopt.h>\nint main(int argc, char *argv[]) { getopt_long(argc, argv, "", 0, 0); return 0; }\n' > $@
+
+check-sysexits.c:
+	printf '#define _BSD_SOURCE 1\n#include <sysexits.h>\nint main(int argc, char *argv[]) { int test = EX_IOERR; return EX_OK; }\n' > $@
+
+check-mmapio.c:
+	printf '#define _POSIX_C_SOURCE 200112L\n#include <unistd.h>\n#include <sys/types.h>\n#include <sys/mman.h>\nint main(void) { ftruncate(0, 0); mmap(0, 0, 0, 0, 0, 0); }\n' > $@
+
 clean:
-	rm -f $(PROG) $(OBJS)
+	rm -f $(PROG) $(OBJS) $(CONFIGOUT)
 
 install: $(PROG)
 	umask a+rx; mkdir -p "$(DESTDIR)$(BINDIR)"
 	cp $(PROG) "$(DESTDIR)$(BINDIR)/"
 	chmod a+rx "$(DESTDIR)$(BINDIR)/$(PROG)"
 
-.PHONY: all clean install
+.PHONY: all clean configure install
  * released under 3-clause BSD license
  */
 
-#include "mirage-features.h"
+#ifdef USE_CONFIG
+#	include "mirage-config.h"
+#else
+#	include "mirage-features.h"
+#endif
+
 #include "mirage-getopt.h"
 
 #ifndef NO_GETOPT_LONG
  * released under 3-clause BSD license
  */
 
-#include "mirage-features.h"
+#ifdef USE_CONFIG
+#	include "mirage-config.h"
+#else
+#	include "mirage-features.h"
+#endif
 
 #ifndef NO_MMAPIO
 #	define _POSIX_C_SOURCE 200112L