Blame configure

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