Reicher82 / toolchain / sbmake

Forked from toolchain/sbmake 3 years ago
Clone

Blame project/config/cfgdefs.sh

b3e7fa
# in projects where [ $mb_use_custom_cfgdefs = yes ],
b3e7fa
# cfgdefs.sh is invoked from within ./configure via
b3e7fa
# . $mb_project_dir/project/cfgdefs.sh
b3e7fa
b3e7fa
# a successful return from cfgdefs.sh will be followed
b3e7fa
# by a second invocation of the config_copy() function,
b3e7fa
# reflecting any changes to common config variables
b3e7fa
# made by cfgdefs.sh.
b3e7fa
b3e7fa
# finally, cfgdefs.sh may update the contents of the
b3e7fa
# config-time generated cfgdefs.mk.
b3e7fa
dbacce
dbacce
# sofort's config test framework
dbacce
. "$mb_project_dir/sofort/cfgtest/cfgtest.sh"
dbacce
dbacce
b3e7fa
for arg ; do
b3e7fa
	case "$arg" in
b3e7fa
		*)
b3e7fa
			error_msg ${arg#}: "unsupported config argument."
b3e7fa
			exit 2
b3e7fa
	esac
b3e7fa
done
b3e7fa
b3e7fa
b3e7fa
cfgdefs_bootstrap()
b3e7fa
{
b3e7fa
	cfgdefs_bootstrap_done=${cfgdefs_bootstrap_done:-}
b3e7fa
b3e7fa
	if [ _$cfgdefs_bootstrap_done = _yes ]; then
b3e7fa
		return 0
b3e7fa
	fi
b3e7fa
b3e7fa
	cfgdefs_objs=
b3e7fa
b3e7fa
	cfgdefs_utilsrc='make.c'
b3e7fa
b3e7fa
	cfgdefs_sources="arch.c buf.c compat.c cond.c dir.c enum.c for.c hash.c job.c"
b3e7fa
	cfgdefs_sources="$cfgdefs_sources lst.c main.c make_malloc.c meta.c metachar.c parse.c"
b3e7fa
	cfgdefs_sources="$cfgdefs_sources str.c suff.c targ.c trace.c util.c var.c"
b3e7fa
b3e7fa
	cfgdefs_cflags="-I${mb_source_dir}/src/internal"
b3e7fa
	cfgdefs_cflags="$cfgdefs_cflags -D_PATH_DEFSYSPATH=\"${mb_source_dir}/mk\""
cf1a49
	cfgdefs_cflags="$cfgdefs_cflags $cfgdefs_added_defs"
b3e7fa
b3e7fa
	cfgdefs_make="$mb_pwd/bootstrap/make"
b3e7fa
b3e7fa
	mkdir -p "$mb_pwd/bootstrap"
b3e7fa
b3e7fa
	printf '\n\n'
b3e7fa
b3e7fa
	for src in $cfgdefs_utilsrc; do
b3e7fa
		obj=${src%%.c}.o
b3e7fa
		cfgdefs_objs="$cfgdefs_objs $mb_pwd/bootstrap/${obj}"
b3e7fa
b3e7fa
		set -x
b3e7fa
b3e7fa
		"$mb_native_cc" $mb_native_cflags $cfgdefs_cflags \
b3e7fa
			-c "$mb_source_dir/src/${src}"             \
b3e7fa
			-o "$mb_pwd/bootstrap/${obj}"
b3e7fa
b3e7fa
		set +x
b3e7fa
	done
b3e7fa
b3e7fa
	for src in $cfgdefs_sources; do
b3e7fa
		obj=${src%%.c}.o
b3e7fa
		cfgdefs_objs="$cfgdefs_objs $mb_pwd/bootstrap/${obj}"
b3e7fa
b3e7fa
		set -x
b3e7fa
b3e7fa
		"$mb_native_cc" $mb_native_cflags $cfgdefs_cflags \
b3e7fa
			-c "$mb_source_dir/src/logic/${src}"       \
b3e7fa
			-o "$mb_pwd/bootstrap/${obj}"
b3e7fa
b3e7fa
		set +x
b3e7fa
	done
b3e7fa
b3e7fa
	"$mb_native_cc" $mb_native_cflags $cfgdefs_cflags \
b3e7fa
		$mb_native_ldflags $cfgdefs_objs           \
b3e7fa
		-o "$cfgdefs_make"
b3e7fa
b3e7fa
	mb_make="$cfgdefs_make"
b3e7fa
b3e7fa
	cfgdefs_bootstrap_done='yes'
b3e7fa
}
b3e7fa
dbacce
dbacce
cfgdefs_output_custom_defs()
dbacce
{
dbacce
	cat "$mb_project_dir/project/config/cfgdefs.in" > cfgdefs.mk
dbacce
}
dbacce
dbacce
dbacce
cfgdefs_perform_common_tests()
dbacce
{
cf1a49
	# bootstrap
cf1a49
	cfgdefs_added_defs=
cf1a49
dbacce
	# interfaces
dbacce
	mb_cfgtest_headers='stdio.h'
dbacce
	cfgtest_interface_presence 'vsnprintf'
dbacce
cf1a49
	if [ $? = '0' ]; then
cf1a49
		cfgdefs_added_defs="$cfgdefs_added_defs -DHAVE_VSNPRINTF"
cf1a49
	fi
cf1a49
dbacce
	mb_cfgtest_headers='string.h'
dbacce
	cfgtest_interface_presence 'strerror'
dbacce
cf1a49
	if [ $? = '0' ]; then
cf1a49
		cfgdefs_added_defs="$cfgdefs_added_defs -DHAVE_STRERROR"
cf1a49
	fi
cf1a49
dbacce
	mb_cfgtest_headers='sys/types.h unistd.h'
dbacce
	cfgtest_interface_presence 'setpgid'
dbacce
cf1a49
	if [ $? = '0' ]; then
cf1a49
		cfgdefs_added_defs="$cfgdefs_added_defs -DHAVE_SETPGID"
cf1a49
	fi
cf1a49
dbacce
	mb_cfgtest_headers='sys/time.h sys/resource.h'
dbacce
	cfgtest_interface_presence 'setrlimit'
dbacce
cf1a49
	if [ $? = '0' ]; then
cf1a49
		cfgdefs_added_defs="$cfgdefs_added_defs -DHAVE_SETRLIMIT"
cf1a49
	fi
cf1a49
dbacce
	mb_cfgtest_headers='stdlib.h'
dbacce
	cfgtest_interface_presence 'setenv'
dbacce
cf1a49
	if [ $? = '0' ]; then
cf1a49
		cfgdefs_added_defs="$cfgdefs_added_defs -DHAVE_SETENV"
cf1a49
	fi
cf1a49
dbacce
	cfgtest_newline
dbacce
}
dbacce
dbacce
dbacce
cfgdefs_perform_native_tests()
dbacce
{
dbacce
	# init
dbacce
	cfgtest_newline
dbacce
	cfgtest_native_section
dbacce
dbacce
	# common tests
dbacce
	cfgdefs_perform_common_tests
dbacce
dbacce
	# pretty cfgdefs.mk
dbacce
	cfgtest_newline
dbacce
}
dbacce
dbacce
cfgdefs_perform_target_tests()
dbacce
{
dbacce
	# init
dbacce
	cfgtest_newline
dbacce
	cfgtest_host_section
dbacce
dbacce
	# common tests
dbacce
	cfgdefs_perform_common_tests
dbacce
dbacce
	# pretty cfgdefs.mk
dbacce
	cfgtest_newline
dbacce
}
dbacce
dbacce
# cfgdefs.in --> cfgdefs.mk
dbacce
cfgdefs_output_custom_defs
dbacce
dbacce
# strict: some tests might fail
dbacce
set +e
dbacce
dbacce
# bootstrapping cflags
dbacce
cfgdefs_perform_native_tests
dbacce
dbacce
# strict: restore mode
dbacce
set -e
dbacce
b3e7fa
# bootstrap
b3e7fa
cfgdefs_bootstrap
b3e7fa
dbacce
# strict: some tests might fail
dbacce
set +e
dbacce
dbacce
# target-specific tests
dbacce
cfgdefs_perform_target_tests
dbacce
dbacce
# strict: restore mode
dbacce
set -e
dbacce
b3e7fa
# all done
b3e7fa
return 0