Blame sofort/cfgtest/cfgtest.sh

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