Reicher82 / python / sbpython3

Forked from python/sbpython3 3 years ago
Clone

Blame sofort/cfgtest.sh

5dc983
# cfgtest.sh: sofort's config test framework,
5dc983
# for use from within a project's custom cfgdefs.sh.
5dc983
5dc983
# in the common scenario, target-specific tests are preceded
5dc983
# by a single invocation of cfgtest_target_section, whereas
5dc983
# native (build) system tests are preceded by the invocation
5dc983
# of cfgtest_native_section.
5dc983
5dc983
# cfgdefs fraework variables:
5dc983
# mb_cfgtest_cc:      the compiler used for the current test
5dc983
# mb_cfgtest_cflags:  the compiler flags used for the current test
5dc983
# mb_cfgtest_cfgtype: the type of the current test (target/native)
5dc983
# mb_cfgtest_makevar: the make variable affected by the current test
5dc983
# mb_cfgtest_headers: headers for ad-hoc inclusion with the current test
5dc983
5dc983
5dc983
cfgtest_newline()
5dc983
{
5dc983
	printf '\n' >> $mb_pwd/cfgdefs.mk
5dc983
}
5dc983
5dc983
5dc983
cfgtest_comment()
5dc983
{
5dc983
	mb_internal_str='#'
5dc983
5dc983
	for mb_internal_arg ; do
5dc983
		mb_internal_str="$mb_internal_str $mb_internal_arg"
5dc983
	done
5dc983
5dc983
	printf '%s\n' "$mb_internal_str" >> $mb_pwd/cfgdefs.mk
5dc983
}
5dc983
5dc983
5dc983
cfgtest_target_section()
5dc983
{
5dc983
	mb_cfgtest_cc=$(make -s -f "$mb_pwd/Makefile.tmp" .display-cc)
5dc983
	mb_cfgtest_cflags=$(make -s -f "$mb_pwd/Makefile.tmp" .display-cflags)
5dc983
	mb_cfgtest_cfgtype='target'
5dc983
5dc983
	cfgtest_comment 'target-specific tests'
5dc983
}
5dc983
5dc983
5dc983
cfgtest_native_section()
5dc983
{
5dc983
	mb_cfgtest_cc="$mb_native_cc"
5dc983
	mb_cfgtest_cflags="$mb_native_cc_cflags"
5dc983
	mb_cfgtest_cfgtype='native'
5dc983
5dc983
	cfgtest_comment 'native system tests'
5dc983
}
5dc983
5dc983
5dc983
cfgtest_makevar_append()
5dc983
{
5dc983
	mb_internal_str='+='
5dc983
5dc983
	for mb_internal_arg ; do
62a36d
		if ! [ -z "$mb_internal_arg" ]; then
62a36d
			mb_internal_str="$mb_internal_str $mb_internal_arg"
62a36d
		fi
5dc983
	done
5dc983
5dc983
	printf '%-24s%s\n' "$mb_cfgtest_makevar" "$mb_internal_str" \
5dc983
		>> $mb_pwd/cfgdefs.mk
5dc983
}
5dc983
5dc983
5dc983
cfgtest_cflags_append()
5dc983
{
5dc983
	if [ $mb_cfgtest_cfgtype = 'target' ]; then
5dc983
		mb_internal_makevar='CFLAGS_CONFIG'
5dc983
	else
5dc983
		mb_internal_makevar='NATIVE_CC_CFLAGS'
5dc983
	fi
5dc983
5dc983
	mb_cfgtest_makevar_saved=$mb_cfgtest_makevar
5dc983
	mb_cfgtest_makevar=$mb_internal_makevar
5dc983
5dc983
	cfgtest_makevar_append "$@"
5dc983
	mb_cfgtest_makevar=$mb_cfgtest_makevar_saved
5dc983
}
5dc983
5dc983
5dc983
cfgtest_ldflags_append()
5dc983
{
5dc983
	if [ $mb_cfgtest_cfgtype = 'target' ]; then
5dc983
		mb_internal_makevar='LDFLAGS_CONFIG'
5dc983
	else
5dc983
		mb_internal_makevar='NATIVE_CC_LDFLAGS'
5dc983
	fi
5dc983
5dc983
	mb_cfgtest_makevar_saved=$mb_cfgtest_makevar
5dc983
	mb_cfgtest_makevar=$mb_internal_makevar
5dc983
5dc983
	cfgtest_makevar_append "$@"
5dc983
	mb_cfgtest_makevar=$mb_cfgtest_makevar_saved
5dc983
}
5dc983
5dc983
5dc983
cfgtest_header_presence()
5dc983
{
5dc983
	$mb_cfgtest_cc -E -xc -             \
5dc983
			$mb_cfgtest_cflags  \
5dc983
			--include="$@"      \
5dc983
		< /dev/null                 \
5dc983
		> /dev/null 2>/dev/null     \
5dc983
	|| return
5dc983
2090f5
	mb_internal_str=$(printf '%s%s' '-DHAVE_' "$@"    \
2090f5
			| sed -e 's/\./_/g' -e 's@/@_@g'  \
5dc983
			| tr "[:lower:]" "[:upper:]")
5dc983
5dc983
	cfgtest_cflags_append "$mb_internal_str"
5dc983
}
5dc983
5dc983
5dc983
cfgtest_header_absence()
5dc983
{
5dc983
	$mb_cfgtest_cc -E -xc -             \
5dc983
			$mb_cfgtest_cflags  \
5dc983
			--include="$@"      \
5dc983
		< /dev/null                 \
5dc983
		> /dev/null 2>/dev/null     \
5dc983
	&& return
5dc983
5dc983
	mb_internal_str=$(printf '%s%s' '-DHAVE_NO_' "$@" \
2090f5
			| sed -e 's/\./_/g' -e 's@/@_@g'  \
5dc983
			| tr "[:lower:]" "[:upper:]")
5dc983
5dc983
	cfgtest_cflags_append "$mb_internal_str"
5dc983
}
5dc983
5dc983
5dc983
cfgtest_interface_presence()
5dc983
{
5dc983
	mb_internal_cflags=''
5dc983
5dc983
	for mb_header in $mb_cfgtest_headers; do
5dc983
		mb_internal_cflags="$mb_internal_cflags --include=$mb_header"
5dc983
	done
5dc983
5dc983
	printf 'void * addr = &%;;' "$@"                  \
5dc983
			| $mb_cfgtest_cc -S -xc - -o -    \
5dc983
			  $mb_cfgtest_cflags              \
5dc983
			  $mb_internal_cflags             \
5dc983
                > /dev/null 2>/dev/null                   \
5dc983
	|| return 1
5dc983
86ce91
	mb_internal_str=$(printf '%s%s' '-DHAVE_' "$@"  \
86ce91
			| sed -e 's/\./_/g'             \
86ce91
			| tr "[:lower:]" "[:upper:]")
86ce91
86ce91
	cfgtest_cflags_append "$mb_internal_str"
86ce91
5dc983
	return 0
5dc983
}
5dc983
5dc983
cfgtest_library_presence()
5dc983
{
5dc983
	printf 'int main(void){return 0;}'                \
5dc983
			| $mb_cfgtest_cc -o a.out -xc -   \
5dc983
			  $mb_cfgtest_cflags              \
5dc983
			  $@                              \
5dc983
                > /dev/null 2>/dev/null                   \
5dc983
	|| return 1
5dc983
5dc983
	rm -f a.out
5dc983
5dc983
	return 0
5dc983
}