Blame sofort/cfgtest/cfgtest.sh

42868e
# cfgtest.sh: sofort's config test framework,
42868e
# for use from within a project's custom cfgdefs.sh.
42868e
42868e
# this file is covered by COPYING.SOFORT.
42868e
42868e
# in the common scenario, host-specific tests are preceded
42868e
# by a single invocation of cfgtest_host_section, whereas
42868e
# native (build) system tests are preceded by the invocation
42868e
# of cfgtest_native_section.
42868e
42868e
# cfgdefs fraework variables:
42868e
# mb_cfgtest_cc:      the compiler used for the current test
42868e
# mb_cfgtest_cflags:  the compiler flags used for the current test
42868e
# mb_cfgtest_cfgtype: the type of the current test (host/native)
42868e
# mb_cfgtest_makevar: the make variable affected by the current test
42868e
# mb_cfgtest_headers: headers for ad-hoc inclusion with the current test
42868e
42868e
42868e
cfgtest_newline()
42868e
{
42868e
	printf '\n' >> $mb_pwd/cfgdefs.mk
42868e
}
42868e
42868e
42868e
cfgtest_comment()
42868e
{
42868e
	mb_internal_str='#'
42868e
42868e
	for mb_internal_arg ; do
42868e
		mb_internal_str="$mb_internal_str $mb_internal_arg"
42868e
	done
42868e
42868e
	printf '%s\n' "$mb_internal_str" >> $mb_pwd/cfgdefs.mk
42868e
}
42868e
42868e
42868e
cfgtest_host_section()
42868e
{
42868e
	mb_cfgtest_cc="$ccenv_host_cc"
42868e
	mb_cfgtest_cfgtype='host'
f88692
	mb_cfgtest_stdin_input=${ccenv_host_stdin_input:-}
53d5f4
	mb_cfgtest_environment=${ccenv_host_cc_environment:-}
e4e9b5
e4e9b5
	mb_cfgtest_cflags=$(${mb_make} -n -f "$mb_pwd/Makefile.tmp" \
e4e9b5
		OS_DSO_EXRULES=default                              \
e4e9b5
		OS_SONAME=symlink                                   \
e4e9b5
		OS_ARCHIVE_EXT='.a'                                 \
e4e9b5
		.cflags-host)
e4e9b5
42868e
	mb_cfgtest_cflags="${mb_cfgtest_cflags#*: }"
42868e
412049
	mb_cfgtest_ldflags=$(${mb_make} -n -f "$mb_pwd/Makefile.tmp" \
412049
		OS_DSO_EXRULES=default                               \
412049
		OS_SONAME=symlink                                    \
412049
		OS_ARCHIVE_EXT='.a'                                  \
412049
		.ldflags-host)
412049
412049
	mb_cfgtest_ldflags="${mb_cfgtest_ldflags#*: }"
42868e
}
42868e
42868e
42868e
cfgtest_native_section()
42868e
{
e4e9b5
	mb_cfgtest_cc="$ccenv_native_cc"
42868e
	mb_cfgtest_cfgtype='native'
f88692
	mb_cfgtest_stdin_input=${ccenv_native_stdin_input:-}
53d5f4
	mb_cfgtest_environment=${ccenv_native_cc_environment:-}
e4e9b5
e4e9b5
	mb_cfgtest_cflags=$(${mb_make} -n -f "$mb_pwd/Makefile.tmp" \
e4e9b5
		OS_DSO_EXRULES=default                              \
e4e9b5
		OS_SONAME=symlink                                   \
e4e9b5
		OS_ARCHIVE_EXT='.a'                                 \
e4e9b5
		.cflags-native)
e4e9b5
42868e
	mb_cfgtest_cflags="${mb_cfgtest_cflags#*: }"
412049
412049
	mb_cfgtest_ldflags=$(${mb_make} -n -f "$mb_pwd/Makefile.tmp" \
412049
		OS_DSO_EXRULES=default                               \
412049
		OS_SONAME=symlink                                    \
412049
		OS_ARCHIVE_EXT='.a'                                  \
412049
		.ldflags-native)
412049
412049
	mb_cfgtest_ldflags="${mb_cfgtest_ldflags#*: }"
42868e
}
42868e
42868e
42868e
cfgtest_prolog()
42868e
{
de8fcd
	cfgtest_line_dots='...........................'
42868e
	cfgtest_line_dots="${cfgtest_line_dots}${cfgtest_line_dots}"
42868e
	cfgtest_tool_desc=" == trying ${mb_cfgtest_cfgtype} ${1}: ${2}"
42868e
	cfgtest_tool_dlen="${#cfgtest_line_dots}"
42868e
42868e
	printf '\n%s\n' '________________________' >&3
42868e
	printf "cfgtest: probing for ${mb_cfgtest_cfgtype} ${1}: ${2}\n\n" >&3
cec2ae
cec2ae
	if [ "${cfgtest_silent:-}" != 'yes' ]; then
cec2ae
		printf "%${cfgtest_tool_dlen}.${cfgtest_tool_dlen}s" \
cec2ae
			"${cfgtest_tool_desc}  ${mb_line_dots}"
cec2ae
	fi
42868e
}
42868e
42868e
42868e
cfgtest_epilog()
42868e
{
de8fcd
	cfgtest_line_dots='...............'
42868e
	cfgtest_tool_dlen="$((${#cfgtest_line_dots} - ${#2}))"
42868e
cec2ae
	if [ "${cfgtest_silent:-}" != 'yes' ]; then
cec2ae
		printf "%${cfgtest_tool_dlen}.${cfgtest_tool_dlen}s  %s.\n" \
cec2ae
			"${cfgtest_line_dots}" "${2}"
cec2ae
	fi
42868e
a3fdc3
	if [ "${1}" = 'snippet' ] && [ -f 'a.out' ]; then
42868e
		rm -f 'a.out'
42868e
	fi
42868e
f88692
	if [ "$mb_cfgtest_stdin_input" = 'no' ]; then
f88692
		rm 'cfgtest_c3RyaWN0X21vZGUK.c'
f88692
	fi
f88692
42868e
	if [ "${1}" = 'snippet' ] && [ "${2}" = '(error)' ]; then
42868e
		printf '\n\ncfgtest: the %s compiler %s %s.\n' \
42868e
			"$mb_cfgtest_cfgtype"                 \
42868e
			'failed to compile the above code'   \
42868e
			"${1}" >&3
42868e
		printf '%s\n' '------------------------' >&3
42868e
		return 1
42868e
	fi
42868e
42868e
	if [ "${2}" = '-----' ]; then
42868e
		printf '\n\ncfgtest: %s %s is missing or cannot be found.\n' "${1}" "${3}" >&3
42868e
		printf '%s\n' '------------------------' >&3
42868e
		return 1
42868e
	elif [ "${1}" = 'size-of-type' ] && [ "${2}" = '(error)' ]; then
42868e
		printf '\n\ncfgtest: could not determine size of type `%s.\n' "${3}'" >&3
42868e
		printf '%s\n' '------------------------' >&3
42868e
		return 1
7aa895
	elif [ "${1}" = 'switch' ] && [ "${2}" = '(error)' ]; then
7aa895
		printf '\n\ncfgtest: the switch `%s is not supported by the %s compiler.\n' \
7aa895
			"${3}'" "$mb_cfgtest_cfgtype" >&3
7aa895
		printf '%s\n' '------------------------' >&3
7aa895
		return 1
42868e
	elif [ "${2}" = '(error)' ]; then
42868e
		printf '\n\ncfgtest: %s `%s is not defined or cannot be used.\n' "${1}" "${3}'" >&3
42868e
		printf '%s\n' '------------------------' >&3
42868e
		return 1
42868e
	fi
42868e
}
42868e
42868e
42868e
cfgtest_entity_size_prolog()
42868e
{
42868e
	cfgtest_line_dots='.......................'
42868e
	cfgtest_line_dots="${cfgtest_line_dots}${cfgtest_line_dots}"
42868e
	cfgtest_tool_desc=" == checking size of ${mb_cfgtest_cfgtype} type: ${@}"
42868e
	cfgtest_tool_dlen="${#cfgtest_line_dots}"
42868e
42868e
	printf '\n%s\n' '________________________' >&3
42868e
	printf "cfgtest: checking size of ${mb_cfgtest_cfgtype} type: ${@}\n\n" >&3
42868e
42868e
	printf "%${cfgtest_tool_dlen}.${cfgtest_tool_dlen}s" \
42868e
		"${cfgtest_tool_desc}  ${mb_line_dots}"
42868e
}
42868e
42868e
bd19b7
cfgtest_makevar_set()
bd19b7
{
bd19b7
	if [ -n "${@}" ]; then
bd19b7
		mb_internal_str='= '
bd19b7
	else
bd19b7
		mb_internal_str='='
bd19b7
	fi
bd19b7
bd19b7
	printf '%-25s%s%s\n' "$mb_cfgtest_makevar" "$mb_internal_str" "${@}" \
bd19b7
		>> $mb_pwd/cfgdefs.mk
bd19b7
bd19b7
	unset cfgtest_internal_unit_test
bd19b7
}
bd19b7
bd19b7
42868e
cfgtest_makevar_append()
42868e
{
42868e
	mb_internal_str='+='
42868e
42868e
	for mb_internal_arg ; do
42868e
		if ! [ -z "$mb_internal_arg" ]; then
42868e
			mb_internal_str="$mb_internal_str $mb_internal_arg"
42868e
		fi
42868e
	done
42868e
42868e
	printf '%-24s%s\n' "$mb_cfgtest_makevar" "$mb_internal_str" \
42868e
		>> $mb_pwd/cfgdefs.mk
42868e
42868e
	unset cfgtest_internal_unit_test
42868e
}
42868e
42868e
42868e
cfgtest_cflags_append()
42868e
{
42868e
	if [ $mb_cfgtest_cfgtype = 'host' ]; then
42868e
		mb_internal_makevar='CFLAGS_CONFIG'
42868e
	else
42868e
		mb_internal_makevar='NATIVE_CFLAGS'
42868e
	fi
42868e
42868e
	mb_cfgtest_makevar_saved=$mb_cfgtest_makevar
42868e
	mb_cfgtest_makevar=$mb_internal_makevar
42868e
42868e
	cfgtest_makevar_append "$@"
42868e
	mb_cfgtest_makevar=$mb_cfgtest_makevar_saved
42868e
}
42868e
42868e
42868e
cfgtest_ldflags_append()
42868e
{
42868e
	if [ $mb_cfgtest_cfgtype = 'host' ]; then
42868e
		mb_internal_makevar='LDFLAGS_CONFIG'
42868e
	else
42868e
		mb_internal_makevar='NATIVE_LDFLAGS'
42868e
	fi
42868e
42868e
	mb_cfgtest_makevar_saved=$mb_cfgtest_makevar
42868e
	mb_cfgtest_makevar=$mb_internal_makevar
42868e
42868e
	cfgtest_makevar_append "$@"
42868e
	mb_cfgtest_makevar=$mb_cfgtest_makevar_saved
42868e
}
42868e
42868e
42868e
cfgtest_common_init()
42868e
{
42868e
	# cfgtest variables
b0a788
	cfgtest_type="${1:-}"
b0a788
f88692
	if [ "$mb_cfgtest_stdin_input" = 'no' ]; then
f88692
		if [ "$cfgtest_type" = 'lib' ]; then
f88692
			cfgtest_fmt='%s cfgtest_c3RyaWN0X21vZGUK.c -o a.out'
7bc486
		elif [ "$cfgtest_type" = 'ldflag' ]; then
7bc486
			cfgtest_fmt='%s cfgtest_c3RyaWN0X21vZGUK.c -o a.out'
f88692
		else
f88692
			cfgtest_fmt='%s -c cfgtest_c3RyaWN0X21vZGUK.c -o a.out'
f88692
		fi
f88692
	elif [ "$cfgtest_type" = 'asm' ]; then
42868e
		cfgtest_fmt='%s -c -xc - -o a.out'
b0a788
	elif [ "$cfgtest_type" = 'lib' ]; then
42868e
		cfgtest_fmt='%s -xc - -o a.out'
7bc486
	elif [ "$cfgtest_type" = 'ldflag' ]; then
7bc486
		cfgtest_fmt='%s -xc - -o a.out'
42868e
	else
42868e
		cfgtest_fmt='%s -S -xc - -o -'
42868e
	fi
42868e
7aa895
b0a788
	if [ "$cfgtest_type" = 'lib' ]; then
42868e
		cfgtest_cmd=$(printf "$cfgtest_fmt %s %s %s" \
42868e
			"$mb_cfgtest_cc"                     \
42868e
			"$mb_cfgtest_cflags"                 \
42868e
			"$mb_cfgtest_ldflags"                \
42868e
			"$cfgtest_libs")
7aa895
7bc486
	elif [ "$cfgtest_type" = 'ldflag' ]; then
7bc486
		cfgtest_cmd=$(printf "$cfgtest_fmt %s %s %s" \
7bc486
			"$mb_cfgtest_cc"                     \
7bc486
			"$mb_cfgtest_cflags"                 \
7bc486
			"$mb_cfgtest_ldflags"                \
7bc486
			"$cfgtest_switches")
7bc486
7aa895
	elif [ "$cfgtest_type" = 'switch' ]; then
7aa895
		cfgtest_cmd=$(printf "$cfgtest_fmt %s %s" \
7aa895
			"$mb_cfgtest_cc"                  \
7aa895
			"$mb_cfgtest_cflags"              \
7aa895
			"$cfgtest_switches")
42868e
	else
42868e
		cfgtest_cmd=$(printf "$cfgtest_fmt %s" \
42868e
			"$mb_cfgtest_cc"               \
42868e
			"$mb_cfgtest_cflags")
42868e
	fi
42868e
7aa895
b46bcb
	if [ -n "$mb_cfgtest_headers" ]; then
42868e
		cfgtest_inc=$(printf '#include <%s>\n' $mb_cfgtest_headers)
42868e
		cfgtest_src=$(printf '%s\n_\n' "$cfgtest_inc" \
42868e
			| m4 -D_="$cfgtest_code_snippet")
b46bcb
	else
b46bcb
		cfgtest_inc=
b46bcb
		cfgtest_src="$cfgtest_code_snippet"
42868e
	fi
42868e
7aa895
42868e
	# config.log
42868e
	printf "$cfgtest_fmt" "$mb_cfgtest_cc" >&3
42868e
fb7e7f
	for cfgtest_cflag in $(printf '%s' "$mb_cfgtest_cflags"); do
42868e
		printf ' \\\n\t%s' "$cfgtest_cflag" >&3
42868e
	done
42868e
088b53
	for cfgtest_ldflag in $(printf '%s' "$mb_cfgtest_ldflags"); do
088b53
		printf ' \\\n\t%s' "$cfgtest_ldflag" >&3
088b53
	done
088b53
b0a788
	if [ "$cfgtest_type" = 'lib' ]; then
fb7e7f
		for cfgtest_lib in $(printf '%s' "$cfgtest_libs"); do
42868e
			printf ' \\\n\t%s' "$cfgtest_lib" >&3
42868e
		done
7aa895
7bc486
	elif [ "$cfgtest_type" = 'switch' ] || [ "$cfgtest_type" = 'ldflag' ]; then
fb7e7f
		for cfgtest_switch in $(printf '%s' "$cfgtest_switches"); do
7aa895
			printf ' \\\n\t%s' "$cfgtest_switch" >&3
7aa895
		done
42868e
	fi
42868e
42868e
	printf ' \\\n'                           >&3
42868e
	printf '<< _SRCEOF\n%s\n' "$cfgtest_src" >&3
56e695
	printf '_SRCEOF\n\n\n'                   >&3
f88692
f88692
	if [ "$mb_cfgtest_stdin_input" = 'no' ]; then
f88692
		printf '%s' "$cfgtest_src" > 'cfgtest_c3RyaWN0X21vZGUK.c'
f88692
		cfgtest_src=
f88692
	fi
42868e
}
42868e
42868e
42868e
cfgtest_header_presence()
42868e
{
42868e
	#init
42868e
	cfgtest_prolog 'header' "${1}"
42868e
42868e
	cfgtest_code_snippet=$(printf '#include <%s>\n' "${1}")
42868e
42868e
	cfgtest_common_init
42868e
42868e
	# execute
42868e
	printf '%s' "$cfgtest_src"                  \
42868e
		| eval $(printf '%s' "$cfgtest_cmd") \
42868e
		> /dev/null 2>&3                      \
42868e
	|| cfgtest_epilog 'header' '-----' "<${1}>"    \
42868e
	|| return
42868e
42868e
	# result
42868e
	mb_internal_str=$(printf '%s%s' '-DHAVE_' "${1}"  \
42868e
			| sed -e 's/\./_/g' -e 's@/@_@g'  \
42868e
			| tr "[:lower:]" "[:upper:]")
42868e
42868e
	if [ -z ${cfgtest_internal_unit_test:-} ]; then
42868e
		cfgtest_cflags_append "$mb_internal_str"
42868e
	else
42868e
		cfgtest_makevar_append "$mb_internal_str"
42868e
	fi
42868e
42868e
	printf 'cfgtest: %s header <%s> was found and may be included.\n' \
42868e
		"$mb_cfgtest_cfgtype" "${1}" >&3
42868e
	printf '%s\n' '------------------------' >&3
42868e
42868e
	cfgtest_epilog 'header' "${1}"
42868e
}
42868e
42868e
42868e
cfgtest_header_absence()
42868e
{
42868e
	#init
42868e
	cfgtest_prolog 'header absence' "${1}"
42868e
42868e
	cfgtest_code_snippet=$(printf '#include <%s>\n' "${1}")
42868e
42868e
	cfgtest_common_init
42868e
42868e
	# execute
42868e
	printf '%s' "$cfgtest_src"                  \
42868e
		| eval $(printf '%s' "$cfgtest_cmd") \
42868e
		> /dev/null 2>&3                      \
42868e
	&& printf 'cfgtest: %s header <%s>: no error.' \
42868e
		"$mb_cfgtest_cfgtype" "${1}" >&3        \
42868e
	&& cfgtest_epilog 'header' "${1}"                \
42868e
	&& return
42868e
42868e
	# result
42868e
	mb_internal_str=$(printf '%s%s' '-DHAVE_NO_' "$@" \
42868e
			| sed -e 's/\./_/g' -e 's@/@_@g'  \
42868e
			| tr "[:lower:]" "[:upper:]")
42868e
42868e
	if [ -z ${cfgtest_internal_unit_test:-} ]; then
42868e
		cfgtest_cflags_append "$mb_internal_str"
42868e
	else
42868e
		cfgtest_makevar_append "$mb_internal_str"
42868e
	fi
42868e
42868e
	printf 'cfgtest: %s header <%s> may not be included.\n' \
42868e
		"$mb_cfgtest_cfgtype" "${1}" >&3
42868e
	printf '%s\n' '------------------------' >&3
42868e
1d7d51
	cfgtest_epilog 'header' '-----' "${1}"
42868e
}
42868e
42868e
42868e
cfgtest_interface_presence()
42868e
{
42868e
	# init
42868e
	cfgtest_prolog 'interface' "${1}"
42868e
42868e
	cfgtest_code_snippet=$(printf 'void * addr = &%;;\n' "${1}")
42868e
42868e
	cfgtest_common_init
42868e
42868e
	# execute
42868e
	printf '%s' "$cfgtest_src"                    \
42868e
		| eval $(printf '%s' "$cfgtest_cmd")   \
42868e
		> /dev/null 2>&3                        \
42868e
	|| cfgtest_epilog 'interface' '(error)' "${1}"   \
42868e
	|| return
42868e
42868e
	# result
42868e
	mb_internal_str=$(printf '%s%s' '-DHAVE_' "$@"  \
42868e
			| sed -e 's/\./_/g'             \
42868e
			| tr "[:lower:]" "[:upper:]")
42868e
42868e
	if [ -z ${cfgtest_internal_unit_test:-} ]; then
42868e
		cfgtest_cflags_append "$mb_internal_str"
42868e
	else
42868e
		cfgtest_makevar_append "$mb_internal_str"
42868e
	fi
42868e
42868e
	printf 'cfgtest: %s interface `%s'"'"' is available.\n' \
42868e
		"$mb_cfgtest_cfgtype" "${1}" >&3
42868e
	printf '%s\n' '------------------------' >&3
42868e
42868e
	cfgtest_epilog 'interface' "${1}"
42868e
42868e
	return 0
42868e
}
42868e
42868e
42868e
cfgtest_decl_presence()
42868e
{
42868e
	# init
42868e
	cfgtest_prolog 'decl' "${1}"
42868e
42868e
	cfgtest_code_snippet=$(printf 'void * any = (void *)(%s);' "${1}")
42868e
42868e
	cfgtest_common_init
42868e
42868e
	# execute
42868e
	printf '%s' "$cfgtest_src"                  \
42868e
		| eval $(printf '%s' "$cfgtest_cmd") \
42868e
		> /dev/null 2>&3                      \
42868e
	|| cfgtest_epilog 'decl' '(error)' "${1}"      \
42868e
	|| return
42868e
42868e
	# does the argument solely consist of the macro or enum member name?
42868e
	mb_internal_str=$(printf '%s' "$@" | tr -d '[a-z][A-Z][0-9][_]')
42868e
42868e
	if [ -n "$mb_internal_str" ]; then
42868e
		cfgtest_epilog 'decl' '(defined)'
42868e
		return 0
42868e
	fi
42868e
42868e
	# result
42868e
	mb_internal_str=$(printf '%s%s' '-DHAVE_DECL_' "$@"  \
42868e
			| sed -e 's/\./_/g'                  \
42868e
			| tr "[:lower:]" "[:upper:]")
42868e
42868e
	if [ -z ${cfgtest_internal_unit_test:-} ]; then
42868e
		cfgtest_cflags_append "$mb_internal_str"
42868e
	else
42868e
		cfgtest_makevar_append "$mb_internal_str"
42868e
	fi
42868e
42868e
	printf 'cfgtest: `%s'"'"' is defined for the %s system.\n' \
42868e
		"${1}" "$mb_cfgtest_cfgtype" >&3
42868e
	printf '%s\n' '------------------------' >&3
42868e
42868e
	cfgtest_epilog 'decl' '(defined)'
42868e
42868e
	return 0
42868e
}
42868e
42868e
42868e
cfgtest_type_size()
42868e
{
42868e
	cfgtest_entity_size_prolog "$@"
42868e
42868e
	mb_internal_size=''
42868e
	mb_internal_test='char x[(sizeof(%s) == %s) ? 1 : -1];'
42868e
42868e
	for mb_internal_guess in 8 4 2 1 16 32 64 128; do
42868e
		if [ -z $mb_internal_size ]; then
42868e
			printf '# guess %s ===>\n' "$mb_internal_guess" >&3
42868e
42868e
			mb_internal_type="$@"
42868e
42868e
			cfgtest_code_snippet=$(printf "$mb_internal_test" \
42868e
				"$mb_internal_type" "$mb_internal_guess")
42868e
42868e
			cfgtest_common_init
42868e
42868e
			printf '%s' "$cfgtest_src"                  \
42868e
				| eval $(printf '%s' "$cfgtest_cmd") \
42868e
				> /dev/null 2>&3                      \
42868e
			&& mb_internal_size=$mb_internal_guess
42868e
42868e
			printf '\n' >&3
42868e
		fi
42868e
	done
42868e
42868e
	# unrecognized type, or type size not within range
42868e
	if [ -z $mb_internal_size ]; then
42868e
		cfgtest_epilog 'size-of-type' '(error)' "@"
42868e
		return 1
42868e
	fi
42868e
42868e
	# -DSIZEOF_TYPE=SIZE
42868e
	mb_internal_str=$(printf '%s%s=%s' '-DSIZEOF_'        \
42868e
				"$mb_internal_type"           \
42868e
				"$mb_internal_size"           \
42868e
			| sed -e 's/\ /_/g' -e 's/*/P/g'      \
42868e
			| tr "[:lower:]" "[:upper:]")
42868e
42868e
	if [ -z ${cfgtest_internal_unit_test:-} ]; then
42868e
		cfgtest_cflags_append "$mb_internal_str"
42868e
	else
42868e
		cfgtest_makevar_append "$mb_internal_str"
42868e
	fi
42868e
42868e
	printf 'cfgtest: size of type `%s'"'"' determined to be %s\n' \
42868e
		"${@}" "$mb_internal_size" >&3
42868e
	printf '%s\n' '------------------------' >&3
42868e
42868e
	cfgtest_epilog 'size-of-type' "$mb_internal_size"
42868e
42868e
	return 0
42868e
}
42868e
42868e
42868e
cfgtest_code_snippet_asm()
42868e
{
42868e
	# init
42868e
	cfgtest_prolog 'support of code snippet' '<...>'
42868e
42868e
	cfgtest_code_snippet="$@"
42868e
42868e
	cfgtest_common_init 'asm'
42868e
42868e
	# execute
42868e
	cfgtest_ret=1
42868e
42868e
	printf '%s' "$cfgtest_src"                  \
42868e
		| eval $(printf '%s' "$cfgtest_cmd") \
42868e
		> /dev/null 2>&3                      \
42868e
	|| cfgtest_epilog 'snippet' '(error)'          \
42868e
	|| return
42868e
42868e
	# result
42868e
	cfgtest_ret=0
42868e
42868e
	printf 'cfgtest: %s compiler: above code snippet compiled successfully.\n\n' \
42868e
		"$mb_cfgtest_cfgtype" >&3
42868e
42868e
	cfgtest_epilog 'snippet' '(ok)'
42868e
42868e
	return 0
42868e
}
42868e
42868e
0f8d30
cfgtest_macro_definition()
0f8d30
{
0f8d30
	# init
0f8d30
	cfgtest_prolog 'macro definition' "${1}"
0f8d30
0f8d30
	cfgtest_code_snippet=$(printf '%s\n'      \
0f8d30
		"#ifndef ${1}"                     \
0f8d30
		"#error macro ${1} is not defined." \
0f8d30
		"#endif")
0f8d30
0f8d30
	cfgtest_common_init 'macro'
0f8d30
0f8d30
	# execute
0f8d30
	cfgtest_ret=1
0f8d30
0f8d30
	printf '%s' "$cfgtest_src"                  \
0f8d30
		| eval $(printf '%s' "$cfgtest_cmd") \
0f8d30
		> /dev/null 2>&3                      \
0f8d30
	|| cfgtest_epilog 'macro' '(error)' "${1}"     \
0f8d30
	|| return
0f8d30
0f8d30
	# result
0f8d30
	cfgtest_ret=0
0f8d30
0f8d30
	printf 'cfgtest: %s compiler: above macro definition test compiled successfully.\n\n' \
0f8d30
		"$mb_cfgtest_cfgtype" >&3
0f8d30
0f8d30
	cfgtest_epilog 'macro' '(defined)'
0f8d30
0f8d30
	return 0
0f8d30
}
0f8d30
0f8d30
42868e
cfgtest_library_presence()
42868e
{
42868e
	# init
42868e
	cfgtest_libs=
42868e
	cfgtest_spc=
42868e
42868e
	for cfgtest_lib in ${@}; do
42868e
		cfgtest_libs="$cfgtest_libs$cfgtest_spc$cfgtest_lib"
42868e
		cfgtest_spc=' '
42868e
	done
42868e
42868e
	if [ "${1}" = "$cfgtest_libs" ]; then
42868e
		cfgtest_prolog 'library' "${1#*-l}"
42868e
	else
42868e
		cfgtest_prolog 'lib module' '(see config.log)'
42868e
	fi
42868e
7a059f
	if [ "$mb_cfgtest_environment" = 'freestanding' ]; then
7a059f
		if [ -z "ccenv_cc_underscore" ]; then
7a059f
			cfgtest_code_snippet='int start(void){return 0;}'
7a059f
		else
7a059f
			cfgtest_code_snippet='int _start(void){return 0;}'
7a059f
		fi
7a059f
	else
7a059f
		cfgtest_code_snippet='int main(void){return 0;}'
7a059f
	fi
42868e
42868e
	cfgtest_common_init 'lib'
42868e
42868e
	# execute
42868e
	printf '%s' "$cfgtest_src"                  \
42868e
		| eval $(printf '%s' "$cfgtest_cmd") \
42868e
		> /dev/null 2>&3                      \
42868e
	|| cfgtest_epilog 'library' '-----' "$@"       \
42868e
	|| return 1
42868e
42868e
	# result
42868e
	printf 'cfgtest: `%s'"'"' was accepted by the linker driver.\n' \
42868e
		"$cfgtest_libs" >&3
42868e
	printf '%s\n' '------------------------' >&3
42868e
42868e
	cfgtest_epilog 'library' '(present)'
42868e
42868e
	return 0
42868e
}
42868e
42868e
7aa895
cfgtest_compiler_switch()
7aa895
{
7aa895
	# init
7aa895
	cfgtest_switches=
7aa895
	cfgtest_spc=
7aa895
fb7e7f
	for cfgtest_switch in $(printf '%s' "${@}"); do
7aa895
		cfgtest_switches="$cfgtest_switches$cfgtest_spc$cfgtest_switch"
7aa895
		cfgtest_spc=' '
7aa895
	done
7aa895
7aa895
	if [ "${1}" = "$cfgtest_switches" ]; then
7aa895
		cfgtest_prolog 'compiler switch' "$cfgtest_switches"
7aa895
	else
7aa895
		cfgtest_prolog 'compiler switch combination' "$cfgtest_switches"
7aa895
	fi
7aa895
7bc486
	case "${1}" in
7bc486
		-Wl,*)
53d5f4
			if [ "$mb_cfgtest_environment" = 'freestanding' ]; then
53d5f4
				cfgtest_switches="$cfgtest_switches -nostdlib -nostartfiles"
53d5f4
53d5f4
				if [ -z "ccenv_cc_underscore" ]; then
53d5f4
					cfgtest_code_snippet='int start(void){return 0;}'
53d5f4
				else
53d5f4
					cfgtest_code_snippet='int _start(void){return 0;}'
53d5f4
				fi
53d5f4
			else
53d5f4
				cfgtest_code_snippet='int main(void){return 0;}'
53d5f4
			fi
53d5f4
7bc486
			cfgtest_common_init 'ldflag'
7bc486
			;;
7bc486
7bc486
		*)
7bc486
			cfgtest_code_snippet=
7bc486
			cfgtest_common_init 'switch'
7bc486
			;;
7bc486
	esac
7aa895
7aa895
	# execute
7aa895
	printf '%s' "$cfgtest_src"                  \
7aa895
		| eval $(printf '%s' "$cfgtest_cmd") \
7aa895
		> /dev/null 2>&3                      \
7aa895
	|| cfgtest_epilog 'switch' '(error)' "$@"      \
7aa895
	|| return 1
7aa895
7aa895
	# result
7aa895
	printf 'cfgtest: the switch `%s was accepted by the compier.\n' \
7aa895
		"$cfgtest_switches'" >&3
7aa895
	printf '%s\n' '------------------------' >&3
7aa895
7aa895
	cfgtest_epilog 'switch' '(accepted)'
7aa895
7aa895
	return 0
7aa895
}
7aa895
7aa895
42868e
cfgtest_unit_header_presence()
42868e
{
42868e
	cfgtest_internal_unit_test='unit_test'
42868e
	cfgtest_header_presence "$@" || return 1
42868e
	return 0
42868e
}
42868e
42868e
42868e
cfgtest_unit_header_absence()
42868e
{
42868e
	cfgtest_internal_unit_test='unit_test'
42868e
	cfgtest_header_absence "$@" || return 1
42868e
	return 0
42868e
}
42868e
42868e
42868e
cfgtest_unit_interface_presence()
42868e
{
42868e
	cfgtest_internal_unit_test='unit_test'
42868e
	cfgtest_interface_presence "$@" || return 1
42868e
	return 0
42868e
}
42868e
42868e
42868e
cfgtest_unit_decl_presence()
42868e
{
42868e
	cfgtest_internal_unit_test='unit_test'
42868e
	cfgtest_decl_presence "$@" || return 1
42868e
	return 0
42868e
}
42868e
42868e
42868e
cfgtest_unit_type_size()
42868e
{
42868e
	cfgtest_internal_unit_test='unit_test'
42868e
	cfgtest_type_size "$@" || return 1
42868e
	return 0
42868e
}