Blame sofort/cfgtest/cfgtest.sh

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