Blame sofort/cfgtest/cfgtest.sh

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