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
{
98322c
	cat "$mb_project_dir"/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
011344
	if [ -z "$mb_config" ]; 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
452aa8
	mb_exec_prefix=$EXEC_PREFIX
52d60d
	mb_bindir=$BINDIR
52d60d
	mb_libdir=$LIBDIR
52d60d
	mb_includedir=$INCLUDEDIR
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
{
011344
	if [ "$mb_project_dir" = "$mb_pwd" ]; then
011344
		if [ "$mb_require_out_of_tree" = yes ]; 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
48b5b4
	[ -z "$mb_prefix" ] 		&& [ -z "$mb_prefix_set" ] \
48b5b4
					&& mb_prefix='/usr/local'
48b5b4
48b5b4
	[ -z "$mb_exec_prefix" ] 	&& [ -z "$mb_exec_prefix_set" ]	\
48b5b4
					&& mb_exec_prefix=$mb_prefix
48b5b4
c51f1b
	[ -z "$mb_bindir" ] 		&& mb_bindir=$mb_exec_prefix/bin
c51f1b
	[ -z "$mb_libdir" ] 		&& mb_libdir=$mb_exec_prefix/lib
c51f1b
	[ -z "$mb_includedir" ]		&& mb_includedir=$mb_prefix/include
c51f1b
	[ -z "$mb_datarootdir" ] 	&& mb_datarootdir=$mb_prefix/share
c51f1b
	[ -z "$mb_mandir" ] 		&& mb_mandir=$mb_datarootdir/man
c51f1b
	[ -z "$mb_docdir" ] 		&& mb_docdir=$mb_datarootdir/doc
c51f1b
	[ -z "$mb_libexecdir" ]		&& mb_libexecdir=$mb_exec_prefix/libexec
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
011344
	if [ -n "$mb_sysroot" ]; then
011344
		if [ -z "$mb_cflags_sysroot" ]; then
52d60d
			mb_cflags_sysroot="--sysroot=$mb_sysroot"
52d60d
		fi
52d60d
011344
		if [ -z "$mb_ldflags_sysroot" ]; then
52d60d
			mb_ldflags_sysroot="-Wl,--sysroot,$mb_sysroot"
52d60d
		fi
52d60d
	fi
52d60d
52d60d
	# debug
011344
	if [ "$mb_debug" = yes ]; then
011344
		if [ -z "$mb_cflags_debug" ]; then
52d60d
			mb_cflags_debug='-g3 -O0'
52d60d
		fi
52d60d
	fi
52d60d
220bb3
	# compiler
011344
	if [ -n "$mb_compiler" ]; then
011344
		if [ -z "$mb_native_cc" ]; then
220bb3
			mb_native_cc=$mb_compiler
52d60d
		fi
52d60d
	fi
2c5c40
2c5c40
	# toolchain
011344
	if [ -z "$mb_toolchain" ]; then
2c5c40
		mb_toolchain='binutils'
2c5c40
	fi
5d406f
5d406f
	# fallback host recipe
011344
	if [ -n "$mb_host" ]; 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
169bd0
169bd0
	# fallback compiler recipe
169bd0
	if [ -n "$mb_compiler" ]; then
169bd0
		if ! [ -f $mb_project_dir/sysinfo/compiler/$mb_compiler.mk ]; then
169bd0
			mb_compiler='any-compiler'
169bd0
		fi
169bd0
	fi
52d60d
}
52d60d
52d60d
52d60d
native_defaults()
52d60d
{
52d60d
	# CC (when set, must be valid)
011344
	if [ -n "$CC" ]; 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
011344
	if [ -z "$mb_native_cc" ]; then
75e6de
		echo "configure: info: could not find a working native compiler."
75e6de
		mb_native_cc='false'
52d60d
	fi
52d60d
011344
	if [ -z "$mb_compiler" ]; then
220bb3
		$mb_native_cc -dM -E - < /dev/null | grep '__clang__' > /dev/null && mb_compiler='clang'
52d60d
	fi
52d60d
011344
	if [ -z "$mb_compiler" ]; then
220bb3
		$mb_native_cc -dM -E - < /dev/null | grep '__GCC' > /dev/null && mb_compiler='gcc'
52d60d
	fi
52d60d
011344
	if [ -z "$mb_compiler" ]; then
220bb3
		$mb_native_cc -dM -E - < /dev/null | grep '__CPARSER__' > /dev/null && mb_compiler='cparser'
52d60d
	fi
52d60d
011344
	if [ -z "$mb_compiler" ]; then
75e6de
		echo "configure: info: could not identify the native compiler."
75e6de
		mb_compiler='any-compiler'
52d60d
	fi
52d60d
52d60d
52d60d
	# host
011344
	if [ -z "$mb_host" ]; then
52d60d
		mb_host='native'
52d60d
	fi
52d60d
52d60d
38f2f3
	# target
011344
	if [ -z "$mb_target" ]; 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
011344
	if [ -z "$mb_native_os_sizeof_pointer" ]; 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
{
011344
	if [ -z "$mb_cross_compile" ] && [ "$mb_host" != native ]; 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'				\
452aa8
			-e 's^@exec_prefix@^'"$mb_exec_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^@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
{
349040
	make -s 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=*)
48b5b4
			mb_prefix_set=yes
52d60d
			mb_prefix=${arg#*=}
52d60d
			;;
452aa8
		--exec-prefix=*)
48b5b4
			mb_exec_prefix_set=yes
452aa8
			mb_exec_prefix=${arg#*=}
452aa8
			;;
52d60d
		--bindir=*)
52d60d
			mb_bindir=${arg#*=}
52d60d
			;;
52d60d
		--libdir=*)
52d60d
			mb_libdir=${arg#*=}
52d60d
			;;
52d60d
		--includedir=*)
52d60d
			mb_includedir=${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