Blame configure

f46039
#!/bin/sh
f46039
# we are no longer lazy.
f46039
f46039
# this script respects both CFLAGS and CFLAGS_CMDLINE,
f46039
# as well as both LDFLAGS and LDFLAGS_CMDLINE, however
f46039
# the latter variable of each pair should be preferred.
f46039
f46039
usage()
f46039
{
f46039
	cat config.usage
f46039
	exit $?
f46039
}
f46039
f46039
error_msg()
f46039
{
f46039
	echo $@ >&2
f46039
}
f46039
f46039
f46039
init_vars()
f46039
{
f46039
	mb_project_dir=$(cd `dirname $0` ; pwd)
f46039
	mb_pwd=`pwd`
f46039
f46039
	if [ x"$mb_config" = x ]; then
f46039
		. $mb_project_dir/config.project || exit 2
f46039
	else
f46039
		. "$mb_config" || exit 2
f46039
	fi
f46039
f46039
	# dirs
f46039
	mb_prefix=$PREFIX
f46039
	mb_bindir=$BINDIR
f46039
	mb_libdir=$LIBDIR
f46039
	mb_includedir=$INCLUDEDIR
f46039
	mb_syslibdir=$LIBDIR
f46039
	mb_mandir=$MANDIR
f46039
	mb_docdir=$DOCDIR
f46039
	mb_libexecdir=$LIBEXECDIR
f46039
f46039
f46039
	# build
f46039
	mb_build=$BUILD
f46039
	mb_host=$HOST
f46039
	mb_target=$TARGET
f46039
	mb_arch=$ARCH
e83fbe
	mb_compiler=$COMPILER
f46039
	mb_sysroot=$SYSROOT
f46039
	mb_cross_compile=$CROSS_COMPILE
f46039
	mb_shell=$SHELL
f46039
f46039
	# switches
f46039
	mb_cflags=$CFLAGS
f46039
	mb_cflags_debug=$CFLAGS_DEBUG
f46039
	mb_cflags_common=$CFLAGS_COMMON
f46039
	mb_cflags_cmdline=$CFLAGS_CMDLINE
f46039
	mb_cflags_config=$CFLAGS_CONFIG
f46039
	mb_cflags_sysroot=$CFLAGS_SYSROOT
e6d235
	mb_cflags_os=$CFLAGS_OS
e6d235
	mb_cflags_site=$CFLAGS_SITE
f46039
	mb_cflags_path=$CFLAGS_PATH
f46039
f46039
	mb_ldflags=$LDFLAGS
f46039
	mb_ldflags_debug=$LDFLAGS_DEBUG
f46039
	mb_ldflags_common=$LDFLAGS_COMMON
f46039
	mb_ldflags_cmdline=$LDFLAGS_CMDLINE
f46039
	mb_ldflags_config=$LDFLAGS_CONFIG
f46039
	mb_ldflags_sysroot=$LDFLAGS_SYSROOT
f46039
	mb_ldflags_path=$LDFLAGS_PATH
f46039
f46039
	mb_pe_subsystem=$PE_SUBSYSTEM
f46039
	mb_pe_image_base=$PE_IMAGE_BASE
f46039
	mb_pe_config_defs=$PE_CONFIG_DEFS
f46039
f46039
	mb_elf_eh_frame=$ELF_EH_FRAME
f46039
	mb_elf_hash_style=$ELF_HASH_STYLE
f46039
	mb_elf_config_defs=$ELF_CONFIG_DEFS
f46039
f46039
	# overrides
f46039
	mb_native_cc=$NATIVE_CC
f46039
	mb_native_os=$NATIVE_OS
f46039
	mb_native_os_bits=$NATIVE_OS_BITS
f46039
	mb_native_os_underscore=$NATIVE_OS_UNDERSCORE
f46039
f46039
	mb_user_cc=$CC
f46039
	mb_user_cpp=$CPP
f46039
	mb_user_cxx=$CXX
f46039
}
f46039
f46039
f46039
verify_build_directory()
f46039
{
f46039
	if [ x"$mb_project_dir" = x"$mb_pwd" ]; then
f46039
		if [ x"$mb_require_out_of_tree" = xyes ]; then
f46039
			error_msg "$mb_package: out-of-tree builds are required."
f46039
			error_msg "please invoke configure again from a clean build directory."
f46039
			exit 2
f46039
		else
f46039
			mb_project_dir='.'
f46039
		fi
f46039
	fi
f46039
}
f46039
f46039
f46039
common_defaults()
f46039
{
f46039
	# dirs
f46039
	[ -z "$mb_prefix" ] 		&& mb_prefix=$mb_default_prefix
f46039
	[ -z "$mb_bindir" ] 		&& mb_bindir=$mb_default_bindir
f46039
	[ -z "$mb_libdir" ] 		&& mb_libdir=$mb_default_libdir
f46039
	[ -z "$mb_includedir" ]		&& mb_includedir=$mb_default_includedir
f46039
	[ -z "$mb_syslibdir" ] 		&& mb_syslibdir=$mb_default_syslibdir
f46039
	[ -z "$mb_mandir" ] 		&& mb_mandir=$mb_default_mandir
f46039
	[ -z "$mb_docdir" ] 		&& mb_docdir=$mb_default_docdir
f46039
	[ -z "$mb_libexecdir" ]		&& mb_libexecdir=$mb_default_libexecdir
f46039
f46039
	# build
f46039
	[ -z "$mb_build" ] 		&& mb_build=$mb_default_build
f46039
	[ -z "$mb_host" ] 		&& mb_host=$mb_default_host
f46039
	[ -z "$mb_target" ] 		&& mb_target=$mb_default_target
f46039
	[ -z "$mb_arch" ] 		&& mb_arch=$mb_default_arch
e83fbe
	[ -z "$mb_compiler" ] 		&& mb_compiler=$mb_default_compiler
f46039
	[ -z "$mb_sysroot" ] 		&& mb_sysroot=$mb_default_sysroot
f46039
	[ -z "$mb_cross_compile" ] 	&& mb_cross_compile=$mb_default_cross_compile
f46039
	[ -z "$mb_shell" ] 		&& mb_shell=$mb_default_shell
f46039
f46039
	# switches
f46039
	[ -z "$mb_cflags_debug" ]	&& mb_cflags_debug=$mb_default_cflags_debug
f46039
	[ -z "$mb_cflags_common" ]	&& mb_cflags_common=$mb_default_cflags_common
f46039
	[ -z "$mb_cflags_cmdline" ]	&& mb_cflags_cmdline=$mb_default_cflags_cmdline
f46039
	[ -z "$mb_cflags_config" ]	&& mb_cflags_config=$mb_default_cflags_config
f46039
	[ -z "$mb_cflags_sysroot" ]	&& mb_cflags_sysroot=$mb_default_cflags_sysroot
e6d235
	[ -z "$mb_cflags_os" ]		&& mb_cflags_os=$mb_default_cflags_os
e6d235
	[ -z "$mb_cflags_site" ]	&& mb_cflags_site=$mb_default_cflags_site
f46039
	[ -z "$mb_cflags_path" ]	&& mb_cflags_path=$mb_default_cflags_path
f46039
f46039
	[ -z "$mb_ldflags_debug" ]	&& mb_ldflags_debug=$mb_default_ldflags_debug
f46039
	[ -z "$mb_ldflags_common" ]	&& mb_ldflags_common=$mb_default_ldflags_common
f46039
	[ -z "$mb_ldflags_cmdline" ]	&& mb_ldflags_cmdline=$mb_default_ldflags_cmdline
f46039
	[ -z "$mb_ldflags_config" ]	&& mb_ldflags_config=$mb_default_ldflags_config
f46039
	[ -z "$mb_ldflags_sysroot" ]	&& mb_ldflags_sysroot=$mb_default_ldflags_sysroot
f46039
	[ -z "$mb_ldflags_path" ]	&& mb_ldflags_path=$mb_default_ldflags_path
f46039
f46039
	[ -z "$mb_pe_subsystem" ]	&& mb_pe_subsystem=$mb_default_pe_subsystem
f46039
	[ -z "$mb_pe_image_base" ]	&& mb_pe_image_base=$mb_default_pe_image_base
f46039
	[ -z "$mb_pe_config_defs" ]	&& mb_pe_config_defs=$mb_default_pe_config_defs
f46039
f46039
	[ -z "$mb_elf_eh_frame" ]	&& mb_elf_eh_frame=$mb_default_elf_eh_frame
f46039
	[ -z "$mb_elf_hash_style" ]	&& mb_elf_hash_style=$mb_default_elf_hash_style
f46039
	[ -z "$mb_elf_config_defs" ]	&& mb_elf_config_defs=$mb_default_elf_config_defs
f46039
f46039
	# host/target
f46039
	[ -z "$mb_host" ] 		&& mb_host=$mb_target
f46039
	[ -z "$mb_target" ] 		&& mb_target=$mb_host
f46039
f46039
	# sysroot
f46039
	if [ x"$mb_sysroot" != x ]; then
f46039
		if [ x"$mb_cflags_sysroot" = x ]; then
f46039
			mb_cflags_sysroot="--sysroot=$mb_sysroot"
f46039
		fi
f46039
f46039
		if [ x"$mb_ldflags_sysroot" = x ]; then
f46039
			mb_ldflags_sysroot="-Wl,--sysroot,$mb_sysroot"
f46039
		fi
f46039
	fi
f46039
f46039
	# debug
f46039
	if [ x"$mb_debug" = xyes ]; then
f46039
		if [ x"$mb_cflags_debug" = x ]; then
f46039
			mb_cflags_debug='-g3 -O0'
f46039
		fi
f46039
	fi
f46039
e83fbe
	# compiler
e83fbe
	if [ x"$mb_compiler" != x ]; then
f46039
		if [ x"$mb_native_cc" = x ]; then
e83fbe
			mb_native_cc=$mb_compiler
f46039
		fi
f46039
	fi
f46039
}
f46039
f46039
f46039
native_defaults()
f46039
{
f46039
	# CC (when set, must be valid)
f46039
	if [ x"$CC" != x ]; then
f46039
		$CC -dM -E - < /dev/null > /dev/null || exit 2
f46039
	fi
f46039
e83fbe
	# compiler
f46039
	[ -z "$mb_native_cc" ] && mb_native_cc=$CC
f46039
	[ -z "$mb_native_cc" ] && mb_native_cc='cc'
f46039
	$mb_native_cc -dM -E - < /dev/null > /dev/null 2>/dev/null || mb_native_cc=
f46039
f46039
	[ -z "$mb_native_cc" ] && mb_native_cc='gcc'
f46039
	$mb_native_cc -dM -E - < /dev/null > /dev/null 2>/dev/null || mb_native_cc=
f46039
f46039
	[ -z "$mb_native_cc" ] && mb_native_cc='clang'
f46039
	$mb_native_cc -dM -E - < /dev/null > /dev/null 2>/dev/null || mb_native_cc=
f46039
f46039
	[ -z "$mb_native_cc" ] && mb_native_cc='cparser'
f46039
	$mb_native_cc -dM -E - < /dev/null > /dev/null 2>/dev/null || mb_native_cc=
f46039
f46039
	if [ x"$mb_native_cc" = x ]; then
f46039
		error_msg "config error: could not find a working native compiler."
f46039
		exit 2
f46039
	fi
f46039
e83fbe
	if [ x"$mb_compiler" = x ]; then
e83fbe
		$mb_native_cc -dM -E - < /dev/null | grep '__clang__' > /dev/null && mb_compiler='clang'
f46039
	fi
f46039
e83fbe
	if [ x"$mb_compiler" = x ]; then
e83fbe
		$mb_native_cc -dM -E - < /dev/null | grep '__GCC' > /dev/null && mb_compiler='gcc'
f46039
	fi
f46039
e83fbe
	if [ x"$mb_compiler" = x ]; then
e83fbe
		$mb_native_cc -dM -E - < /dev/null | grep '__CPARSER__' > /dev/null && mb_compiler='cparser'
f46039
	fi
f46039
e83fbe
	if [ x"$mb_compiler" = x ]; then
f46039
		error_msg "config error: could not identify the native compiler."
f46039
		exit 2
f46039
	fi
f46039
f46039
f46039
	# host
f46039
	if [ x"$mb_host" = x ]; then
f46039
		mb_host='native'
f46039
	fi
f46039
f46039
f46039
	# target
f46039
	if [ x"$mb_target" = x ]; then
f46039
		mb_target='native'
f46039
	fi
f46039
f46039
f46039
	# os
f46039
	mb_native_os=`uname | tr '[:upper:]' '[:lower:]'`
f46039
f46039
	mb_native_os_sizeof_pointer=`$mb_native_cc -dM -E - < /dev/null \
f46039
			| grep __SIZEOF_POINTER__  \
f46039
			| cut -d ' ' -f3`
f46039
f46039
	mb_native_os_bits=`expr '8' '*' '0'"$mb_native_os_sizeof_pointer"`
f46039
f46039
	if [ $mb_native_os_bits = 32 ]; then
f46039
		mb_native_os_underscore='_'
f46039
	else
f46039
		mb_native_os_underscore=''
f46039
	fi
f46039
f46039
	if [ x"$mb_native_os_sizeof_pointer" = x ]; then
f46039
		error_msg "config error: could not determine size of pointer on native system."
f46039
		exit 2
f46039
	fi
f46039
f46039
	[ -z "$mb_native_os" ] 			&& mb_native_os=$mb_native_os
f46039
	[ -z "$mb_native_os_bits" ] 		&& mb_native_os_bits=$mb_native_os_bits
f46039
	[ -z "$mb_native_os_underscore" ]	&& mb_native_os_underscore=$mb_native_os_underscore
f46039
}
f46039
f46039
f46039
cross_defaults()
f46039
{
f46039
	if [ x"$mb_cross_compile" = x ] && [ x"$mb_host" != xnative ]; then
f46039
		mb_cross_compile=$mb_host'-'
f46039
	fi
f46039
}
f46039
f46039
f46039
config_copy()
f46039
{
f46039
	sed 		-e 's^@package@^'"$mb_package"'^g' 				\
f46039
			-e 's^@project_dir@^'"$mb_project_dir"'^g'			\
f46039
											\
f46039
			-e 's^@build@^'"$mb_build"'^g'					\
f46039
			-e 's^@host@^'"$mb_host"'^g'					\
f46039
			-e 's^@target@^'"$mb_target"'^g'				\
f46039
			-e 's^@arch@^'"$mb_arch"'^g'					\
e83fbe
			-e 's^@compiler@^'"$mb_compiler"'^g'				\
f46039
			-e 's^@sysroot@^'"$mb_sysroot"'^g'				\
f46039
			-e 's^@cross_compile@^'"$mb_cross_compile"'^g'			\
f46039
			-e 's^@shell@^'"$mb_shell"'^g'					\
f46039
											\
f46039
			-e 's^@cflags@^'"$mb_cflags"'^g'				\
f46039
			-e 's^@cflags_debug@^'"$mb_cflags_debug"'^g'			\
f46039
			-e 's^@cflags_common@^'"$mb_cflags_common"'^g'			\
f46039
			-e 's^@cflags_cmdline@^'"$mb_cflags $mb_cflags_cmdline"'^g'	\
f46039
			-e 's^@cflags_config@^'"$mb_cflags_config"'^g'			\
f46039
			-e 's^@cflags_sysroot@^'"$mb_cflags_sysroot"'^g'		\
e6d235
			-e 's^@cflags_os@^'"$mb_cflags_os"'^g'				\
e6d235
			-e 's^@cflags_site@^'"$mb_cflags_site"'^g'			\
f46039
			-e 's^@cflags_path@^'"$mb_cflags_path"'^g'			\
f46039
											\
f46039
			-e 's^@ldflags@^'"$mb_ldflags"'^g'				\
f46039
			-e 's^@ldflags_debug@^'"$mb_ldflags_debug"'^g'			\
f46039
			-e 's^@ldflags_common@^'"$mb_ldflags_common"'^g'		\
f46039
			-e 's^@ldflags_cmdline@^'"$mb_ldflags $mb_ldflags_cmdline"'^g'	\
f46039
			-e 's^@ldflags_config@^'"$mb_ldflags_config"'^g'		\
f46039
			-e 's^@ldflags_sysroot@^'"$mb_ldflags_sysroot"'^g'		\
f46039
			-e 's^@ldflags_path@^'"$mb_ldflags_path"'^g'			\
f46039
											\
f46039
			-e 's^@pe_subsystem@^'"$mb_pe_subsystem"'^g'			\
f46039
			-e 's^@pe_image\_base@^'"$mb_pe_image_base"'^g'			\
f46039
			-e 's^@pe_config\_defs@^'"$mb_pe_config_defs"'^g'		\
f46039
											\
f46039
			-e 's^@elf_eh\_frame@^'"$mb_elf_eh_frame"'^g'			\
f46039
			-e 's^@elf_hash\_style@^'"$mb_elf_hash_style"'^g'		\
f46039
			-e 's^@elf_config\_defs@^'"$mb_elf_config_defs"'^g'		\
f46039
											\
f46039
			-e 's^@prefix@^'"$mb_prefix"'^g'				\
f46039
			-e 's^@bindir@^'"$mb_bindir"'^g'				\
f46039
			-e 's^@libdir@^'"$mb_libdir"'^g'				\
f46039
			-e 's^@includedir@^'"$mb_includedir"'^g'			\
f46039
			-e 's^@syslibdir@^'"$mb_syslibdir"'^g'				\
f46039
			-e 's^@mandir@^'"$mb_mandir"'^g'				\
f46039
			-e 's^@docdir@^'"$mb_docdir"'^g'				\
f46039
			-e 's^@libexecdir@^'"$mb_libexecdir"'^g'			\
f46039
											\
f46039
			-e 's^@native_cc@^'"$mb_native_cc"'^g'				\
f46039
			-e 's^@native_os@^'"$mb_native_os"'^g'				\
f46039
			-e 's^@native_os_bits@^'"$mb_native_os_bits"'^g'		\
f46039
			-e 's^@native_os_underscore@^'"$mb_native_os_underscore"'^g'	\
f46039
											\
f46039
			-e 's^@user_cc@^'"$mb_user_cc"'^g'				\
f46039
			-e 's^@user_cpp@^'"$mb_user_cpp"'^g'				\
f46039
			-e 's^@user_cxx@^'"$mb_user_cxx"'^g'				\
f46039
		$mb_project_dir/Makefile.in > $mb_pwd/Makefile
f46039
}
f46039
f46039
f46039
config_host()
f46039
{
f46039
	make host.tag && return 0
f46039
f46039
	error_msg "configure was able to generate a Makefile for the selected host,"
e83fbe
	error_msg "however the host-targeting compiler was found to be missing"
f46039
	error_msg "at least one of the required headers or features."
f46039
	exit 2
f46039
}
f46039
f46039
f46039
config_status()
f46039
{
f46039
	printf "\n\n"
f46039
	make .display
f46039
	printf "\nconfiguration completed successfully.\n\n"
f46039
}
f46039
f46039
# one: init
f46039
init_vars
f46039
verify_build_directory
f46039
f46039
f46039
# two: args
f46039
for arg ; do
f46039
	case "$arg" in
f46039
		--help)	usage
f46039
			;;
f46039
f46039
		# dirs
f46039
		--prefix=*)
f46039
			mb_prefix=${arg#*=}
f46039
			;;
f46039
		--bindir=*)
f46039
			mb_bindir=${arg#*=}
f46039
			;;
f46039
		--libdir=*)
f46039
			mb_libdir=${arg#*=}
f46039
			;;
f46039
		--includedir=*)
f46039
			mb_includedir=${arg#*=}
f46039
			;;
f46039
		--syslibdir=*)
f46039
			mb_syslibdir=${arg#*=}
f46039
			;;
f46039
		--mandir=*)
f46039
			mb_mandir=${arg#*=}
f46039
			;;
f46039
		--libexecdir=*)
f46039
			mb_libexecdir=${arg#*=}
f46039
			;;
f46039
f46039
f46039
		# build
f46039
		--build=*)
f46039
			mb_build=${arg#*=}
f46039
			;;
f46039
		--host=*)
f46039
			mb_host=${arg#*=}
f46039
			;;
f46039
		--target=*)
f46039
			mb_target=${arg#*=}
f46039
			;;
f46039
		--arch=*)
f46039
			mb_arch=${arg#*=}
f46039
			;;
e83fbe
		--compiler=*)
e83fbe
			mb_compiler=${arg#*=}
f46039
			;;
f46039
		--sysroot=*)
f46039
			mb_sysroot=${arg#*=}
f46039
			;;
f46039
		--cross-compile=*)
f46039
			mb_cross_compile=${arg#*=}
f46039
			;;
f46039
		--shell=*)
f46039
			mb_shell=${arg#*=}
f46039
			;;
f46039
		--debug)
f46039
			mb_debug='yes'
f46039
			;;
f46039
		*)
f46039
			error_msg ${arg#}: "unsupported config argument."
f46039
			exit 2
f46039
			;;
f46039
	esac
f46039
done
f46039
f46039
f46039
f46039
# three: defaults
f46039
common_defaults
f46039
native_defaults
f46039
cross_defaults
f46039
f46039
f46039
f46039
# four: config
f46039
config_copy
f46039
config_host
f46039
config_status
f46039
f46039
f46039
# all done
f46039
exit 0