Blame sofort/cfgtest/cfgtest.sh

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