Blame configure

66a30d
#!/bin/sh
66a30d
# we are no longer lazy.
66a30d
66a30d
# this script respects both CFLAGS and CFLAGS_CMDLINE,
66a30d
# as well as both LDFLAGS and LDFLAGS_CMDLINE, however
66a30d
# the latter variable of each pair should be preferred.
66a30d
66a30d
usage()
66a30d
{
66a30d
	cat "$mb_project_dir"/config.usage
66a30d
	exit $?
66a30d
}
66a30d
66a30d
error_msg()
66a30d
{
66a30d
	echo "$@" >&2
66a30d
}
66a30d
66a30d
warning_msg()
66a30d
{
66a30d
	echo "$@" >&2
66a30d
}
66a30d
66a30d
66a30d
init_vars()
66a30d
{
66a30d
	mb_project_dir=$(cd "$(dirname $0)" ; pwd)
66a30d
	mb_pwd=`pwd`
66a30d
66a30d
	if [ -z "$mb_config" ]; then
66a30d
		. $mb_project_dir/config.project || exit 2
66a30d
	else
66a30d
		. "$mb_config" || exit 2
66a30d
	fi
66a30d
66a30d
	# project
66a30d
	mb_nickname=$NICKNAME
66a30d
	mb_source_dir=$SOURCE_DIR
66a30d
66a30d
	# dirs
66a30d
	mb_prefix=$PREFIX
66a30d
	mb_exec_prefix=$EXEC_PREFIX
66a30d
	mb_bindir=$BINDIR
66a30d
	mb_sbindir=$SBINDIR
66a30d
	mb_libdir=$LIBDIR
66a30d
	mb_includedir=$INCLUDEDIR
66a30d
	mb_oldincludedir=$OLDINCLUDEDIR
66a30d
	mb_mandir=$MANDIR
66a30d
	mb_docdir=$DOCDIR
66a30d
	mb_libexecdir=$LIBEXECDIR
66a30d
66a30d
	mb_sysconfdir=$SYSCONFDIR
66a30d
	mb_sharedstatedir=$SHAREDSTATEDIR
66a30d
	mb_localstatedir=$LOCALSTATEDIR
66a30d
	mb_runstatedir=$RUNSTATEDIR
66a30d
	mb_datarootdir=$DATAROOTDIR
66a30d
	mb_datadir=$DATADIR
66a30d
	mb_infodir=$INFODIR
66a30d
	mb_localedir=$LOCALEDIR
66a30d
	mb_htmldir=$HTMLDIR
66a30d
	mb_dvidir=$DVIDIR
66a30d
	mb_pdfdir=$PDFDIR
66a30d
	mb_psdir=$PSDIR
66a30d
66a30d
66a30d
	# build
66a30d
	mb_build=$BUILD
66a30d
	mb_host=$HOST
66a30d
	mb_cchost=$CCHOST
f6645d
	mb_cfghost=$CFGHOST
66a30d
	mb_target=$TARGET
66a30d
	mb_arch=$ARCH
66a30d
	mb_compiler=$COMPILER
66a30d
	mb_toolchain=$TOOLCHAIN
66a30d
	mb_sysroot=$SYSROOT
66a30d
	mb_cross_compile=$CROSS_COMPILE
66a30d
	mb_shell=$SHELL
66a30d
66a30d
	# switches
66a30d
	mb_cflags=$CFLAGS
66a30d
	mb_cflags_debug=$CFLAGS_DEBUG
66a30d
	mb_cflags_common=$CFLAGS_COMMON
66a30d
	mb_cflags_cmdline=$CFLAGS_CMDLINE
66a30d
	mb_cflags_config=$CFLAGS_CONFIG
66a30d
	mb_cflags_sysroot=$CFLAGS_SYSROOT
66a30d
	mb_cflags_os=$CFLAGS_OS
66a30d
	mb_cflags_site=$CFLAGS_SITE
66a30d
	mb_cflags_path=$CFLAGS_PATH
66a30d
	mb_cflags_strict=$CFLAGS_STRICT
66a30d
	mb_cflags_util=$CFLAGS_UTIL
66a30d
	mb_cflags_last=$CFLAGS_LAST
66a30d
	mb_cflags_once=$CFLAGS_ONCE
66a30d
66a30d
	mb_ldflags=$LDFLAGS
66a30d
	mb_ldflags_debug=$LDFLAGS_DEBUG
66a30d
	mb_ldflags_common=$LDFLAGS_COMMON
66a30d
	mb_ldflags_cmdline=$LDFLAGS_CMDLINE
66a30d
	mb_ldflags_config=$LDFLAGS_CONFIG
66a30d
	mb_ldflags_sysroot=$LDFLAGS_SYSROOT
66a30d
	mb_ldflags_path=$LDFLAGS_PATH
66a30d
	mb_ldflags_strict=$LDFLAGS_STRICT
66a30d
	mb_ldflags_util=$LDFLAGS_UTIL
66a30d
	mb_ldflags_last=$LDFLAGS_LAST
66a30d
	mb_ldflags_once=$LDFLAGS_ONCE
66a30d
66a30d
	mb_pe_subsystem=$PE_SUBSYSTEM
66a30d
	mb_pe_image_base=$PE_IMAGE_BASE
66a30d
	mb_pe_config_defs=$PE_CONFIG_DEFS
66a30d
66a30d
	mb_elf_eh_frame=$ELF_EH_FRAME
66a30d
	mb_elf_hash_style=$ELF_HASH_STYLE
66a30d
	mb_elf_config_defs=$ELF_CONFIG_DEFS
66a30d
66a30d
	# overrides
66a30d
	mb_native_cc=$NATIVE_CC
66a30d
	mb_native_os=$NATIVE_OS
66a30d
	mb_native_os_bits=$NATIVE_OS_BITS
66a30d
	mb_native_os_underscore=$NATIVE_OS_UNDERSCORE
66a30d
66a30d
	mb_user_cc=$CC
66a30d
	mb_user_cpp=$CPP
66a30d
	mb_user_cxx=$CXX
66a30d
}
66a30d
66a30d
66a30d
verify_build_directory()
66a30d
{
66a30d
	if [ "$mb_project_dir" = "$mb_pwd" ]; then
66a30d
		if [ "$mb_require_out_of_tree" = yes ]; then
66a30d
			error_msg "$mb_package: out-of-tree builds are required."
66a30d
			error_msg "please invoke configure again from a clean build directory."
66a30d
			exit 2
66a30d
		else
66a30d
			mb_project_dir='.'
66a30d
		fi
66a30d
	fi
66a30d
}
66a30d
66a30d
66a30d
verify_source_directory()
66a30d
{
66a30d
	if [ -z "$mb_source_dir" ]; then
66a30d
		if [ "$mb_require_source_dir" = yes ]; then
66a30d
			error_msg "$mb_package: specifying an external source directory is required."
66a30d
			error_msg "you can set the source directory either via --source-dir=<path>,"
66a30d
			error_msg "or by setting the SOURCE_DIR variable."
66a30d
			exit 2
66a30d
		fi
66a30d
	fi
66a30d
}
66a30d
66a30d
66a30d
common_defaults()
66a30d
{
66a30d
	# git
66a30d
	if [ -n "$mb_source_dir" ]; then
66a30d
		if [ -d "$mb_source_dir/.git" ]; then
66a30d
			mb_git_reference_index="\$(SOURCE_DIR)/.git/index"
66a30d
		fi
66a30d
	elif [ -d "$mb_project_dir/.git" ]; then
66a30d
		mb_git_reference_index="\$(PROJECT_DIR)/.git/index"
66a30d
	fi
66a30d
66a30d
	# project
66a30d
	[ -z "$mb_nickname" ] 		&& mb_nickname=$mb_package
66a30d
	[ -z "$mb_source_dir" ] 	&& mb_source_dir=$mb_project_dir
66a30d
	[ -z "$mb_avoid_version" ] 	&& mb_avoid_version='no'
66a30d
66a30d
	# pkgconfig
66a30d
	[ -z "$mb_pkgname" ]		&& mb_pkgname="$mb_default_pkgname"
66a30d
	[ -z "$mb_pkgdesc" ]		&& mb_pkgdesc="$mb_default_pkgdesc"
66a30d
	[ -z "$mb_pkgusrc" ]		&& mb_pkgusrc="$mb_default_pkgusrc"
66a30d
	[ -z "$mb_pkgrepo" ]		&& mb_pkgrepo="$mb_default_pkgrepo"
66a30d
	[ -z "$mb_pkgpsrc" ]		&& mb_pkgpsrc="$mb_default_pkgpsrc"
66a30d
	[ -z "$mb_pkgdurl" ]		&& mb_pkgdurl="$mb_default_pkgdurl"
66a30d
	[ -z "$mb_pkgdefs" ]		&& mb_pkgdefs="$mb_default_pkgdefs"
66a30d
	[ -z "$mb_pkglibs" ]		&& mb_pkglibs="$mb_default_pkglibs"
66a30d
66a30d
	# dirs
66a30d
	[ -z "$mb_prefix" ] 		&& [ -z "$mb_prefix_set" ] \
66a30d
					&& mb_prefix='/usr/local'
66a30d
66a30d
	[ -z "$mb_exec_prefix" ] 	&& [ -z "$mb_exec_prefix_set" ]	\
66a30d
					&& mb_exec_prefix=$mb_prefix
66a30d
66a30d
	[ -z "$mb_bindir" ] 		&& [ -z "$mb_bindir_set" ] \
66a30d
					&& [ -z "$mb_bindir_basename" ] \
66a30d
					&& mb_bindir=$mb_exec_prefix/bin
66a30d
66a30d
	[ -z "$mb_bindir" ] 		&& [ -z "$mb_bindir_set" ] \
66a30d
					&& mb_bindir=$mb_exec_prefix/$mb_bindir_basename
66a30d
66a30d
	[ -z "$mb_sbindir" ] 		&& mb_sbindir=$mb_exec_prefix/sbin
66a30d
	[ -z "$mb_libdir" ] 		&& mb_libdir=$mb_exec_prefix/lib
66a30d
	[ -z "$mb_includedir" ]		&& mb_includedir=$mb_prefix/include
66a30d
	[ -z "$mb_oldincludedir" ]	&& mb_oldincludedir=$mb_prefix/include
66a30d
	[ -z "$mb_datarootdir" ] 	&& mb_datarootdir=$mb_prefix/share
66a30d
	[ -z "$mb_mandir" ] 		&& mb_mandir=$mb_datarootdir/man
66a30d
	[ -z "$mb_docdir" ] 		&& mb_docdir=$mb_datarootdir/doc
66a30d
	[ -z "$mb_libexecdir" ]		&& mb_libexecdir=$mb_exec_prefix/libexec
66a30d
66a30d
	[ -z "$mb_sysconfdir" ] 	&& mb_sysconfdir=$mb_exec_prefix/etc
66a30d
	[ -z "$mb_sharedstatedir" ] 	&& mb_sharedstatedir=$mb_prefix/com
66a30d
	[ -z "$mb_localstatedir" ] 	&& mb_localstatedir=$mb_prefix/var
66a30d
	[ -z "$mb_runstatedir" ] 	&& mb_runstatedir=$mb_localstatedir/run
66a30d
	[ -z "$mb_datarootdir" ] 	&& mb_datarootdir=$mb_prefix/share
66a30d
	[ -z "$mb_datadir" ] 		&& mb_datadir=$mb_datarootdir
66a30d
	[ -z "$mb_infodir" ] 		&& mb_infodir=$mb_datarootdir/info
66a30d
	[ -z "$mb_localedir" ] 		&& mb_localedir=$mb_datarootdir/locale
66a30d
	[ -z "$mb_htmldir" ] 		&& mb_htmldir=$mb_docdir
66a30d
	[ -z "$mb_dvidir" ] 		&& mb_dvidir=$mb_docdir
66a30d
	[ -z "$mb_pdfdir" ] 		&& mb_pdfdir=$mb_docdir
66a30d
	[ -z "$mb_psdir" ] 		&& mb_psdir=$mb_docdir
66a30d
66a30d
66a30d
	# build
66a30d
	[ -z "$mb_build" ] 		&& mb_build=$mb_default_build
66a30d
	[ -z "$mb_host" ] 		&& mb_host=$mb_default_host
66a30d
	[ -z "$mb_cchost" ] 		&& mb_cchost=$mb_default_cchost
f6645d
	[ -z "$mb_cfghost" ] 		&& mb_cfghost=$mb_default_cfghost
66a30d
	[ -z "$mb_target" ] 		&& mb_target=$mb_default_target
66a30d
	[ -z "$mb_arch" ] 		&& mb_arch=$mb_default_arch
66a30d
	[ -z "$mb_compiler" ] 		&& mb_compiler=$mb_default_compiler
66a30d
	[ -z "$mb_toolchain" ] 		&& mb_toolchain=$mb_default_toolchain
66a30d
	[ -z "$mb_sysroot" ] 		&& mb_sysroot=$mb_default_sysroot
66a30d
	[ -z "$mb_cross_compile" ] 	&& mb_cross_compile=$mb_default_cross_compile
66a30d
	[ -z "$mb_shell" ] 		&& mb_shell=$mb_default_shell
66a30d
66a30d
	# switches
66a30d
	[ -z "$mb_cflags_debug" ]	&& mb_cflags_debug=$mb_default_cflags_debug
66a30d
	[ -z "$mb_cflags_common" ]	&& mb_cflags_common=$mb_default_cflags_common
66a30d
	[ -z "$mb_cflags_cmdline" ]	&& mb_cflags_cmdline=$mb_default_cflags_cmdline
66a30d
	[ -z "$mb_cflags_config" ]	&& mb_cflags_config=$mb_default_cflags_config
66a30d
	[ -z "$mb_cflags_sysroot" ]	&& mb_cflags_sysroot=$mb_default_cflags_sysroot
66a30d
	[ -z "$mb_cflags_os" ]		&& mb_cflags_os=$mb_default_cflags_os
66a30d
	[ -z "$mb_cflags_site" ]	&& mb_cflags_site=$mb_default_cflags_site
66a30d
	[ -z "$mb_cflags_path" ]	&& mb_cflags_path=$mb_default_cflags_path
66a30d
	[ -z "$mb_cflags_strict" ]	&& mb_cflags_strict=$mb_default_cflags_strict
66a30d
	[ -z "$mb_cflags_util" ]	&& mb_cflags_util=$mb_default_cflags_util
66a30d
	[ -z "$mb_cflags_last" ]	&& mb_cflags_last=$mb_default_cflags_last
66a30d
	[ -z "$mb_cflags_once" ]	&& mb_cflags_once=$mb_default_cflags_once
66a30d
66a30d
	[ -z "$mb_ldflags_debug" ]	&& mb_ldflags_debug=$mb_default_ldflags_debug
66a30d
	[ -z "$mb_ldflags_common" ]	&& mb_ldflags_common=$mb_default_ldflags_common
66a30d
	[ -z "$mb_ldflags_cmdline" ]	&& mb_ldflags_cmdline=$mb_default_ldflags_cmdline
66a30d
	[ -z "$mb_ldflags_config" ]	&& mb_ldflags_config=$mb_default_ldflags_config
66a30d
	[ -z "$mb_ldflags_sysroot" ]	&& mb_ldflags_sysroot=$mb_default_ldflags_sysroot
66a30d
	[ -z "$mb_ldflags_path" ]	&& mb_ldflags_path=$mb_default_ldflags_path
66a30d
	[ -z "$mb_ldflags_strict" ]	&& mb_ldflags_strict=$mb_default_ldflags_strict
66a30d
	[ -z "$mb_ldflags_util" ]	&& mb_ldflags_util=$mb_default_ldflags_util
66a30d
	[ -z "$mb_ldflags_last" ]	&& mb_ldflags_last=$mb_default_ldflags_last
66a30d
	[ -z "$mb_ldflags_once" ]	&& mb_ldflags_once=$mb_default_ldflags_once
66a30d
66a30d
	[ -z "$mb_pe_subsystem" ]	&& mb_pe_subsystem=$mb_default_pe_subsystem
66a30d
	[ -z "$mb_pe_image_base" ]	&& mb_pe_image_base=$mb_default_pe_image_base
66a30d
	[ -z "$mb_pe_config_defs" ]	&& mb_pe_config_defs=$mb_default_pe_config_defs
66a30d
66a30d
	[ -z "$mb_elf_eh_frame" ]	&& mb_elf_eh_frame=$mb_default_elf_eh_frame
66a30d
	[ -z "$mb_elf_hash_style" ]	&& mb_elf_hash_style=$mb_default_elf_hash_style
66a30d
	[ -z "$mb_elf_config_defs" ]	&& mb_elf_config_defs=$mb_default_elf_config_defs
66a30d
66a30d
	# config
66a30d
	[ -z "$mb_all_static" ]		&& mb_all_static='no'
66a30d
	[ -z "$mb_all_shared" ]		&& mb_all_shared='no'
66a30d
	[ -z "$mb_disable_frontend" ]	&& mb_disable_frontend='no'
66a30d
	[ -z "$mb_disable_static" ]	&& mb_disable_static='no'
66a30d
	[ -z "$mb_disable_shared" ]	&& mb_disable_shared='no'
66a30d
66a30d
	# host/target
66a30d
	[ -z "$mb_host" ] 		&& mb_host=$mb_target
66a30d
	[ -z "$mb_target" ] 		&& mb_target=$mb_host
66a30d
66a30d
	# sysroot
66a30d
	if [ -n "$mb_sysroot" ]; then
66a30d
		if [ -z "$mb_cflags_sysroot" ]; then
66a30d
			mb_cflags_sysroot="--sysroot=$mb_sysroot"
66a30d
		fi
66a30d
66a30d
		if [ -z "$mb_ldflags_sysroot" ]; then
66a30d
			mb_ldflags_sysroot="--sysroot=$mb_sysroot"
66a30d
		fi
66a30d
	fi
66a30d
66a30d
	# debug
66a30d
	if [ "$mb_debug" = yes ]; then
66a30d
		if [ -z "$mb_cflags_debug" ]; then
66a30d
			mb_cflags_debug='-g3 -O0'
66a30d
		fi
66a30d
	fi
66a30d
66a30d
	# compiler
66a30d
	if [ -n "$mb_compiler" ]; then
66a30d
		if [ -z "$mb_native_cc" ]; then
66a30d
			mb_native_cc=$mb_compiler
66a30d
		fi
66a30d
	fi
66a30d
66a30d
	# toolchain
66a30d
	if [ -z "$mb_toolchain" ]; then
66a30d
		mb_toolchain='binutils'
66a30d
	fi
66a30d
66a30d
	# fallback host recipe
66a30d
	if [ -n "$mb_host" ]; then
66a30d
		if ! [ -f $mb_project_dir/sysinfo/host/$mb_host.mk ]; then
66a30d
			if [ -z "$mb_cross_compile" ]; then
66a30d
				mb_cross_compile=$mb_host-
66a30d
			fi
66a30d
66a30d
			mb_host='any-host';
66a30d
		fi
66a30d
	fi
66a30d
66a30d
	# fallback compiler recipe
66a30d
	if [ -n "$mb_compiler" ]; then
66a30d
		if ! [ -f $mb_project_dir/sysinfo/compiler/$mb_compiler.mk ]; then
66a30d
			mb_compiler='any-compiler'
66a30d
		fi
66a30d
	fi
66a30d
}
66a30d
66a30d
66a30d
native_defaults()
66a30d
{
66a30d
	# CC (when set, must be valid)
66a30d
	if [ -n "$CC" ]; then
66a30d
		$CC -dM -E - < /dev/null > /dev/null || exit 2
66a30d
	fi
66a30d
66a30d
	# compiler
66a30d
	[ -z "$mb_native_cc" ] && mb_native_cc=$CC
66a30d
	[ -z "$mb_native_cc" ] && mb_native_cc='cc'
66a30d
	$mb_native_cc -dM -E - < /dev/null > /dev/null 2>/dev/null || mb_native_cc=
66a30d
66a30d
	[ -z "$mb_native_cc" ] && mb_native_cc='gcc'
66a30d
	$mb_native_cc -dM -E - < /dev/null > /dev/null 2>/dev/null || mb_native_cc=
66a30d
66a30d
	[ -z "$mb_native_cc" ] && mb_native_cc='clang'
66a30d
	$mb_native_cc -dM -E - < /dev/null > /dev/null 2>/dev/null || mb_native_cc=
66a30d
66a30d
	[ -z "$mb_native_cc" ] && mb_native_cc='cparser'
66a30d
	$mb_native_cc -dM -E - < /dev/null > /dev/null 2>/dev/null || mb_native_cc=
66a30d
66a30d
	if [ -z "$mb_native_cc" ]; then
66a30d
		echo "configure: info: could not find a working native compiler."
66a30d
		mb_native_cc='false'
66a30d
	fi
66a30d
66a30d
	if [ -z "$mb_compiler" ]; then
66a30d
		$mb_native_cc -dM -E - < /dev/null | grep -q '__clang__' && mb_compiler='clang'
66a30d
	fi
66a30d
66a30d
	if [ -z "$mb_compiler" ]; then
66a30d
		$mb_native_cc -dM -E - < /dev/null | grep -q '__GCC' && mb_compiler='gcc'
66a30d
	fi
66a30d
66a30d
	if [ -z "$mb_compiler" ]; then
66a30d
		$mb_native_cc -dM -E - < /dev/null | grep -q "^gcc" && mb_compiler='gcc'
66a30d
	fi
66a30d
66a30d
	if [ -z "$mb_compiler" ]; then
66a30d
		$mb_native_cc -dM -E - < /dev/null | grep -q '__CPARSER__' && mb_compiler='cparser'
66a30d
	fi
66a30d
66a30d
	if [ -z "$mb_compiler" ]; then
66a30d
		echo "configure: info: could not identify the native compiler."
66a30d
		mb_compiler='any-compiler'
66a30d
	fi
66a30d
66a30d
66a30d
	# host
66a30d
	if [ -z "$mb_host" ]; then
66a30d
		mb_host='native'
66a30d
	fi
66a30d
66a30d
66a30d
	# target
66a30d
	if [ -z "$mb_target" ]; then
66a30d
		mb_target='native'
66a30d
	fi
66a30d
66a30d
66a30d
	# os
66a30d
	if [ -z "$mb_native_os" ]; then
66a30d
		mb_native_os=`uname | tr '[:upper:]' '[:lower:]'`
66a30d
	fi
66a30d
66a30d
	mb_native_os_sizeof_pointer=`$mb_native_cc -dM -E - < /dev/null \
66a30d
			| awk '$2 == "__SIZEOF_POINTER__" { print $3 }'`
66a30d
66a30d
	mb_native_os_bits=$((8 * ${mb_native_os_sizeof_pointer:-0}))
66a30d
66a30d
	if [ $mb_native_os_bits = 32 ]; then
66a30d
		mb_native_os_underscore='_'
66a30d
	else
66a30d
		mb_native_os_underscore=''
66a30d
	fi
66a30d
66a30d
	if [ -z "$mb_native_os_sizeof_pointer" ]; then
66a30d
		warning_msg "config error: could not determine size of pointer on native system."
66a30d
	fi
66a30d
66a30d
	# grumpily support crooked uname output
66a30d
	if ! [ -f $mb_project_dir/sysinfo/os/$mb_native_os.mk ]; then
66a30d
		mb_native_os=`echo $mb_native_os | cut -d'_' -f1`
66a30d
	fi
66a30d
66a30d
	# fallback os recipe
66a30d
	if ! [ -f $mb_project_dir/sysinfo/os/$mb_native_os.mk ]; then
66a30d
		mb_native_os='any-os';
66a30d
	fi
66a30d
}
66a30d
66a30d
66a30d
cross_defaults()
66a30d
{
66a30d
	if [ -z "$mb_cross_compile" ] && [ "$mb_host" != native ]; then
66a30d
		mb_cross_compile=$mb_host'-'
66a30d
	fi
66a30d
}
66a30d
66a30d
66a30d
config_flags()
66a30d
{
66a30d
	mb_ldflags_tmp=" $mb_ldflags "
66a30d
	mb_ldflags_libs=`echo "$mb_ldflags_tmp" | sed 's/ -static / /g'`
66a30d
66a30d
	if [ "$mb_ldflags_tmp" != "$mb_ldflags_libs" ]; then
66a30d
		mb_ldflags="$mb_ldflags_libs"
66a30d
		mb_ldflags_util="$mb_ldflags_util -static"
66a30d
	fi
66a30d
66a30d
	# ccstrict
66a30d
	if [ "$mb_ccstrict" = 'yes' ]; then
66a30d
		mb_cflags_strict='-Wall -Werror -Wextra -Wundef'
66a30d
	fi
66a30d
66a30d
	# ldstrict
66a30d
	if [ "$mb_ldstrict" = 'yes' ]; then
66a30d
		mb_ldflags_strict='-Wl,--no-undefined'
66a30d
	fi
66a30d
}
66a30d
66a30d
66a30d
config_copy()
66a30d
{
66a30d
	sed 		-e 's^@package@^'"$mb_package"'^g' 				\
66a30d
			-e 's^@nickname@^'"$mb_nickname"'^g'				\
66a30d
			-e 's^@project_dir@^'"$mb_project_dir"'^g'			\
66a30d
			-e 's^@source_dir@^'"$mb_source_dir"'^g'			\
66a30d
			-e 's^@git_reference_index@^'"$mb_git_reference_index"'^g'	\
66a30d
			-e 's^@custom_install_headers@^'"$mb_custom_install_headers"'^g' \
66a30d
			-e 's^@avoid_version@^'"$mb_avoid_version"'^g'			\
66a30d
											\
66a30d
			-e 's^@pkgname@^'"$mb_pkgname"'^g'				\
66a30d
			-e 's^@pkgdesc@^'"$mb_pkgdesc"'^g'				\
66a30d
			-e 's^@pkgusrc@^'"$mb_pkgusrc"'^g'				\
66a30d
			-e 's^@pkgrepo@^'"$mb_pkgrepo"'^g'				\
66a30d
			-e 's^@pkgpsrc@^'"$mb_pkgpsrc"'^g'				\
66a30d
			-e 's^@pkgdurl@^'"$mb_pkgdurl"'^g'				\
66a30d
			-e 's^@pkgdefs@^'"$mb_pkgdefs"'^g'				\
66a30d
			-e 's^@pkglibs@^'"$mb_pkglibs"'^g'				\
66a30d
											\
66a30d
			-e 's^@build@^'"$mb_build"'^g'					\
66a30d
			-e 's^@host@^'"$mb_host"'^g'					\
66a30d
			-e 's^@target@^'"$mb_target"'^g'				\
66a30d
			-e 's^@arch@^'"$mb_arch"'^g'					\
66a30d
			-e 's^@compiler@^'"$mb_compiler"'^g'				\
66a30d
			-e 's^@toolchain@^'"$mb_toolchain"'^g'				\
66a30d
			-e 's^@sysroot@^'"$mb_sysroot"'^g'				\
66a30d
			-e 's^@cross_compile@^'"$mb_cross_compile"'^g'			\
66a30d
			-e 's^@shell@^'"$mb_shell"'^g'					\
66a30d
											\
66a30d
			-e 's^@cflags@^'"$mb_cflags"'^g'				\
66a30d
			-e 's^@cflags_debug@^'"$mb_cflags_debug"'^g'			\
66a30d
			-e 's^@cflags_common@^'"$mb_cflags_common"'^g'			\
66a30d
			-e 's^@cflags_cmdline@^'"$mb_cflags $mb_cflags_cmdline"'^g'	\
66a30d
			-e 's^@cflags_config@^'"$mb_cflags_config"'^g'			\
66a30d
			-e 's^@cflags_sysroot@^'"$mb_cflags_sysroot"'^g'		\
66a30d
			-e 's^@cflags_os@^'"$mb_cflags_os"'^g'				\
66a30d
			-e 's^@cflags_site@^'"$mb_cflags_site"'^g'			\
66a30d
			-e 's^@cflags_path@^'"$mb_cflags_path"'^g'			\
66a30d
			-e 's^@cflags_strict@^'"$mb_cflags_strict"'^g'			\
66a30d
			-e 's^@cflags_util@^'"$mb_cflags_util"'^g'			\
66a30d
			-e 's^@cflags_last@^'"$mb_cflags_last"'^g'			\
66a30d
			-e 's^@cflags_once@^'"$mb_cflags_once"'^g'			\
66a30d
											\
66a30d
			-e 's^@ldflags@^'"$mb_ldflags"'^g'				\
66a30d
			-e 's^@ldflags_debug@^'"$mb_ldflags_debug"'^g'			\
66a30d
			-e 's^@ldflags_common@^'"$mb_ldflags_common"'^g'		\
66a30d
			-e 's^@ldflags_cmdline@^'"$mb_ldflags $mb_ldflags_cmdline"'^g'	\
66a30d
			-e 's^@ldflags_config@^'"$mb_ldflags_config"'^g'		\
66a30d
			-e 's^@ldflags_sysroot@^'"$mb_ldflags_sysroot"'^g'		\
66a30d
			-e 's^@ldflags_path@^'"$mb_ldflags_path"'^g'			\
66a30d
			-e 's^@ldflags_strict@^'"$mb_ldflags_strict"'^g'		\
66a30d
			-e 's^@ldflags_util@^'"$mb_ldflags_util"'^g'			\
66a30d
			-e 's^@ldflags_last@^'"$mb_ldflags_last"'^g'			\
66a30d
			-e 's^@ldflags_once@^'"$mb_ldflags_once"'^g'			\
66a30d
											\
66a30d
			-e 's^@pe_subsystem@^'"$mb_pe_subsystem"'^g'			\
66a30d
			-e 's^@pe_image\_base@^'"$mb_pe_image_base"'^g'			\
66a30d
			-e 's^@pe_config\_defs@^'"$mb_pe_config_defs"'^g'		\
66a30d
											\
66a30d
			-e 's^@elf_eh\_frame@^'"$mb_elf_eh_frame"'^g'			\
66a30d
			-e 's^@elf_hash\_style@^'"$mb_elf_hash_style"'^g'		\
66a30d
			-e 's^@elf_config\_defs@^'"$mb_elf_config_defs"'^g'		\
66a30d
											\
66a30d
			-e 's^@prefix@^'"$mb_prefix"'^g'				\
66a30d
			-e 's^@exec_prefix@^'"$mb_exec_prefix"'^g'			\
66a30d
			-e 's^@bindir@^'"$mb_bindir"'^g'				\
66a30d
			-e 's^@sbindir@^'"$mb_sbindir"'^g'				\
66a30d
			-e 's^@libdir@^'"$mb_libdir"'^g'				\
66a30d
			-e 's^@includedir@^'"$mb_includedir"'^g'			\
66a30d
			-e 's^@oldincludedir@^'"$mb_oldincludedir"'^g'			\
66a30d
			-e 's^@mandir@^'"$mb_mandir"'^g'				\
66a30d
			-e 's^@docdir@^'"$mb_docdir"'^g'				\
66a30d
			-e 's^@libexecdir@^'"$mb_libexecdir"'^g'			\
66a30d
											\
66a30d
			-e 's^@sysconfdir@^'"$mb_sysconfdir"'^g'			\
66a30d
			-e 's^@sharedstatedir@^'"$mb_sharedstatedir"'^g'		\
66a30d
			-e 's^@localstatedir@^'"$mb_localstatedir"'^g'			\
66a30d
			-e 's^@runstatedir@^'"$mb_runstatedir"'^g'			\
66a30d
			-e 's^@datarootdir@^'"$mb_datarootdir"'^g'			\
66a30d
			-e 's^@datadir@^'"$mb_datadir"'^g'				\
66a30d
			-e 's^@infodir@^'"$mb_infodir"'^g'				\
66a30d
			-e 's^@localedir@^'"$mb_localedir"'^g'				\
66a30d
			-e 's^@htmldir@^'"$mb_htmldir"'^g'				\
66a30d
			-e 's^@dvidir@^'"$mb_dvidir"'^g'				\
66a30d
			-e 's^@pdfdir@^'"$mb_pdfdir"'^g'				\
66a30d
			-e 's^@psdir@^'"$mb_psdir"'^g'					\
66a30d
											\
66a30d
			-e 's^@native_cc@^'"$mb_native_cc"'^g'				\
66a30d
			-e 's^@native_os@^'"$mb_native_os"'^g'				\
66a30d
			-e 's^@native_os_bits@^'"$mb_native_os_bits"'^g'		\
66a30d
			-e 's^@native_os_underscore@^'"$mb_native_os_underscore"'^g'	\
66a30d
											\
66a30d
			-e 's^@user_cc@^'"$mb_user_cc"'^g'				\
66a30d
			-e 's^@user_cpp@^'"$mb_user_cpp"'^g'				\
66a30d
			-e 's^@user_cxx@^'"$mb_user_cxx"'^g'				\
66a30d
											\
66a30d
			-e 's^@all_static@^'"$mb_all_static"'^g'			\
66a30d
			-e 's^@all_shared@^'"$mb_all_shared"'^g'			\
66a30d
			-e 's^@disable_frontend@^'"$mb_disable_frontend"'^g'		\
66a30d
			-e 's^@disable_static@^'"$mb_disable_static"'^g'		\
66a30d
			-e 's^@disable_shared@^'"$mb_disable_shared"'^g'		\
66a30d
		$mb_project_dir/Makefile.in > $mb_pwd/Makefile.tmp || exit 2
66a30d
66a30d
	if [ -z "$mb_cchost" ]; then
66a30d
		if [ "$mb_host" = 'native' ]; then
66a30d
			mb_cchost=`make -s -f $mb_pwd/Makefile.tmp cchost`
66a30d
		else
66a30d
			mb_cchost=$mb_host
66a30d
		fi
66a30d
	fi
66a30d
f6645d
	if [ -z "$mb_cfghost" ]; then
f6645d
		mb_cfghost=$mb_cchost
f6645d
	fi
f6645d
f6645d
	sed		-e 's^@cchost@^'"$mb_cchost"'^g'     \
f6645d
			-e 's^@cfghost@^'"$mb_cfghost"'^g'   \
f6645d
		$mb_pwd/Makefile.tmp > $mb_pwd/Makefile.host || exit 2
66a30d
66a30d
	rm  $mb_pwd/Makefile.tmp                   || exit 2
66a30d
	mv  $mb_pwd/Makefile.host $mb_pwd/Makefile || exit 2
66a30d
}
66a30d
66a30d
66a30d
config_support()
66a30d
{
66a30d
	[ "$mb_disable_shared" = 'yes' ] && return 0
66a30d
66a30d
	mbt_cc=`make .display-cc`
66a30d
	mbt_cflags=`make .display-cflags`
66a30d
	mbt_source='int foo(int x){return ++x;}'
66a30d
	mbt_result='no'
66a30d
66a30d
	rm -f a.out
66a30d
	echo "$mbt_source" | "$mbt_cc" -shared -o a.out -xc -
66a30d
	stat a.out >/dev/null 2>&1 && mbt_result='yes'
66a30d
	rm -f a.out
66a30d
66a30d
	if [ "$mbt_result" = 'no' ]; then
66a30d
		mb_disable_shared='yes'
66a30d
		config_copy
66a30d
	fi
66a30d
}
66a30d
66a30d
66a30d
config_host()
66a30d
{
66a30d
	make -s host.tag && return 0
66a30d
66a30d
	error_msg "configure was able to generate a Makefile for the selected host,"
66a30d
	error_msg "however the host-targeting compiler was found to be missing"
66a30d
	error_msg "at least one of the required headers or features."
66a30d
	exit 2
66a30d
}
66a30d
66a30d
66a30d
config_status()
66a30d
{
66a30d
	printf "\n\n"
66a30d
	make .display
66a30d
	printf "\nconfiguration completed successfully.\n\n"
66a30d
}
66a30d
66a30d
# one: init
66a30d
init_vars
66a30d
verify_build_directory
66a30d
66a30d
66a30d
# two: args
66a30d
for arg ; do
66a30d
	case "$arg" in
66a30d
		--help)	usage
66a30d
			;;
66a30d
66a30d
		# dirs
66a30d
		--prefix=*)
66a30d
			mb_prefix_set=yes
66a30d
			mb_prefix=${arg#*=}
66a30d
			;;
66a30d
		--exec-prefix=*)
66a30d
			mb_exec_prefix_set=yes
66a30d
			mb_exec_prefix=${arg#*=}
66a30d
			;;
66a30d
		--bindir=*)
66a30d
			mb_bindir_set=yes
66a30d
			mb_bindir=${arg#*=}
66a30d
			;;
66a30d
		--sbindir=*)
66a30d
			mb_sbindir=${arg#*=}
66a30d
			;;
66a30d
		--libdir=*)
66a30d
			mb_libdir=${arg#*=}
66a30d
			;;
66a30d
		--includedir=*)
66a30d
			mb_includedir=${arg#*=}
66a30d
			;;
66a30d
		--oldincludedir=*)
66a30d
			mb_oldincludedir=${arg#*=}
66a30d
			;;
66a30d
		--mandir=*)
66a30d
			mb_mandir=${arg#*=}
66a30d
			;;
66a30d
		--libexecdir=*)
66a30d
			mb_libexecdir=${arg#*=}
66a30d
			;;
66a30d
66a30d
66a30d
		--sysconfdir=*)
66a30d
			mb_sysconfdir=${arg#*=}
66a30d
			;;
66a30d
		--sharedstatedir=*)
66a30d
			mb_sharedstatedir=${arg#*=}
66a30d
			;;
66a30d
		--localstatedir=*)
66a30d
			mb_localstatedir=${arg#*=}
66a30d
			;;
66a30d
		--runstatedir=*)
66a30d
			mb_runstatedir=${arg#*=}
66a30d
			;;
66a30d
		--datarootdir=*)
66a30d
			mb_datarootdir=${arg#*=}
66a30d
			;;
66a30d
		--datadir=*)
66a30d
			mb_datadir=${arg#*=}
66a30d
			;;
66a30d
		--infodir=*)
66a30d
			mb_infodir=${arg#*=}
66a30d
			;;
66a30d
		--localedir=*)
66a30d
			mb_localedir=${arg#*=}
66a30d
			;;
66a30d
		--htmldir=*)
66a30d
			mb_htmldir=${arg#*=}
66a30d
			;;
66a30d
		--dvidir=*)
66a30d
			mb_dvidir=${arg#*=}
66a30d
			;;
66a30d
		--pdfdir=*)
66a30d
			mb_pdfdir=${arg#*=}
66a30d
			;;
66a30d
		--psdir=*)
66a30d
			mb_psdir=${arg#*=}
66a30d
			;;
66a30d
66a30d
66a30d
		# build
66a30d
		--build=*)
66a30d
			mb_build=${arg#*=}
66a30d
			;;
66a30d
		--host=*)
66a30d
			mb_host=${arg#*=}
66a30d
			;;
66a30d
		--cchost=*)
66a30d
			mb_cchost=${arg#*=}
66a30d
			;;
f6645d
		--cfghost=*)
f6645d
			mb_cfghost=${arg#*=}
f6645d
			;;
66a30d
		--target=*)
66a30d
			mb_target=${arg#*=}
66a30d
			;;
66a30d
		--arch=*)
66a30d
			mb_arch=${arg#*=}
66a30d
			;;
66a30d
		--compiler=*)
66a30d
			mb_compiler=${arg#*=}
66a30d
			;;
66a30d
		--toolchain=*)
66a30d
			mb_toolchain=${arg#*=}
66a30d
			;;
66a30d
		--sysroot=*)
66a30d
			mb_sysroot=${arg#*=}
66a30d
			;;
66a30d
		--cross-compile=*)
66a30d
			mb_cross_compile=${arg#*=}
66a30d
			;;
66a30d
		--shell=*)
66a30d
			mb_shell=${arg#*=}
66a30d
			;;
66a30d
		--debug)
66a30d
			mb_debug='yes'
66a30d
			;;
66a30d
66a30d
		# config
66a30d
		--all-static)
66a30d
			mb_all_static='yes'
66a30d
			;;
66a30d
		--all-shared)
66a30d
			mb_all_shared='yes'
66a30d
			;;
66a30d
		--disable-frontend)
66a30d
			mb_disable_frontend='yes'
66a30d
			;;
66a30d
		--disable-app)
66a30d
			mb_disable_frontend='yes'
66a30d
			;;
66a30d
		--enable-frontend)
66a30d
			mb_disable_frontend='no'
66a30d
			;;
66a30d
		--enable-app)
66a30d
			mb_disable_frontend='no'
66a30d
			;;
66a30d
		--disable-static)
66a30d
			mb_disable_static='yes'
66a30d
			;;
66a30d
		--disable-shared)
66a30d
			mb_disable_shared='yes'
66a30d
			;;
66a30d
		--enable-static)
66a30d
			mb_disable_static='no'
66a30d
			;;
66a30d
		--enable-shared)
66a30d
			mb_disable_shared='no'
66a30d
			;;
66a30d
66a30d
		# convenience
66a30d
		--strict)
66a30d
			mb_ccstrict='yes'
66a30d
			mb_ldstrict='yes'
66a30d
			;;
66a30d
		--ccstrict)
66a30d
			mb_ccstrict='yes'
66a30d
			;;
66a30d
		--ldstrict)
66a30d
			mb_ldstrict='yes'
66a30d
			;;
66a30d
66a30d
		# project
66a30d
		--nickname=*)
66a30d
			mb_nickname=${arg#*=}
66a30d
			;;
66a30d
		--program-prefix=*)
66a30d
			mb_program_prefix=${arg#*=}
66a30d
			;;
66a30d
		--avoid-version)
66a30d
			mb_avoid_version='yes'
66a30d
			;;
66a30d
		--source-dir=*)
66a30d
			mb_source_dir=${arg#*=}
66a30d
			;;
66a30d
66a30d
		# pkgconfig
66a30d
		--pkgname=*)
66a30d
			mb_pkgname=${arg#*=}
66a30d
			;;
66a30d
66a30d
		--pkgdesc=*)
66a30d
			mb_pkgdesc=${arg#*=}
66a30d
			;;
66a30d
66a30d
		--pkgusrc=*)
66a30d
			mb_pkgusrc=${arg#*=}
66a30d
			;;
66a30d
66a30d
		--pkgrepo=*)
66a30d
			mb_pkgrepo=${arg#*=}
66a30d
			;;
66a30d
66a30d
		--pkgpsrc=*)
66a30d
			mb_pkgpsrc=${arg#*=}
66a30d
			;;
66a30d
66a30d
		--pkgdurl=*)
66a30d
			mb_pkgdurl=${arg#*=}
66a30d
			;;
66a30d
66a30d
		--pkgdefs=*)
66a30d
			mb_pkgdefs=${arg#*=}
66a30d
			;;
66a30d
66a30d
		--pkglibs=*)
66a30d
			mb_pkglibs=${arg#*=}
66a30d
			;;
66a30d
66a30d
		# compatibility
66a30d
		--enable-dependency-tracking)
66a30d
			;;
66a30d
		--disable-dependency-tracking)
66a30d
			;;
66a30d
66a30d
		*)
66a30d
			error_msg ${arg#}: "unsupported config argument."
66a30d
			exit 2
66a30d
			;;
66a30d
	esac
66a30d
done
66a30d
66a30d
66a30d
66a30d
# three: validation
66a30d
verify_source_directory
66a30d
66a30d
if ! [ -z "$mb_program_prefix" ]; then
66a30d
	error_msg "--program-prefix is not yet fully support (must be null)."
66a30d
fi
66a30d
66a30d
66a30d
66a30d
# four: defaults
66a30d
common_defaults
66a30d
native_defaults
66a30d
cross_defaults
66a30d
66a30d
66a30d
66a30d
# five: config
66a30d
config_flags
66a30d
config_copy
66a30d
config_support
66a30d
config_host
66a30d
config_status
66a30d
66a30d
66a30d
# all done
66a30d
exit 0