Blame configure

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