docs(perf): Updated
[para.git] / scripts / checkmakes
bloba1d983d527654999f71317ff582234a0f9add277
1 #!/bin/sh
4 # Check different makes
6 # Copyright 2023 and 2024 Odin Kroeger.
8 # This file is part of Para.
10 # Para is free software: you can redistribute it and/or modify it
11 # under the terms of the GNU Affero General Public License as published
12 # by the Free Software Foundation, either version 3 of the License,
13 # or (at your option) any later version.
15 # Para is distributed in the hope that it will be useful, but WITHOUT
16 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
17 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General
18 # Public License for more details.
20 # You should have received a copy of the GNU Affero General Public
21 # License along with Para. If not, see <https://www.gnu.org/licenses/>.
24 # shellcheck disable=2015,2031
28 # Defaults
31 # Makes to test
32 makes='make bmake bsdmake gmake makepp remake'
34 # Be quiet?
35 quiet=
37 # Be verbose?
38 verbose=
42 # Init
45 set -Cefu
46 scriptsdir="$(cd "$(dirname -- "$0")" && pwd)"
47 : "${scriptsdir:?}"
48 readonly scriptsdir
49 srcdir="$(cd "$scriptsdir/.." && pwd)"
50 : "${srcdir:?}"
51 readonly srcdir
52 # shellcheck disable=1091
53 . "$srcdir/libutil.sh" || exit
54 init || exit
55 mktmpdir -d"$srcdir" || exit
59 # Constants
62 # Current working directory
63 wd="$(pwd)" || exit
64 : "${wd:?}"
65 readonly wd
69 # Options
72 OPTARG='' OPTIND=1 opt=''
73 # shellcheck disable=2034
74 while getopts 'dc:hqv' opt
76 # shellcheck disable=2154
77 case $opt in
78 (h) exec cat <<EOF
79 $progname - test different makes
81 Usage: $progname [-c cc] [-d] [-q] [-v] [make ...]
82 $progname -h
84 Options:
85 -c cc Use cc as C compiler.
86 -d Enable debugging mode.
87 -q Be quieter.
88 -v Show, rather than log, test output.
89 -h Show this help screen.
90 EOF
92 (d) set -x ;;
93 (c) CC="$OPTARG" ;;
94 (q) quiet=y ;;
95 (v) verbose=y ;;
96 (*) exit 2
97 esac
98 done
99 shift $((OPTIND - 1))
100 unset opt
102 # shellcheck disable=2086
103 [ $# -eq 0 ] && set -- $makes
105 # Use a fast compiler, if one is available
106 if ! [ "${CC-}" ]
107 then
108 for cc in tcc clang c99 cc
110 if command -v "$cc" >/dev/null
111 then
112 CC="$cc"
113 break
115 done
117 [ "${CC-}" ] && export CC
121 # Source tree
124 warn -q 'Copying source tree...'
125 cd "$srcdir" || exit
126 logged -d"$wd" make -e distar="$TMPDIR/dist.tgz" dist=dist "$TMPDIR/dist.tgz"
127 cd "$TMPDIR" || exit
128 tar xzf dist.tgz
129 cd dist || exit
130 warn -q 'Configuring build...'
131 logged -d"$wd" ./configure
135 # Main
138 nmakes=0 failures=
139 for make
141 absfname="$(command -v "$make" 2>/dev/null)" || continue
143 while [ "$i" -lt "$nmakes" ]
145 eval seenmake="\"\${make_$i-}\""
146 # shellcheck disable=2154
147 if cmp "$absfname" "$seenmake" >/dev/null 2>&1
148 then
149 warn '%s has already been checked as %s' \
150 "$make" "${seenmake##*/}"
151 continue 2
153 i="$((i + 1))"
154 done
155 eval "make_$nmakes"='$absfname'
156 nmakes="$((nmakes + 1))"
158 warn 'Checking %s...' "$make"
159 logged -d"$wd" "$make" -e mrproper &&
160 logged -d"$wd" "$make" -e all ||
161 failures="$failures$make, "
162 done
164 if [ "$failures" ]
165 then err 'Failures: %s' "${failures%, }"
166 else warn -qc32 'All makes passed'