Blame configure

52d60d
#!/bin/sh
52d60d
# we are no longer lazy.
52d60d
52d60d
# this script respects both CFLAGS and CFLAGS_CMDLINE,
52d60d
# as well as both LDFLAGS and LDFLAGS_CMDLINE, however
52d60d
# the latter variable of each pair should be preferred.
52d60d
52d60d
usage()
52d60d
{
52d60d
	cat config.usage
52d60d
	exit $?
52d60d
}
52d60d
52d60d
error_msg()
52d60d
{
52d60d
	echo $@ >&2
52d60d
}
52d60d
52d60d
52d60d
init_vars()
52d60d
{
52d60d
	mb_project_dir=$(cd `dirname $0` ; pwd)
52d60d
	mb_pwd=`pwd`
52d60d
52d60d
	if [ x"$mb_config" = x ]; then
52d60d
		. $mb_project_dir/config.project || exit 2
52d60d
	else
52d60d
		. "$mb_config" || exit 2
52d60d
	fi
52d60d
52d60d
	# dirs
52d60d
	mb_prefix=$PREFIX
52d60d
	mb_bindir=$BINDIR
52d60d
	mb_libdir=$LIBDIR
52d60d
	mb_includedir=$INCLUDEDIR
52d60d
	mb_syslibdir=$LIBDIR
52d60d
	mb_mandir=$MANDIR
52d60d
	mb_docdir=$DOCDIR
52d60d
	mb_libexecdir=$LIBEXECDIR
52d60d
52d60d
52d60d
	# build
52d60d
	mb_build=$BUILD
52d60d
	mb_host=$HOST
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
52d60d
	mb_cflags_path=$CFLAGS_PATH
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
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
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
{
52d60d
	if [ x"$mb_project_dir" = x"$mb_pwd" ]; then
52d60d
		if [ x"$mb_require_out_of_tree" = xyes ]; then
52d60d
			error_msg "$mb_package: out-of-tree builds are required."
52d60d
			error_msg "please invoke configure again from a clean build directory."
52d60d
			exit 2
52d60d
		else
52d60d
			mb_project_dir='.'
52d60d
		fi
52d60d
	fi
52d60d
}
52d60d
52d60d
52d60d
common_defaults()
52d60d
{
52d60d
	# dirs
52d60d
	[ -z "$mb_prefix" ] 		&& mb_prefix=$mb_default_prefix
52d60d
	[ -z "$mb_bindir" ] 		&& mb_bindir=$mb_default_bindir
52d60d
	[ -z "$mb_libdir" ] 		&& mb_libdir=$mb_default_libdir
52d60d
	[ -z "$mb_includedir" ]		&& mb_includedir=$mb_default_includedir
52d60d
	[ -z "$mb_syslibdir" ] 		&& mb_syslibdir=$mb_default_syslibdir
52d60d
	[ -z "$mb_mandir" ] 		&& mb_mandir=$mb_default_mandir
52d60d
	[ -z "$mb_docdir" ] 		&& mb_docdir=$mb_default_docdir
52d60d
	[ -z "$mb_libexecdir" ]		&& mb_libexecdir=$mb_default_libexecdir
52d60d
52d60d
	# build
52d60d
	[ -z "$mb_build" ] 		&& mb_build=$mb_default_build
52d60d
	[ -z "$mb_host" ] 		&& mb_host=$mb_default_host
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
52d60d
	[ -z "$mb_cflags_path" ]	&& mb_cflags_path=$mb_default_cflags_path
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
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
52d60d
	# host/target
52d60d
	[ -z "$mb_host" ] 		&& mb_host=$mb_target
f6d994
	[ -z "$mb_target" ] 		&& mb_target=$mb_host
52d60d
52d60d
	# sysroot
52d60d
	if [ x"$mb_sysroot" != x ]; then
52d60d
		if [ x"$mb_cflags_sysroot" = x ]; then
52d60d
			mb_cflags_sysroot="--sysroot=$mb_sysroot"
52d60d
		fi
52d60d
52d60d
		if [ x"$mb_ldflags_sysroot" = x ]; then
52d60d
			mb_ldflags_sysroot="-Wl,--sysroot,$mb_sysroot"
52d60d
		fi
52d60d
	fi
52d60d
52d60d
	# debug
52d60d
	if [ x"$mb_debug" = xyes ]; then
52d60d
		if [ x"$mb_cflags_debug" = x ]; then
52d60d
			mb_cflags_debug='-g3 -O0'
52d60d
		fi
52d60d
	fi
52d60d
220bb3
	# compiler
220bb3
	if [ x"$mb_compiler" != x ]; then
52d60d
		if [ x"$mb_native_cc" = x ]; then
220bb3
			mb_native_cc=$mb_compiler
52d60d
		fi
52d60d
	fi
2c5c40
2c5c40
	# toolchain
2c5c40
	if [ x"$mb_toolchain" = x ]; then
2c5c40
		mb_toolchain='binutils'
2c5c40
	fi
5d406f
5d406f
	# fallback host recipe
5d406f
	if [ x"$mb_host" != x ]; 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
52d60d
}
52d60d
52d60d
52d60d
native_defaults()
52d60d
{
52d60d
	# CC (when set, must be valid)
52d60d
	if [ x"$CC" != x ]; then
52d60d
		$CC -dM -E - < /dev/null > /dev/null || exit 2
52d60d
	fi
52d60d
220bb3
	# compiler
52d60d
	[ -z "$mb_native_cc" ] && mb_native_cc=$CC
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
52d60d
	if [ x"$mb_native_cc" = x ]; then
52d60d
		error_msg "config error: could not find a working native compiler."
52d60d
		exit 2
52d60d
	fi
52d60d
220bb3
	if [ x"$mb_compiler" = x ]; then
220bb3
		$mb_native_cc -dM -E - < /dev/null | grep '__clang__' > /dev/null && mb_compiler='clang'
52d60d
	fi
52d60d
220bb3
	if [ x"$mb_compiler" = x ]; then
220bb3
		$mb_native_cc -dM -E - < /dev/null | grep '__GCC' > /dev/null && mb_compiler='gcc'
52d60d
	fi
52d60d
220bb3
	if [ x"$mb_compiler" = x ]; then
220bb3
		$mb_native_cc -dM -E - < /dev/null | grep '__CPARSER__' > /dev/null && mb_compiler='cparser'
52d60d
	fi
52d60d
220bb3
	if [ x"$mb_compiler" = x ]; then
52d60d
		error_msg "config error: could not identify the native compiler."
52d60d
		exit 2
52d60d
	fi
52d60d
52d60d
52d60d
	# host
52d60d
	if [ x"$mb_host" = x ]; then
52d60d
		mb_host='native'
52d60d
	fi
52d60d
52d60d
38f2f3
	# target
38f2f3
	if [ x"$mb_target" = x ]; then
38f2f3
		mb_target='native'
38f2f3
	fi
38f2f3
38f2f3
52d60d
	# os
52d60d
	mb_native_os=`uname | tr '[:upper:]' '[:lower:]'`
52d60d
52d60d
	mb_native_os_sizeof_pointer=`$mb_native_cc -dM -E - < /dev/null \
52d60d
			| grep __SIZEOF_POINTER__  \
52d60d
			| cut -d ' ' -f3`
52d60d
52d60d
	mb_native_os_bits=`expr '8' '*' '0'"$mb_native_os_sizeof_pointer"`
52d60d
52d60d
	if [ $mb_native_os_bits = 32 ]; then
52d60d
		mb_native_os_underscore='_'
52d60d
	else
52d60d
		mb_native_os_underscore=''
52d60d
	fi
52d60d
52d60d
	if [ x"$mb_native_os_sizeof_pointer" = x ]; then
52d60d
		error_msg "config error: could not determine size of pointer on native system."
52d60d
		exit 2
52d60d
	fi
52d60d
52d60d
	[ -z "$mb_native_os" ] 			&& mb_native_os=$mb_native_os
52d60d
	[ -z "$mb_native_os_bits" ] 		&& mb_native_os_bits=$mb_native_os_bits
52d60d
	[ -z "$mb_native_os_underscore" ]	&& mb_native_os_underscore=$mb_native_os_underscore
52d60d
}
52d60d
52d60d
52d60d
cross_defaults()
52d60d
{
52d60d
	if [ x"$mb_cross_compile" = x ] && [ x"$mb_host" != xnative ]; then
52d60d
		mb_cross_compile=$mb_host'-'
52d60d
	fi
52d60d
}
52d60d
52d60d
52d60d
config_copy()
52d60d
{
52d60d
	sed 		-e 's^@package@^'"$mb_package"'^g' 				\
52d60d
			-e 's^@project_dir@^'"$mb_project_dir"'^g'			\
52d60d
											\
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'		\
52d60d
			-e 's^@cflags_path@^'"$mb_cflags_path"'^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'			\
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'				\
52d60d
			-e 's^@bindir@^'"$mb_bindir"'^g'				\
52d60d
			-e 's^@libdir@^'"$mb_libdir"'^g'				\
52d60d
			-e 's^@includedir@^'"$mb_includedir"'^g'			\
52d60d
			-e 's^@syslibdir@^'"$mb_syslibdir"'^g'				\
52d60d
			-e 's^@mandir@^'"$mb_mandir"'^g'				\
52d60d
			-e 's^@docdir@^'"$mb_docdir"'^g'				\
52d60d
			-e 's^@libexecdir@^'"$mb_libexecdir"'^g'			\
52d60d
											\
52d60d
			-e 's^@native_cc@^'"$mb_native_cc"'^g'				\
52d60d
			-e 's^@native_os@^'"$mb_native_os"'^g'				\
52d60d
			-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'				\
52d60d
		$mb_project_dir/Makefile.in > $mb_pwd/Makefile
52d60d
}
52d60d
52d60d
52d60d
config_host()
52d60d
{
52d60d
	make 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=*)
52d60d
			mb_prefix=${arg#*=}
52d60d
			;;
52d60d
		--bindir=*)
52d60d
			mb_bindir=${arg#*=}
52d60d
			;;
52d60d
		--libdir=*)
52d60d
			mb_libdir=${arg#*=}
52d60d
			;;
52d60d
		--includedir=*)
52d60d
			mb_includedir=${arg#*=}
52d60d
			;;
52d60d
		--syslibdir=*)
52d60d
			mb_syslibdir=${arg#*=}
52d60d
			;;
52d60d
		--mandir=*)
52d60d
			mb_mandir=${arg#*=}
52d60d
			;;
52d60d
		--libexecdir=*)
52d60d
			mb_libexecdir=${arg#*=}
52d60d
			;;
52d60d
52d60d
52d60d
		# build
52d60d
		--build=*)
52d60d
			mb_build=${arg#*=}
52d60d
			;;
52d60d
		--host=*)
52d60d
			mb_host=${arg#*=}
52d60d
			;;
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)
52d60d
			mb_debug='yes'
52d60d
			;;
52d60d
		*)
52d60d
			error_msg ${arg#}: "unsupported config argument."
52d60d
			exit 2
52d60d
			;;
52d60d
	esac
52d60d
done
52d60d
52d60d
52d60d
52d60d
# three: defaults
52d60d
common_defaults
52d60d
native_defaults
52d60d
cross_defaults
52d60d
52d60d
52d60d
52d60d
# four: config
52d60d
config_copy
52d60d
config_host
52d60d
config_status
52d60d
52d60d
52d60d
# all done
52d60d
exit 0