Blame sofort/cfgtest/cfgtest.sh

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