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>
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.
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.
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"
22 ab1569ee 2023-05-06 op # don't ship releases with -Werror
23 ab1569ee 2023-05-06 op test "$RELEASE" = no && CDIAGFLAGS="${CDIAGFLAGS} -Werror"
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"
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"
39 ab1569ee 2023-05-06 op # singletest name var extra-cflags extra-libs msg
40 ab1569ee 2023-05-06 op singletest() {
42 ab1569ee 2023-05-06 op if [ -z "$msg" ]; then
43 ab1569ee 2023-05-06 op if [ -n "$3" ]; then
45 ab1569ee 2023-05-06 op elif [ -n "$4" ]; then
48 ab1569ee 2023-05-06 op elif [ "$msg" = no ]; then
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
56 ab1569ee 2023-05-06 op if $CC tests/$1.c $CFLAGS -Werror $3 -o test-$1 $LDFLAGS $4 >&3 2>&3;
58 ab1569ee 2023-05-06 op rm -f test-$1 test-$1.d
60 ab1569ee 2023-05-06 op echo "$1: $CC$msg succeeded" >&3
61 ab1569ee 2023-05-06 op echo "$1$msg: yes"
67 ab1569ee 2023-05-06 op echo "$1: $CC$msg failed with $?" >&3
68 ab1569ee 2023-05-06 op echo "$1$msg: no"
71 ab1569ee 2023-05-06 op rm -f test-$1 test-$1.d
76 ab1569ee 2023-05-06 op # runtest name var extra-cflags extra-libs pkgconfig-name
78 ab1569ee 2023-05-06 op if singletest "$1" "$2" "" ""; then
79 ab1569ee 2023-05-06 op eval HAVE_$2=1
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"
89 ab1569ee 2023-05-06 op if [ -n "$4" ]; then
90 ab1569ee 2023-05-06 op push_ldflags "$4"
92 ab1569ee 2023-05-06 op eval HAVE_$2=1
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
111 ab1569ee 2023-05-06 op if [ -f compat/$1.c ]; then
112 ab1569ee 2023-05-06 op COMPATS="${COMPATS+$COMPATS }compat/$1.c"
115 ab1569ee 2023-05-06 op eval HAVE_$2=0
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
125 ab1569ee 2023-05-06 op if ! singletest WAIT_ANY WAIT_ANY; then
126 ab1569ee 2023-05-06 op push_cflags -DWAIT_ANY=-1
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
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"
156 ab1569ee 2023-05-06 op if [ -n "$COMPATS" ]; then
157 ab1569ee 2023-05-06 op CFLAGS="-I compat $CFLAGS"
160 ab1569ee 2023-05-06 op CFLAGS="$CFLAGS $CDIAGFLAGS"
162 ab1569ee 2023-05-06 op exec > config.h
163 ab1569ee 2023-05-06 op echo "config.h writing..." >&2
166 ab1569ee 2023-05-06 op #ifndef CONFIG_H
167 ab1569ee 2023-05-06 op #define CONFIG_H
169 ab1569ee 2023-05-06 op #ifdef __cplusplus
170 ab1569ee 2023-05-06 op # error "Do not use C++: this is a C application."
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}
198 ab1569ee 2023-05-06 op exec > config.mk
199 ab1569ee 2023-05-06 op echo "config.mk: writing..." >&2
202 ab1569ee 2023-05-06 op include ../config.mk
205 ab1569ee 2023-05-06 op CFLAGS = ${CFLAGS}
206 ab1569ee 2023-05-06 op LDFLAGS = ${LDFLAGS}
208 ab1569ee 2023-05-06 op COMPATS = ${COMPATS}