Blame configure

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