Blame sofort/cfgtest/cfgtest.sh

32ff4c
# cfgtest.sh: sofort's config test framework,
32ff4c
# for use from within a project's custom cfgdefs.sh.
32ff4c
ece8bd
# this file is covered by COPYING.SOFORT.
ece8bd
cb3894
# in the common scenario, host-specific tests are preceded
cb3894
# by a single invocation of cfgtest_host_section, whereas
32ff4c
# native (build) system tests are preceded by the invocation
32ff4c
# of cfgtest_native_section.
32ff4c
32ff4c
# cfgdefs fraework variables:
32ff4c
# mb_cfgtest_cc:      the compiler used for the current test
32ff4c
# mb_cfgtest_cflags:  the compiler flags used for the current test
cb3894
# mb_cfgtest_cfgtype: the type of the current test (host/native)
32ff4c
# mb_cfgtest_makevar: the make variable affected by the current test
32ff4c
# mb_cfgtest_headers: headers for ad-hoc inclusion with the current test
32ff4c
32ff4c
32ff4c
cfgtest_newline()
32ff4c
{
32ff4c
	printf '\n' >> $mb_pwd/cfgdefs.mk
32ff4c
}
32ff4c
32ff4c
32ff4c
cfgtest_comment()
32ff4c
{
32ff4c
	mb_internal_str='#'
32ff4c
32ff4c
	for mb_internal_arg ; do
32ff4c
		mb_internal_str="$mb_internal_str $mb_internal_arg"
32ff4c
	done
32ff4c
32ff4c
	printf '%s\n' "$mb_internal_str" >> $mb_pwd/cfgdefs.mk
32ff4c
}
32ff4c
32ff4c
cb3894
cfgtest_host_section()
32ff4c
{
3ecffe
	mb_cfgtest_cc="$ccenv_host_cc"
cb3894
	mb_cfgtest_cfgtype='host'
2be47c
	mb_cfgtest_stdin_input=${ccenv_host_stdin_input:-}
a50c64
	mb_cfgtest_environment=${ccenv_host_cc_environment:-}
280fd1
280fd1
	mb_cfgtest_cflags=$(${mb_make} -n -f "$mb_pwd/Makefile.tmp" \
280fd1
		OS_DSO_EXRULES=default                              \
280fd1
		OS_SONAME=symlink                                   \
280fd1
		OS_ARCHIVE_EXT='.a'                                 \
280fd1
		.cflags-host)
280fd1
1fe2d7
	mb_cfgtest_cflags="${mb_cfgtest_cflags#*: }"
32ff4c
a3c8c8
	mb_cfgtest_ldflags=$(${mb_make} -n -f "$mb_pwd/Makefile.tmp" \
a3c8c8
		OS_DSO_EXRULES=default                               \
a3c8c8
		OS_SONAME=symlink                                    \
a3c8c8
		OS_ARCHIVE_EXT='.a'                                  \
a3c8c8
		.ldflags-host)
a3c8c8
a3c8c8
	mb_cfgtest_ldflags="${mb_cfgtest_ldflags#*: }"
32ff4c
}
32ff4c
32ff4c
32ff4c
cfgtest_native_section()
32ff4c
{
280fd1
	mb_cfgtest_cc="$ccenv_native_cc"
32ff4c
	mb_cfgtest_cfgtype='native'
2be47c
	mb_cfgtest_stdin_input=${ccenv_native_stdin_input:-}
a50c64
	mb_cfgtest_environment=${ccenv_native_cc_environment:-}
280fd1
280fd1
	mb_cfgtest_cflags=$(${mb_make} -n -f "$mb_pwd/Makefile.tmp" \
280fd1
		OS_DSO_EXRULES=default                              \
280fd1
		OS_SONAME=symlink                                   \
280fd1
		OS_ARCHIVE_EXT='.a'                                 \
280fd1
		.cflags-native)
280fd1
1fe2d7
	mb_cfgtest_cflags="${mb_cfgtest_cflags#*: }"
a3c8c8
a3c8c8
	mb_cfgtest_ldflags=$(${mb_make} -n -f "$mb_pwd/Makefile.tmp" \
a3c8c8
		OS_DSO_EXRULES=default                               \
a3c8c8
		OS_SONAME=symlink                                    \
a3c8c8
		OS_ARCHIVE_EXT='.a'                                  \
a3c8c8
		.ldflags-native)
a3c8c8
a3c8c8
	mb_cfgtest_ldflags="${mb_cfgtest_ldflags#*: }"
32ff4c
}
32ff4c
32ff4c
cf05c9
cfgtest_prolog()
cf05c9
{
bce9d8
	cfgtest_line_dots='...........................'
cf05c9
	cfgtest_line_dots="${cfgtest_line_dots}${cfgtest_line_dots}"
cf05c9
	cfgtest_tool_desc=" == trying ${mb_cfgtest_cfgtype} ${1}: ${2}"
cf05c9
	cfgtest_tool_dlen="${#cfgtest_line_dots}"
cf05c9
cf05c9
	printf '\n%s\n' '________________________' >&3
cf05c9
	printf "cfgtest: probing for ${mb_cfgtest_cfgtype} ${1}: ${2}\n\n" >&3
f01114
f01114
	if [ "${cfgtest_silent:-}" != 'yes' ]; then
f01114
		printf "%${cfgtest_tool_dlen}.${cfgtest_tool_dlen}s" \
f01114
			"${cfgtest_tool_desc}  ${mb_line_dots}"
f01114
	fi
cf05c9
}
cf05c9
cf05c9
cf05c9
cfgtest_epilog()
cf05c9
{
bce9d8
	cfgtest_line_dots='...............'
53fd56
	cfgtest_tool_dlen="$((${#cfgtest_line_dots} - ${#2}))"
cf05c9
f01114
	if [ "${cfgtest_silent:-}" != 'yes' ]; then
f01114
		printf "%${cfgtest_tool_dlen}.${cfgtest_tool_dlen}s  %s.\n" \
f01114
			"${cfgtest_line_dots}" "${2}"
f01114
	fi
cf05c9
b2a35a
	if [ "${1}" = 'snippet' ] && [ -f 'a.out' ]; then
3fe72c
		rm -f 'a.out'
3fe72c
	fi
3fe72c
2be47c
	if [ "$mb_cfgtest_stdin_input" = 'no' ]; then
2be47c
		rm 'cfgtest_c3RyaWN0X21vZGUK.c'
2be47c
	fi
2be47c
3fe72c
	if [ "${1}" = 'snippet' ] && [ "${2}" = '(error)' ]; then
3fe72c
		printf '\n\ncfgtest: the %s compiler %s %s.\n' \
3fe72c
			"$mb_cfgtest_cfgtype"                 \
3fe72c
			'failed to compile the above code'   \
3fe72c
			"${1}" >&3
3fe72c
		printf '%s\n' '------------------------' >&3
3fe72c
		return 1
3fe72c
	fi
3fe72c
53fd56
	if [ "${2}" = '-----' ]; then
3fe72c
		printf '\n\ncfgtest: %s %s is missing or cannot be found.\n' "${1}" "${3}" >&3
960949
		printf '%s\n' '------------------------' >&3
960949
		return 1
1d55c8
	elif [ "${1}" = 'size-of-type' ] && [ "${2}" = '(error)' ]; then
3fe72c
		printf '\n\ncfgtest: could not determine size of type `%s.\n' "${3}'" >&3
1d55c8
		printf '%s\n' '------------------------' >&3
1d55c8
		return 1
be1531
	elif [ "${1}" = 'switch' ] && [ "${2}" = '(error)' ]; then
be1531
		printf '\n\ncfgtest: the switch `%s is not supported by the %s compiler.\n' \
be1531
			"${3}'" "$mb_cfgtest_cfgtype" >&3
be1531
		printf '%s\n' '------------------------' >&3
be1531
		return 1
53fd56
	elif [ "${2}" = '(error)' ]; then
3fe72c
		printf '\n\ncfgtest: %s `%s is not defined or cannot be used.\n' "${1}" "${3}'" >&3
cf05c9
		printf '%s\n' '------------------------' >&3
cf05c9
		return 1
cf05c9
	fi
cf05c9
}
cf05c9
cf05c9
1d55c8
cfgtest_entity_size_prolog()
1d55c8
{
1d55c8
	cfgtest_line_dots='.......................'
1d55c8
	cfgtest_line_dots="${cfgtest_line_dots}${cfgtest_line_dots}"
1d55c8
	cfgtest_tool_desc=" == checking size of ${mb_cfgtest_cfgtype} type: ${@}"
1d55c8
	cfgtest_tool_dlen="${#cfgtest_line_dots}"
1d55c8
1d55c8
	printf '\n%s\n' '________________________' >&3
1d55c8
	printf "cfgtest: checking size of ${mb_cfgtest_cfgtype} type: ${@}\n\n" >&3
1d55c8
1d55c8
	printf "%${cfgtest_tool_dlen}.${cfgtest_tool_dlen}s" \
1d55c8
		"${cfgtest_tool_desc}  ${mb_line_dots}"
1d55c8
}
1d55c8
1d55c8
32ff4c
cfgtest_makevar_append()
32ff4c
{
32ff4c
	mb_internal_str='+='
32ff4c
32ff4c
	for mb_internal_arg ; do
68a078
		if ! [ -z "$mb_internal_arg" ]; then
68a078
			mb_internal_str="$mb_internal_str $mb_internal_arg"
68a078
		fi
32ff4c
	done
32ff4c
32ff4c
	printf '%-24s%s\n' "$mb_cfgtest_makevar" "$mb_internal_str" \
32ff4c
		>> $mb_pwd/cfgdefs.mk
3eaf7b
3eaf7b
	unset cfgtest_internal_unit_test
32ff4c
}
32ff4c
32ff4c
32ff4c
cfgtest_cflags_append()
32ff4c
{
cb3894
	if [ $mb_cfgtest_cfgtype = 'host' ]; then
32ff4c
		mb_internal_makevar='CFLAGS_CONFIG'
32ff4c
	else
7e34aa
		mb_internal_makevar='NATIVE_CFLAGS'
32ff4c
	fi
32ff4c
32ff4c
	mb_cfgtest_makevar_saved=$mb_cfgtest_makevar
32ff4c
	mb_cfgtest_makevar=$mb_internal_makevar
32ff4c
32ff4c
	cfgtest_makevar_append "$@"
32ff4c
	mb_cfgtest_makevar=$mb_cfgtest_makevar_saved
32ff4c
}
32ff4c
32ff4c
32ff4c
cfgtest_ldflags_append()
32ff4c
{
cb3894
	if [ $mb_cfgtest_cfgtype = 'host' ]; then
32ff4c
		mb_internal_makevar='LDFLAGS_CONFIG'
32ff4c
	else
7e34aa
		mb_internal_makevar='NATIVE_LDFLAGS'
32ff4c
	fi
32ff4c
32ff4c
	mb_cfgtest_makevar_saved=$mb_cfgtest_makevar
32ff4c
	mb_cfgtest_makevar=$mb_internal_makevar
32ff4c
32ff4c
	cfgtest_makevar_append "$@"
32ff4c
	mb_cfgtest_makevar=$mb_cfgtest_makevar_saved
32ff4c
}
32ff4c
32ff4c
3fe72c
cfgtest_common_init()
32ff4c
{
3fe72c
	# cfgtest variables
a85024
	cfgtest_type="${1:-}"
a85024
2be47c
	if [ "$mb_cfgtest_stdin_input" = 'no' ]; then
2be47c
		if [ "$cfgtest_type" = 'lib' ]; then
2be47c
			cfgtest_fmt='%s cfgtest_c3RyaWN0X21vZGUK.c -o a.out'
fd723f
		elif [ "$cfgtest_type" = 'ldflag' ]; then
fd723f
			cfgtest_fmt='%s cfgtest_c3RyaWN0X21vZGUK.c -o a.out'
2be47c
		else
2be47c
			cfgtest_fmt='%s -c cfgtest_c3RyaWN0X21vZGUK.c -o a.out'
2be47c
		fi
2be47c
	elif [ "$cfgtest_type" = 'asm' ]; then
3fe72c
		cfgtest_fmt='%s -c -xc - -o a.out'
a85024
	elif [ "$cfgtest_type" = 'lib' ]; then
3fe72c
		cfgtest_fmt='%s -xc - -o a.out'
fd723f
	elif [ "$cfgtest_type" = 'ldflag' ]; then
fd723f
		cfgtest_fmt='%s -xc - -o a.out'
3fe72c
	else
3fe72c
		cfgtest_fmt='%s -S -xc - -o -'
3fe72c
	fi
cf05c9
be1531
a85024
	if [ "$cfgtest_type" = 'lib' ]; then
3fe72c
		cfgtest_cmd=$(printf "$cfgtest_fmt %s %s %s" \
3fe72c
			"$mb_cfgtest_cc"                     \
3fe72c
			"$mb_cfgtest_cflags"                 \
3fe72c
			"$mb_cfgtest_ldflags"                \
3fe72c
			"$cfgtest_libs")
be1531
fd723f
	elif [ "$cfgtest_type" = 'ldflag' ]; then
fd723f
		cfgtest_cmd=$(printf "$cfgtest_fmt %s %s %s" \
fd723f
			"$mb_cfgtest_cc"                     \
fd723f
			"$mb_cfgtest_cflags"                 \
fd723f
			"$mb_cfgtest_ldflags"                \
fd723f
			"$cfgtest_switches")
fd723f
be1531
	elif [ "$cfgtest_type" = 'switch' ]; then
be1531
		cfgtest_cmd=$(printf "$cfgtest_fmt %s %s" \
be1531
			"$mb_cfgtest_cc"                  \
be1531
			"$mb_cfgtest_cflags"              \
be1531
			"$cfgtest_switches")
3fe72c
	else
3fe72c
		cfgtest_cmd=$(printf "$cfgtest_fmt %s" \
3fe72c
			"$mb_cfgtest_cc"               \
3fe72c
			"$mb_cfgtest_cflags")
3fe72c
	fi
3fe72c
be1531
46680f
	if [ -n "$mb_cfgtest_headers" ]; then
3fe72c
		cfgtest_inc=$(printf '#include <%s>\n' $mb_cfgtest_headers)
3fe72c
		cfgtest_src=$(printf '%s\n_\n' "$cfgtest_inc" \
3fe72c
			| m4 -D_="$cfgtest_code_snippet")
46680f
	else
46680f
		cfgtest_inc=
46680f
		cfgtest_src="$cfgtest_code_snippet"
3fe72c
	fi
3fe72c
be1531
3fe72c
	# config.log
3fe72c
	printf "$cfgtest_fmt" "$mb_cfgtest_cc" >&3
cf05c9
f76b35
	for cfgtest_cflag in $(printf '%s' "$mb_cfgtest_cflags"); do
3fe72c
		printf ' \\\n\t%s' "$cfgtest_cflag" >&3
cf05c9
	done
cf05c9
33d5bf
	for cfgtest_ldflag in $(printf '%s' "$mb_cfgtest_ldflags"); do
33d5bf
		printf ' \\\n\t%s' "$cfgtest_ldflag" >&3
33d5bf
	done
33d5bf
a85024
	if [ "$cfgtest_type" = 'lib' ]; then
f76b35
		for cfgtest_lib in $(printf '%s' "$cfgtest_libs"); do
3fe72c
			printf ' \\\n\t%s' "$cfgtest_lib" >&3
3fe72c
		done
be1531
fd723f
	elif [ "$cfgtest_type" = 'switch' ] || [ "$cfgtest_type" = 'ldflag' ]; then
f76b35
		for cfgtest_switch in $(printf '%s' "$cfgtest_switches"); do
be1531
			printf ' \\\n\t%s' "$cfgtest_switch" >&3
be1531
		done
3fe72c
	fi
3fe72c
3fe72c
	printf ' \\\n'                           >&3
3fe72c
	printf '<< _SRCEOF\n%s\n' "$cfgtest_src" >&3
70e30a
	printf '_SRCEOF\n\n\n'                   >&3
2be47c
2be47c
	if [ "$mb_cfgtest_stdin_input" = 'no' ]; then
2be47c
		printf '%s' "$cfgtest_src" > 'cfgtest_c3RyaWN0X21vZGUK.c'
2be47c
		cfgtest_src=
2be47c
	fi
3fe72c
}
cf05c9
cf05c9
3fe72c
cfgtest_header_presence()
3fe72c
{
3fe72c
	#init
3fe72c
	cfgtest_prolog 'header' "${1}"
3fe72c
3fe72c
	cfgtest_code_snippet=$(printf '#include <%s>\n' "${1}")
3fe72c
3fe72c
	cfgtest_common_init
3fe72c
3fe72c
	# execute
3fe72c
	printf '%s' "$cfgtest_src"                  \
3fe72c
		| eval $(printf '%s' "$cfgtest_cmd") \
3fe72c
		> /dev/null 2>&3                      \
3fe72c
	|| cfgtest_epilog 'header' '-----' "<${1}>"    \
32ff4c
	|| return
32ff4c
3fe72c
	# result
cf05c9
	mb_internal_str=$(printf '%s%s' '-DHAVE_' "${1}"  \
c457f5
			| sed -e 's/\./_/g' -e 's@/@_@g'  \
32ff4c
			| tr "[:lower:]" "[:upper:]")
32ff4c
f1eb02
	if [ -z ${cfgtest_internal_unit_test:-} ]; then
3eaf7b
		cfgtest_cflags_append "$mb_internal_str"
3eaf7b
	else
3eaf7b
		cfgtest_makevar_append "$mb_internal_str"
3eaf7b
	fi
cf05c9
cf05c9
	printf 'cfgtest: %s header <%s> was found and may be included.\n' \
cf05c9
		"$mb_cfgtest_cfgtype" "${1}" >&3
cf05c9
	printf '%s\n' '------------------------' >&3
cf05c9
53fd56
	cfgtest_epilog 'header' "${1}"
32ff4c
}
32ff4c
32ff4c
32ff4c
cfgtest_header_absence()
32ff4c
{
3fe72c
	#init
cf05c9
	cfgtest_prolog 'header absence' "${1}"
cf05c9
3fe72c
	cfgtest_code_snippet=$(printf '#include <%s>\n' "${1}")
cf05c9
3fe72c
	cfgtest_common_init
cf05c9
3fe72c
	# execute
3fe72c
	printf '%s' "$cfgtest_src"                  \
3fe72c
		| eval $(printf '%s' "$cfgtest_cmd") \
3fe72c
		> /dev/null 2>&3                      \
3fe72c
	&& printf 'cfgtest: %s header <%s>: no error.' \
3fe72c
		"$mb_cfgtest_cfgtype" "${1}" >&3        \
3fe72c
	&& cfgtest_epilog 'header' "${1}"                \
32ff4c
	&& return
32ff4c
3fe72c
	# result
32ff4c
	mb_internal_str=$(printf '%s%s' '-DHAVE_NO_' "$@" \
c457f5
			| sed -e 's/\./_/g' -e 's@/@_@g'  \
32ff4c
			| tr "[:lower:]" "[:upper:]")
32ff4c
f1eb02
	if [ -z ${cfgtest_internal_unit_test:-} ]; then
3eaf7b
		cfgtest_cflags_append "$mb_internal_str"
3eaf7b
	else
3eaf7b
		cfgtest_makevar_append "$mb_internal_str"
3eaf7b
	fi
cf05c9
cf05c9
	printf 'cfgtest: %s header <%s> may not be included.\n' \
cf05c9
		"$mb_cfgtest_cfgtype" "${1}" >&3
cf05c9
	printf '%s\n' '------------------------' >&3
cf05c9
e6eab3
	cfgtest_epilog 'header' '-----' "${1}"
32ff4c
}
32ff4c
32ff4c
32ff4c
cfgtest_interface_presence()
32ff4c
{
3fe72c
	# init
960949
	cfgtest_prolog 'interface' "${1}"
960949
3fe72c
	cfgtest_code_snippet=$(printf 'void * addr = &%;;\n' "${1}")
960949
3fe72c
	cfgtest_common_init
960949
3fe72c
	# execute
3fe72c
	printf '%s' "$cfgtest_src"                    \
3fe72c
		| eval $(printf '%s' "$cfgtest_cmd")   \
3fe72c
		> /dev/null 2>&3                        \
3fe72c
	|| cfgtest_epilog 'interface' '(error)' "${1}"   \
3fe72c
	|| return
32ff4c
3fe72c
	# result
502550
	mb_internal_str=$(printf '%s%s' '-DHAVE_' "$@"  \
502550
			| sed -e 's/\./_/g'             \
502550
			| tr "[:lower:]" "[:upper:]")
502550
f1eb02
	if [ -z ${cfgtest_internal_unit_test:-} ]; then
3eaf7b
		cfgtest_cflags_append "$mb_internal_str"
3eaf7b
	else
3eaf7b
		cfgtest_makevar_append "$mb_internal_str"
3eaf7b
	fi
502550
960949
	printf 'cfgtest: %s interface `%s'"'"' is available.\n' \
960949
		"$mb_cfgtest_cfgtype" "${1}" >&3
960949
	printf '%s\n' '------------------------' >&3
960949
53fd56
	cfgtest_epilog 'interface' "${1}"
960949
32ff4c
	return 0
32ff4c
}
32ff4c
73a6fd
73a6fd
cfgtest_decl_presence()
73a6fd
{
3fe72c
	# init
53fd56
	cfgtest_prolog 'decl' "${1}"
53fd56
53fd56
	cfgtest_code_snippet=$(printf 'void * any = (void *)(%s);' "${1}")
53fd56
3fe72c
	cfgtest_common_init
53fd56
3fe72c
	# execute
3fe72c
	printf '%s' "$cfgtest_src"                  \
2992d7
		| eval $(printf '%s' "$cfgtest_cmd") \
3fe72c
		> /dev/null 2>&3                      \
3fe72c
	|| cfgtest_epilog 'decl' '(error)' "${1}"      \
3fe72c
	|| return
73a6fd
73a6fd
	# does the argument solely consist of the macro or enum member name?
73a6fd
	mb_internal_str=$(printf '%s' "$@" | tr -d '[a-z][A-Z][0-9][_]')
73a6fd
73a6fd
	if [ -n "$mb_internal_str" ]; then
53fd56
		cfgtest_epilog 'decl' '(defined)'
73a6fd
		return 0
73a6fd
	fi
73a6fd
3fe72c
	# result
73a6fd
	mb_internal_str=$(printf '%s%s' '-DHAVE_DECL_' "$@"  \
73a6fd
			| sed -e 's/\./_/g'                  \
73a6fd
			| tr "[:lower:]" "[:upper:]")
73a6fd
f1eb02
	if [ -z ${cfgtest_internal_unit_test:-} ]; then
3eaf7b
		cfgtest_cflags_append "$mb_internal_str"
3eaf7b
	else
3eaf7b
		cfgtest_makevar_append "$mb_internal_str"
3eaf7b
	fi
73a6fd
53fd56
	printf 'cfgtest: `%s'"'"' is defined for the %s system.\n' \
53fd56
		"${1}" "$mb_cfgtest_cfgtype" >&3
53fd56
	printf '%s\n' '------------------------' >&3
53fd56
53fd56
	cfgtest_epilog 'decl' '(defined)'
53fd56
73a6fd
	return 0
73a6fd
}
73a6fd
73a6fd
e0398c
cfgtest_type_size()
e0398c
{
1d55c8
	cfgtest_entity_size_prolog "$@"
1d55c8
e0398c
	mb_internal_size=''
e0398c
	mb_internal_test='char x[(sizeof(%s) == %s) ? 1 : -1];'
e0398c
e0398c
	for mb_internal_guess in 8 4 2 1 16 32 64 128; do
e0398c
		if [ -z $mb_internal_size ]; then
3fe72c
			printf '# guess %s ===>\n' "$mb_internal_guess" >&3
3fe72c
e0398c
			mb_internal_type="$@"
e0398c
3fe72c
			cfgtest_code_snippet=$(printf "$mb_internal_test" \
3fe72c
				"$mb_internal_type" "$mb_internal_guess")
e0398c
3fe72c
			cfgtest_common_init
3fe72c
3fe72c
			printf '%s' "$cfgtest_src"                  \
3fe72c
				| eval $(printf '%s' "$cfgtest_cmd") \
3fe72c
				> /dev/null 2>&3                      \
e0398c
			&& mb_internal_size=$mb_internal_guess
3fe72c
3fe72c
			printf '\n' >&3
e0398c
		fi
e0398c
	done
e0398c
e0398c
	# unrecognized type, or type size not within range
e0398c
	if [ -z $mb_internal_size ]; then
3fe72c
		cfgtest_epilog 'size-of-type' '(error)' "@"
e0398c
		return 1
e0398c
	fi
e0398c
e0398c
	# -DSIZEOF_TYPE=SIZE
e0398c
	mb_internal_str=$(printf '%s%s=%s' '-DSIZEOF_'        \
e0398c
				"$mb_internal_type"           \
e0398c
				"$mb_internal_size"           \
e0398c
			| sed -e 's/\ /_/g' -e 's/*/P/g'      \
e0398c
			| tr "[:lower:]" "[:upper:]")
e0398c
e0398c
	if [ -z ${cfgtest_internal_unit_test:-} ]; then
e0398c
		cfgtest_cflags_append "$mb_internal_str"
e0398c
	else
e0398c
		cfgtest_makevar_append "$mb_internal_str"
e0398c
	fi
e0398c
1d55c8
	printf 'cfgtest: size of type `%s'"'"' determined to be %s\n' \
1d55c8
		"${@}" "$mb_internal_size" >&3
1d55c8
	printf '%s\n' '------------------------' >&3
1d55c8
1d55c8
	cfgtest_epilog 'size-of-type' "$mb_internal_size"
1d55c8
e0398c
	return 0
e0398c
}
e0398c
e0398c
3fe72c
cfgtest_code_snippet_asm()
f66c30
{
3fe72c
	# init
3fe72c
	cfgtest_prolog 'support of code snippet' '<...>'
f66c30
3fe72c
	cfgtest_code_snippet="$@"
f66c30
3fe72c
	cfgtest_common_init 'asm'
f66c30
3fe72c
	# execute
98b935
	cfgtest_ret=1
98b935
3fe72c
	printf '%s' "$cfgtest_src"                  \
3fe72c
		| eval $(printf '%s' "$cfgtest_cmd") \
3fe72c
		> /dev/null 2>&3                      \
3fe72c
	|| cfgtest_epilog 'snippet' '(error)'          \
3fe72c
	|| return
3fe72c
3fe72c
	# result
3fe72c
	cfgtest_ret=0
98b935
3fe72c
	printf 'cfgtest: %s compiler: above code snippet compiled successfully.\n\n' \
3fe72c
		"$mb_cfgtest_cfgtype" >&3
98b935
3fe72c
	cfgtest_epilog 'snippet' '(ok)'
98b935
3fe72c
	return 0
98b935
}
98b935
98b935
46ddc8
cfgtest_macro_definition()
46ddc8
{
46ddc8
	# init
46ddc8
	cfgtest_prolog 'macro definition' "${1}"
46ddc8
46ddc8
	cfgtest_code_snippet=$(printf '%s\n'      \
46ddc8
		"#ifndef ${1}"                     \
46ddc8
		"#error macro ${1} is not defined." \
46ddc8
		"#endif")
46ddc8
46ddc8
	cfgtest_common_init 'macro'
46ddc8
46ddc8
	# execute
46ddc8
	cfgtest_ret=1
46ddc8
46ddc8
	printf '%s' "$cfgtest_src"                  \
46ddc8
		| eval $(printf '%s' "$cfgtest_cmd") \
46ddc8
		> /dev/null 2>&3                      \
46ddc8
	|| cfgtest_epilog 'macro' '(error)' "${1}"     \
46ddc8
	|| return
46ddc8
46ddc8
	# result
46ddc8
	cfgtest_ret=0
46ddc8
46ddc8
	printf 'cfgtest: %s compiler: above macro definition test compiled successfully.\n\n' \
46ddc8
		"$mb_cfgtest_cfgtype" >&3
46ddc8
46ddc8
	cfgtest_epilog 'macro' '(defined)'
46ddc8
46ddc8
	return 0
46ddc8
}
46ddc8
46ddc8
32ff4c
cfgtest_library_presence()
32ff4c
{
3fe72c
	# init
79612e
	cfgtest_libs=
79612e
	cfgtest_spc=
79612e
79612e
	for cfgtest_lib in ${@}; do
79612e
		cfgtest_libs="$cfgtest_libs$cfgtest_spc$cfgtest_lib"
79612e
		cfgtest_spc=' '
79612e
	done
79612e
79612e
	if [ "${1}" = "$cfgtest_libs" ]; then
79612e
		cfgtest_prolog 'library' "${1#*-l}"
79612e
	else
79612e
		cfgtest_prolog 'lib module' '(see config.log)'
79612e
	fi
79612e
a6934a
	if [ "$mb_cfgtest_environment" = 'freestanding' ]; then
a6934a
		if [ -z "ccenv_cc_underscore" ]; then
a6934a
			cfgtest_code_snippet='int start(void){return 0;}'
a6934a
		else
a6934a
			cfgtest_code_snippet='int _start(void){return 0;}'
a6934a
		fi
a6934a
	else
a6934a
		cfgtest_code_snippet='int main(void){return 0;}'
a6934a
	fi
79612e
3fe72c
	cfgtest_common_init 'lib'
79612e
3fe72c
	# execute
3fe72c
	printf '%s' "$cfgtest_src"                  \
2992d7
		| eval $(printf '%s' "$cfgtest_cmd") \
3fe72c
		> /dev/null 2>&3                      \
3fe72c
	|| cfgtest_epilog 'library' '-----' "$@"       \
32ff4c
	|| return 1
32ff4c
3fe72c
	# result
79612e
	printf 'cfgtest: `%s'"'"' was accepted by the linker driver.\n' \
79612e
		"$cfgtest_libs" >&3
79612e
	printf '%s\n' '------------------------' >&3
79612e
79612e
	cfgtest_epilog 'library' '(present)'
79612e
32ff4c
	return 0
32ff4c
}
3eaf7b
3eaf7b
be1531
cfgtest_compiler_switch()
be1531
{
be1531
	# init
be1531
	cfgtest_switches=
be1531
	cfgtest_spc=
be1531
f76b35
	for cfgtest_switch in $(printf '%s' "${@}"); do
be1531
		cfgtest_switches="$cfgtest_switches$cfgtest_spc$cfgtest_switch"
be1531
		cfgtest_spc=' '
be1531
	done
be1531
be1531
	if [ "${1}" = "$cfgtest_switches" ]; then
be1531
		cfgtest_prolog 'compiler switch' "$cfgtest_switches"
be1531
	else
be1531
		cfgtest_prolog 'compiler switch combination' "$cfgtest_switches"
be1531
	fi
be1531
fd723f
	case "${1}" in
fd723f
		-Wl,*)
a50c64
			if [ "$mb_cfgtest_environment" = 'freestanding' ]; then
a50c64
				cfgtest_switches="$cfgtest_switches -nostdlib -nostartfiles"
a50c64
a50c64
				if [ -z "ccenv_cc_underscore" ]; then
a50c64
					cfgtest_code_snippet='int start(void){return 0;}'
a50c64
				else
a50c64
					cfgtest_code_snippet='int _start(void){return 0;}'
a50c64
				fi
a50c64
			else
a50c64
				cfgtest_code_snippet='int main(void){return 0;}'
a50c64
			fi
a50c64
fd723f
			cfgtest_common_init 'ldflag'
fd723f
			;;
fd723f
fd723f
		*)
fd723f
			cfgtest_code_snippet=
fd723f
			cfgtest_common_init 'switch'
fd723f
			;;
fd723f
	esac
be1531
be1531
	# execute
be1531
	printf '%s' "$cfgtest_src"                  \
be1531
		| eval $(printf '%s' "$cfgtest_cmd") \
be1531
		> /dev/null 2>&3                      \
be1531
	|| cfgtest_epilog 'switch' '(error)' "$@"      \
be1531
	|| return 1
be1531
be1531
	# result
be1531
	printf 'cfgtest: the switch `%s was accepted by the compier.\n' \
be1531
		"$cfgtest_switches'" >&3
be1531
	printf '%s\n' '------------------------' >&3
be1531
be1531
	cfgtest_epilog 'switch' '(accepted)'
be1531
be1531
	return 0
be1531
}
be1531
be1531
3eaf7b
cfgtest_unit_header_presence()
3eaf7b
{
3eaf7b
	cfgtest_internal_unit_test='unit_test'
3eaf7b
	cfgtest_header_presence "$@" || return 1
3eaf7b
	return 0
3eaf7b
}
3eaf7b
3eaf7b
3eaf7b
cfgtest_unit_header_absence()
3eaf7b
{
3eaf7b
	cfgtest_internal_unit_test='unit_test'
3eaf7b
	cfgtest_header_absence "$@" || return 1
3eaf7b
	return 0
3eaf7b
}
3eaf7b
3eaf7b
3eaf7b
cfgtest_unit_interface_presence()
3eaf7b
{
3eaf7b
	cfgtest_internal_unit_test='unit_test'
3eaf7b
	cfgtest_interface_presence "$@" || return 1
3eaf7b
	return 0
3eaf7b
}
3eaf7b
3eaf7b
3eaf7b
cfgtest_unit_decl_presence()
3eaf7b
{
3eaf7b
	cfgtest_internal_unit_test='unit_test'
3eaf7b
	cfgtest_decl_presence "$@" || return 1
3eaf7b
	return 0
3eaf7b
}
e0398c
e0398c
e0398c
cfgtest_unit_type_size()
e0398c
{
e0398c
	cfgtest_internal_unit_test='unit_test'
e0398c
	cfgtest_type_size "$@" || return 1
e0398c
	return 0
e0398c
}