Blame sofort/cfgtest/cfgtest.sh

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