Blame configure

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