Blame sofort/cfgtest/cfgtest.sh

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