Blame sofort/cfgtest/cfgtest.sh

e1aed4
# cfgtest.sh: sofort's config test framework,
e1aed4
# for use from within a project's custom cfgdefs.sh.
e1aed4
e1aed4
# this file is covered by COPYING.SOFORT.
e1aed4
e1aed4
# in the common scenario, host-specific tests are preceded
e1aed4
# by a single invocation of cfgtest_host_section, whereas
e1aed4
# native (build) system tests are preceded by the invocation
e1aed4
# of cfgtest_native_section.
e1aed4
e1aed4
# cfgdefs fraework variables:
e1aed4
# mb_cfgtest_cc:      the compiler used for the current test
cce299
# mb_cfgtest_pkgconf: the pkgconf utility used for the current test
e1aed4
# mb_cfgtest_cflags:  the compiler flags used for the current test
e1aed4
# mb_cfgtest_cfgtype: the type of the current test (host/native)
e1aed4
# mb_cfgtest_makevar: the make variable affected by the current test
e1aed4
# mb_cfgtest_headers: headers for ad-hoc inclusion with the current test
8af0b4
# mb_cfgtest_attr:    if supported, the compiler-specific attribute definition
e1aed4
e1aed4
e1aed4
cfgtest_newline()
e1aed4
{
e1aed4
	printf '\n' >> $mb_pwd/cfgdefs.mk
e1aed4
}
e1aed4
e1aed4
e1aed4
cfgtest_comment()
e1aed4
{
e1aed4
	mb_internal_str='#'
e1aed4
e1aed4
	for mb_internal_arg ; do
e1aed4
		mb_internal_str="$mb_internal_str $mb_internal_arg"
e1aed4
	done
e1aed4
e1aed4
	printf '%s\n' "$mb_internal_str" >> $mb_pwd/cfgdefs.mk
e1aed4
}
e1aed4
e1aed4
e1aed4
cfgtest_host_section()
e1aed4
{
e1aed4
	mb_cfgtest_cc="$ccenv_host_cc"
cce299
	mb_cfgtest_pkgconf="${ccenv_host_pkgconf:-false}"
e1aed4
	mb_cfgtest_cfgtype='host'
eb6ed9
	mb_cfgtest_stdin_input=${ccenv_host_stdin_input:-}
3009f7
	mb_cfgtest_environment=${ccenv_host_cc_environment:-}
c37c0c
c37c0c
	mb_cfgtest_cflags=$(${mb_make} -n -f "$mb_pwd/Makefile.tmp" \
c37c0c
		OS_DSO_EXRULES=default                              \
c37c0c
		OS_SONAME=symlink                                   \
c37c0c
		OS_ARCHIVE_EXT='.a'                                 \
c37c0c
		.cflags-host)
c37c0c
e1aed4
	mb_cfgtest_cflags="${mb_cfgtest_cflags#*: }"
e1aed4
b981fd
	mb_cfgtest_ldflags=$(${mb_make} -n -f "$mb_pwd/Makefile.tmp" \
b981fd
		OS_DSO_EXRULES=default                               \
b981fd
		OS_SONAME=symlink                                    \
b981fd
		OS_ARCHIVE_EXT='.a'                                  \
b981fd
		.ldflags-host)
b981fd
b981fd
	mb_cfgtest_ldflags="${mb_cfgtest_ldflags#*: }"
e1aed4
}
e1aed4
e1aed4
e1aed4
cfgtest_native_section()
e1aed4
{
c37c0c
	mb_cfgtest_cc="$ccenv_native_cc"
cce299
	mb_cfgtest_pkgconf="${ccenv_native_pkgconf:-false}"
e1aed4
	mb_cfgtest_cfgtype='native'
eb6ed9
	mb_cfgtest_stdin_input=${ccenv_native_stdin_input:-}
3009f7
	mb_cfgtest_environment=${ccenv_native_cc_environment:-}
c37c0c
c37c0c
	mb_cfgtest_cflags=$(${mb_make} -n -f "$mb_pwd/Makefile.tmp" \
c37c0c
		OS_DSO_EXRULES=default                              \
c37c0c
		OS_SONAME=symlink                                   \
c37c0c
		OS_ARCHIVE_EXT='.a'                                 \
c37c0c
		.cflags-native)
c37c0c
e1aed4
	mb_cfgtest_cflags="${mb_cfgtest_cflags#*: }"
b981fd
b981fd
	mb_cfgtest_ldflags=$(${mb_make} -n -f "$mb_pwd/Makefile.tmp" \
b981fd
		OS_DSO_EXRULES=default                               \
b981fd
		OS_SONAME=symlink                                    \
b981fd
		OS_ARCHIVE_EXT='.a'                                  \
b981fd
		.ldflags-native)
b981fd
b981fd
	mb_cfgtest_ldflags="${mb_cfgtest_ldflags#*: }"
e1aed4
}
e1aed4
e1aed4
e1aed4
cfgtest_prolog()
e1aed4
{
a356f3
	cfgtest_line_dots='...........................'
e1aed4
	cfgtest_line_dots="${cfgtest_line_dots}${cfgtest_line_dots}"
e1aed4
	cfgtest_tool_desc=" == trying ${mb_cfgtest_cfgtype} ${1}: ${2}"
e1aed4
	cfgtest_tool_dlen="${#cfgtest_line_dots}"
e1aed4
e1aed4
	printf '\n%s\n' '________________________' >&3
e1aed4
	printf "cfgtest: probing for ${mb_cfgtest_cfgtype} ${1}: ${2}\n\n" >&3
3f07d8
3f07d8
	if [ "${cfgtest_silent:-}" != 'yes' ]; then
3f07d8
		printf "%${cfgtest_tool_dlen}.${cfgtest_tool_dlen}s" \
3f07d8
			"${cfgtest_tool_desc}  ${mb_line_dots}"
3f07d8
	fi
e1aed4
}
e1aed4
e1aed4
e1aed4
cfgtest_epilog()
e1aed4
{
a356f3
	cfgtest_line_dots='...............'
e1aed4
	cfgtest_tool_dlen="$((${#cfgtest_line_dots} - ${#2}))"
e1aed4
3f07d8
	if [ "${cfgtest_silent:-}" != 'yes' ]; then
3f07d8
		printf "%${cfgtest_tool_dlen}.${cfgtest_tool_dlen}s  %s.\n" \
3f07d8
			"${cfgtest_line_dots}" "${2}"
3f07d8
	fi
e1aed4
847065
	if [ "${1}" = 'snippet' ] && [ -f 'a.out' ]; then
e1aed4
		rm -f 'a.out'
e1aed4
	fi
e1aed4
eb6ed9
	if [ "$mb_cfgtest_stdin_input" = 'no' ]; then
eb6ed9
		rm 'cfgtest_c3RyaWN0X21vZGUK.c'
eb6ed9
	fi
eb6ed9
e1aed4
	if [ "${1}" = 'snippet' ] && [ "${2}" = '(error)' ]; then
e1aed4
		printf '\n\ncfgtest: the %s compiler %s %s.\n' \
e1aed4
			"$mb_cfgtest_cfgtype"                 \
e1aed4
			'failed to compile the above code'   \
e1aed4
			"${1}" >&3
e1aed4
		printf '%s\n' '------------------------' >&3
e1aed4
		return 1
e1aed4
	fi
e1aed4
8af0b4
	if [ "${1}" = 'attr' ] && [ "${2}" = '(error)' ]; then
8af0b4
		printf '\n\ncfgtest: the %s compiler %s %s_ attribute.\n' \
8af0b4
			"$mb_cfgtest_cfgtype"                            \
8af0b4
			'does not appear to support the _'              \
8af0b4
			"${3}" >&3
8af0b4
		printf '%s\n' '------------------------' >&3
8af0b4
		return 1
8af0b4
	fi
8af0b4
cce299
	if [ "${2}" = '-----' ] || [ "${2}" = '(missing)' ]; then
e1aed4
		printf '\n\ncfgtest: %s %s is missing or cannot be found.\n' "${1}" "${3}" >&3
e1aed4
		printf '%s\n' '------------------------' >&3
e1aed4
		return 1
e1aed4
	elif [ "${1}" = 'size-of-type' ] && [ "${2}" = '(error)' ]; then
e1aed4
		printf '\n\ncfgtest: could not determine size of type `%s.\n' "${3}'" >&3
e1aed4
		printf '%s\n' '------------------------' >&3
e1aed4
		return 1
a488f5
	elif [ "${1}" = 'switch' ] && [ "${2}" = '(error)' ]; then
a488f5
		printf '\n\ncfgtest: the switch `%s is not supported by the %s compiler.\n' \
a488f5
			"${3}'" "$mb_cfgtest_cfgtype" >&3
a488f5
		printf '%s\n' '------------------------' >&3
a488f5
		return 1
e1aed4
	elif [ "${2}" = '(error)' ]; then
e1aed4
		printf '\n\ncfgtest: %s `%s is not defined or cannot be used.\n' "${1}" "${3}'" >&3
e1aed4
		printf '%s\n' '------------------------' >&3
e1aed4
		return 1
e1aed4
	fi
e1aed4
}
e1aed4
e1aed4
e1aed4
cfgtest_entity_size_prolog()
e1aed4
{
e1aed4
	cfgtest_line_dots='.......................'
e1aed4
	cfgtest_line_dots="${cfgtest_line_dots}${cfgtest_line_dots}"
e1aed4
	cfgtest_tool_desc=" == checking size of ${mb_cfgtest_cfgtype} type: ${@}"
e1aed4
	cfgtest_tool_dlen="${#cfgtest_line_dots}"
e1aed4
e1aed4
	printf '\n%s\n' '________________________' >&3
e1aed4
	printf "cfgtest: checking size of ${mb_cfgtest_cfgtype} type: ${@}\n\n" >&3
e1aed4
e1aed4
	printf "%${cfgtest_tool_dlen}.${cfgtest_tool_dlen}s" \
e1aed4
		"${cfgtest_tool_desc}  ${mb_line_dots}"
e1aed4
}
e1aed4
e1aed4
5e6a75
cfgtest_makevar_set()
5e6a75
{
5e6a75
	if [ -n "${@}" ]; then
5e6a75
		mb_internal_str='= '
5e6a75
	else
5e6a75
		mb_internal_str='='
5e6a75
	fi
5e6a75
5e6a75
	printf '%-25s%s%s\n' "$mb_cfgtest_makevar" "$mb_internal_str" "${@}" \
5e6a75
		>> $mb_pwd/cfgdefs.mk
5e6a75
5e6a75
	unset cfgtest_internal_unit_test
5e6a75
}
5e6a75
5e6a75
e1aed4
cfgtest_makevar_append()
e1aed4
{
e1aed4
	mb_internal_str='+='
e1aed4
e1aed4
	for mb_internal_arg ; do
e1aed4
		if ! [ -z "$mb_internal_arg" ]; then
e1aed4
			mb_internal_str="$mb_internal_str $mb_internal_arg"
e1aed4
		fi
e1aed4
	done
e1aed4
e1aed4
	printf '%-24s%s\n' "$mb_cfgtest_makevar" "$mb_internal_str" \
e1aed4
		>> $mb_pwd/cfgdefs.mk
e1aed4
e1aed4
	unset cfgtest_internal_unit_test
e1aed4
}
e1aed4
e1aed4
e1aed4
cfgtest_cflags_append()
e1aed4
{
e1aed4
	if [ $mb_cfgtest_cfgtype = 'host' ]; then
e1aed4
		mb_internal_makevar='CFLAGS_CONFIG'
e1aed4
	else
e1aed4
		mb_internal_makevar='NATIVE_CFLAGS'
e1aed4
	fi
e1aed4
e1aed4
	mb_cfgtest_makevar_saved=$mb_cfgtest_makevar
e1aed4
	mb_cfgtest_makevar=$mb_internal_makevar
e1aed4
e1aed4
	cfgtest_makevar_append "$@"
e1aed4
	mb_cfgtest_makevar=$mb_cfgtest_makevar_saved
e1aed4
}
e1aed4
e1aed4
e1aed4
cfgtest_ldflags_append()
e1aed4
{
e1aed4
	if [ $mb_cfgtest_cfgtype = 'host' ]; then
e1aed4
		mb_internal_makevar='LDFLAGS_CONFIG'
e1aed4
	else
e1aed4
		mb_internal_makevar='NATIVE_LDFLAGS'
e1aed4
	fi
e1aed4
e1aed4
	mb_cfgtest_makevar_saved=$mb_cfgtest_makevar
e1aed4
	mb_cfgtest_makevar=$mb_internal_makevar
e1aed4
e1aed4
	cfgtest_makevar_append "$@"
e1aed4
	mb_cfgtest_makevar=$mb_cfgtest_makevar_saved
e1aed4
}
e1aed4
e1aed4
e1aed4
cfgtest_common_init()
e1aed4
{
e1aed4
	# cfgtest variables
3272d3
	cfgtest_type="${1:-}"
3272d3
eb6ed9
	if [ "$mb_cfgtest_stdin_input" = 'no' ]; then
eb6ed9
		if [ "$cfgtest_type" = 'lib' ]; then
eb6ed9
			cfgtest_fmt='%s cfgtest_c3RyaWN0X21vZGUK.c -o a.out'
0078d6
		elif [ "$cfgtest_type" = 'ldflag' ]; then
0078d6
			cfgtest_fmt='%s cfgtest_c3RyaWN0X21vZGUK.c -o a.out'
eb6ed9
		else
eb6ed9
			cfgtest_fmt='%s -c cfgtest_c3RyaWN0X21vZGUK.c -o a.out'
eb6ed9
		fi
eb6ed9
	elif [ "$cfgtest_type" = 'asm' ]; then
e1aed4
		cfgtest_fmt='%s -c -xc - -o a.out'
8af0b4
	elif [ "$cfgtest_type" = 'attr' ]; then
8af0b4
		cfgtest_fmt='%s -c -xc - -o a.out -Werror'
3272d3
	elif [ "$cfgtest_type" = 'lib' ]; then
e1aed4
		cfgtest_fmt='%s -xc - -o a.out'
0078d6
	elif [ "$cfgtest_type" = 'ldflag' ]; then
0078d6
		cfgtest_fmt='%s -xc - -o a.out'
e1aed4
	else
e1aed4
		cfgtest_fmt='%s -S -xc - -o -'
e1aed4
	fi
e1aed4
a488f5
3272d3
	if [ "$cfgtest_type" = 'lib' ]; then
e1aed4
		cfgtest_cmd=$(printf "$cfgtest_fmt %s %s %s" \
e1aed4
			"$mb_cfgtest_cc"                     \
e1aed4
			"$mb_cfgtest_cflags"                 \
e1aed4
			"$mb_cfgtest_ldflags"                \
e1aed4
			"$cfgtest_libs")
a488f5
0078d6
	elif [ "$cfgtest_type" = 'ldflag' ]; then
0078d6
		cfgtest_cmd=$(printf "$cfgtest_fmt %s %s %s" \
0078d6
			"$mb_cfgtest_cc"                     \
0078d6
			"$mb_cfgtest_cflags"                 \
0078d6
			"$mb_cfgtest_ldflags"                \
0078d6
			"$cfgtest_switches")
0078d6
a488f5
	elif [ "$cfgtest_type" = 'switch' ]; then
a488f5
		cfgtest_cmd=$(printf "$cfgtest_fmt %s %s" \
a488f5
			"$mb_cfgtest_cc"                  \
a488f5
			"$mb_cfgtest_cflags"              \
a488f5
			"$cfgtest_switches")
e1aed4
	else
e1aed4
		cfgtest_cmd=$(printf "$cfgtest_fmt %s" \
e1aed4
			"$mb_cfgtest_cc"               \
e1aed4
			"$mb_cfgtest_cflags")
e1aed4
	fi
e1aed4
a488f5
34ee4b
	if [ -n "$mb_cfgtest_headers" ]; then
e1aed4
		cfgtest_inc=$(printf '#include <%s>\n' $mb_cfgtest_headers)
e1aed4
		cfgtest_src=$(printf '%s\n_\n' "$cfgtest_inc" \
e1aed4
			| m4 -D_="$cfgtest_code_snippet")
34ee4b
	else
34ee4b
		cfgtest_inc=
34ee4b
		cfgtest_src="$cfgtest_code_snippet"
e1aed4
	fi
e1aed4
a488f5
e1aed4
	# config.log
e1aed4
	printf "$cfgtest_fmt" "$mb_cfgtest_cc" >&3
e1aed4
6eb87c
	for cfgtest_cflag in $(printf '%s' "$mb_cfgtest_cflags"); do
e1aed4
		printf ' \\\n\t%s' "$cfgtest_cflag" >&3
e1aed4
	done
e1aed4
8692c9
	for cfgtest_ldflag in $(printf '%s' "$mb_cfgtest_ldflags"); do
8692c9
		printf ' \\\n\t%s' "$cfgtest_ldflag" >&3
8692c9
	done
8692c9
3272d3
	if [ "$cfgtest_type" = 'lib' ]; then
6eb87c
		for cfgtest_lib in $(printf '%s' "$cfgtest_libs"); do
e1aed4
			printf ' \\\n\t%s' "$cfgtest_lib" >&3
e1aed4
		done
a488f5
0078d6
	elif [ "$cfgtest_type" = 'switch' ] || [ "$cfgtest_type" = 'ldflag' ]; then
6eb87c
		for cfgtest_switch in $(printf '%s' "$cfgtest_switches"); do
a488f5
			printf ' \\\n\t%s' "$cfgtest_switch" >&3
a488f5
		done
e1aed4
	fi
e1aed4
e1aed4
	printf ' \\\n'                           >&3
e1aed4
	printf '<< _SRCEOF\n%s\n' "$cfgtest_src" >&3
d3381e
	printf '_SRCEOF\n\n\n'                   >&3
eb6ed9
eb6ed9
	if [ "$mb_cfgtest_stdin_input" = 'no' ]; then
eb6ed9
		printf '%s' "$cfgtest_src" > 'cfgtest_c3RyaWN0X21vZGUK.c'
eb6ed9
		cfgtest_src=
eb6ed9
	fi
e1aed4
}
e1aed4
e1aed4
e1aed4
cfgtest_header_presence()
e1aed4
{
e1aed4
	#init
e1aed4
	cfgtest_prolog 'header' "${1}"
e1aed4
e1aed4
	cfgtest_code_snippet=$(printf '#include <%s>\n' "${1}")
c930cc
	cfgtest_code_onedecl='int fn(void){return 0;}'
c930cc
c930cc
	cfgtest_code_snippet=$(printf '%s\n%s\n' \
c930cc
			"$cfgtest_code_snippet"   \
c930cc
			"$cfgtest_code_onedecl")
e1aed4
e1aed4
	cfgtest_common_init
e1aed4
e1aed4
	# execute
c930cc
	printf '%s\n' "$cfgtest_src"                \
e1aed4
		| eval $(printf '%s' "$cfgtest_cmd") \
e1aed4
		> /dev/null 2>&3                      \
e1aed4
	|| cfgtest_epilog 'header' '-----' "<${1}>"    \
e1aed4
	|| return
e1aed4
e1aed4
	# result
e1aed4
	mb_internal_str=$(printf '%s%s' '-DHAVE_' "${1}"  \
e1aed4
			| sed -e 's/\./_/g' -e 's@/@_@g'  \
e1aed4
			| tr "[:lower:]" "[:upper:]")
e1aed4
e1aed4
	if [ -z ${cfgtest_internal_unit_test:-} ]; then
e1aed4
		cfgtest_cflags_append "$mb_internal_str"
e1aed4
	else
e1aed4
		cfgtest_makevar_append "$mb_internal_str"
e1aed4
	fi
e1aed4
e1aed4
	printf 'cfgtest: %s header <%s> was found and may be included.\n' \
e1aed4
		"$mb_cfgtest_cfgtype" "${1}" >&3
e1aed4
	printf '%s\n' '------------------------' >&3
e1aed4
e1aed4
	cfgtest_epilog 'header' "${1}"
e1aed4
}
e1aed4
e1aed4
e1aed4
cfgtest_header_absence()
e1aed4
{
e1aed4
	#init
e1aed4
	cfgtest_prolog 'header absence' "${1}"
e1aed4
e1aed4
	cfgtest_code_snippet=$(printf '#include <%s>\n' "${1}")
c930cc
	cfgtest_code_onedecl='int fn(void){return 0;}'
c930cc
c930cc
	cfgtest_code_snippet=$(printf '%s\n%s\n' \
c930cc
			"$cfgtest_code_snippet"   \
c930cc
			"$cfgtest_code_onedecl")
e1aed4
e1aed4
	cfgtest_common_init
e1aed4
e1aed4
	# execute
c930cc
	printf '%s\n' "$cfgtest_src"                \
e1aed4
		| eval $(printf '%s' "$cfgtest_cmd") \
e1aed4
		> /dev/null 2>&3                      \
e1aed4
	&& printf 'cfgtest: %s header <%s>: no error.' \
e1aed4
		"$mb_cfgtest_cfgtype" "${1}" >&3        \
e1aed4
	&& cfgtest_epilog 'header' "${1}"                \
e1aed4
	&& return
e1aed4
e1aed4
	# result
e1aed4
	mb_internal_str=$(printf '%s%s' '-DHAVE_NO_' "$@" \
e1aed4
			| sed -e 's/\./_/g' -e 's@/@_@g'  \
e1aed4
			| tr "[:lower:]" "[:upper:]")
e1aed4
e1aed4
	if [ -z ${cfgtest_internal_unit_test:-} ]; then
e1aed4
		cfgtest_cflags_append "$mb_internal_str"
e1aed4
	else
e1aed4
		cfgtest_makevar_append "$mb_internal_str"
e1aed4
	fi
e1aed4
e1aed4
	printf 'cfgtest: %s header <%s> may not be included.\n' \
e1aed4
		"$mb_cfgtest_cfgtype" "${1}" >&3
e1aed4
	printf '%s\n' '------------------------' >&3
e1aed4
70d4ac
	cfgtest_epilog 'header' '-----' "${1}"
e1aed4
}
e1aed4
e1aed4
e1aed4
cfgtest_interface_presence()
e1aed4
{
e1aed4
	# init
e1aed4
	cfgtest_prolog 'interface' "${1}"
e1aed4
e1aed4
	cfgtest_code_snippet=$(printf 'void * addr = &%;;\n' "${1}")
e1aed4
e1aed4
	cfgtest_common_init
e1aed4
e1aed4
	# execute
c930cc
	printf '%s\n' "$cfgtest_src"                  \
e1aed4
		| eval $(printf '%s' "$cfgtest_cmd")   \
e1aed4
		> /dev/null 2>&3                        \
e1aed4
	|| cfgtest_epilog 'interface' '(error)' "${1}"   \
e1aed4
	|| return
e1aed4
e1aed4
	# result
e1aed4
	mb_internal_str=$(printf '%s%s' '-DHAVE_' "$@"  \
e1aed4
			| sed -e 's/\./_/g'             \
e1aed4
			| tr "[:lower:]" "[:upper:]")
e1aed4
e1aed4
	if [ -z ${cfgtest_internal_unit_test:-} ]; then
e1aed4
		cfgtest_cflags_append "$mb_internal_str"
e1aed4
	else
e1aed4
		cfgtest_makevar_append "$mb_internal_str"
e1aed4
	fi
e1aed4
e1aed4
	printf 'cfgtest: %s interface `%s'"'"' is available.\n' \
e1aed4
		"$mb_cfgtest_cfgtype" "${1}" >&3
e1aed4
	printf '%s\n' '------------------------' >&3
e1aed4
e1aed4
	cfgtest_epilog 'interface' "${1}"
e1aed4
e1aed4
	return 0
e1aed4
}
e1aed4
e1aed4
e1aed4
cfgtest_decl_presence()
e1aed4
{
e1aed4
	# init
e1aed4
	cfgtest_prolog 'decl' "${1}"
e1aed4
e1aed4
	cfgtest_code_snippet=$(printf 'void * any = (void *)(%s);' "${1}")
e1aed4
e1aed4
	cfgtest_common_init
e1aed4
e1aed4
	# execute
c930cc
	printf '%s\n' "$cfgtest_src"                \
e1aed4
		| eval $(printf '%s' "$cfgtest_cmd") \
e1aed4
		> /dev/null 2>&3                      \
e1aed4
	|| cfgtest_epilog 'decl' '(error)' "${1}"      \
e1aed4
	|| return
e1aed4
e1aed4
	# does the argument solely consist of the macro or enum member name?
e1aed4
	mb_internal_str=$(printf '%s' "$@" | tr -d '[a-z][A-Z][0-9][_]')
e1aed4
e1aed4
	if [ -n "$mb_internal_str" ]; then
e1aed4
		cfgtest_epilog 'decl' '(defined)'
e1aed4
		return 0
e1aed4
	fi
e1aed4
e1aed4
	# result
e1aed4
	mb_internal_str=$(printf '%s%s' '-DHAVE_DECL_' "$@"  \
e1aed4
			| sed -e 's/\./_/g'                  \
e1aed4
			| tr "[:lower:]" "[:upper:]")
e1aed4
e1aed4
	if [ -z ${cfgtest_internal_unit_test:-} ]; then
e1aed4
		cfgtest_cflags_append "$mb_internal_str"
e1aed4
	else
e1aed4
		cfgtest_makevar_append "$mb_internal_str"
e1aed4
	fi
e1aed4
e1aed4
	printf 'cfgtest: `%s'"'"' is defined for the %s system.\n' \
e1aed4
		"${1}" "$mb_cfgtest_cfgtype" >&3
e1aed4
	printf '%s\n' '------------------------' >&3
e1aed4
e1aed4
	cfgtest_epilog 'decl' '(defined)'
e1aed4
e1aed4
	return 0
e1aed4
}
e1aed4
e1aed4
e1aed4
cfgtest_type_size()
e1aed4
{
e1aed4
	cfgtest_entity_size_prolog "$@"
e1aed4
e1aed4
	mb_internal_size=''
e1aed4
	mb_internal_test='char x[(sizeof(%s) == %s) ? 1 : -1];'
e1aed4
e1aed4
	for mb_internal_guess in 8 4 2 1 16 32 64 128; do
e1aed4
		if [ -z $mb_internal_size ]; then
e1aed4
			printf '# guess %s ===>\n' "$mb_internal_guess" >&3
e1aed4
e1aed4
			mb_internal_type="$@"
e1aed4
e1aed4
			cfgtest_code_snippet=$(printf "$mb_internal_test" \
e1aed4
				"$mb_internal_type" "$mb_internal_guess")
e1aed4
e1aed4
			cfgtest_common_init
e1aed4
c930cc
			printf '%s\n' "$cfgtest_src"                \
e1aed4
				| eval $(printf '%s' "$cfgtest_cmd") \
e1aed4
				> /dev/null 2>&3                      \
e1aed4
			&& mb_internal_size=$mb_internal_guess
e1aed4
e1aed4
			printf '\n' >&3
e1aed4
		fi
e1aed4
	done
e1aed4
e1aed4
	# unrecognized type, or type size not within range
e1aed4
	if [ -z $mb_internal_size ]; then
e1aed4
		cfgtest_epilog 'size-of-type' '(error)' "@"
e1aed4
		return 1
e1aed4
	fi
e1aed4
e1aed4
	# -DSIZEOF_TYPE=SIZE
e1aed4
	mb_internal_str=$(printf '%s%s=%s' '-DSIZEOF_'        \
e1aed4
				"$mb_internal_type"           \
e1aed4
				"$mb_internal_size"           \
e1aed4
			| sed -e 's/\ /_/g' -e 's/*/P/g'      \
e1aed4
			| tr "[:lower:]" "[:upper:]")
e1aed4
e1aed4
	if [ -z ${cfgtest_internal_unit_test:-} ]; then
e1aed4
		cfgtest_cflags_append "$mb_internal_str"
e1aed4
	else
e1aed4
		cfgtest_makevar_append "$mb_internal_str"
e1aed4
	fi
e1aed4
e1aed4
	printf 'cfgtest: size of type `%s'"'"' determined to be %s\n' \
e1aed4
		"${@}" "$mb_internal_size" >&3
e1aed4
	printf '%s\n' '------------------------' >&3
e1aed4
e1aed4
	cfgtest_epilog 'size-of-type' "$mb_internal_size"
e1aed4
e1aed4
	return 0
e1aed4
}
e1aed4
e1aed4
8af0b4
cfgtest_attr_visibility()
8af0b4
{
8af0b4
	# init
8af0b4
	cfgtest_prolog 'compiler visibility attr' "${1}"
8af0b4
8af0b4
	cfgtest_attr_syntax='__attribute__((__visibility__("'"${1}"'")))'
8af0b4
	cfgtest_code_snippet="$cfgtest_attr_syntax"' int f_'"${1}"'(void);'
8af0b4
8af0b4
	cfgtest_common_init 'attr'
8af0b4
8af0b4
	# execute
8af0b4
	cfgtest_ret=1
8af0b4
c930cc
	printf '%s\n' "$cfgtest_src"                \
8af0b4
		| eval $(printf '%s' "$cfgtest_cmd") \
8af0b4
		> /dev/null 2>&3                      \
8af0b4
	|| cfgtest_epilog 'attr' '(error)' "${1}"      \
8af0b4
	|| return
8af0b4
8af0b4
	# result
8af0b4
	mb_cfgtest_attr=$(printf '__attribute__\\(\\(__visibility__\\(\\"%s\\"\\)\\)\\)' "${1}")
8af0b4
8af0b4
	cfgtest_ret=0
8af0b4
8af0b4
	printf 'cfgtest: %s compiler: above attribute is supported; see also ccenv/%s.mk.\n\n' \
8af0b4
		"$mb_cfgtest_cfgtype" "$mb_cfgtest_cfgtype" >&3
8af0b4
8af0b4
	cfgtest_epilog 'attr' '(ok)'
8af0b4
8af0b4
	return 0
8af0b4
}
8af0b4
8af0b4
e1aed4
cfgtest_code_snippet_asm()
e1aed4
{
e1aed4
	# init
e1aed4
	cfgtest_prolog 'support of code snippet' '<...>'
e1aed4
e1aed4
	cfgtest_code_snippet="$@"
e1aed4
e1aed4
	cfgtest_common_init 'asm'
e1aed4
e1aed4
	# execute
e1aed4
	cfgtest_ret=1
e1aed4
c930cc
	printf '%s\n' "$cfgtest_src"                \
e1aed4
		| eval $(printf '%s' "$cfgtest_cmd") \
e1aed4
		> /dev/null 2>&3                      \
e1aed4
	|| cfgtest_epilog 'snippet' '(error)'          \
e1aed4
	|| return
e1aed4
e1aed4
	# result
e1aed4
	cfgtest_ret=0
e1aed4
e1aed4
	printf 'cfgtest: %s compiler: above code snippet compiled successfully.\n\n' \
e1aed4
		"$mb_cfgtest_cfgtype" >&3
e1aed4
e1aed4
	cfgtest_epilog 'snippet' '(ok)'
e1aed4
e1aed4
	return 0
e1aed4
}
e1aed4
e1aed4
b05268
cfgtest_macro_definition()
b05268
{
b05268
	# init
b05268
	cfgtest_prolog 'macro definition' "${1}"
b05268
b05268
	cfgtest_code_snippet=$(printf '%s\n'      \
b05268
		"#ifndef ${1}"                     \
b05268
		"#error macro ${1} is not defined." \
b05268
		"#endif")
b05268
b05268
	cfgtest_common_init 'macro'
b05268
b05268
	# execute
b05268
	cfgtest_ret=1
b05268
c930cc
	printf '%s\n' "$cfgtest_src"                \
b05268
		| eval $(printf '%s' "$cfgtest_cmd") \
b05268
		> /dev/null 2>&3                      \
b05268
	|| cfgtest_epilog 'macro' '(error)' "${1}"     \
b05268
	|| return
b05268
b05268
	# result
b05268
	cfgtest_ret=0
b05268
b05268
	printf 'cfgtest: %s compiler: above macro definition test compiled successfully.\n\n' \
b05268
		"$mb_cfgtest_cfgtype" >&3
b05268
b05268
	cfgtest_epilog 'macro' '(defined)'
b05268
b05268
	return 0
b05268
}
b05268
b05268
e1aed4
cfgtest_library_presence()
e1aed4
{
e1aed4
	# init
e1aed4
	cfgtest_libs=
e1aed4
	cfgtest_spc=
e1aed4
e1aed4
	for cfgtest_lib in ${@}; do
e1aed4
		cfgtest_libs="$cfgtest_libs$cfgtest_spc$cfgtest_lib"
e1aed4
		cfgtest_spc=' '
e1aed4
	done
e1aed4
e1aed4
	if [ "${1}" = "$cfgtest_libs" ]; then
e1aed4
		cfgtest_prolog 'library' "${1#*-l}"
e1aed4
	else
e1aed4
		cfgtest_prolog 'lib module' '(see config.log)'
e1aed4
	fi
e1aed4
3b8c0b
	if [ "$mb_cfgtest_environment" = 'freestanding' ]; then
3b8c0b
		if [ -z "ccenv_cc_underscore" ]; then
3b8c0b
			cfgtest_code_snippet='int start(void){return 0;}'
3b8c0b
		else
3b8c0b
			cfgtest_code_snippet='int _start(void){return 0;}'
3b8c0b
		fi
3b8c0b
	else
3b8c0b
		cfgtest_code_snippet='int main(void){return 0;}'
3b8c0b
	fi
e1aed4
e1aed4
	cfgtest_common_init 'lib'
e1aed4
e1aed4
	# execute
c930cc
	printf '%s\n' "$cfgtest_src"                \
e1aed4
		| eval $(printf '%s' "$cfgtest_cmd") \
e1aed4
		> /dev/null 2>&3                      \
e1aed4
	|| cfgtest_epilog 'library' '-----' "$@"       \
e1aed4
	|| return 1
e1aed4
e1aed4
	# result
e1aed4
	printf 'cfgtest: `%s'"'"' was accepted by the linker driver.\n' \
e1aed4
		"$cfgtest_libs" >&3
e1aed4
	printf '%s\n' '------------------------' >&3
e1aed4
e1aed4
	cfgtest_epilog 'library' '(present)'
e1aed4
e1aed4
	return 0
e1aed4
}
e1aed4
e1aed4
cce299
cfgtest_package_exists()
cce299
{
cce299
	# init
cce299
	cfgtest_pkg=
cce299
cce299
	for cfgtest_arg in ${@}; do
cce299
		case "$cfgtest_arg" in
cce299
			-*)
cce299
				;;
cce299
cce299
			*)
cce299
				cfgtest_pkg="$cfgtest_arg"
cce299
				;;
cce299
		esac
cce299
	done
cce299
cce299
	cfgtest_prolog 'package' "$cfgtest_pkg"
cce299
cce299
	# execute
cce299
	"$mb_cfgtest_pkgconf" "${@}"                         \
cce299
		> /dev/null 2>&3                              \
cce299
	|| cfgtest_epilog 'package' '(missing)' "$cfgtest_pkg" \
cce299
	|| return 1
cce299
cce299
	# result
cce299
	printf 'cfgtest: package `%s'"'"' was found.\n' \
cce299
		"$cfgtest_pkg" >&3
cce299
	printf '%s\n' '------------------------' >&3
cce299
cce299
	cfgtest_epilog 'package' '(exists)' "$cfgtest_pkg"
cce299
cce299
	return 0
cce299
}
cce299
cce299
cce299
cfgtest_package_config()
cce299
{
cce299
	# init
cce299
	if ! cfgtest_package_exists "${@}"; then
cce299
		return 0
cce299
	fi
cce299
cce299
	cfgtest_pkg=
cce299
cce299
	for cfgtest_arg in ${@}; do
cce299
		case "$cfgtest_arg" in
cce299
			-*)
cce299
				;;
cce299
cce299
			*)
cce299
				cfgtest_pkg="$cfgtest_arg"
cce299
				;;
cce299
		esac
cce299
	done
cce299
cce299
	cfgtest_makevar_prefix=
cce299
	cfgtest_pkgconf_prefix=
cce299
cce299
	if [ "$mb_cfgtest_cfgtype" = 'native' ]; then
cce299
		cfgtest_makevar_prefix='_NATIVE'
cce299
	else
cce299
		if [ -n "${mb_sysroot}" ]; then
cce299
			cfgtest_pkgconf_prefix="--define-variable=prefix=${mb_sysroot}"
cce299
		fi
cce299
	fi
cce299
cce299
	cfgtest_newline
cce299
	cfgtest_comment 'package config:' "$cfgtest_pkg"
cce299
cce299
	# foo.pc
cce299
	cfgtest_pkgconf_path=$("$mb_cfgtest_pkgconf" \
cce299
			--path "${@}"                 \
cce299
		2>/dev/null || true)
cce299
cce299
	if [ -z "$cfgtest_pkgconf_path" ]; then
cce299
		cfgtest_pkgconf_path=$("$mb_cfgtest_pkgconf" \
cce299
				--debug "${@}" 2>&1           \
cce299
				| grep ".pc'$"                 \
cce299
				| head -n1                      \
cce299
			|| true)
cce299
cce299
		cfgtest_pkgconf_path="${cfgtest_pkgconf_path##* \'}"
cce299
		cfgtest_pkgconf_path="${cfgtest_pkgconf_path%%\'}"
cce299
	fi
cce299
cce299
	mb_cfgtest_makevar=$(printf '%s_PKGCONF_%s'             \
cce299
			"$cfgtest_makevar_prefix" "$cfgtest_pkg" \
cce299
		| tr '[[:lower:]]' '[[:upper:]]'                  \
cce299
		| sed -e 's/-/_/g')
cce299
cce299
	cfgtest_makevar_set "$cfgtest_pkgconf_path"
cce299
cce299
	# --cflags
cce299
	cfgtest_pkgconf_path=$("$mb_cfgtest_pkgconf" \
cce299
			"$cfgtest_pkgconf_prefix"     \
cce299
			--cflags "${@}"                \
cce299
		| sed 's/[ \t]*$//')
cce299
cce299
	mb_cfgtest_makevar=$(printf '%s_CFLAGS_%s'              \
cce299
			"$cfgtest_makevar_prefix" "$cfgtest_pkg" \
cce299
		| tr '[[:lower:]]' '[[:upper:]]'                  \
cce299
		| sed -e 's/-/_/g')
cce299
cce299
	cfgtest_makevar_set "$cfgtest_pkgconf_path"
cce299
cce299
	# --ldflags
cce299
	cfgtest_pkgconf_path=$("$mb_cfgtest_pkgconf" \
cce299
			"$cfgtest_pkgconf_prefix"     \
cce299
			--libs "${@}"                  \
cce299
		| sed 's/[ \t]*$//')
cce299
cce299
	mb_cfgtest_makevar=$(printf '%s_LDFLAGS_%s'             \
cce299
			"$cfgtest_makevar_prefix" "$cfgtest_pkg" \
cce299
		| tr '[[:lower:]]' '[[:upper:]]'                  \
cce299
		| sed -e 's/-/_/g')
cce299
cce299
	cfgtest_makevar_set "$cfgtest_pkgconf_path"
cce299
cce299
	return 0
cce299
}
cce299
cce299
a488f5
cfgtest_compiler_switch()
a488f5
{
a488f5
	# init
a488f5
	cfgtest_switches=
a488f5
	cfgtest_spc=
a488f5
6eb87c
	for cfgtest_switch in $(printf '%s' "${@}"); do
a488f5
		cfgtest_switches="$cfgtest_switches$cfgtest_spc$cfgtest_switch"
a488f5
		cfgtest_spc=' '
a488f5
	done
a488f5
5a381c
	if [ -n "${cfgtest_switch_arg:-}" ]; then
5a381c
		cfgtest_prolog 'compiler switch' "${cfgtest_switches%=*}"
5a381c
5a381c
	elif [ "${1}" = "$cfgtest_switches" ]; then
a488f5
		cfgtest_prolog 'compiler switch' "$cfgtest_switches"
5a381c
a488f5
	else
a488f5
		cfgtest_prolog 'compiler switch combination' "$cfgtest_switches"
a488f5
	fi
a488f5
0078d6
	case "${1}" in
0078d6
		-Wl,*)
3009f7
			if [ "$mb_cfgtest_environment" = 'freestanding' ]; then
3009f7
				cfgtest_switches="$cfgtest_switches -nostdlib -nostartfiles"
3009f7
3009f7
				if [ -z "ccenv_cc_underscore" ]; then
3009f7
					cfgtest_code_snippet='int start(void){return 0;}'
3009f7
				else
3009f7
					cfgtest_code_snippet='int _start(void){return 0;}'
3009f7
				fi
3009f7
			else
3009f7
				cfgtest_code_snippet='int main(void){return 0;}'
3009f7
			fi
3009f7
0078d6
			cfgtest_common_init 'ldflag'
0078d6
			;;
0078d6
0078d6
		*)
c930cc
			cfgtest_code_snippet='int fn(void){return 0;}'
0078d6
			cfgtest_common_init 'switch'
0078d6
			;;
0078d6
	esac
a488f5
a488f5
	# execute
c930cc
	printf '%s\n' "$cfgtest_src"                \
a488f5
		| eval $(printf '%s' "$cfgtest_cmd") \
a488f5
		> /dev/null 2>&3                      \
a488f5
	|| cfgtest_epilog 'switch' '(error)' "$@"      \
a488f5
	|| return 1
a488f5
a488f5
	# result
fcd329
	printf 'cfgtest: the switch `%s was accepted by the compiler.\n' \
a488f5
		"$cfgtest_switches'" >&3
a488f5
	printf '%s\n' '------------------------' >&3
a488f5
a488f5
	cfgtest_epilog 'switch' '(accepted)'
a488f5
a488f5
	return 0
a488f5
}
a488f5
a488f5
5a381c
cfgtest_compiler_switch_arg()
5a381c
{
5a381c
	cfgtest_switch_arg='yes'
5a381c
5a381c
	if cfgtest_compiler_switch "${@}"; then
5a381c
		cfgtest_ret=0
5a381c
	else
5a381c
		cfgtest_ret=1
5a381c
	fi
5a381c
5a381c
	unset cfgtest_switch_arg
5a381c
5a381c
	return $cfgtest_ret
5a381c
}
5a381c
5a381c
e1aed4
cfgtest_unit_header_presence()
e1aed4
{
e1aed4
	cfgtest_internal_unit_test='unit_test'
e1aed4
	cfgtest_header_presence "$@" || return 1
e1aed4
	return 0
e1aed4
}
e1aed4
e1aed4
e1aed4
cfgtest_unit_header_absence()
e1aed4
{
e1aed4
	cfgtest_internal_unit_test='unit_test'
e1aed4
	cfgtest_header_absence "$@" || return 1
e1aed4
	return 0
e1aed4
}
e1aed4
e1aed4
e1aed4
cfgtest_unit_interface_presence()
e1aed4
{
e1aed4
	cfgtest_internal_unit_test='unit_test'
e1aed4
	cfgtest_interface_presence "$@" || return 1
e1aed4
	return 0
e1aed4
}
e1aed4
e1aed4
e1aed4
cfgtest_unit_decl_presence()
e1aed4
{
e1aed4
	cfgtest_internal_unit_test='unit_test'
e1aed4
	cfgtest_decl_presence "$@" || return 1
e1aed4
	return 0
e1aed4
}
e1aed4
e1aed4
e1aed4
cfgtest_unit_type_size()
e1aed4
{
e1aed4
	cfgtest_internal_unit_test='unit_test'
e1aed4
	cfgtest_type_size "$@" || return 1
e1aed4
	return 0
e1aed4
}