Blame


1 ab1569ee 2023-05-06 op #!/bin/sh
2 ab1569ee 2023-05-06 op #
3 ab1569ee 2023-05-06 op # Copyright (c) 2014, 2015, 2016 Ingo Schwarze <schwarze@openbsd.org>
4 ab1569ee 2023-05-06 op # Copyright (c) 2017, 2018 Kristaps Dzonsons <kristaps@bsd.lv>
5 ab1569ee 2023-05-06 op # Copyright (c) 2022, 2023 Omar Polo <op@openbsd.org>
6 ab1569ee 2023-05-06 op #
7 ab1569ee 2023-05-06 op # Permission to use, copy, modify, and distribute this software for any
8 ab1569ee 2023-05-06 op # purpose with or without fee is hereby granted, provided that the above
9 ab1569ee 2023-05-06 op # copyright notice and this permission notice appear in all copies.
10 ab1569ee 2023-05-06 op #
11 ab1569ee 2023-05-06 op # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 ab1569ee 2023-05-06 op # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 ab1569ee 2023-05-06 op # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 ab1569ee 2023-05-06 op # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 ab1569ee 2023-05-06 op # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 ab1569ee 2023-05-06 op # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 ab1569ee 2023-05-06 op # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 ab1569ee 2023-05-06 op
19 ab1569ee 2023-05-06 op CDIAGFLAGS="-Wall -Wuninitialized -Wunused -Wmissing-prototypes"
20 ab1569ee 2023-05-06 op CDIAGFLAGS="${CDIAGFLAGS} -Wstrict-prototypes -Wno-pointer-sign"
21 ab1569ee 2023-05-06 op
22 ab1569ee 2023-05-06 op # don't ship releases with -Werror
23 ab1569ee 2023-05-06 op test "$RELEASE" = no && CDIAGFLAGS="${CDIAGFLAGS} -Werror"
24 ab1569ee 2023-05-06 op
25 ab1569ee 2023-05-06 op COMPATS=
26 ab1569ee 2023-05-06 op
27 ab1569ee 2023-05-06 op push_cflags() {
28 ab1569ee 2023-05-06 op if ! echo "$CFLAGS" | grep -q -e "$1"; then
29 ab1569ee 2023-05-06 op CFLAGS="${CFLAGS+$CFLAGS } $1"
30 ab1569ee 2023-05-06 op fi
31 ab1569ee 2023-05-06 op }
32 ab1569ee 2023-05-06 op
33 ab1569ee 2023-05-06 op push_ldflags() {
34 ab1569ee 2023-05-06 op if ! echo "$LDFLAGS" | grep -q -e "$1"; then
35 ab1569ee 2023-05-06 op LDFLAGS="${LDFLAGS+$LDFLAGS } $1"
36 ab1569ee 2023-05-06 op fi
37 ab1569ee 2023-05-06 op }
38 ab1569ee 2023-05-06 op
39 ab1569ee 2023-05-06 op # singletest name var extra-cflags extra-libs msg
40 ab1569ee 2023-05-06 op singletest() {
41 ab1569ee 2023-05-06 op msg="$5"
42 ab1569ee 2023-05-06 op if [ -z "$msg" ]; then
43 ab1569ee 2023-05-06 op if [ -n "$3" ]; then
44 ab1569ee 2023-05-06 op msg=" ($3)"
45 ab1569ee 2023-05-06 op elif [ -n "$4" ]; then
46 ab1569ee 2023-05-06 op msg=" ($4)"
47 ab1569ee 2023-05-06 op fi
48 ab1569ee 2023-05-06 op elif [ "$msg" = no ]; then
49 ab1569ee 2023-05-06 op msg=""
50 ab1569ee 2023-05-06 op fi
51 ab1569ee 2023-05-06 op
52 ab1569ee 2023-05-06 op cat >&3 <<EOF
53 ab1569ee 2023-05-06 op $1: testing...
54 ab1569ee 2023-05-06 op $CC tests/$1.c $CFLAGS -Werror $3 -o test-$1 $LDFLAGS $4
55 ab1569ee 2023-05-06 op EOF
56 ab1569ee 2023-05-06 op if $CC tests/$1.c $CFLAGS -Werror $3 -o test-$1 $LDFLAGS $4 >&3 2>&3;
57 ab1569ee 2023-05-06 op then
58 ab1569ee 2023-05-06 op rm -f test-$1 test-$1.d
59 ab1569ee 2023-05-06 op
60 ab1569ee 2023-05-06 op echo "$1: $CC$msg succeeded" >&3
61 ab1569ee 2023-05-06 op echo "$1$msg: yes"
62 ab1569ee 2023-05-06 op echo >&3
63 ab1569ee 2023-05-06 op
64 ab1569ee 2023-05-06 op return 0
65 ab1569ee 2023-05-06 op fi
66 ab1569ee 2023-05-06 op
67 ab1569ee 2023-05-06 op echo "$1: $CC$msg failed with $?" >&3
68 ab1569ee 2023-05-06 op echo "$1$msg: no"
69 ab1569ee 2023-05-06 op echo >&3
70 ab1569ee 2023-05-06 op
71 ab1569ee 2023-05-06 op rm -f test-$1 test-$1.d
72 ab1569ee 2023-05-06 op
73 ab1569ee 2023-05-06 op return 1
74 ab1569ee 2023-05-06 op }
75 ab1569ee 2023-05-06 op
76 ab1569ee 2023-05-06 op # runtest name var extra-cflags extra-libs pkgconfig-name
77 ab1569ee 2023-05-06 op runtest() {
78 ab1569ee 2023-05-06 op if singletest "$1" "$2" "" ""; then
79 ab1569ee 2023-05-06 op eval HAVE_$2=1
80 ab1569ee 2023-05-06 op return 0
81 ab1569ee 2023-05-06 op fi
82 ab1569ee 2023-05-06 op
83 ab1569ee 2023-05-06 op if [ -n "$3" -o -n "$4" ]; then
84 ab1569ee 2023-05-06 op echo "retrying with ${3+$3 }$4" >&3
85 ab1569ee 2023-05-06 op if singletest "$1" "$2" "$3" "$4"; then
86 ab1569ee 2023-05-06 op if [ -n "$3" ]; then
87 ab1569ee 2023-05-06 op push_cflags "$3"
88 ab1569ee 2023-05-06 op fi
89 ab1569ee 2023-05-06 op if [ -n "$4" ]; then
90 ab1569ee 2023-05-06 op push_ldflags "$4"
91 ab1569ee 2023-05-06 op fi
92 ab1569ee 2023-05-06 op eval HAVE_$2=1
93 ab1569ee 2023-05-06 op return 0
94 ab1569ee 2023-05-06 op fi
95 ab1569ee 2023-05-06 op fi
96 ab1569ee 2023-05-06 op
97 ab1569ee 2023-05-06 op if [ -n "$5" -a -n "$pkgconfig" ]; then
98 ab1569ee 2023-05-06 op if $pkgconfig "$5"; then
99 ab1569ee 2023-05-06 op cflags="$($pkgconfig --cflags "$5")"
100 ab1569ee 2023-05-06 op ldflags="$($pkgconfig --libs "$5")"
101 ab1569ee 2023-05-06 op echo "retrying with $pkgconfig" >&3
102 ab1569ee 2023-05-06 op if singletest "$1" "$2" "$cflags" "$ldflags"; then
103 ab1569ee 2023-05-06 op push_cflags "$cflags"
104 ab1569ee 2023-05-06 op push_ldflags "$ldflags"
105 ab1569ee 2023-05-06 op eval HAVE_$2=1
106 ab1569ee 2023-05-06 op return 0
107 ab1569ee 2023-05-06 op fi
108 ab1569ee 2023-05-06 op fi
109 ab1569ee 2023-05-06 op fi
110 ab1569ee 2023-05-06 op
111 ab1569ee 2023-05-06 op if [ -f compat/$1.c ]; then
112 ab1569ee 2023-05-06 op COMPATS="${COMPATS+$COMPATS }compat/$1.c"
113 ab1569ee 2023-05-06 op fi
114 ab1569ee 2023-05-06 op
115 ab1569ee 2023-05-06 op eval HAVE_$2=0
116 ab1569ee 2023-05-06 op return 1
117 ab1569ee 2023-05-06 op }
118 ab1569ee 2023-05-06 op
119 ab1569ee 2023-05-06 op if singletest MMD _MMD -MMD >/dev/null; then
120 ab1569ee 2023-05-06 op push_cflags -MMD
121 ab1569ee 2023-05-06 op echo "adding -MMD to CFLAGS" >&2
122 ab1569ee 2023-05-06 op echo "adding -MMD to CFLAGS" >&3
123 ab1569ee 2023-05-06 op fi
124 ab1569ee 2023-05-06 op
125 ab1569ee 2023-05-06 op if ! singletest WAIT_ANY WAIT_ANY; then
126 ab1569ee 2023-05-06 op push_cflags -DWAIT_ANY=-1
127 ab1569ee 2023-05-06 op fi
128 ab1569ee 2023-05-06 op
129 ab1569ee 2023-05-06 op runtest __progname __PROGNAME || true
130 ab1569ee 2023-05-06 op runtest err ERR || true
131 ab1569ee 2023-05-06 op runtest freezero FREEZERO || true
132 ab1569ee 2023-05-06 op runtest getdtablecount GETDTABLECOUNT || true
133 ab1569ee 2023-05-06 op runtest getdtablesize GETDTABLESIZE || true
134 ab1569ee 2023-05-06 op runtest getexecname GETEXECNAME || true
135 ab1569ee 2023-05-06 op runtest getprogname GETPROGNAME || true
136 ab1569ee 2023-05-06 op runtest libevent LIBEVENT "" -levent libevent_core || true
137 ab1569ee 2023-05-06 op runtest pledge PLEDGE || true
138 ab1569ee 2023-05-06 op runtest recallocarray RECALLOCARRAY -D_OPENBSD_SOURCE || true
139 ab1569ee 2023-05-06 op runtest setgroups SETGROUPS -D_BSD_SOURCE || true
140 ab1569ee 2023-05-06 op runtest setproctitle SETPROCTITLE || true
141 ab1569ee 2023-05-06 op runtest setresgid SETRESGID -D_GNU_SOURCE || true
142 ab1569ee 2023-05-06 op runtest setresuid SETRESUID -D_GNU_SOURCE || true
143 ab1569ee 2023-05-06 op runtest sqlite3 SQLITE3 "" -lsqlite3 sqlite3 || true
144 ab1569ee 2023-05-06 op runtest strlcat STRLCAT || true
145 ab1569ee 2023-05-06 op runtest strlcpy STRLCPY || true
146 ab1569ee 2023-05-06 op runtest strtonum STRTONUM || true
147 ab1569ee 2023-05-06 op runtest sys_queue SYS_QUEUE || true
148 ab1569ee 2023-05-06 op runtest sys_tree SYS_TREE || true
149 ab1569ee 2023-05-06 op runtest unveil UNVEIL || true
150 ab1569ee 2023-05-06 op runtest vasprintf VASPRINTF -D_GNU_SOURCE || true
151 ab1569ee 2023-05-06 op
152 ab1569ee 2023-05-06 op if [ "$HAVE_SYS_QUEUE" -eq 0 -o "$HAVE_SYS_TREE" -eq 0 ]; then
153 ab1569ee 2023-05-06 op CFLAGS="-I compat/sys $CFLAGS"
154 ab1569ee 2023-05-06 op fi
155 ab1569ee 2023-05-06 op
156 ab1569ee 2023-05-06 op if [ -n "$COMPATS" ]; then
157 ab1569ee 2023-05-06 op CFLAGS="-I compat $CFLAGS"
158 ab1569ee 2023-05-06 op fi
159 ab1569ee 2023-05-06 op
160 ab1569ee 2023-05-06 op CFLAGS="$CFLAGS $CDIAGFLAGS"
161 ab1569ee 2023-05-06 op
162 ab1569ee 2023-05-06 op exec > config.h
163 ab1569ee 2023-05-06 op echo "config.h writing..." >&2
164 ab1569ee 2023-05-06 op
165 ab1569ee 2023-05-06 op cat <<EOF
166 ab1569ee 2023-05-06 op #ifndef CONFIG_H
167 ab1569ee 2023-05-06 op #define CONFIG_H
168 ab1569ee 2023-05-06 op
169 ab1569ee 2023-05-06 op #ifdef __cplusplus
170 ab1569ee 2023-05-06 op # error "Do not use C++: this is a C application."
171 ab1569ee 2023-05-06 op #endif
172 ab1569ee 2023-05-06 op
173 ab1569ee 2023-05-06 op #define HAVE___PROGNAME ${HAVE___PROGNAME}
174 ab1569ee 2023-05-06 op #define HAVE_ERR ${HAVE_ERR}
175 ab1569ee 2023-05-06 op #define HAVE_FREEZERO ${HAVE_FREEZERO}
176 ab1569ee 2023-05-06 op #define HAVE_GETDTABLECOUNT ${HAVE_GETDTABLECOUNT}
177 ab1569ee 2023-05-06 op #define HAVE_GETDTABLESIZE ${HAVE_GETDTABLESIZE}
178 ab1569ee 2023-05-06 op #define HAVE_GETEXECNAME ${HAVE_GETEXECNAME}
179 ab1569ee 2023-05-06 op #define HAVE_GETPROGNAME ${HAVE_GETPROGNAME}
180 ab1569ee 2023-05-06 op #define HAVE_SQLITE3 ${HAVE_SQLITE3}
181 ab1569ee 2023-05-06 op #define HAVE_PLEDGE ${HAVE_PLEDGE}
182 ab1569ee 2023-05-06 op #define HAVE_RECALLOCARRAY ${HAVE_RECALLOCARRAY}
183 ab1569ee 2023-05-06 op #define HAVE_SETGROUPS ${HAVE_SETGROUPS}
184 ab1569ee 2023-05-06 op #define HAVE_SETPROCTITLE ${HAVE_SETPROCTITLE}
185 ab1569ee 2023-05-06 op #define HAVE_SETRESGID ${HAVE_SETRESGID}
186 ab1569ee 2023-05-06 op #define HAVE_SETRESUID ${HAVE_SETRESUID}
187 ab1569ee 2023-05-06 op #define HAVE_STRLCAT ${HAVE_STRLCAT}
188 ab1569ee 2023-05-06 op #define HAVE_STRLCPY ${HAVE_STRLCPY}
189 ab1569ee 2023-05-06 op #define HAVE_STRTONUM ${HAVE_STRTONUM}
190 ab1569ee 2023-05-06 op #define HAVE_SYS_QUEUE ${HAVE_SYS_QUEUE}
191 ab1569ee 2023-05-06 op #define HAVE_SYS_TREE ${HAVE_SYS_TREE}
192 ab1569ee 2023-05-06 op #define HAVE_UNVEIL ${HAVE_UNVEIL}
193 ab1569ee 2023-05-06 op #define HAVE_VASPRINTF ${HAVE_VASPRINTF}
194 ab1569ee 2023-05-06 op
195 ab1569ee 2023-05-06 op #endif
196 ab1569ee 2023-05-06 op EOF
197 ab1569ee 2023-05-06 op
198 ab1569ee 2023-05-06 op exec > config.mk
199 ab1569ee 2023-05-06 op echo "config.mk: writing..." >&2
200 ab1569ee 2023-05-06 op
201 ab1569ee 2023-05-06 op cat <<EOF
202 ab1569ee 2023-05-06 op include ../config.mk
203 ab1569ee 2023-05-06 op
204 ab1569ee 2023-05-06 op CC = ${CC}
205 ab1569ee 2023-05-06 op CFLAGS = ${CFLAGS}
206 ab1569ee 2023-05-06 op LDFLAGS = ${LDFLAGS}
207 ab1569ee 2023-05-06 op
208 ab1569ee 2023-05-06 op COMPATS = ${COMPATS}
209 ab1569ee 2023-05-06 op EOF