Blame configure

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