Commits

Michał Górny committed 92afc01

Replace the buildsystem with autotools.

Comments (0)

Files changed (10)

INSTALL

-* mirage2iso install guide *
-
-
-1. PREREQUISITES
-
- * C99-capable C toolkit,
- * libmirage < 1.2,
- * pkg-config.
-
-
-2. CONFIGURATION
-
-If you don't have pkg-config or libmirage < 1.2 installed, expect
-standard compilation failure with some less or more readable output.
-
-Use 'configure' script to determine system capabilities, configure
-the build and create the Makefile:
-	$ ./configure
-
-To get list of options that configure accepts, use:
-	$ ./configure --help
-
-
-3. COMPILATION
-
-It's all just plain make. It uses following variables either provided
-in command-line or gathered from environment:
-	CC, CFLAGS, LDFLAGS
-
-If your environment is set right, you can compile m2i by calling:
-	$ make
-
-
-4. INSTALLATION
-
-The Makefile provides an 'install' target which installs the binary
-in the appropriate directory. By default, that is '/usr/local'; you may
-fine-tune the install prefix using '--prefix' option to configure
-script. You can also install m2i into fake root using DESTDIR macro.
-
-To simply install:
-	# make install
-
-If you're going to create a package you would probably use:
-	# make DESTDIR="${D}" install
-instead, where "${D}" is the fake root dir.
-
-
-* (c) 2009 Michał Górny, released under 3-clause BSD license *
+bin_PROGRAMS = mirage2iso
+
+mirage2iso_SOURCES = mirage2iso.c mirage-compat.h mirage-getopt.c mirage-getopt.h \
+	mirage-password.c mirage-password.h mirage-wrapper.c mirage-wrapper.h
+mirage2iso_LDADD = $(LIBMIRAGE_LIBS) $(LIBASSUAN_LIBS)
+mirage2iso_CPPFLAGS = $(LIBMIRAGE_CFLAGS) $(LIBASSUAN_CFLAGS)

Makefile.in

-.PHONY: check
-
-check: default tests/Makefile
-	[ ! -f tests/Makefile ] || { cd tests; $(MAKE) -k MIRAGE2ISO=../mirage2iso tests && echo 'All tests succeeded.' || { echo; echo "$$(wc -l < tests-failed) of $$(wc -l < tests-list) tests failed. Failed tests are:"; cat tests-failed; echo; false; }; }
-
-tests/Makefile: tests/tests-list tests/tests-gen.awk
-	awk -f tests/tests-gen.awk < $< > $@

configure

-#!/bin/sh
-# mirage2iso
-# (c) 2009/10 Michał Górny
-# Released under the terms of the 3-clause BSD license.
-
-PN=mirage2iso
-PV=0.3
-FC_API_WANT=0
-
-FC_CONFIG_H=mirage-config.h
-FC_MAKEFILE_IN=Makefile.in
-
-conf_init() {
-	fc_inherit cc install
-	fc_export_functions \
-		conf_get_targets \
-		conf_check_results \
-		conf_get_exports \
-		conf_help \
-		conf_arg_parse
-}
-
-conf_get_targets() {
-	# post command-line parsing tasks
-
-	: ${WITH_ASSUAN:=1}
-	: ${ENABLE_LFS:=1}
-
-	if ! pkg-config --exists libmirage; then
-		echo "Your pkg-config is unable to find libmirage." >&2
-		echo >&2
-		echo "To be able to build mirage2iso, you need to have both pkg-config" >&2
-		echo "and libmirage with development headers installed." >&2
-		exit 1
-	else
-		echo 'libmirage found.' >&2
-	fi
-
-	# configuration tests
-
-	fc_cc_try_link getopt \
-		'#define _GNU_SOURCE 1\n#include <getopt.h>' \
-		'getopt_long(argc, argv, "", 0, 0); return 0;'
-	fc_cc_try_link sysexits \
-		'#include <sysexits.h>' \
-		'return EX_OK + EX_IOERR;'
-	fc_cc_try_link mmapio \
-		'#define _POSIX_C_SOURCE 200112L\n#include <unistd.h>\n#include <sys/types.h>\n#include <sys/mman.h>' \
-		'return (ftruncate(0, 0) || mmap(0, 0, 0, 0, 0, 0) == MAP_FAILED);'
-	fc_cc_try_link falloc \
-		'#define _POSIX_C_SOURCE 200112L\n#include <fcntl.h>' \
-		'return fallocate(0, 0, 0);'
-	fc_cc_try_link termios \
-		'#define _POSIX_C_SOURCE 200112L\n#include <stdio.h>\n#include <termios.h>\n#include <unistd.h>' \
-		'struct termios term; return tcgetattr(fileno(stdin), &term);'
-
-	if [ ${WITH_ASSUAN} -eq 1 ]; then
-		# We allow libassuan-config to fail, and fallback to '-lassuan' then.
-
-		local libs
-		libs=$(libassuan-config --libs 2>/dev/null)
-		: ${libs:=-lassuan} # fallback
-
-		fc_export ASSUAN_CPPFLAGS "$(libassuan-config --cflags 2>/dev/null)"
-		fc_export ASSUAN_LIBS "${libs}"
-
-		fc_cc_try_link assuan \
-			'#define _ISO_C99_SOURCE 1\n#include <assuan.h>' \
-			'assuan_context_t ctx; assuan_error_t ret = assuan_pipe_connect(&ctx, "/bin/true", 0, 0); assuan_disconnect(ctx); return ret;' \
-			'$(ASSUAN_CPPFLAGS)' '$(ASSUAN_LIBS)'
-		fc_cc_try_link assuan2 \
-			'#define _ISO_C99_SOURCE 1\n#include <gpg-error.h>\n#include <assuan.h>' \
-			'assuan_context_t ctx; assuan_new(&ctx); gpg_error_t ret = assuan_pipe_connect(ctx, "/bin/true", 0, 0, 0, 0, 0); assuan_release(ctx); return ret;' \
-			'$(ASSUAN_CPPFLAGS)' '$(ASSUAN_LIBS)'
-	fi
-
-	if [ ${ENABLE_LFS} -eq 1 ]; then
-		touch lfs-enabled
-	fi
-
-	# actual targets
-
-	fc_cc_build ${PN} 'mirage2iso.c mirage-getopt.c mirage-wrapper.c mirage-password.c' \
-		'$(CONF_CPPFLAGS)' '$(CONF_LIBS)' '$(CONF_LDFLAGS)'
-
-	fc_install '$(DOCDIR)' NEWS README
-	fc_install_exe '$(BINDIR)' ${PN}
-
-	# subdirs
-
-	fc_add_subdir tests
-}
-
-conf_check_results() {
-	if [ -f lfs-enabled ]; then
-	    echo "Enabling Large File Support (if available)." >&2
-		fc_def _LARGEFILE_SOURCE
-		fc_def _LARGEFILE64_SOURCE
-		fc_def _FILE_OFFSET_BITS 64
-		rm -f lfs-enabled
-	fi
-
-	fc_check getopt 'getopt_long()' || fc_def NO_GETOPT_LONG
-	fc_check sysexits '<sysexits.h>' || fc_def NO_SYSEXITS
-	fc_check mmapio 'mmap() & ftruncate()' || fc_def NO_MMAPIO
-	fc_check falloc 'posix_fallocate()' || fc_def NO_FALLOCATE
-	fc_check termios 'termios' || fc_def NO_TERMIOS
-	if ! fc_check assuan2 'assuan-2'; then
-		fc_def NO_ASSUAN2
-		fc_check assuan 'assuan' || fc_def NO_ASSUAN
-	fi
-}
-
-conf_get_exports() {
-	local cppflags libs
-
-	cppflags=$(pkg-config --cflags libmirage)
-	libs=$(pkg-config --libs-only-l libmirage)
-
-	if fc_check assuan2 || fc_check assuan; then
-		cppflags="${cppflags} \$(ASSUAN_CPPFLAGS)"
-		libs="${libs} \$(ASSUAN_LIBS)"
-	fi
-
-	fc_export CONF_CPPFLAGS "${cppflags}"
-	fc_export CONF_LDFLAGS "$(pkg-config --libs-only-L --libs-only-other libmirage)"
-	fc_export CONF_LIBS "${libs}"
-}
-
-conf_help() {
-	cat <<_EOF_
-	--without-assuan	Disable use of assuan
-	--disable-lfs		Disable Large File Support
-_EOF_
-}
-
-unset WITH_ASSUAN ENABLE_LFS
-
-conf_arg_parse() {
-	case "${1}" in
-		--with-assuan)
-			WITH_ASSUAN=1
-			;;
-		--without-assuan)
-			WITH_ASSUAN=0
-			;;
-		--enable-lfs)
-			ENABLE_LFS=1
-			;;
-		--disable-lfs)
-			ENABLE_LFS=0
-			;;
-		*)
-			return 0
-	esac
-
-	return 1
-}
-
-. ./fastconf.sh
+AC_PREREQ([2.60])
+AC_INIT([mirage2iso], [0.3])
+AC_CONFIG_AUX_DIR([build-aux])
+AM_INIT_AUTOMAKE([1.6 foreign dist-bzip2 no-dependencies])
+
+AC_PROG_CC_C99
+AC_USE_SYSTEM_EXTENSIONS
+PKG_CHECK_MODULES([LIBMIRAGE], [libmirage])
+AC_CHECK_FUNCS([ftruncate getopt_long mmap posix_fallocate])
+
+AC_ARG_WITH([libassuan],
+	[AS_HELP_STRING([--without-libassuan],
+		[Disable use of libassuan])])
+AS_IF([test x"$with_libassuan" != x"no"],
+	[AM_PATH_LIBASSUAN([2.0.0], [
+		AC_DEFINE([HAVE_LIBASSUAN2], [1], [Define if you have libassuan >= 2])
+		AC_DEFINE([HAVE_LIBASSUAN], [1], [Define if you have libassuan])
+	], [AM_PATH_LIBASSUAN([], [
+		AC_DEFINE([HAVE_LIBASSUAN], [1], [Define if you have libassuan])
+	])])])
+
+AC_SYS_POSIX_TERMIOS
+AS_IF([test x"$ac_cv_sys_posix_termios" = x"yes"],
+	[AC_DEFINE([HAVE_TERMIOS], [1], [Define if you have termios headers and functions])])
+
+AC_CONFIG_HEADER([mirage-config.h])
+AC_CONFIG_FILES([Makefile])
+AC_OUTPUT

fastconf.sh

-#!/bin/false
-# fastconf basic definitions file
-# Do not call directly, source within the ./configure script instead.
-# (c) 2010 Michał Górny
-# Released under the terms of the 3-clause BSD license.
-
-# PART 0
-# basic use checks
-
-# The configure script should set PN and PV to the program name
-# and version respectively before sourcing fastconf.sh, e.g.:
-#	PN=foobar
-#	PV=0.0.1
-#	. ./fastconf.sh
-
-if [ -z "${PN}" -o -z "${PV}" ]; then
-	echo 'IMPORTANT: Please set ${PN} and ${PV} in the configure script!' >&2
-
-	# We can try to guess PN but not PV.
-	if [ -z "${PN}" ]; then
-		PN=$(basename "${PWD}")
-		echo "Falling back to PN=${PN}" >&2
-	fi
-
-	if [ -z "${PV}" ]; then
-		PACKAGE=${PN}
-	else
-		PACKAGE=${PN}-${PV}
-	fi
-	echo "Guessing PACKAGE=${PACKAGE}" >&2
-else
-	PACKAGE=${PN}-${PV}
-fi
-
-# You can use FC_CONFIG_H to override the default config header file
-# name.
-: ${FC_CONFIG_H:=config.h}
-
-# The file to be appended to the Makefile. None if unset.
-: ${FC_MAKEFILE_IN}
-
-: ${FC_INSTALL_UMASK:=a+rx}
-: ${FC_INSTALL_CHMOD:=a+r}
-: ${FC_INSTALL_CHMOD_EXE:=a+rx}
-
-# PART I
-# command-line parsing
-
-# Synopsis: _fc_cmdline_unset
-# Cleans up the environment for a clean fc_cmdline_parse() call.
-_fc_cmdline_unset() {
-	unset PREFIX EXEC_PREFIX \
-		BINDIR SBINDIR LIBEXECDIR SYSCONFDIR \
-		LOCALSTATEDIR \
-		LIBDIR INCLUDEDIR DATAROOTDIR DATADIR \
-		LOCALEDIR MANDIR DOCDIR HTMLDIR
-}
-
-# Callback: conf_help
-# Optional. Called after printing the standard help message. Should
-# print additional option descriptions to stdout, and return true.
-# stderr is dropped. If conf_help() succeeds, _fc_cmdline_help() prints
-# additional blank line afterwards.
-
-# Synopsis: _fc_cmdline_help
-# Print the help message for command-line options.
-_fc_cmdline_help() {
-	cat <<_EOF_
-Synopsis:
-	./configure [options]
-
-Options:
-	--prefix=DIR		Prefix used to install arch-independent files
-				(\${PREFIX}, default: /usr/local)
-	--exec-prefix=DIR	Prefix used to install arch-dependent files
-				(\${EXEC_PREFIX}, default: \${PREFIX})
-
-	--bindir=DIR		Path to install user binaries
-				(default: \${EXEC_PREFIX}/bin)
-	--sbindir=DIR		Path to install system admin binaries
-				(default: \${EXEC_PREFIX}/sbin)
-	--libexecdir=DIR	Path to install program executables
-				(default: \${EXEC_PREFIX}/libexec)
-	--sysconfdir=DIR	Path to install read-only local data (config)
-				(default: \${PREFIX}/etc)
-	--localstatedir=DIR	Path to install writable local data
-				(default: \${PREFIX}/var)
-	--libdir=DIR		Path to install libraries
-				(default: \${EXEC_PREFIX}/lib)
-	--includedir=DIR	Path to install C header files
-				(default: \${PREFIX}/include)
-	--datarootdir=DIR	Path to install read-only system data
-				(\${DATAROOTDIR}, default: \${PREFIX}/share)
-	--datadir=DIR		Path to install read-only program data
-				(default: \${DATAROOTDIR})
-	--localedir=DIR		Path to install locale data
-				(default: \${DATAROOTDIR}/locale)
-	--mandir=DIR		Path to install manpages
-				(default: \${DATAROOTDIR}/man)
-	--docdir=DIR		Path to install documentation (\${DOCDIR},
-				 default: \${DATAROOTDIR}/doc/\${PACKAGE})
-	--htmldir=DIR		Path to install HTML docs
-				(default: \${DOCDIR})
-
-_EOF_
-
-	conf_help 2>/dev/null && echo
-}
-
-# Callback: conf_arg_parse "${@}"
-# Mandatory. Is called by fc_cmdline_parse() for unknown options,
-# passing the remaining command-line as the argument. This function
-# should return true if the option was parsed, false otherwise.
-
-# Synopsis: _fc_cmdline_parse "${@}"
-# Parses the passed command-line arguments, preserving the original
-# argv.
-_fc_cmdline_parse() {
-	while [ ${#} -gt 0 ]; do
-		case "${1}" in
-			--create-config=*)
-				_fc_create_config "${1#--create-config=}"
-				exit 0
-				;;
-			--make=*)
-				_fc_build "${1#--make=}"
-				exit ${?}
-				;;
-			--prefix=*)
-				PREFIX=${1#--prefix=}
-				;;
-			--exec-prefix=*)
-				EXEC_PREFIX=${1#--exec-prefix=}
-				;;
-			--bindir=*)
-				BINDIR=${1#--bindir=}
-				;;
-			--sbindir=*)
-				SBINDIR=${1#--sbindir=}
-				;;
-			--libexecdir=*)
-				LIBEXECDIR=${1#--libexecdir=}
-				;;
-			--sysconfdir=*)
-				SYSCONFDIR=${1#--sysconfdir=}
-				;;
-			--localstatedir=*)
-				LOCALSTATEDIR=${1#--localstatedir=}
-				;;
-			--libdir=*)
-				LIBDIR=${1#--libdir=}
-				;;
-			--includedir=*)
-				INCLUDEDIR=${1#--includedir=}
-				;;
-			--datarootdir=*)
-				DATAROOTDIR=${1#--datarootdir=}
-				;;
-			--datadir=*)
-				DATADIR=${1#--datadir=}
-				;;
-			--localedir=*)
-				LOCALEDIR=${1#--localedir=}
-				;;
-			--mandir=*)
-				MANDIR=${1#--mandir=}
-				;;
-			--docdir=*)
-				DOCDIR=${1#--docdir=}
-				;;
-			--htmldir=*)
-				HTMLDIR=${1#--htmldir=}
-				;;
-			--help)
-				_fc_cmdline_help
-				exit 1
-				;;
-			*)
-				# XXX: support argument shifting in conf_arg_parse()
-				if conf_arg_parse "${@}"; then
-					# autoconf lists more than a single option here if applicable
-					# but it's easier for us to print them one-by-one
-					# and we keep the form to satisfy portage's QA checks
-					echo "configure: WARNING: unrecognized options: ${1}" >&2
-				fi
-		esac
-
-		shift
-	done
-}
-
-# Callback: conf_cmdline_parsed
-# Mandatory. Called when command-line parsing is done. Should setup
-# local defaults and parse the results.
-
-# Synopsis: _fc_cmdline_default
-# Set default paths for directories not matched by _fc_cmdline_parse().
-_fc_cmdline_default() {
-	: ${PREFIX=/usr/local}
-	: ${EXEC_PREFIX=\$(PREFIX)}
-
-	: ${BINDIR=\$(EXEC_PREFIX)/bin}
-	: ${SBINDIR=\$(EXEC_PREFIX)/sbin}
-	: ${LIBEXECDIR=\$(EXEC_PREFIX)/libexec}
-	: ${SYSCONFDIR=\$(PREFIX)/etc}
-	: ${LOCALSTATEDIR=\$(PREFIX)/var}
-	: ${LIBDIR=\$(EXEC_PREFIX)/lib}
-	: ${INCLUDEDIR=\$(PREFIX)/include}
-	: ${DATAROOTDIR=\$(PREFIX)/share}
-	: ${DATADIR=\$(DATADIR)}
-	: ${LOCALEDIR=\$(DATAROOTDIR)/locale}
-	: ${MANDIR=\$(DATAROOTDIR)/man}
-	: ${DOCDIR=\$(DATAROOTDIR)/doc/${PACKAGE}}
-	: ${HTMLDIR=\$(DOCDIR)}
-}
-
-# PART II
-# System checks support
-
-# Synopsis: _fc_mkrule_code <name> <includes> <code>
-# Output a Makefile rule creating a simple C program code using passed
-# <includes> and <code>. The program would take the form of:
-#	<includes>
-#	int main(int argc, char *argv[]) { <code> }
-# where <includes> and <code> can contain escapes and apostrophes have
-# to be escaped.
-_fc_cc_mkrule_code() {
-	printf "%s.c:\n\t@printf '%%b%s { %%b }%s' '%s' '%s' > \$@\n" \
-		"${1}" '\nint main(int argc, char *argv[])' '\n' "${2}" "${3}"
-}
-
-# Synopsis: _fc_mkcall_compile <infiles> [<cppflags>]
-_fc_cc_mkcall_compile() {
-	printf '\t%s %s %s %s\n' \
-		'$(CC) -c $(CFLAGS) $(CPPFLAGS)' "${2}" \
-		'-o $@' "${1}"
-}
-# Synopsis: _fc_mkcall_link <infiles> [<cppflags>] [<libs>] [<ldflags>]
-_fc_cc_mkcall_link() {
-	printf '\t%s %s %s %s %s %s %s\n' \
-		'$(CC) $(CFLAGS) $(CPPFLAGS)' "${2}" "${4}" \
-		'$(LDFLAGS) -o $@' "${1}" \
-		'$(LIBS)' "${3}"
-}
-
-# Synopsis: _fc_mkrule_compile_and_link <name> [<cppflags>] [<libs>] [<ldflags>]
-_fc_cc_mkrule_compile_and_link() {
-	printf "%s: %s.c\n" "${1}" "${1}"
-	_fc_cc_mkcall_link '$<' "${2}" "${3}" "${4}"
-}
-
-# Synopsis: _fc_append_test <name>
-_fc_append_test() {
-	FC_TESTLIST=${FC_TESTLIST+${FC_TESTLIST} }${1}
-}
-
-# Synopsis: _fc_append_source <name.c>
-_fc_append_source() {
-	FC_TESTLIST_SOURCES=${FC_TESTLIST_SOURCES+${FC_TESTLIST_SOURCES} }${1}
-}
-
-# Synopsis: fc_cc_try_link <name> <includes> <code> [<cppflags>] [<libs>] [<ldflags>]
-# Output a Makefile rule trying to link a test program <name>, passing
-# <cppflags>, <ldflags> and <libs> to the compiler. For the description
-# of <includes> and <code> see _fc_mkrule_code().
-fc_cc_try_link() {
-	_fc_cc_mkrule_code "check-${1}" "${2}" "${3}"
-	_fc_cc_mkrule_compile_and_link "check-${1}" "${4}" "${5}" "${6}"
-	echo
-
-	_fc_append_test "check-${1}"
-	_fc_append_source "check-${1}.c"
-}
-
-# Synopsis: fc_def <name> [<val>]
-# Output '#define <name> <val>'.
-fc_def() {
-	echo "#define ${1}${2+ ${2}}"
-}
-
-# Synopsis: fc_check <name> [<desc>]
-# Check whether the check <name> succeeded and return either true
-# or false. If <desc> is provided, print either "<desc> found"
-# or "<desc> unavailable."
-fc_check() {
-	if [ -f "check-${1}" ]; then
-		[ -n "${2}" ] && echo "${2} found." >&2
-		return 0
-	else
-		[ -n "${2}" ] && echo "${2} unavailable." >&2
-		return 1
-	fi
-}
-
-# Callback: conf_check_results
-# Called when './configure --create-config=*' is called. Should check
-# the configure results (using fc_check) and define the appropriate
-# macros for config.h file (using fc_def).
-
-# Callback: conf_get_exports
-# Called by './configure --create-config' and './configure --make'.
-# Should check the configure results and export necessary macros for
-# make (using fc_export).
-
-# Synopsis: _fc_create_config <config-file>
-# Call conf_check_results() to get the config.h file contents and write
-# them into <config-file>. Afterwards, call conf_get_exports() to get
-# the necessary make macros and append them to Makefile.
-_fc_create_config() {
-	conf_check_results > "${1}"
-	fc_export FC_EXPORTED 1 >> Makefile
-	conf_get_exports >> Makefile
-}
-
-# PART III
-# Makefile generation
-
-# Synopsis: fc_export <name> <value>
-# Write a variable/macro export for make. Can be used within
-# conf_get_targets() and conf_get_exports().
-fc_export() {
-	echo "${1}=${2}"
-}
-
-# Synopsis: _fc_append_output <name>
-_fc_append_output() {
-	FC_OUTPUTLIST=${FC_OUTPUTLIST+${FC_OUTPUTLIST} }${1}
-}
-
-# Synopsis: fc_cc_compile <src> [<cppflags>]
-# Output a Makefile rule ompiling a single source file <src> into object
-# <src%.*>.o, passing <cppflags> to the compiler.
-fc_cc_compile() {
-	local out
-	out=${1%.*}.o
-
-	echo "${out}: ${1}"
-	_fc_cc_mkcall_compile '$<' "${2}"
-	echo
-
-	_fc_append_output "${out}"
-}
-
-# Synopsis: fc_cc_link <prog> <objects> [<cppflags>] [<libs>] [<ldflags>]
-# Output a Makefile rule linking the <prog> executable from <objects>
-# object list (whitespace-delimitered), passing <cppflags>, <ldflags>
-# and <libs> to the compiler.
-fc_cc_link() {
-	echo "${1}: ${2}"
-	_fc_cc_mkcall_link "${2}" "${3}" "${4}" "${5}"
-	echo
-
-	_fc_append_output "${1}"
-}
-
-# Synopsis: fc_cc_build <prog> <sources> [<cppflags>] [<libs>] [<ldflags>]
-# Output Makefile rules compiling <sources> into object files, and then
-# linking them together as <prog>. <cppflags>, <ldflags> and <libs> will
-# be passed to the compiler as appropriate.
-fc_cc_build() {
-	local f outf
-	unset outf
-
-	for f in ${2}; do
-		fc_cc_compile ${f} "${3}"
-		outf=${outf+${outf} }${f%.*}.o
-	done
-	fc_cc_link "${1}" "${outf}" "${3}" "${4}" "${5}"
-}
-
-# Synopsis: fc_set_target <target> <prereqs>
-# Output a simple make target <target>, setting its prerequisities to
-# <prereqs>.
-fc_set_target() {
-	echo "${1}: ${2}"
-
-	FC_TARGETLIST=${FC_TARGETLIST+${FC_TARGETLIST} }${1}
-}
-
-# Synopsis: fc_add_subdir <subdir>
-# Support descending into a subdirectory <subdir> within the default
-# targets.
-fc_add_subdir() {
-	FC_SUBDIRS=${FC_SUBDIRS+${FC_SUBDIRS} }${1}
-}
-
-# Synopsis: fc_install_dir <dir>
-# Setup creating <dir> along with parent directories, making them all
-# world-readable.
-_fc_install_dir() {
-	FC_INSTALL="${FC_INSTALL}
-	umask ${FC_INSTALL_UMASK}; mkdir -p \"\$(DESTDIR)${1}\""
-}
-
-# Synopsis: fc_install_chmod <mode> <dest> <files>
-fc_install_chmod() {
-	local dest mode
-	mode=${1}
-	dest=${2}
-	shift
-	shift
-
-	_fc_install_dir "${dest}"
-	FC_INSTALL="${FC_INSTALL}
-	cp ${@} \"\$(DESTDIR)${dest}\"
-	cd \"\$(DESTDIR)${dest}\" && chmod ${mode} ${@}"
-
-	FC_INSTALL_PREREQS=${FC_INSTALL_PREREQS+${FC_INSTALL_PREREQS} }${@}
-}
-
-# Synopsis: fc_install <dest> <files>
-# Setup installing <files> into <dest>, creating parent directories if
-# necessary and making them world-readable afterwards.
-fc_install() {
-	fc_install_chmod ${FC_INSTALL_CHMOD} "${@}"
-}
-
-# Synopsis: fc_install_exe <dest> <files>
-# Setup installing <files> into <dest>, creating parent directories if
-# necessary and making them world-executable afterwards.
-fc_install_exe() {
-	fc_install_chmod ${FC_INSTALL_CHMOD_EXE} "${@}"
-}
-
-# Synopsis: _fc_build [<target>]
-# Call make to build target <target> (or the default one if no target is
-# passed), passing the necessary defines to make.
-_fc_build() {
-	local ifs_save
-	ifs_save=${IFS}
-	IFS='
-'
-	set -- "${1}" $(conf_get_exports)
-	IFS=${ifs_save}
-
-	echo make "${@}" >&2
-	make "${@}"
-}
-
-# Synopsis: _fc_setup_subdir_rules <target>
-_fc_setup_subdir_rules() {
-	local d
-
-	for d in ${FC_SUBDIRS}; do
-		printf '\t+[ ! -f "%s"/Makefile ] || { cd "%s" && make %s; }' ${d} ${d} ${1}
-	done
-}
-
-# Callback: conf_get_targets
-# Called by fc_setup_makefile() in order to get the complete target list
-# for the Makefile. This should output targets for both the configure
-# and build phases.
-
-# Synopsis: fc_setup_makefile <out> [<in>]
-# Create an actual Makefile in file <out>, appending the file <in>
-# afterwards (if supplied).
-fc_setup_makefile() {
-	unset FC_TESTLIST FC_TESTLIST_SOURCES FC_OUTPUTLIST FC_TARGETLIST \
-		FC_INSTALL FC_INSTALL_PREREQS FC_SUBDIRS
-
-	cat > "${1}" <<_EOF_
-# generated automatically by ./configure
-# please modify ./configure${2+ ${2}} instead
-
-DESTDIR =
-
-PREFIX = ${PREFIX}
-EXEC_PREFIX = ${EXEC_PREFIX}
-
-BINDIR = ${BINDIR}
-SBINDIR = ${SBINDIR}
-LIBEXECDIR = ${LIBEXECDIR}
-SYSCONFDIR = ${SYSCONFDIR}
-LOCALSTATEDIR = ${LOCALSTATEDIR}
-LIBDIR = ${LIBDIR}
-INCLUDEDIR = ${INCLUDEDIR}
-DATAROOTDIR = ${DATAROOTDIR}
-DATADIR = ${DATADIR}
-LOCALEDIR = ${LOCALEDIR}
-MANDIR = ${MANDIR}
-DOCDIR = ${DOCDIR}
-HTMLDIR = ${HTMLDIR}
-
-default: ${FC_CONFIG_H}
-	@+if [ -n "\$(FC_EXPORTED)" ]; then \$(MAKE) all; else ./configure --make=all; fi
-	@+\$(MAKE) confclean
-
-_EOF_
-
-	conf_get_targets >> "${1}"
-
-	cat - ${2} >> "${1}" <<_EOF_
-
-config:
-	@rm -f ${FC_CONFIG_H}
-	@+\$(MAKE) ${FC_CONFIG_H}
-	@+\$(MAKE) confclean
-
-${FC_CONFIG_H}:
-	@echo "** MAKE CONFIG STARTING **" >&2
-	@+\$(MAKE) confclean
-	-+\$(MAKE) -k ${FC_TESTLIST}
-	./configure --create-config=\$@
-	@echo "** MAKE CONFIG FINISHED **" >&2
-
-confclean:
-	@rm -f ${FC_TESTLIST} ${FC_TESTLIST_SOURCES}
-
-clean:
-	rm -f ${FC_OUTPUTLIST}
-$(_fc_setup_subdir_rules clean)
-
-distclean: clean confclean
-	rm -f Makefile ${FC_CONFIG_H}
-$(_fc_setup_subdir_rules distclean)
-
-.PHONY: all clean config confclean default distclean \
-	${FC_TARGETLIST} ${FC_INSTALL+install}
-
-all: ${FC_INSTALL_PREREQS}
-$(_fc_setup_subdir_rules all)
-
-${FC_INSTALL+install: default${FC_INSTALL}}
-${FC_INSTALL+$(_fc_setup_subdir_rules install)}
-_EOF_
-	rm -f ${FC_CONFIG_H}
-}
-
-# INITIALIZATION RULES
-
-_fc_cmdline_unset
-_fc_cmdline_parse "${@}"
-_fc_cmdline_default
-
-fc_setup_makefile Makefile ${FC_MAKEFILE_IN}
-exit 0
  * Released under the terms of the 3-clause BSD license.
  */
 
-#include "mirage-config.h"
+#ifdef HAVE_CONFIG_H
+#	include "mirage-config.h"
+#endif
 #include "mirage-getopt.h"
 
-#ifndef NO_GETOPT_LONG
-#	define _GNU_SOURCE 1
+#ifdef HAVE_GETOPT_LONG
 #	include <getopt.h>
-#else
-#	define _ISOC99_SOURCE 1
 #endif
 
 #include <stdlib.h>
 	return true;
 }
 
-#ifndef NO_GETOPT_LONG
+#ifdef HAVE_GETOPT_LONG
 
 short int mirage_getopt(const int argc, char* const argv[], const struct mirage_opt* const opts, union mirage_optarg_val *outval, const char* newargv[]) {
 	const struct mirage_opt *op;
  * Released under the terms of the 3-clause BSD license.
  */
 
-#include "mirage-config.h"
-
-#ifndef NO_TERMIOS
-#	define _POSIX_C_SOURCE 200112L
-#else
-#	define _ISOC99_SOURCE 1
+#ifdef HAVE_CONFIG_H
+#	include "mirage-config.h"
 #endif
 
 #include <stdlib.h>
 #include <stdbool.h>
 #include <string.h>
 
-#ifndef NO_TERMIOS
+#ifdef HAVE_TERMIOS
 #	include <termios.h>
 #	include <unistd.h>
 #endif
 
-#ifndef NO_ASSUAN
+#ifdef HAVE_LIBASSUAN
 #	include <stddef.h>
-#	ifndef NO_ASSUAN2
+#	ifdef HAVE_LIBASSUAN2
 #		include <gpg-error.h>
 #	endif
 #	include <assuan.h>
 	return true;
 }
 
-#ifndef NO_ASSUAN
+#ifdef HAVE_LIBASSUAN
 
 /* XXX: more portable solution? */
 static const char* mirage_getshell(void) {
 	return "/bin/sh";
 }
 
-#ifndef NO_ASSUAN2
+#ifdef HAVE_LIBASSUAN2
 /* this should be less risky than redefining gpg_* for assuan1 */
 
 typedef gpg_error_t assuan_error_t;
 	assuan_context_t ctx;
 	assuan_error_t err;
 
-#ifndef NO_ASSUAN2
+#ifdef HAVE_LIBASSUAN2
 	if (((err = assuan_new(&ctx))) != GPG_ERR_NO_ERROR) {
 		fprintf(stderr, "Failed to initialize libassuan: %s\n", assuan_strerror(err));
 		return error;
 #endif
 
 static bool mirage_echo(const bool newstate) {
-#ifndef NO_TERMIOS
+#ifdef HAVE_TERMIOS
 	const int fd = fileno(stdin);
 	struct termios term;
 
 	if (buf) /* password already there */
 		return buf;
 
-#ifndef NO_ASSUAN
+#ifdef HAVE_LIBASSUAN
 	switch (mirage_input_password_pinentry()) {
 		case error: break;
 		case success: return buf;
  * Released under the terms of the 3-clause BSD license.
  */
 
-#define _ISOC99_SOURCE 1
+#ifdef HAVE_CONFIG_H
+#	include "mirage-config.h"
+#endif
 
 #include <stdlib.h>
 #include <stdio.h>
  * Released under the terms of the 3-clause BSD license.
  */
 
-#include "mirage-config.h"
-
-#if !defined(NO_MMAPIO) || !defined(NO_FTRUNCATE)
-#	define _POSIX_C_SOURCE 200112L
-#else
-#	define _ISOC99_SOURCE 1
+#ifdef HAVE_CONFIG_H
+#	include "mirage-config.h"
 #endif
 
 #include <stdlib.h>
 #include <string.h>
 #include <errno.h>
 
-#ifndef NO_MMAPIO
+#if defined(HAVE_FTRUNCATE) && defined(HAVE_MMAP)
 #	include <sys/types.h>
 #	include <sys/stat.h>
 #	include <sys/mman.h>
 #	include <fcntl.h>
 #	include <unistd.h>
 #else
-#	ifndef NO_FALLOCATE
+#	ifdef HAVE_FALLOCATE
 #		include <fcntl.h>
 #	endif
 #endif
 bool quiet = false;
 bool verbose = false;
 
-#ifndef NO_MMAPIO
+#if defined(HAVE_FTRUNCATE) && defined(HAVE_MMAP)
 static bool force_stdio = false;
 #endif
 
-static const char* const VERSION = "0.3";
-
 static const struct mirage_opt opts[] = {
 	{ "force", mirage_arg_none, 'f', "Force replacing guessed output file" },
 	{ "help", mirage_arg_none, '?', "Take a wild guess" },
 		perror("posix_fadvise() failed");
 #endif
 
-#ifndef NO_FALLOCATE
+#ifdef HAVE_POSIX_FALLOCATE
 	if ((errno = posix_fallocate(fd, 0, size))) {
 		perror("posix_fallocate() failed");
 
 	return true;
 }
 
-#ifndef NO_MMAPIO
+#if defined(HAVE_FTRUNCATE) && defined(HAVE_MMAP)
 static int mmapio_open(const char* const fn, const size_t size, FILE** const f, void** const out) {
 	*f = fopen(fn, "w+b");
 	if (!*f) {
 		return EX_CANTCREAT;
 	}
 
-#if !defined(NO_MMAPIO) || !defined(NO_FALLOCATE)
+#if (defined(HAVE_FTRUNCATE) && defined(HAVE_MMAP)) || defined(HAVE_POSIX_FALLOCATE)
 	if (!common_posix_filesetup(fileno(*f), size))
 		return EX_CANTCREAT;
 #endif
 		if (verbose)
 			fprintf(stderr, "Using standard output stream for track %d\n", track_num);
 	} else {
-#ifndef NO_MMAPIO
+#if defined(HAVE_FTRUNCATE) && defined(HAVE_MMAP)
 		if (!force_stdio)
 			ret = mmapio_open(fn, size, &f, &out);
 #endif
 	}
 
 	if (!miragewrap_output_track(out, track_num, f)) {
-#ifndef NO_MMAPIO
+#if defined(HAVE_FTRUNCATE) && defined(HAVE_MMAP)
 		if (out && munmap(out, size))
 			perror("munmap() failed");
 #endif
 		return EX_IOERR;
 	}
 
-#ifndef NO_MMAPIO
+#if defined(HAVE_FTRUNCATE) && defined(HAVE_MMAP)
 	if (out && munmap(out, size))
 		perror("munmap() failed");
 #endif
 				session_num = val.as_int;
 				break;
 			case 'S':
-#ifndef NO_MMAPIO
+#if defined(HAVE_FTRUNCATE) && defined(HAVE_MMAP)
 				force_stdio = true;
 #else
 				fprintf(stderr, "mirage2iso compiled without mmap support, --stdio is always on\n");
 	}
 
 	if (use_stdout) {
-#ifndef NO_MMAPIO
+#if defined(HAVE_FTRUNCATE) && defined(HAVE_MMAP)
 		if (force_stdio && !quiet)
 			fprintf(stderr, "--stdout already implies --stdio, no need to specify it\n");
 		else