Blame configure

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