Blame configure

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