Blame sofort/cfgtest/cfgtest.sh

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