Blame configure

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