Blame configure

26e14f
#!/bin/sh
26e14f
794c0a
set -eu
794c0a
99b9ed
trap config_failure 1 2 EXIT
99b9ed
4f10f1
# before we begin...
4f10f1
mb_path="$PATH"
7f84a3
mb_script="$0"
7f84a3
mb_success=no
4f10f1
26e14f
usage()
26e14f
{
26e14f
	cat "$mb_project_dir"/config.usage
f7cf5c
dd7c0a
	if [ _$mb_use_custom_cfgdefs = _yes ]; then
f7cf5c
		printf '\n\n%s%s\n' \
f7cf5c
			" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^" \
f7cf5c
			"^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"
f7cf5c
f7cf5c
		printf '%s%s\n' \
f7cf5c
			"| Listed above are configure's common switches " \
f7cf5c
			"and environment variables.     |"
f7cf5c
f7cf5c
		printf '%s%s\n' \
f7cf5c
			"| Found below are project-specific variables " \
f7cf5c
			"and other customization options. |"
f7cf5c
f7cf5c
		printf '%s%s\n\n\n' \
f7cf5c
			" ___________________________________________" \
f7cf5c
			"__________________________________"
f7cf5c
f7cf5c
		cat "$mb_project_dir"/project/config/cfgdefs.usage
f7cf5c
	fi
f7cf5c
f7cf5c
	exit 0
26e14f
}
26e14f
26e14f
error_msg()
26e14f
{
e9aa93
	printf '%s' "$@" >&2
26e14f
}
26e14f
26e14f
warning_msg()
26e14f
{
e9aa93
	printf '%s' "$@" >&2
26e14f
}
26e14f
26e14f
26e14f
init_vars()
26e14f
{
2e3adc
	mb_project_dir=$(cd -- "${mb_script%/*}/" ; pwd -P)
01ad87
	mb_pwd=$(pwd -P)
26e14f
062152
	mb_custom_cfgdefs_args=''
062152
	mb_custom_cfgdefs_space=''
062152
b11689
	sfrt_impl_dir=$mb_project_dir/sofort
b11689
	sfrt_config_dir=$sfrt_impl_dir/config
b11689
	sfrt_core_dir=$sfrt_impl_dir/core
b11689
	sfrt_config_vars=$sfrt_config_dir/config.vars
b11689
	sfrt_flag_vars=$sfrt_config_dir/flag.vars
b11689
	sfrt_cfgdefs_in=$sfrt_config_dir/cfgdefs.in
b11689
721644
	mb_make_vars=$(< "$sfrt_config_vars" \
721644
		grep -v -e '^#' -e '^$' | tr '[:lower:]' '[:upper:]')
88d72b
721644
	mb_impl_vars=$(< "$sfrt_config_vars" \
721644
		grep -v -e '^#' -e '^$' | sed 's/^/mb_/g')
80edc7
721644
	mb_proj_vars=$(< "$sfrt_config_vars" \
721644
		grep -v -e '^#' -e '^$' | sed 's/^/mb_default_/g')
80edc7
721644
	mb_flag_vars=$(< "$sfrt_flag_vars" \
721644
		grep -v -e '^#' -e '^$')
80edc7
80edc7
	mb_vars="$mb_make_vars $mb_impl_vars $mb_proj_vars $mb_flag_vars"
80edc7
12a073
	for mb_var in $(printf '%s' "$mb_vars") ; do
88d72b
		mb_expr=$mb_var='${'$mb_var':-}'
88d72b
		eval "$mb_expr"
88d72b
	done
88d72b
dee5ee
	# ccenv
dee5ee
	. $mb_project_dir/sofort/ccenv/ccenv.sh
dee5ee
4e005e
	if ! [ -L ./ccenv ]; then
dee5ee
		if [ -d ./ccenv ]; then
dee5ee
			rm -f ./ccenv/host.mk
dee5ee
			rm -f ./ccenv/native.mk
dee5ee
			rmdir ./ccenv
dee5ee
		fi
dee5ee
	fi
dee5ee
dee5ee
	# config.project
26e14f
	if [ -z "$mb_config" ]; then
d415fa
		. $mb_project_dir/config.project
26e14f
	else
d415fa
		. "$mb_config"
26e14f
	fi
26e14f
26e14f
	# project
26e14f
	mb_nickname=$NICKNAME
26e14f
	mb_source_dir=$SOURCE_DIR
26e14f
26e14f
	# dirs
26e14f
	mb_prefix=$PREFIX
26e14f
	mb_exec_prefix=$EXEC_PREFIX
26e14f
	mb_bindir=$BINDIR
035302
	mb_sbindir=$SBINDIR
26e14f
	mb_libdir=$LIBDIR
26e14f
	mb_includedir=$INCLUDEDIR
cdceaf
	mb_oldincludedir=$OLDINCLUDEDIR
26e14f
	mb_mandir=$MANDIR
26e14f
	mb_docdir=$DOCDIR
26e14f
	mb_libexecdir=$LIBEXECDIR
26e14f
cdceaf
	mb_sysconfdir=$SYSCONFDIR
cdceaf
	mb_sharedstatedir=$SHAREDSTATEDIR
cdceaf
	mb_localstatedir=$LOCALSTATEDIR
cdceaf
	mb_runstatedir=$RUNSTATEDIR
cdceaf
	mb_datarootdir=$DATAROOTDIR
cdceaf
	mb_datadir=$DATADIR
cdceaf
	mb_infodir=$INFODIR
cdceaf
	mb_localedir=$LOCALEDIR
cdceaf
	mb_htmldir=$HTMLDIR
cdceaf
	mb_dvidir=$DVIDIR
cdceaf
	mb_pdfdir=$PDFDIR
cdceaf
	mb_psdir=$PSDIR
cdceaf
26e14f
26e14f
	# build
26e14f
	mb_build=$BUILD
04eb52
	mb_cchost=$CCHOST
5079dc
	mb_cfghost=$CFGHOST
26e14f
	mb_arch=$ARCH
26e14f
	mb_compiler=$COMPILER
26e14f
	mb_toolchain=$TOOLCHAIN
26e14f
	mb_sysroot=$SYSROOT
26e14f
	mb_cross_compile=$CROSS_COMPILE
26e14f
	mb_shell=$SHELL
26e14f
26e14f
	# switches
26e14f
	mb_cflags=$CFLAGS
26e14f
	mb_cflags_debug=$CFLAGS_DEBUG
26e14f
	mb_cflags_common=$CFLAGS_COMMON
26e14f
	mb_cflags_cmdline=$CFLAGS_CMDLINE
26e14f
	mb_cflags_config=$CFLAGS_CONFIG
26e14f
	mb_cflags_sysroot=$CFLAGS_SYSROOT
26e14f
	mb_cflags_os=$CFLAGS_OS
26e14f
	mb_cflags_site=$CFLAGS_SITE
26e14f
	mb_cflags_path=$CFLAGS_PATH
26e14f
	mb_cflags_strict=$CFLAGS_STRICT
26e14f
	mb_cflags_util=$CFLAGS_UTIL
26e14f
	mb_cflags_last=$CFLAGS_LAST
26e14f
	mb_cflags_once=$CFLAGS_ONCE
26e14f
26e14f
	mb_ldflags=$LDFLAGS
26e14f
	mb_ldflags_debug=$LDFLAGS_DEBUG
26e14f
	mb_ldflags_common=$LDFLAGS_COMMON
26e14f
	mb_ldflags_cmdline=$LDFLAGS_CMDLINE
26e14f
	mb_ldflags_config=$LDFLAGS_CONFIG
26e14f
	mb_ldflags_sysroot=$LDFLAGS_SYSROOT
26e14f
	mb_ldflags_path=$LDFLAGS_PATH
26e14f
	mb_ldflags_strict=$LDFLAGS_STRICT
26e14f
	mb_ldflags_util=$LDFLAGS_UTIL
26e14f
	mb_ldflags_last=$LDFLAGS_LAST
26e14f
	mb_ldflags_once=$LDFLAGS_ONCE
26e14f
26e14f
	mb_pe_subsystem=$PE_SUBSYSTEM
26e14f
	mb_pe_image_base=$PE_IMAGE_BASE
26e14f
26e14f
	# overrides
26e14f
	mb_user_cc=$CC
26e14f
	mb_user_cpp=$CPP
26e14f
	mb_user_cxx=$CXX
dee5ee
dee5ee
	mb_native_cc=$NATIVE_CC
dee5ee
	mb_native_cpp=$NATIVE_CPP
dee5ee
	mb_native_cxx=$NATIVE_CXX
dee5ee
dee5ee
	mb_native_host=$NATIVE_HOST
dee5ee
	mb_native_cfghost=$NATIVE_CFGHOST
dee5ee
	mb_native_cflags=$NATIVE_CFLAGS
dee5ee
	mb_native_ldflags=$NATIVE_LDFLAGS
2732d1
2732d1
	mb_native_pe_subsystem=$NATIVE_PE_SUBSYSTEM
2732d1
	mb_native_pe_image_base=$NATIVE_PE_IMAGE_BASE
26e14f
}
26e14f
26e14f
26e14f
verify_build_directory()
26e14f
{
26e14f
	if [ "$mb_project_dir" = "$mb_pwd" ]; then
dd7c0a
		if [ _$mb_require_out_of_tree = _yes ]; then
26e14f
			error_msg "$mb_package: out-of-tree builds are required."
26e14f
			error_msg "please invoke configure again from a clean build directory."
d415fa
			exit 1
26e14f
		else
26e14f
			mb_project_dir='.'
26e14f
		fi
26e14f
	fi
99b9ed
99b9ed
	rm -f Makefile Makefile.host Makefile.tmp Makefile.failed
26e14f
}
26e14f
26e14f
26e14f
verify_source_directory()
26e14f
{
26e14f
	if [ -z "$mb_source_dir" ]; then
dd7c0a
		if [ _$mb_require_source_dir = _yes ]; then
26e14f
			error_msg "$mb_package: specifying an external source directory is required."
26e14f
			error_msg "you can set the source directory either via --source-dir=<path>,"
26e14f
			error_msg "or by setting the SOURCE_DIR variable."
d415fa
			exit 1
26e14f
		fi
26e14f
	fi
26e14f
}
26e14f
26e14f
26e14f
common_defaults()
26e14f
{
4148b7
	# project-specific config definitions
4148b7
	if [ _$mb_use_custom_cfgdefs = _yes ]; then
4148b7
		cat $sfrt_cfgdefs_in > cfgdefs.mk
4148b7
	else
4148b7
		printf '%s %s\n\n' \
4148b7
				'# this project does not include' \
4148b7
				'a custom config step.'           \
4148b7
			> cfgdefs.mk
4148b7
		cat $sfrt_cfgdefs_in >> cfgdefs.mk
4148b7
4148b7
		if [ -f $mb_project_dir/project/cfgdefs.in ]; then
4148b7
			cat $mb_project_dir/project/cfgdefs.in >> cfgdefs.mk
4148b7
		fi
4148b7
	fi
4148b7
4148b7
	# user build-time overrides
4148b7
	touch usrdefs.mk
4148b7
26e14f
	# git
26e14f
	if [ -n "$mb_source_dir" ]; then
26e14f
		if [ -d "$mb_source_dir/.git" ]; then
26e14f
			mb_git_reference_index="\$(SOURCE_DIR)/.git/index"
26e14f
		fi
26e14f
	elif [ -d "$mb_project_dir/.git" ]; then
26e14f
		mb_git_reference_index="\$(PROJECT_DIR)/.git/index"
26e14f
	fi
26e14f
26e14f
	# project
144bad
	[ -n "$mb_nickname" ] 		|| mb_nickname=$mb_package
144bad
	[ -n "$mb_source_dir" ] 	|| mb_source_dir=$mb_project_dir
144bad
	[ -n "$mb_avoid_version" ] 	|| mb_avoid_version='no'
26e14f
750435
	# pkgconfig
144bad
	[ -n "$mb_pkgname" ]		|| mb_pkgname="$mb_default_pkgname"
144bad
	[ -n "$mb_pkgdesc" ]		|| mb_pkgdesc="$mb_default_pkgdesc"
144bad
	[ -n "$mb_pkgusrc" ]		|| mb_pkgusrc="$mb_default_pkgusrc"
144bad
	[ -n "$mb_pkgrepo" ]		|| mb_pkgrepo="$mb_default_pkgrepo"
144bad
	[ -n "$mb_pkgpsrc" ]		|| mb_pkgpsrc="$mb_default_pkgpsrc"
144bad
	[ -n "$mb_pkgdurl" ]		|| mb_pkgdurl="$mb_default_pkgdurl"
144bad
	[ -n "$mb_pkgdefs" ]		|| mb_pkgdefs="$mb_default_pkgdefs"
144bad
	[ -n "$mb_pkglibs" ]		|| mb_pkglibs="$mb_default_pkglibs"
750435
26e14f
	# dirs
144bad
	[ -n "$mb_prefix" ] 		|| [ -n "$mb_prefix_set" ] \
144bad
					|| mb_prefix='/usr/local'
144bad
144bad
	[ -n "$mb_exec_prefix" ] 	|| [ -n "$mb_exec_prefix_set" ]	\
144bad
					|| mb_exec_prefix=$mb_prefix
144bad
144bad
	[ -n "$mb_bindir" ] 		|| [ -n "$mb_bindir_set" ] \
144bad
					|| [ -n "$mb_bindir_basename" ] \
144bad
					|| mb_bindir=$mb_exec_prefix/bin
144bad
144bad
	[ -n "$mb_bindir" ] 		|| [ -n "$mb_bindir_set" ] \
144bad
					|| mb_bindir=$mb_exec_prefix/$mb_bindir_basename
144bad
144bad
	[ -n "$mb_sbindir" ] 		|| mb_sbindir=$mb_exec_prefix/sbin
144bad
	[ -n "$mb_libdir" ] 		|| mb_libdir=$mb_exec_prefix/lib
144bad
	[ -n "$mb_includedir" ]		|| mb_includedir=$mb_prefix/include
144bad
	[ -n "$mb_oldincludedir" ]	|| mb_oldincludedir=$mb_prefix/include
144bad
	[ -n "$mb_datarootdir" ] 	|| mb_datarootdir=$mb_prefix/share
144bad
	[ -n "$mb_mandir" ] 		|| mb_mandir=$mb_datarootdir/man
144bad
	[ -n "$mb_docdir" ] 		|| mb_docdir=$mb_datarootdir/doc
144bad
	[ -n "$mb_libexecdir" ]		|| mb_libexecdir=$mb_exec_prefix/libexec
144bad
144bad
	[ -n "$mb_sysconfdir" ] 	|| mb_sysconfdir=$mb_exec_prefix/etc
144bad
	[ -n "$mb_sharedstatedir" ] 	|| mb_sharedstatedir=$mb_prefix/com
144bad
	[ -n "$mb_localstatedir" ] 	|| mb_localstatedir=$mb_prefix/var
144bad
	[ -n "$mb_runstatedir" ] 	|| mb_runstatedir=$mb_localstatedir/run
144bad
	[ -n "$mb_datarootdir" ] 	|| mb_datarootdir=$mb_prefix/share
144bad
	[ -n "$mb_datadir" ] 		|| mb_datadir=$mb_datarootdir
144bad
	[ -n "$mb_infodir" ] 		|| mb_infodir=$mb_datarootdir/info
144bad
	[ -n "$mb_localedir" ] 		|| mb_localedir=$mb_datarootdir/locale
144bad
	[ -n "$mb_htmldir" ] 		|| mb_htmldir=$mb_docdir
144bad
	[ -n "$mb_dvidir" ] 		|| mb_dvidir=$mb_docdir
144bad
	[ -n "$mb_pdfdir" ] 		|| mb_pdfdir=$mb_docdir
144bad
	[ -n "$mb_psdir" ] 		|| mb_psdir=$mb_docdir
cdceaf
26e14f
	# switches
144bad
	[ -n "$mb_cflags_debug" ]	|| mb_cflags_debug=$mb_default_cflags_debug
144bad
	[ -n "$mb_cflags_common" ]	|| mb_cflags_common=$mb_default_cflags_common
144bad
	[ -n "$mb_cflags_cmdline" ]	|| mb_cflags_cmdline=$mb_default_cflags_cmdline
144bad
	[ -n "$mb_cflags_config" ]	|| mb_cflags_config=$mb_default_cflags_config
144bad
	[ -n "$mb_cflags_sysroot" ]	|| mb_cflags_sysroot=$mb_default_cflags_sysroot
144bad
	[ -n "$mb_cflags_os" ]		|| mb_cflags_os=$mb_default_cflags_os
144bad
	[ -n "$mb_cflags_site" ]	|| mb_cflags_site=$mb_default_cflags_site
144bad
	[ -n "$mb_cflags_path" ]	|| mb_cflags_path=$mb_default_cflags_path
144bad
	[ -n "$mb_cflags_strict" ]	|| mb_cflags_strict=$mb_default_cflags_strict
144bad
	[ -n "$mb_cflags_util" ]	|| mb_cflags_util=$mb_default_cflags_util
144bad
	[ -n "$mb_cflags_last" ]	|| mb_cflags_last=$mb_default_cflags_last
144bad
	[ -n "$mb_cflags_once" ]	|| mb_cflags_once=$mb_default_cflags_once
144bad
144bad
	[ -n "$mb_ldflags_debug" ]	|| mb_ldflags_debug=$mb_default_ldflags_debug
144bad
	[ -n "$mb_ldflags_common" ]	|| mb_ldflags_common=$mb_default_ldflags_common
144bad
	[ -n "$mb_ldflags_cmdline" ]	|| mb_ldflags_cmdline=$mb_default_ldflags_cmdline
144bad
	[ -n "$mb_ldflags_config" ]	|| mb_ldflags_config=$mb_default_ldflags_config
144bad
	[ -n "$mb_ldflags_sysroot" ]	|| mb_ldflags_sysroot=$mb_default_ldflags_sysroot
144bad
	[ -n "$mb_ldflags_path" ]	|| mb_ldflags_path=$mb_default_ldflags_path
144bad
	[ -n "$mb_ldflags_strict" ]	|| mb_ldflags_strict=$mb_default_ldflags_strict
144bad
	[ -n "$mb_ldflags_util" ]	|| mb_ldflags_util=$mb_default_ldflags_util
144bad
	[ -n "$mb_ldflags_last" ]	|| mb_ldflags_last=$mb_default_ldflags_last
144bad
	[ -n "$mb_ldflags_once" ]	|| mb_ldflags_once=$mb_default_ldflags_once
26e14f
7145e8
	# native switches
144bad
	[ -n "$mb_native_cflags" ]	|| mb_native_cflags=$mb_default_native_cflags
144bad
	[ -n "$mb_native_ldflags" ]	|| mb_native_ldflags=$mb_default_native_ldflags
7145e8
26e14f
	# config
144bad
	[ -n "$mb_all_static" ]		|| mb_all_static='no'
144bad
	[ -n "$mb_all_shared" ]		|| mb_all_shared='no'
144bad
	[ -n "$mb_disable_frontend" ]	|| mb_disable_frontend='no'
144bad
	[ -n "$mb_disable_static" ]	|| mb_disable_static='no'
144bad
	[ -n "$mb_disable_shared" ]	|| mb_disable_shared='no'
26e14f
26e14f
	# host/target
144bad
	[ -n "$mb_host" ] 		|| mb_host=$mb_target
144bad
	[ -n "$mb_target" ] 		|| mb_target=$mb_host
26e14f
26e14f
	# sysroot
26e14f
	if [ -n "$mb_sysroot" ]; then
26e14f
		if [ -z "$mb_cflags_sysroot" ]; then
26e14f
			mb_cflags_sysroot="--sysroot=$mb_sysroot"
26e14f
		fi
26e14f
26e14f
		if [ -z "$mb_ldflags_sysroot" ]; then
26e14f
			mb_ldflags_sysroot="--sysroot=$mb_sysroot"
26e14f
		fi
26e14f
	fi
26e14f
26e14f
	# debug
dd7c0a
	if [ _$mb_debug = _yes ]; then
26e14f
		if [ -z "$mb_cflags_debug" ]; then
26e14f
			mb_cflags_debug='-g3 -O0'
26e14f
		fi
26e14f
	fi
297266
e37496
	# shell
e37496
	if [ -z "$mb_shell" ]; then
e37496
		mb_shell='/bin/sh'
e37496
	fi
e37496
297266
	# inherited cflags & ldflags
297266
	mb_cflags_cmdline="$mb_cflags_cmdline $mb_cflags"
297266
	mb_ldflags_cmdline="$mb_ldflags_cmdline $mb_ldflags"
26e14f
}
26e14f
26e14f
26e14f
config_flags()
26e14f
{
26e14f
	mb_ldflags_tmp=" $mb_ldflags "
e9aa93
	mb_ldflags_libs=$(printf '%s' "$mb_ldflags_tmp" | sed 's/ -static / /g')
26e14f
26e14f
	if [ "$mb_ldflags_tmp" != "$mb_ldflags_libs" ]; then
26e14f
		mb_ldflags="$mb_ldflags_libs"
26e14f
		mb_ldflags_util="$mb_ldflags_util -static"
26e14f
	fi
26e14f
26e14f
	# ccstrict
dd7c0a
	if [ _$mb_ccstrict = _yes ]; then
26e14f
		mb_cflags_strict='-Wall -Werror -Wextra -Wundef'
26e14f
	fi
26e14f
26e14f
	# ldstrict
dd7c0a
	if [ _$mb_ldstrict = _yes ]; then
26e14f
		mb_ldflags_strict='-Wl,--no-undefined'
26e14f
	fi
26e14f
}
26e14f
26e14f
26e14f
config_copy()
26e14f
{
b11689
	mb_vars=$(cut -d'=' -f1 $sfrt_config_vars \
80edc7
			| grep -v '^#')
80edc7
80edc7
	mb_sed_substs=" \
12a073
		$(for __var in $(printf '%s' "$mb_vars"); do   \
80edc7
			printf '%s"$%s"%s' "-e 's^@$__var@^'" \
80edc7
				"mb_$__var" "'^g' ";           \
80edc7
		done)"
80edc7
80edc7
	eval sed $mb_sed_substs \
80edc7
		$mb_project_dir/Makefile.in    \
07b491
			| sed -e 's/[[:blank:]]*$//g' \
80edc7
			> $mb_pwd/Makefile.tmp
dee5ee
}
04eb52
5fdd07
dee5ee
config_ccenv()
dee5ee
{
dee5ee
	mkdir -p ./ccenv
dee5ee
	touch ./ccenv/host.mk
dee5ee
	touch ./ccenv/native.mk
f7cf5c
dee5ee
	ccenv_set_host_variables
dee5ee
	ccenv_set_native_variables
f64fbb
f64fbb
	config_copy
dee5ee
}
f7cf5c
f7cf5c
config_custom()
f7cf5c
{
dd7c0a
	if [ _$mb_use_custom_cfgdefs = _yes ]; then
062152
		eval . $mb_project_dir/project/config/cfgdefs.sh \
062152
			"$mb_custom_cfgdefs_args"
f7cf5c
		config_copy
f7cf5c
	fi
04eb52
dd7c0a
	if [ _$mb_use_custom_usrdefs = _yes ]; then
f7cf5c
		. $mb_project_dir/project/usrdefs.sh
f7cf5c
	fi
f7cf5c
}
f7cf5c
f7cf5c
f7cf5c
config_cfghost()
f7cf5c
{
5079dc
	if [ -z "$mb_cfghost" ]; then
5079dc
		mb_cfghost=$mb_cchost
5079dc
	fi
5079dc
5079dc
	sed		-e 's^@cchost@^'"$mb_cchost"'^g'     \
5079dc
			-e 's^@cfghost@^'"$mb_cfghost"'^g'   \
d415fa
		$mb_pwd/Makefile.tmp > $mb_pwd/Makefile.host
04eb52
d415fa
	rm  $mb_pwd/Makefile.tmp
d415fa
	mv  $mb_pwd/Makefile.host $mb_pwd/Makefile
26e14f
}
26e14f
26e14f
26e14f
config_host()
26e14f
{
26e14f
	make -s host.tag && return 0
26e14f
26e14f
	error_msg "configure was able to generate a Makefile for the selected host,"
26e14f
	error_msg "however the host-targeting compiler was found to be missing"
26e14f
	error_msg "at least one of the required headers or features."
26e14f
	exit 2
26e14f
}
26e14f
26e14f
26e14f
config_status()
26e14f
{
12a073
	printf '\n\n'
b52e41
	make -j1 .display
12a073
	printf '\nconfiguration completed successfully.\n\n'
26e14f
}
26e14f
99b9ed
99b9ed
config_failure()
99b9ed
{
292001
	if [ _$mb_success = _yes ]; then
292001
		return 0
292001
	fi
292001
99b9ed
	if [ -f Makefile ]; then
99b9ed
		mb_error='failed to use the generated Makefile.'
99b9ed
		printf '\n%s: error: %s\n' "${0}" "$mb_error" >&2
99b9ed
		mv Makefile Makefile.failed
99b9ed
	fi
99b9ed
99b9ed
	exit 2
99b9ed
}
99b9ed
99b9ed
99b9ed
config_success()
99b9ed
{
99b9ed
	trap '' EXIT
292001
	mb_success=yes
99b9ed
	exit 0
99b9ed
}
99b9ed
99b9ed
26e14f
# one: init
26e14f
init_vars
26e14f
verify_build_directory
26e14f
26e14f
26e14f
# two: args
26e14f
for arg ; do
26e14f
	case "$arg" in
dee5ee
		--help)
dee5ee
			usage
dee5ee
			;;
dee5ee
		--help=ccenv)
dee5ee
			ccenv_usage
dee5ee
			;;
dee5ee
dee5ee
		# ccenv
dee5ee
		--cross-compile=*)
dee5ee
			mb_cross_compile=${arg#*=}
dee5ee
			;;
dee5ee
		--compiler=*)
dee5ee
			mb_compiler=${arg#*=}
dee5ee
			;;
dee5ee
		--toolchain=*)
dee5ee
			mb_toolchain=${arg#*=}
dee5ee
			;;
dee5ee
		--zealous)
dee5ee
			mb_agnostic=yes
dee5ee
			mb_zealous=
dee5ee
			;;
dee5ee
		--zealous=*)
dee5ee
			mb_zealous=${arg#*=}
dee5ee
			;;
dee5ee
		--ccenv=*)
dee5ee
			mb_ccenv=${arg#*=}
26e14f
			;;
26e14f
26e14f
		# dirs
26e14f
		--prefix=*)
26e14f
			mb_prefix_set=yes
26e14f
			mb_prefix=${arg#*=}
26e14f
			;;
26e14f
		--exec-prefix=*)
26e14f
			mb_exec_prefix_set=yes
26e14f
			mb_exec_prefix=${arg#*=}
26e14f
			;;
26e14f
		--bindir=*)
04cd68
			mb_bindir_set=yes
26e14f
			mb_bindir=${arg#*=}
26e14f
			;;
035302
		--sbindir=*)
035302
			mb_sbindir=${arg#*=}
035302
			;;
26e14f
		--libdir=*)
26e14f
			mb_libdir=${arg#*=}
26e14f
			;;
26e14f
		--includedir=*)
26e14f
			mb_includedir=${arg#*=}
26e14f
			;;
cdceaf
		--oldincludedir=*)
cdceaf
			mb_oldincludedir=${arg#*=}
cdceaf
			;;
26e14f
		--mandir=*)
26e14f
			mb_mandir=${arg#*=}
26e14f
			;;
26e14f
		--libexecdir=*)
26e14f
			mb_libexecdir=${arg#*=}
26e14f
			;;
26e14f
26e14f
cdceaf
		--sysconfdir=*)
cdceaf
			mb_sysconfdir=${arg#*=}
cdceaf
			;;
cdceaf
		--sharedstatedir=*)
cdceaf
			mb_sharedstatedir=${arg#*=}
cdceaf
			;;
cdceaf
		--localstatedir=*)
cdceaf
			mb_localstatedir=${arg#*=}
cdceaf
			;;
cdceaf
		--runstatedir=*)
cdceaf
			mb_runstatedir=${arg#*=}
cdceaf
			;;
cdceaf
		--datarootdir=*)
cdceaf
			mb_datarootdir=${arg#*=}
cdceaf
			;;
cdceaf
		--datadir=*)
cdceaf
			mb_datadir=${arg#*=}
cdceaf
			;;
cdceaf
		--infodir=*)
cdceaf
			mb_infodir=${arg#*=}
cdceaf
			;;
cdceaf
		--localedir=*)
cdceaf
			mb_localedir=${arg#*=}
cdceaf
			;;
cdceaf
		--htmldir=*)
cdceaf
			mb_htmldir=${arg#*=}
cdceaf
			;;
cdceaf
		--dvidir=*)
cdceaf
			mb_dvidir=${arg#*=}
cdceaf
			;;
cdceaf
		--pdfdir=*)
cdceaf
			mb_pdfdir=${arg#*=}
cdceaf
			;;
cdceaf
		--psdir=*)
cdceaf
			mb_psdir=${arg#*=}
cdceaf
			;;
cdceaf
cdceaf
26e14f
		# build
26e14f
		--build=*)
26e14f
			mb_build=${arg#*=}
26e14f
			;;
26e14f
		--host=*)
26e14f
			mb_host=${arg#*=}
26e14f
			;;
04eb52
		--cchost=*)
04eb52
			mb_cchost=${arg#*=}
04eb52
			;;
5079dc
		--cfghost=*)
5079dc
			mb_cfghost=${arg#*=}
5079dc
			;;
26e14f
		--target=*)
26e14f
			mb_target=${arg#*=}
26e14f
			;;
26e14f
		--arch=*)
26e14f
			mb_arch=${arg#*=}
26e14f
			;;
26e14f
		--sysroot=*)
26e14f
			mb_sysroot=${arg#*=}
26e14f
			;;
26e14f
		--shell=*)
26e14f
			mb_shell=${arg#*=}
26e14f
			;;
26e14f
		--debug)
dd7c0a
			mb_debug=yes
26e14f
			;;
26e14f
26e14f
		# config
26e14f
		--all-static)
dd7c0a
			mb_all_static=yes
8702a2
			mb_all_shared=no
26e14f
			;;
26e14f
		--all-shared)
dd7c0a
			mb_all_shared=yes
8702a2
			mb_all_static=no
26e14f
			;;
26e14f
		--disable-frontend)
dd7c0a
			mb_disable_frontend=yes
26e14f
			;;
26e14f
		--disable-app)
dd7c0a
			mb_disable_frontend=yes
26e14f
			;;
26e14f
		--enable-frontend)
26e14f
			mb_disable_frontend='no'
26e14f
			;;
26e14f
		--enable-app)
26e14f
			mb_disable_frontend='no'
26e14f
			;;
26e14f
		--disable-static)
dd7c0a
			mb_disable_static=yes
26e14f
			;;
26e14f
		--disable-shared)
dd7c0a
			mb_disable_shared=yes
26e14f
			;;
26e14f
		--enable-static)
26e14f
			mb_disable_static='no'
26e14f
			;;
26e14f
		--enable-shared)
26e14f
			mb_disable_shared='no'
26e14f
			;;
26e14f
26e14f
		# convenience
26e14f
		--strict)
dd7c0a
			mb_ccstrict=yes
dd7c0a
			mb_ldstrict=yes
26e14f
			;;
26e14f
		--ccstrict)
dd7c0a
			mb_ccstrict=yes
26e14f
			;;
26e14f
		--ldstrict)
dd7c0a
			mb_ldstrict=yes
26e14f
			;;
26e14f
26e14f
		# project
26e14f
		--nickname=*)
26e14f
			mb_nickname=${arg#*=}
26e14f
			;;
95c5c7
		--program-prefix=*)
95c5c7
			mb_program_prefix=${arg#*=}
95c5c7
			;;
26e14f
		--avoid-version)
dd7c0a
			mb_avoid_version=yes
26e14f
			;;
26e14f
		--source-dir=*)
26e14f
			mb_source_dir=${arg#*=}
26e14f
			;;
cbbb14
		--srcdir=*)
cbbb14
			mb_source_dir=${arg#*=}
cbbb14
			;;
26e14f
750435
		# pkgconfig
750435
		--pkgname=*)
750435
			mb_pkgname=${arg#*=}
750435
			;;
750435
750435
		--pkgdesc=*)
750435
			mb_pkgdesc=${arg#*=}
750435
			;;
750435
750435
		--pkgusrc=*)
750435
			mb_pkgusrc=${arg#*=}
750435
			;;
750435
750435
		--pkgrepo=*)
750435
			mb_pkgrepo=${arg#*=}
750435
			;;
750435
750435
		--pkgpsrc=*)
750435
			mb_pkgpsrc=${arg#*=}
750435
			;;
750435
750435
		--pkgdurl=*)
750435
			mb_pkgdurl=${arg#*=}
750435
			;;
750435
750435
		--pkgdefs=*)
750435
			mb_pkgdefs=${arg#*=}
750435
			;;
750435
750435
		--pkglibs=*)
750435
			mb_pkglibs=${arg#*=}
750435
			;;
750435
f7a506
		# compatibility
f7a506
		--enable-dependency-tracking)
f7a506
			;;
f7a506
		--disable-dependency-tracking)
f7a506
			;;
f7a506
26e14f
		*)
dd7c0a
			if [ _$mb_use_custom_cfgdefs = _yes ]; then
062152
				mb_escaped_arg=\'$(printf '%s\n' "$arg" | sed -e "s/'/'\\\\''/g")\'
062152
				mb_escaped_arg="$mb_custom_cfgdefs_space$mb_escaped_arg"
062152
				mb_custom_cfgdefs_args="$mb_custom_cfgdefs_args$mb_escaped_arg"
062152
				mb_custom_cfgdefs_space=' '
f7cf5c
			else
f7cf5c
				error_msg ${arg#}: "unsupported config argument."
f7cf5c
				exit 2
f7cf5c
			fi
26e14f
			;;
26e14f
	esac
26e14f
done
26e14f
26e14f
26e14f
26e14f
# three: validation
26e14f
verify_source_directory
26e14f
95c5c7
if ! [ -z "$mb_program_prefix" ]; then
95c5c7
	error_msg "--program-prefix is not yet fully support (must be null)."
95c5c7
fi
95c5c7
26e14f
26e14f
26e14f
# four: defaults
26e14f
common_defaults
26e14f
26e14f
26e14f
# five: config
26e14f
config_flags
26e14f
config_copy
dee5ee
config_ccenv
f7cf5c
config_custom
f7cf5c
config_cfghost
26e14f
config_host
26e14f
config_status
26e14f
26e14f
26e14f
# all done
99b9ed
config_success