Blame configure

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