Blame configure

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