1#!/bin/sh
2
3# Check -V option.
4. "${srcdir=.}/init.sh"
5
6run_prog_skip_if_failed date +%Y > /dev/null
7year="$(date +%Y)"
8
9run_strace -V > "$LOG"
10
11getstr()
12{
13	sed -r -n 's/#define[[:space:]]*'"$1"'[[:space:]]*"([^"]*)".*/\1/p' \
14		../../config.h
15}
16
17# getoption OPTION YES_STRING [NO_STRING]
18#
19# Returns YES_STRING in case OPTION is enabled (present in config.h and has
20# a non-zero numeric value). Otherwise, NO_STRING (or empty string, if not
21# specified) is returned.
22getoption()
23{
24	local opt
25	opt=$(sed -r -n 's/#define[[:space:]]*'"$1"'[[:space:]]*([0-9]+)$/\1/p' \
26		../../config.h)
27	if [ -n "$opt" -a "$opt" -ne 0 ]; then
28		printf "%s" "$2"
29	else
30		printf "%s" "${3-}"
31	fi
32}
33
34config_year=$(getstr COPYRIGHT_YEAR)
35
36[ "$year" -ge "$config_year" ] && [ "$config_year" -ge 2017 ] || {
37	echo >&2 "The year derived from config.h (${config_year}) does not pass sanity checks."
38	exit 1
39}
40
41option_unwind=$(getoption USE_LIBUNWIND " stack-unwind")
42option_demangle=$(getoption USE_DEMANGLE " stack-demangle")
43
44option_m32=
45option_mx32=
46case "$STRACE_NATIVE_ARCH" in
47x86_64)
48	option_m32=$(getoption HAVE_M32_MPERS ' m32-mpers' ' no-m32-mpers')
49	option_mx32=$(getoption HAVE_MX32_MPERS ' mx32-mpers' ' no-mx32-mpers')
50	;;
51aarch64|powerpc64|riscv|s390x|sparc64|tile|x32)
52	option_m32=$(getoption HAVE_M32_MPERS ' m32-mpers' ' no-m32-mpers')
53	;;
54esac
55
56features="${option_unwind}${option_demangle}${option_m32}${option_mx32}"
57[ -n "$features" ] || features=" (none)"
58
59cat > "$EXP" << __EOF__
60$(getstr PACKAGE_NAME) -- version $(getstr PACKAGE_VERSION)
61Copyright (c) 1991-${config_year} The strace developers <$(getstr PACKAGE_URL)>.
62This is free software; see the source for copying conditions.  There is NO
63warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
64
65Optional features enabled:${features}
66__EOF__
67
68match_diff "$LOG" "$EXP"
69