Reicher82 / python / sbpython3

Forked from python/sbpython3 3 years ago
Clone

Blame sofort/cfgtest/cfgtest.sh

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