Blame configure

ea5470
#!/bin/sh
ea5470
4804f7
set -eu
4804f7
248ad4
trap config_failure 1 2 EXIT
248ad4
ea5470
usage()
ea5470
{
ea5470
	cat "$mb_project_dir"/config.usage
da95e7
ed2ed6
	if [ _$mb_use_custom_cfgdefs = _yes ]; then
da95e7
		printf '\n\n%s%s\n' \
da95e7
			" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^" \
da95e7
			"^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"
da95e7
da95e7
		printf '%s%s\n' \
da95e7
			"| Listed above are configure's common switches " \
da95e7
			"and environment variables.     |"
da95e7
da95e7
		printf '%s%s\n' \
da95e7
			"| Found below are project-specific variables " \
da95e7
			"and other customization options. |"
da95e7
da95e7
		printf '%s%s\n\n\n' \
da95e7
			" ___________________________________________" \
da95e7
			"__________________________________"
da95e7
da95e7
		cat "$mb_project_dir"/project/config/cfgdefs.usage
da95e7
	fi
da95e7
da95e7
	exit 0
ea5470
}
ea5470
ea5470
error_msg()
ea5470
{
ea5470
	echo "$@" >&2
ea5470
}
ea5470
ea5470
warning_msg()
ea5470
{
ea5470
	echo "$@" >&2
ea5470
}
ea5470
ea5470
ea5470
init_vars()
ea5470
{
18bbd0
	mb_project_dir=$(cd "$(dirname $0)" ; pwd)
8e5d5a
	mb_pwd=$(pwd)
ea5470
ed3296
	mb_custom_cfgdefs_args=''
ed3296
	mb_custom_cfgdefs_space=''
ed3296
1411f5
	mb_make_vars=$(cat $mb_project_dir/sofort/config.vars \
1411f5
		| grep -v -e '^#' -e '^$' | tr '[:lower:]' '[:upper:]')
a01d03
1411f5
	mb_impl_vars=$(cat $mb_project_dir/sofort/config.vars \
1411f5
		| grep -v -e '^#' -e '^$' | sed 's/^/mb_/g')
1411f5
1411f5
	mb_proj_vars=$(cat $mb_project_dir/sofort/config.vars \
1411f5
		| grep -v -e '^#' -e '^$' | sed 's/^/mb_default_/g')
1411f5
1411f5
	mb_flag_vars=$(cat $mb_project_dir/sofort/flag.vars \
1411f5
		| grep -v -e '^#' -e '^$')
1411f5
1411f5
	mb_vars="$mb_make_vars $mb_impl_vars $mb_proj_vars $mb_flag_vars"
1411f5
1411f5
	for mb_var in $mb_vars ; do
a01d03
		mb_expr=$mb_var='${'$mb_var':-}'
a01d03
		eval "$mb_expr"
a01d03
	done
a01d03
97f8b2
	# ccenv
97f8b2
	. $mb_project_dir/sofort/ccenv/ccenv.sh
97f8b2
97f8b2
	if ! readlink ./ccenv > /dev/null; then
97f8b2
		if [ -d ./ccenv ]; then
97f8b2
			rm -f ./ccenv/host.mk
97f8b2
			rm -f ./ccenv/native.mk
97f8b2
			rmdir ./ccenv
97f8b2
		fi
97f8b2
	fi
97f8b2
97f8b2
	# config.project
ea5470
	if [ -z "$mb_config" ]; then
7327b8
		. $mb_project_dir/config.project
ea5470
	else
7327b8
		. "$mb_config"
ea5470
	fi
ea5470
2d4980
	# project-specific config definitions
ed2ed6
	if [ _$mb_use_custom_cfgdefs = _yes ]; then
795327
		cat $mb_project_dir/sofort/cfgdefs.in \
795327
			> cfgdefs.mk
795327
	else
795327
		printf '%s %s\n\n' \
795327
				'# this project does not include' \
795327
				'a custom config step.'           \
795327
			> cfgdefs.mk
795327
		cat $mb_project_dir/sofort/cfgdefs.in >> cfgdefs.mk
2d4980
	fi
2d4980
2d4980
	# user build-time overrides
795327
	touch usrdefs.mk
2d4980
ea5470
	# project
ea5470
	mb_nickname=$NICKNAME
ea5470
	mb_source_dir=$SOURCE_DIR
ea5470
ea5470
	# dirs
ea5470
	mb_prefix=$PREFIX
ea5470
	mb_exec_prefix=$EXEC_PREFIX
ea5470
	mb_bindir=$BINDIR
ea5470
	mb_sbindir=$SBINDIR
ea5470
	mb_libdir=$LIBDIR
ea5470
	mb_includedir=$INCLUDEDIR
ea5470
	mb_oldincludedir=$OLDINCLUDEDIR
ea5470
	mb_mandir=$MANDIR
ea5470
	mb_docdir=$DOCDIR
ea5470
	mb_libexecdir=$LIBEXECDIR
ea5470
ea5470
	mb_sysconfdir=$SYSCONFDIR
ea5470
	mb_sharedstatedir=$SHAREDSTATEDIR
ea5470
	mb_localstatedir=$LOCALSTATEDIR
ea5470
	mb_runstatedir=$RUNSTATEDIR
ea5470
	mb_datarootdir=$DATAROOTDIR
ea5470
	mb_datadir=$DATADIR
ea5470
	mb_infodir=$INFODIR
ea5470
	mb_localedir=$LOCALEDIR
ea5470
	mb_htmldir=$HTMLDIR
ea5470
	mb_dvidir=$DVIDIR
ea5470
	mb_pdfdir=$PDFDIR
ea5470
	mb_psdir=$PSDIR
ea5470
ea5470
ea5470
	# build
ea5470
	mb_build=$BUILD
ea5470
	mb_host=$HOST
22e406
	mb_cchost=$CCHOST
486035
	mb_cfghost=$CFGHOST
ea5470
	mb_target=$TARGET
ea5470
	mb_arch=$ARCH
ea5470
	mb_compiler=$COMPILER
ea5470
	mb_toolchain=$TOOLCHAIN
ea5470
	mb_sysroot=$SYSROOT
ea5470
	mb_cross_compile=$CROSS_COMPILE
ea5470
	mb_shell=$SHELL
ea5470
ea5470
	# switches
ea5470
	mb_cflags=$CFLAGS
ea5470
	mb_cflags_debug=$CFLAGS_DEBUG
ea5470
	mb_cflags_common=$CFLAGS_COMMON
ea5470
	mb_cflags_cmdline=$CFLAGS_CMDLINE
ea5470
	mb_cflags_config=$CFLAGS_CONFIG
ea5470
	mb_cflags_sysroot=$CFLAGS_SYSROOT
ea5470
	mb_cflags_os=$CFLAGS_OS
ea5470
	mb_cflags_site=$CFLAGS_SITE
ea5470
	mb_cflags_path=$CFLAGS_PATH
ea5470
	mb_cflags_strict=$CFLAGS_STRICT
ea5470
	mb_cflags_util=$CFLAGS_UTIL
ea5470
	mb_cflags_last=$CFLAGS_LAST
ea5470
	mb_cflags_once=$CFLAGS_ONCE
ea5470
ea5470
	mb_ldflags=$LDFLAGS
ea5470
	mb_ldflags_debug=$LDFLAGS_DEBUG
ea5470
	mb_ldflags_common=$LDFLAGS_COMMON
ea5470
	mb_ldflags_cmdline=$LDFLAGS_CMDLINE
ea5470
	mb_ldflags_config=$LDFLAGS_CONFIG
ea5470
	mb_ldflags_sysroot=$LDFLAGS_SYSROOT
ea5470
	mb_ldflags_path=$LDFLAGS_PATH
ea5470
	mb_ldflags_strict=$LDFLAGS_STRICT
ea5470
	mb_ldflags_util=$LDFLAGS_UTIL
ea5470
	mb_ldflags_last=$LDFLAGS_LAST
ea5470
	mb_ldflags_once=$LDFLAGS_ONCE
ea5470
ea5470
	mb_pe_subsystem=$PE_SUBSYSTEM
ea5470
	mb_pe_image_base=$PE_IMAGE_BASE
ea5470
	mb_pe_config_defs=$PE_CONFIG_DEFS
ea5470
ea5470
	mb_elf_eh_frame=$ELF_EH_FRAME
ea5470
	mb_elf_hash_style=$ELF_HASH_STYLE
ea5470
	mb_elf_config_defs=$ELF_CONFIG_DEFS
ea5470
ea5470
	# overrides
ea5470
	mb_user_cc=$CC
ea5470
	mb_user_cpp=$CPP
ea5470
	mb_user_cxx=$CXX
97f8b2
97f8b2
	mb_native_cc=$NATIVE_CC
97f8b2
	mb_native_cpp=$NATIVE_CPP
97f8b2
	mb_native_cxx=$NATIVE_CXX
97f8b2
97f8b2
	mb_native_host=$NATIVE_HOST
97f8b2
	mb_native_cfghost=$NATIVE_CFGHOST
97f8b2
	mb_native_cflags=$NATIVE_CFLAGS
97f8b2
	mb_native_ldflags=$NATIVE_LDFLAGS
ea5470
}
ea5470
ea5470
ea5470
verify_build_directory()
ea5470
{
ea5470
	if [ "$mb_project_dir" = "$mb_pwd" ]; then
ed2ed6
		if [ _$mb_require_out_of_tree = _yes ]; then
ea5470
			error_msg "$mb_package: out-of-tree builds are required."
ea5470
			error_msg "please invoke configure again from a clean build directory."
7327b8
			exit 1
ea5470
		else
ea5470
			mb_project_dir='.'
ea5470
		fi
ea5470
	fi
248ad4
248ad4
	rm -f Makefile Makefile.host Makefile.tmp Makefile.failed
ea5470
}
ea5470
ea5470
ea5470
verify_source_directory()
ea5470
{
ea5470
	if [ -z "$mb_source_dir" ]; then
ed2ed6
		if [ _$mb_require_source_dir = _yes ]; then
ea5470
			error_msg "$mb_package: specifying an external source directory is required."
ea5470
			error_msg "you can set the source directory either via --source-dir=<path>,"
ea5470
			error_msg "or by setting the SOURCE_DIR variable."
7327b8
			exit 1
ea5470
		fi
ea5470
	fi
ea5470
}
ea5470
ea5470
ea5470
common_defaults()
ea5470
{
ea5470
	# git
ea5470
	if [ -n "$mb_source_dir" ]; then
ea5470
		if [ -d "$mb_source_dir/.git" ]; then
ea5470
			mb_git_reference_index="\$(SOURCE_DIR)/.git/index"
ea5470
		fi
ea5470
	elif [ -d "$mb_project_dir/.git" ]; then
ea5470
		mb_git_reference_index="\$(PROJECT_DIR)/.git/index"
ea5470
	fi
ea5470
ea5470
	# project
ea5470
	[ -z "$mb_nickname" ] 		&& mb_nickname=$mb_package
ea5470
	[ -z "$mb_source_dir" ] 	&& mb_source_dir=$mb_project_dir
ea5470
	[ -z "$mb_avoid_version" ] 	&& mb_avoid_version='no'
ea5470
406b0d
	# pkgconfig
406b0d
	[ -z "$mb_pkgname" ]		&& mb_pkgname="$mb_default_pkgname"
406b0d
	[ -z "$mb_pkgdesc" ]		&& mb_pkgdesc="$mb_default_pkgdesc"
406b0d
	[ -z "$mb_pkgusrc" ]		&& mb_pkgusrc="$mb_default_pkgusrc"
406b0d
	[ -z "$mb_pkgrepo" ]		&& mb_pkgrepo="$mb_default_pkgrepo"
406b0d
	[ -z "$mb_pkgpsrc" ]		&& mb_pkgpsrc="$mb_default_pkgpsrc"
406b0d
	[ -z "$mb_pkgdurl" ]		&& mb_pkgdurl="$mb_default_pkgdurl"
406b0d
	[ -z "$mb_pkgdefs" ]		&& mb_pkgdefs="$mb_default_pkgdefs"
406b0d
	[ -z "$mb_pkglibs" ]		&& mb_pkglibs="$mb_default_pkglibs"
406b0d
ea5470
	# dirs
ea5470
	[ -z "$mb_prefix" ] 		&& [ -z "$mb_prefix_set" ] \
ea5470
					&& mb_prefix='/usr/local'
ea5470
ea5470
	[ -z "$mb_exec_prefix" ] 	&& [ -z "$mb_exec_prefix_set" ]	\
ea5470
					&& mb_exec_prefix=$mb_prefix
ea5470
4a4338
	[ -z "$mb_bindir" ] 		&& [ -z "$mb_bindir_set" ] \
4a4338
					&& [ -z "$mb_bindir_basename" ] \
4a4338
					&& mb_bindir=$mb_exec_prefix/bin
4a4338
4a4338
	[ -z "$mb_bindir" ] 		&& [ -z "$mb_bindir_set" ] \
4a4338
					&& mb_bindir=$mb_exec_prefix/$mb_bindir_basename
4a4338
ea5470
	[ -z "$mb_sbindir" ] 		&& mb_sbindir=$mb_exec_prefix/sbin
ea5470
	[ -z "$mb_libdir" ] 		&& mb_libdir=$mb_exec_prefix/lib
ea5470
	[ -z "$mb_includedir" ]		&& mb_includedir=$mb_prefix/include
ea5470
	[ -z "$mb_oldincludedir" ]	&& mb_oldincludedir=$mb_prefix/include
ea5470
	[ -z "$mb_datarootdir" ] 	&& mb_datarootdir=$mb_prefix/share
ea5470
	[ -z "$mb_mandir" ] 		&& mb_mandir=$mb_datarootdir/man
ea5470
	[ -z "$mb_docdir" ] 		&& mb_docdir=$mb_datarootdir/doc
ea5470
	[ -z "$mb_libexecdir" ]		&& mb_libexecdir=$mb_exec_prefix/libexec
ea5470
ea5470
	[ -z "$mb_sysconfdir" ] 	&& mb_sysconfdir=$mb_exec_prefix/etc
ea5470
	[ -z "$mb_sharedstatedir" ] 	&& mb_sharedstatedir=$mb_prefix/com
ea5470
	[ -z "$mb_localstatedir" ] 	&& mb_localstatedir=$mb_prefix/var
ea5470
	[ -z "$mb_runstatedir" ] 	&& mb_runstatedir=$mb_localstatedir/run
ea5470
	[ -z "$mb_datarootdir" ] 	&& mb_datarootdir=$mb_prefix/share
ea5470
	[ -z "$mb_datadir" ] 		&& mb_datadir=$mb_datarootdir
ea5470
	[ -z "$mb_infodir" ] 		&& mb_infodir=$mb_datarootdir/info
ea5470
	[ -z "$mb_localedir" ] 		&& mb_localedir=$mb_datarootdir/locale
ea5470
	[ -z "$mb_htmldir" ] 		&& mb_htmldir=$mb_docdir
ea5470
	[ -z "$mb_dvidir" ] 		&& mb_dvidir=$mb_docdir
ea5470
	[ -z "$mb_pdfdir" ] 		&& mb_pdfdir=$mb_docdir
ea5470
	[ -z "$mb_psdir" ] 		&& mb_psdir=$mb_docdir
ea5470
ea5470
ea5470
	# build
ea5470
	[ -z "$mb_build" ] 		&& mb_build=$mb_default_build
ea5470
	[ -z "$mb_host" ] 		&& mb_host=$mb_default_host
22e406
	[ -z "$mb_cchost" ] 		&& mb_cchost=$mb_default_cchost
486035
	[ -z "$mb_cfghost" ] 		&& mb_cfghost=$mb_default_cfghost
ea5470
	[ -z "$mb_target" ] 		&& mb_target=$mb_default_target
ea5470
	[ -z "$mb_arch" ] 		&& mb_arch=$mb_default_arch
ea5470
	[ -z "$mb_compiler" ] 		&& mb_compiler=$mb_default_compiler
ea5470
	[ -z "$mb_toolchain" ] 		&& mb_toolchain=$mb_default_toolchain
ea5470
	[ -z "$mb_sysroot" ] 		&& mb_sysroot=$mb_default_sysroot
ea5470
	[ -z "$mb_cross_compile" ] 	&& mb_cross_compile=$mb_default_cross_compile
ea5470
	[ -z "$mb_shell" ] 		&& mb_shell=$mb_default_shell
ea5470
ea5470
	# switches
ea5470
	[ -z "$mb_cflags_debug" ]	&& mb_cflags_debug=$mb_default_cflags_debug
ea5470
	[ -z "$mb_cflags_common" ]	&& mb_cflags_common=$mb_default_cflags_common
ea5470
	[ -z "$mb_cflags_cmdline" ]	&& mb_cflags_cmdline=$mb_default_cflags_cmdline
ea5470
	[ -z "$mb_cflags_config" ]	&& mb_cflags_config=$mb_default_cflags_config
ea5470
	[ -z "$mb_cflags_sysroot" ]	&& mb_cflags_sysroot=$mb_default_cflags_sysroot
ea5470
	[ -z "$mb_cflags_os" ]		&& mb_cflags_os=$mb_default_cflags_os
ea5470
	[ -z "$mb_cflags_site" ]	&& mb_cflags_site=$mb_default_cflags_site
ea5470
	[ -z "$mb_cflags_path" ]	&& mb_cflags_path=$mb_default_cflags_path
ea5470
	[ -z "$mb_cflags_strict" ]	&& mb_cflags_strict=$mb_default_cflags_strict
ea5470
	[ -z "$mb_cflags_util" ]	&& mb_cflags_util=$mb_default_cflags_util
ea5470
	[ -z "$mb_cflags_last" ]	&& mb_cflags_last=$mb_default_cflags_last
ea5470
	[ -z "$mb_cflags_once" ]	&& mb_cflags_once=$mb_default_cflags_once
ea5470
ea5470
	[ -z "$mb_ldflags_debug" ]	&& mb_ldflags_debug=$mb_default_ldflags_debug
ea5470
	[ -z "$mb_ldflags_common" ]	&& mb_ldflags_common=$mb_default_ldflags_common
ea5470
	[ -z "$mb_ldflags_cmdline" ]	&& mb_ldflags_cmdline=$mb_default_ldflags_cmdline
ea5470
	[ -z "$mb_ldflags_config" ]	&& mb_ldflags_config=$mb_default_ldflags_config
ea5470
	[ -z "$mb_ldflags_sysroot" ]	&& mb_ldflags_sysroot=$mb_default_ldflags_sysroot
ea5470
	[ -z "$mb_ldflags_path" ]	&& mb_ldflags_path=$mb_default_ldflags_path
ea5470
	[ -z "$mb_ldflags_strict" ]	&& mb_ldflags_strict=$mb_default_ldflags_strict
ea5470
	[ -z "$mb_ldflags_util" ]	&& mb_ldflags_util=$mb_default_ldflags_util
ea5470
	[ -z "$mb_ldflags_last" ]	&& mb_ldflags_last=$mb_default_ldflags_last
ea5470
	[ -z "$mb_ldflags_once" ]	&& mb_ldflags_once=$mb_default_ldflags_once
ea5470
ea5470
	[ -z "$mb_pe_subsystem" ]	&& mb_pe_subsystem=$mb_default_pe_subsystem
ea5470
	[ -z "$mb_pe_image_base" ]	&& mb_pe_image_base=$mb_default_pe_image_base
ea5470
	[ -z "$mb_pe_config_defs" ]	&& mb_pe_config_defs=$mb_default_pe_config_defs
ea5470
ea5470
	[ -z "$mb_elf_eh_frame" ]	&& mb_elf_eh_frame=$mb_default_elf_eh_frame
ea5470
	[ -z "$mb_elf_hash_style" ]	&& mb_elf_hash_style=$mb_default_elf_hash_style
ea5470
	[ -z "$mb_elf_config_defs" ]	&& mb_elf_config_defs=$mb_default_elf_config_defs
ea5470
ea5470
	# config
ea5470
	[ -z "$mb_all_static" ]		&& mb_all_static='no'
ea5470
	[ -z "$mb_all_shared" ]		&& mb_all_shared='no'
ea5470
	[ -z "$mb_disable_frontend" ]	&& mb_disable_frontend='no'
ea5470
	[ -z "$mb_disable_static" ]	&& mb_disable_static='no'
ea5470
	[ -z "$mb_disable_shared" ]	&& mb_disable_shared='no'
ea5470
ea5470
	# host/target
ea5470
	[ -z "$mb_host" ] 		&& mb_host=$mb_target
ea5470
	[ -z "$mb_target" ] 		&& mb_target=$mb_host
ea5470
ea5470
	# sysroot
ea5470
	if [ -n "$mb_sysroot" ]; then
ea5470
		if [ -z "$mb_cflags_sysroot" ]; then
ea5470
			mb_cflags_sysroot="--sysroot=$mb_sysroot"
ea5470
		fi
ea5470
ea5470
		if [ -z "$mb_ldflags_sysroot" ]; then
ea5470
			mb_ldflags_sysroot="--sysroot=$mb_sysroot"
ea5470
		fi
ea5470
	fi
ea5470
ea5470
	# debug
ed2ed6
	if [ _$mb_debug = _yes ]; then
ea5470
		if [ -z "$mb_cflags_debug" ]; then
ea5470
			mb_cflags_debug='-g3 -O0'
ea5470
		fi
ea5470
	fi
ea5470
}
ea5470
ea5470
ea5470
config_flags()
ea5470
{
ea5470
	mb_ldflags_tmp=" $mb_ldflags "
8e5d5a
	mb_ldflags_libs=$(echo "$mb_ldflags_tmp" | sed 's/ -static / /g')
ea5470
ea5470
	if [ "$mb_ldflags_tmp" != "$mb_ldflags_libs" ]; then
ea5470
		mb_ldflags="$mb_ldflags_libs"
ea5470
		mb_ldflags_util="$mb_ldflags_util -static"
ea5470
	fi
ea5470
ea5470
	# ccstrict
ed2ed6
	if [ _$mb_ccstrict = _yes ]; then
ea5470
		mb_cflags_strict='-Wall -Werror -Wextra -Wundef'
ea5470
	fi
ea5470
ea5470
	# ldstrict
ed2ed6
	if [ _$mb_ldstrict = _yes ]; then
ea5470
		mb_ldflags_strict='-Wl,--no-undefined'
ea5470
	fi
ea5470
}
ea5470
ea5470
ea5470
config_copy()
ea5470
{
1411f5
	mb_vars=$(cut -d'=' -f1 "$mb_project_dir/sofort/config.vars" \
1411f5
			| grep -v '^#')
1411f5
1411f5
	mb_sed_substs=" \
1411f5
		$(for __var in $mb_vars; do                  \
1411f5
			printf '%s"$%s"%s' "-e 's^@$__var@^'" \
1411f5
				"mb_$__var" "'^g' ";           \
1411f5
		done)"
1411f5
1411f5
	eval sed $mb_sed_substs \
1411f5
		$mb_project_dir/Makefile.in    \
1411f5
			| sed -e 's/[ \t]*$//g' \
1411f5
			> $mb_pwd/Makefile.tmp
97f8b2
}
22e406
729764
97f8b2
config_ccenv()
97f8b2
{
97f8b2
	mkdir -p ./ccenv
97f8b2
	touch ./ccenv/host.mk
97f8b2
	touch ./ccenv/native.mk
da95e7
97f8b2
	ccenv_set_host_variables
97f8b2
	ccenv_set_native_variables
97f8b2
}
da95e7
da95e7
config_custom()
da95e7
{
ed2ed6
	if [ _$mb_use_custom_cfgdefs = _yes ]; then
ed3296
		eval . $mb_project_dir/project/config/cfgdefs.sh \
ed3296
			"$mb_custom_cfgdefs_args"
da95e7
		config_copy
da95e7
	fi
22e406
ed2ed6
	if [ _$mb_use_custom_usrdefs = _yes ]; then
da95e7
		. $mb_project_dir/project/usrdefs.sh
da95e7
	fi
da95e7
}
da95e7
da95e7
da95e7
config_cfghost()
da95e7
{
486035
	if [ -z "$mb_cfghost" ]; then
486035
		mb_cfghost=$mb_cchost
486035
	fi
486035
486035
	sed		-e 's^@cchost@^'"$mb_cchost"'^g'     \
486035
			-e 's^@cfghost@^'"$mb_cfghost"'^g'   \
7327b8
		$mb_pwd/Makefile.tmp > $mb_pwd/Makefile.host
22e406
7327b8
	rm  $mb_pwd/Makefile.tmp
7327b8
	mv  $mb_pwd/Makefile.host $mb_pwd/Makefile
ea5470
}
ea5470
ea5470
ea5470
config_support()
ea5470
{
ed2ed6
	[ _$mb_disable_shared = _yes ] && return 0
ea5470
8e5d5a
	mbt_cc=$(make .display-cc)
8e5d5a
	mbt_cflags=$(make .display-cflags)
ea5470
	mbt_source='int foo(int x){return ++x;}'
ff5a6c
	mbt_result=no
ea5470
ea5470
	rm -f a.out
ff5a6c
	printf '%s' "$mbt_source" | $mbt_cc -shared -o a.out -xc -
ff5a6c
	[ -f a.out ] && mbt_result=yes
ea5470
	rm -f a.out
ea5470
ff5a6c
	if [ $mbt_result = no ]; then
ed2ed6
		mb_disable_shared=yes
ea5470
		config_copy
ea5470
	fi
ea5470
}
ea5470
ea5470
ea5470
config_host()
ea5470
{
ea5470
	make -s host.tag && return 0
ea5470
ea5470
	error_msg "configure was able to generate a Makefile for the selected host,"
ea5470
	error_msg "however the host-targeting compiler was found to be missing"
ea5470
	error_msg "at least one of the required headers or features."
ea5470
	exit 2
ea5470
}
ea5470
ea5470
ea5470
config_status()
ea5470
{
ea5470
	printf "\n\n"
ea5470
	make .display
ea5470
	printf "\nconfiguration completed successfully.\n\n"
ea5470
}
ea5470
248ad4
248ad4
config_failure()
248ad4
{
248ad4
	if [ -f Makefile ]; then
248ad4
		mb_error='failed to use the generated Makefile.'
248ad4
		printf '\n%s: error: %s\n' "${0}" "$mb_error" >&2
248ad4
		mv Makefile Makefile.failed
248ad4
	fi
248ad4
248ad4
	exit 2
248ad4
}
248ad4
248ad4
248ad4
config_success()
248ad4
{
248ad4
	trap '' EXIT
248ad4
	exit 0
248ad4
}
248ad4
248ad4
ea5470
# one: init
ea5470
init_vars
ea5470
verify_build_directory
ea5470
ea5470
ea5470
# two: args
ea5470
for arg ; do
ea5470
	case "$arg" in
97f8b2
		--help)
97f8b2
			usage
97f8b2
			;;
97f8b2
		--help=ccenv)
97f8b2
			ccenv_usage
97f8b2
			;;
97f8b2
97f8b2
		# ccenv
97f8b2
		--cross-compile=*)
97f8b2
			mb_cross_compile=${arg#*=}
97f8b2
			;;
97f8b2
		--compiler=*)
97f8b2
			mb_compiler=${arg#*=}
97f8b2
			;;
97f8b2
		--toolchain=*)
97f8b2
			mb_toolchain=${arg#*=}
97f8b2
			;;
97f8b2
		--zealous)
97f8b2
			mb_agnostic=yes
97f8b2
			mb_zealous=
97f8b2
			;;
97f8b2
		--zealous=*)
97f8b2
			mb_zealous=${arg#*=}
97f8b2
			;;
97f8b2
		--ccenv=*)
97f8b2
			mb_ccenv=${arg#*=}
ea5470
			;;
ea5470
ea5470
		# dirs
ea5470
		--prefix=*)
ea5470
			mb_prefix_set=yes
ea5470
			mb_prefix=${arg#*=}
ea5470
			;;
ea5470
		--exec-prefix=*)
ea5470
			mb_exec_prefix_set=yes
ea5470
			mb_exec_prefix=${arg#*=}
ea5470
			;;
ea5470
		--bindir=*)
4a4338
			mb_bindir_set=yes
ea5470
			mb_bindir=${arg#*=}
ea5470
			;;
ea5470
		--sbindir=*)
ea5470
			mb_sbindir=${arg#*=}
ea5470
			;;
ea5470
		--libdir=*)
ea5470
			mb_libdir=${arg#*=}
ea5470
			;;
ea5470
		--includedir=*)
ea5470
			mb_includedir=${arg#*=}
ea5470
			;;
ea5470
		--oldincludedir=*)
ea5470
			mb_oldincludedir=${arg#*=}
ea5470
			;;
ea5470
		--mandir=*)
ea5470
			mb_mandir=${arg#*=}
ea5470
			;;
ea5470
		--libexecdir=*)
ea5470
			mb_libexecdir=${arg#*=}
ea5470
			;;
ea5470
ea5470
ea5470
		--sysconfdir=*)
ea5470
			mb_sysconfdir=${arg#*=}
ea5470
			;;
ea5470
		--sharedstatedir=*)
ea5470
			mb_sharedstatedir=${arg#*=}
ea5470
			;;
ea5470
		--localstatedir=*)
ea5470
			mb_localstatedir=${arg#*=}
ea5470
			;;
ea5470
		--runstatedir=*)
ea5470
			mb_runstatedir=${arg#*=}
ea5470
			;;
ea5470
		--datarootdir=*)
ea5470
			mb_datarootdir=${arg#*=}
ea5470
			;;
ea5470
		--datadir=*)
ea5470
			mb_datadir=${arg#*=}
ea5470
			;;
ea5470
		--infodir=*)
ea5470
			mb_infodir=${arg#*=}
ea5470
			;;
ea5470
		--localedir=*)
ea5470
			mb_localedir=${arg#*=}
ea5470
			;;
ea5470
		--htmldir=*)
ea5470
			mb_htmldir=${arg#*=}
ea5470
			;;
ea5470
		--dvidir=*)
ea5470
			mb_dvidir=${arg#*=}
ea5470
			;;
ea5470
		--pdfdir=*)
ea5470
			mb_pdfdir=${arg#*=}
ea5470
			;;
ea5470
		--psdir=*)
ea5470
			mb_psdir=${arg#*=}
ea5470
			;;
ea5470
ea5470
ea5470
		# build
ea5470
		--build=*)
ea5470
			mb_build=${arg#*=}
ea5470
			;;
ea5470
		--host=*)
ea5470
			mb_host=${arg#*=}
ea5470
			;;
22e406
		--cchost=*)
22e406
			mb_cchost=${arg#*=}
22e406
			;;
486035
		--cfghost=*)
486035
			mb_cfghost=${arg#*=}
486035
			;;
ea5470
		--target=*)
ea5470
			mb_target=${arg#*=}
ea5470
			;;
ea5470
		--arch=*)
ea5470
			mb_arch=${arg#*=}
ea5470
			;;
ea5470
		--sysroot=*)
ea5470
			mb_sysroot=${arg#*=}
ea5470
			;;
ea5470
		--shell=*)
ea5470
			mb_shell=${arg#*=}
ea5470
			;;
ea5470
		--debug)
ed2ed6
			mb_debug=yes
ea5470
			;;
ea5470
ea5470
		# config
ea5470
		--all-static)
ed2ed6
			mb_all_static=yes
ea5470
			;;
ea5470
		--all-shared)
ed2ed6
			mb_all_shared=yes
ea5470
			;;
ea5470
		--disable-frontend)
ed2ed6
			mb_disable_frontend=yes
ea5470
			;;
ea5470
		--disable-app)
ed2ed6
			mb_disable_frontend=yes
ea5470
			;;
ea5470
		--enable-frontend)
ea5470
			mb_disable_frontend='no'
ea5470
			;;
ea5470
		--enable-app)
ea5470
			mb_disable_frontend='no'
ea5470
			;;
ea5470
		--disable-static)
ed2ed6
			mb_disable_static=yes
ea5470
			;;
ea5470
		--disable-shared)
ed2ed6
			mb_disable_shared=yes
ea5470
			;;
ea5470
		--enable-static)
ea5470
			mb_disable_static='no'
ea5470
			;;
ea5470
		--enable-shared)
ea5470
			mb_disable_shared='no'
ea5470
			;;
ea5470
ea5470
		# convenience
ea5470
		--strict)
ed2ed6
			mb_ccstrict=yes
ed2ed6
			mb_ldstrict=yes
ea5470
			;;
ea5470
		--ccstrict)
ed2ed6
			mb_ccstrict=yes
ea5470
			;;
ea5470
		--ldstrict)
ed2ed6
			mb_ldstrict=yes
ea5470
			;;
ea5470
ea5470
		# project
ea5470
		--nickname=*)
ea5470
			mb_nickname=${arg#*=}
ea5470
			;;
e828ba
		--program-prefix=*)
e828ba
			mb_program_prefix=${arg#*=}
e828ba
			;;
ea5470
		--avoid-version)
ed2ed6
			mb_avoid_version=yes
ea5470
			;;
ea5470
		--source-dir=*)
ea5470
			mb_source_dir=${arg#*=}
ea5470
			;;
ea5470
406b0d
		# pkgconfig
406b0d
		--pkgname=*)
406b0d
			mb_pkgname=${arg#*=}
406b0d
			;;
406b0d
406b0d
		--pkgdesc=*)
406b0d
			mb_pkgdesc=${arg#*=}
406b0d
			;;
406b0d
406b0d
		--pkgusrc=*)
406b0d
			mb_pkgusrc=${arg#*=}
406b0d
			;;
406b0d
406b0d
		--pkgrepo=*)
406b0d
			mb_pkgrepo=${arg#*=}
406b0d
			;;
406b0d
406b0d
		--pkgpsrc=*)
406b0d
			mb_pkgpsrc=${arg#*=}
406b0d
			;;
406b0d
406b0d
		--pkgdurl=*)
406b0d
			mb_pkgdurl=${arg#*=}
406b0d
			;;
406b0d
406b0d
		--pkgdefs=*)
406b0d
			mb_pkgdefs=${arg#*=}
406b0d
			;;
406b0d
406b0d
		--pkglibs=*)
406b0d
			mb_pkglibs=${arg#*=}
406b0d
			;;
406b0d
ca9d19
		# compatibility
ca9d19
		--enable-dependency-tracking)
ca9d19
			;;
ca9d19
		--disable-dependency-tracking)
ca9d19
			;;
ca9d19
ea5470
		*)
ed2ed6
			if [ _$mb_use_custom_cfgdefs = _yes ]; then
ed3296
				mb_escaped_arg=\'$(printf '%s\n' "$arg" | sed -e "s/'/'\\\\''/g")\'
ed3296
				mb_escaped_arg="$mb_custom_cfgdefs_space$mb_escaped_arg"
ed3296
				mb_custom_cfgdefs_args="$mb_custom_cfgdefs_args$mb_escaped_arg"
ed3296
				mb_custom_cfgdefs_space=' '
da95e7
			else
da95e7
				error_msg ${arg#}: "unsupported config argument."
da95e7
				exit 2
da95e7
			fi
ea5470
			;;
ea5470
	esac
ea5470
done
ea5470
ea5470
ea5470
ea5470
# three: validation
ea5470
verify_source_directory
ea5470
e828ba
if ! [ -z "$mb_program_prefix" ]; then
e828ba
	error_msg "--program-prefix is not yet fully support (must be null)."
e828ba
fi
e828ba
ea5470
ea5470
ea5470
# four: defaults
ea5470
common_defaults
ea5470
ea5470
ea5470
# five: config
ea5470
config_flags
ea5470
config_copy
97f8b2
config_ccenv
da95e7
config_custom
da95e7
config_cfghost
ea5470
config_support
ea5470
config_host
ea5470
config_status
ea5470
ea5470
ea5470
# all done
248ad4
config_success