Blame configure

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