Blame configure

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