Blame sofort/cfgtest/cfgtest.sh

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