Blame sofort/cfgtest/cfgtest.sh

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