Blame sofort/cfgtest/cfgtest.sh

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