Blame sofort/cfgtest/cfgtest.sh

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