Blame configure

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