3 83f0f95a 2022-09-29 op # Copyright (c) 2014, 2015, 2016 Ingo Schwarze <schwarze@openbsd.org>
4 83f0f95a 2022-09-29 op # Copyright (c) 2017, 2018 Kristaps Dzonsons <kristaps@bsd.lv>
5 83f0f95a 2022-09-29 op # Copyright (c) 2022 Omar Polo <op@omarpolo.com>
7 83f0f95a 2022-09-29 op # Permission to use, copy, modify, and distribute this software for any
8 83f0f95a 2022-09-29 op # purpose with or without fee is hereby granted, provided that the above
9 83f0f95a 2022-09-29 op # copyright notice and this permission notice appear in all copies.
11 83f0f95a 2022-09-29 op # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 83f0f95a 2022-09-29 op # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 83f0f95a 2022-09-29 op # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 83f0f95a 2022-09-29 op # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 83f0f95a 2022-09-29 op # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 83f0f95a 2022-09-29 op # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 83f0f95a 2022-09-29 op # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21 83f0f95a 2022-09-29 op RELEASE="${RELEASE:-no}"
25 83f0f95a 2022-09-29 op echo "usage: $0 [--help] [--prefix=prefix] [OPTION=VALUE...]" >&2
29 83f0f95a 2022-09-29 op if command -v yacc 2>/dev/null >&2; then
31 83f0f95a 2022-09-29 op elif command -v bison 2>/dev/null >&2; then
34 83f0f95a 2022-09-29 op # assume yacc by default. Make will fail building parse.y if
35 83f0f95a 2022-09-29 op # not from a release tarball, but at least it'll have a decent
36 83f0f95a 2022-09-29 op # error message.
40 83f0f95a 2022-09-29 op if command -v pkg-config 2>/dev/null >&2; then
41 83f0f95a 2022-09-29 op pkgconfig=pkg-config
49 83f0f95a 2022-09-29 op while [ $# -gt 0 ]; do
50 83f0f95a 2022-09-29 op key="${1%%=*}"
53 83f0f95a 2022-09-29 op if [ "$key" = --help ]; then
57 83f0f95a 2022-09-29 op if [ "$key" = --prefix ]; then
59 83f0f95a 2022-09-29 op if [ "$1" = --prefix ]; then # no =, look at next arg
60 83f0f95a 2022-09-29 op if !shift 2>&1 >/dev/null; then
61 83f0f95a 2022-09-29 op echo "$0: missing value for --prefix" >&2
68 83f0f95a 2022-09-29 op if [ "$1" = "$key" ]; then
69 83f0f95a 2022-09-29 op echo "$0: invalid key-value: $1" >&2
73 83f0f95a 2022-09-29 op case "$key" in
77 83f0f95a 2022-09-29 op CFLAGS="$val" ;;
79 83f0f95a 2022-09-29 op conf="$val" ;;
81 83f0f95a 2022-09-29 op LDADD="$val" ;;
83 83f0f95a 2022-09-29 op LDADD_IMSG="$val" ;;
84 83f0f95a 2022-09-29 op LDADD_LIBEVENT)
85 83f0f95a 2022-09-29 op LDADD_LIBEVENT="$val" ;;
86 83f0f95a 2022-09-29 op LDADD_LIBSOCKET)
87 83f0f95a 2022-09-29 op LDADD_LIBSOCKET="$val" ;;
89 83f0f95a 2022-09-29 op pkgconfig="$val" ;;
91 83f0f95a 2022-09-29 op sock="$sock" ;;
93 83f0f95a 2022-09-29 op user="$val" ;;
95 83f0f95a 2022-09-29 op YACC="$val" ;;
102 83f0f95a 2022-09-29 op CDIAGFLAGS="${CDIAGFLAGS} -Wall -Wextra -Wpointer-arith -Wuninitialized"
103 83f0f95a 2022-09-29 op CDIAGFLAGS="${CDIAGFLAGS} -Wstrict-prototypes -Wmissing-prototypes -Wunused"
104 83f0f95a 2022-09-29 op CDIAGFLAGS="${CDIAGFLAGS} -Wsign-compare -Wshadow -Wno-unused-parameter"
105 83f0f95a 2022-09-29 op CDIAGFLAGS="${CDIAGFLAGS} -Wno-missing-field-initializers"
106 83f0f95a 2022-09-29 op CDIAGFLAGS="${CDIAGFLAGS} -Wno-pointer-sign"
108 83f0f95a 2022-09-29 op # don't ship releases with -Werror
109 83f0f95a 2022-09-29 op test "$RELEASE" = no && CDIAGFLAGS="${CDIAGFLAGS} -Werror"
111 83f0f95a 2022-09-29 op CFLAGS="${CFLAGS:--O2 -pipe} ${CDIAGFLAGS}"
112 83f0f95a 2022-09-29 op CC="${CC:-cc}"
113 83f0f95a 2022-09-29 op LIBS="${LIBS:-}"
114 83f0f95a 2022-09-29 op LDFLAGS="${LDFLAGS:-}"
116 83f0f95a 2022-09-29 op HOSTCC="${HOSTCC:-${CC}}"
117 83f0f95a 2022-09-29 op HOSTCFLAGS="${HOSTCFLAGS:-${CFLAGS}}"
119 83f0f95a 2022-09-29 op echo "running configure for \`template':" >&2
120 83f0f95a 2022-09-29 op (cd ./template && ./configure CC="$HOSTCC" CFLAGS="$HOSTCFLAGS" YACC="$YACC")
121 83f0f95a 2022-09-29 op echo "returning to the configure for \`galileo':" >&2
123 83f0f95a 2022-09-29 op CFLAGS="${CFLAGS} -I. -Itemplate"
124 c353c651 2022-09-30 op test -n "$conf" && CFLAGS="${CFLAGS} -DGALILEO_CONF=\"\\\"$conf\\\"\""
125 c353c651 2022-09-30 op test -n "$user" && CFLAGS="${CFLAGS} -DGALILEO_USER=\"\\\"$user\\\"\""
126 c353c651 2022-09-30 op test -n "$sock" && CFLAGS="${CFLAGS} -DGALILEO_SOCK=\"\\\"$conf\\\"\""
128 83f0f95a 2022-09-29 op [ -w config.log ] && mv config.log config.log.old
130 83f0f95a 2022-09-29 op exec 3> config.log
131 83f0f95a 2022-09-29 op echo "config.log: writing..."
135 83f0f95a 2022-09-29 op HAVE_ACCEPT4=
136 83f0f95a 2022-09-29 op HAVE_ASR_RUN=
137 83f0f95a 2022-09-29 op HAVE_BUFFEREVENT_READ_PRESSURE_CB=
139 83f0f95a 2022-09-29 op HAVE_EVENT_ASR_RUN=
140 83f0f95a 2022-09-29 op HAVE_FREEZERO=
141 83f0f95a 2022-09-29 op HAVE_GETDTABLECOUNT=
142 83f0f95a 2022-09-29 op HAVE_GETDTABLESIZE=
143 83f0f95a 2022-09-29 op HAVE_GETEXECNAME=
144 83f0f95a 2022-09-29 op HAVE_GETPROGNAME=
146 83f0f95a 2022-09-29 op HAVE_LIBEVENT=
147 83f0f95a 2022-09-29 op HAVE_LIBEVENT2=
149 83f0f95a 2022-09-29 op HAVE_REALLOCARRAY=
150 83f0f95a 2022-09-29 op HAVE_RECALLOCARRAY=
151 83f0f95a 2022-09-29 op HAVE_SETGROUPS=
152 83f0f95a 2022-09-29 op HAVE_SETPROCTITLE=
153 e2764fac 2022-09-30 op HAVE_SETRESGID=
154 e2764fac 2022-09-30 op HAVE_SETRESUID=
155 83f0f95a 2022-09-29 op HAVE_STRLCAT=
156 83f0f95a 2022-09-29 op HAVE_STRLCPY=
157 83f0f95a 2022-09-29 op HAVE_STRTONUM=
158 83f0f95a 2022-09-29 op HAVE_SYS_QUEUE=
159 83f0f95a 2022-09-29 op HAVE_SYS_TREE=
161 83f0f95a 2022-09-29 op HAVE_VASPRINTF=
162 66e7e5ec 2022-11-11 op HAVE_WAIT_ANY=
163 83f0f95a 2022-09-29 op HAVE___PROGNAME=
165 83f0f95a 2022-09-29 op # singletest name var extra-cflags extra-libs msg
166 83f0f95a 2022-09-29 op singletest() {
168 83f0f95a 2022-09-29 op if [ -z "$msg" ]; then
169 83f0f95a 2022-09-29 op if [ -n "$3" ]; then
171 83f0f95a 2022-09-29 op elif [ -n "$4" ]; then
174 83f0f95a 2022-09-29 op elif [ "$msg" = no ]; then
178 83f0f95a 2022-09-29 op cat >&3 <<EOF
179 83f0f95a 2022-09-29 op ${1}: testing...
180 83f0f95a 2022-09-29 op $CC tests/${1}.c -Werror $3 -o test-$1 $LDFLAGS $4
182 83f0f95a 2022-09-29 op if $CC tests/${1}.c -Werror $3 -o test-$1 $LDFLAGS $4 >&3 2>&3; then
183 83f0f95a 2022-09-29 op rm -f test-${1} test-${1}.d
185 83f0f95a 2022-09-29 op echo "${1}: $CC$msg succeeded" >&3
186 83f0f95a 2022-09-29 op echo "${1}$msg: yes"
192 83f0f95a 2022-09-29 op echo "${1}: $CC$msg failed with $?" >&3
193 83f0f95a 2022-09-29 op echo "${1}$msg: no"
199 83f0f95a 2022-09-29 op # deptest name var
201 83f0f95a 2022-09-29 op if singletest "$1" "$2" "${CFLAGS}" "${LIBS}" no; then
202 83f0f95a 2022-09-29 op eval HAVE_${2}=1
206 83f0f95a 2022-09-29 op if [ -f compat/${1}.c ]; then
207 83f0f95a 2022-09-29 op COMPATS="compat/${1}.c $COMPATS"
210 83f0f95a 2022-09-29 op eval HAVE_${2}=0
214 83f0f95a 2022-09-29 op # runtest name var extra-cflags extra-libs pkgconfig-name
216 83f0f95a 2022-09-29 op if singletest "$1" "$2" "" ""; then
217 83f0f95a 2022-09-29 op eval HAVE_${2}=1
221 83f0f95a 2022-09-29 op if [ -n "$3" -o -n "$4" ]; then
222 83f0f95a 2022-09-29 op echo "retrying with ${3+$3 }$4" >&3
223 83f0f95a 2022-09-29 op if singletest "$1" "$2" "$3" "$4"; then
224 83f0f95a 2022-09-29 op if [ -n "$3" ]; then
225 83f0f95a 2022-09-29 op CFLAGS="$CFLAGS $3"
227 83f0f95a 2022-09-29 op if [ -n "${4}" ]; then
228 83f0f95a 2022-09-29 op LIBS="$LIBS $4"
230 83f0f95a 2022-09-29 op eval HAVE_${2}=1
235 83f0f95a 2022-09-29 op if [ -n "$5" -a -n "$pkgconfig" ]; then
236 83f0f95a 2022-09-29 op if $pkgconfig "$5"; then
237 83f0f95a 2022-09-29 op cflags="$($pkgconfig --cflags "$5")"
238 83f0f95a 2022-09-29 op ldflags="$($pkgconfig --libs "$5")"
239 83f0f95a 2022-09-29 op echo "retrying with pkg-config" >&3
240 83f0f95a 2022-09-29 op if singletest "$1" "$2" "$3" "$cflags" "$ldflags"; then
241 83f0f95a 2022-09-29 op CFLAGS="$CFLAGS $cflags"
242 83f0f95a 2022-09-29 op LIBS="$LIBS $ldflags"
243 83f0f95a 2022-09-29 op eval HAVE_${2}=1
249 83f0f95a 2022-09-29 op if [ -f compat/${1}.c ]; then
250 83f0f95a 2022-09-29 op COMPATS="compat/${1}.c $COMPATS"
253 83f0f95a 2022-09-29 op eval HAVE_${2}=0
257 08d22200 2022-09-30 op if singletest MMD _MMD -MMD >/dev/null; then
258 08d22200 2022-09-30 op CFLAGS="${CFLAGS} -MMD"
259 83f0f95a 2022-09-29 op echo "adding -MMD to CFLAGS" >&2
260 83f0f95a 2022-09-29 op echo "adding -MMD to CFLAGS" >&3
263 66e7e5ec 2022-11-11 op if ! singletest WAIT_ANY WAIT_ANY; then
264 66e7e5ec 2022-11-11 op CFLAGS="${CFLAGS} -DWAIT_ANY=-1"
267 83f0f95a 2022-09-29 op runtest accept4 ACCEPT4 -D_GNU_SOURCE || true
268 83f0f95a 2022-09-29 op runtest asr_run ASR_RUN "" "-lasr" || true
269 83f0f95a 2022-09-29 op runtest err ERR || true
270 83f0f95a 2022-09-29 op runtest freezero FREEZERO || true
271 83f0f95a 2022-09-29 op runtest getdtablecount GETDTABLECOUNT || true
272 83f0f95a 2022-09-29 op runtest getdtablesize GETDTABLESIZE || true
273 83f0f95a 2022-09-29 op runtest getexecname GETEXECNAME || true
274 83f0f95a 2022-09-29 op runtest getprogname GETPROGNAME || true
275 83f0f95a 2022-09-29 op runtest imsg IMSG "" "-lutil" libimsg || true
276 83f0f95a 2022-09-29 op runtest libevent LIBEVENT "" "-levent" libevent_core || true
277 83f0f95a 2022-09-29 op runtest libtls LIBTLS "" "-ltls" libtls || true
278 83f0f95a 2022-09-29 op runtest pledge PLEDGE || true
279 83f0f95a 2022-09-29 op runtest reallocarray REALLOCARRAY -D_OPENBSD_SOURCE || true
280 83f0f95a 2022-09-29 op runtest recallocarray RECALLOCARRAY -D_OPENBSD_SOURCE || true
281 83f0f95a 2022-09-29 op runtest setgroups SETGROUPS -D_BSD_SOURCE || true
282 83f0f95a 2022-09-29 op runtest setproctitle SETPROCTITLE || true
283 e2764fac 2022-09-30 op runtest setresgid SETRESGID -D_GNU_SOURCE || true
284 e2764fac 2022-09-30 op runtest setresuid SETRESUID -D_GNU_SOURCE || true
285 83f0f95a 2022-09-29 op runtest strlcat STRLCAT || true
286 83f0f95a 2022-09-29 op runtest strlcpy STRLCPY || true
287 83f0f95a 2022-09-29 op runtest strtonum STRTONUM || true
288 83f0f95a 2022-09-29 op runtest sys_queue SYS_QUEUE || true
289 83f0f95a 2022-09-29 op runtest sys_tree SYS_TREE || true
290 83f0f95a 2022-09-29 op runtest unveil UNVEIL || true
291 83f0f95a 2022-09-29 op runtest vasprintf VASPRINTF -D_GNU_SOURCE || true
292 83f0f95a 2022-09-29 op runtest __progname __PROGNAME || true
294 83f0f95a 2022-09-29 op deptest bufferevent_read_pressure_cb BEV_READ_PRESSURE || true
295 83f0f95a 2022-09-29 op deptest event_asr_run EVENT_ASR_RUN || true
296 83f0f95a 2022-09-29 op deptest libevent2 LIBEVENT2 || true
298 83f0f95a 2022-09-29 op # mandatory things:
300 83f0f95a 2022-09-29 op if [ "${HAVE_ACCEPT4}" -eq 0 ]; then
301 83f0f95a 2022-09-29 op echo "Fatal: missing accept4(2)" >&2
302 83f0f95a 2022-09-29 op echo "Fatal: missing accept4(2)" >&3
306 83f0f95a 2022-09-29 op if [ "${HAVE_ASR_RUN}" -eq 0 ]; then
307 83f0f95a 2022-09-29 op echo "Fatal: missing libasr" >&2
308 83f0f95a 2022-09-29 op echo "Fatal: missing libasr" >&3
312 83f0f95a 2022-09-29 op if [ "${HAVE_LIBEVENT}" -eq 0 ]; then
313 83f0f95a 2022-09-29 op echo "Fatal: missing libevent" >&2
314 83f0f95a 2022-09-29 op echo "Fatal: missing libevent" >&3
318 83f0f95a 2022-09-29 op if [ "${HAVE_LIBTLS}" -eq 0 ]; then
319 83f0f95a 2022-09-29 op echo "Fatal: missing libtls" >&2
320 83f0f95a 2022-09-29 op echo "Fatal: missing libtls" >&3
324 83f0f95a 2022-09-29 op if [ "${HAVE_SETGROUPS}" -eq 0 ]; then
325 83f0f95a 2022-09-29 op echo "Fatal: missing setgroups(2)" >&2
326 83f0f95a 2022-09-29 op echo "Fatal: missing setgroups(2)" >&3
330 83f0f95a 2022-09-29 op # things we can provide by ourselves:
332 83f0f95a 2022-09-29 op if [ "${HAVE_IMSG}" -eq 0 ]; then
333 83f0f95a 2022-09-29 op CFLAGS="-I compat/imsg ${CFLAGS}"
334 83f0f95a 2022-09-29 op COMPATS="compat/imsg/imsg.c compat/imsg/imsg-buffer.c ${COMPATS}"
337 83f0f95a 2022-09-29 op if [ "${HAVE_SYS_QUEUE}" -eq 0 -o "${HAVE_SYS_TREE}" -eq 0 ]; then
338 83f0f95a 2022-09-29 op CFLAGS="-I compat/sys ${CFLAGS}"
341 83f0f95a 2022-09-29 op if [ -n "${COMPATS}" ]; then
342 83f0f95a 2022-09-29 op CFLAGS="-I compat/ ${CFLAGS}"
345 83f0f95a 2022-09-29 op exec > config.h
346 83f0f95a 2022-09-29 op echo "config.h: writing..." >&2
349 83f0f95a 2022-09-29 op #ifndef CONFIG_H
350 83f0f95a 2022-09-29 op #define CONFIG_H
352 83f0f95a 2022-09-29 op #ifdef __cplusplus
353 83f0f95a 2022-09-29 op # error "Do not use C++: this is a C application."
356 83f0f95a 2022-09-29 op #define HAVE_ACCEPT4 ${HAVE_ACCEPT4}
357 83f0f95a 2022-09-29 op #define HAVE_ASR_RUN ${HAVE_ASR_RUN}
358 83f0f95a 2022-09-29 op #define HAVE_BUFFEREVENT_READ_PRESSURE_CB ${HAVE_BUFFEREVENT_READ_PRESSURE_CB}
359 83f0f95a 2022-09-29 op #define HAVE_ERR ${HAVE_ERR}
360 83f0f95a 2022-09-29 op #define HAVE_EVENT_ASR_RUN ${HAVE_EVENT_ASR_RUN}
361 83f0f95a 2022-09-29 op #define HAVE_FREEZERO ${HAVE_FREEZERO}
362 83f0f95a 2022-09-29 op #define HAVE_GETDTABLECOUNT ${HAVE_GETDTABLECOUNT}
363 83f0f95a 2022-09-29 op #define HAVE_GETDTABLESIZE ${HAVE_GETDTABLESIZE}
364 83f0f95a 2022-09-29 op #define HAVE_GETEXECNAME ${HAVE_GETEXECNAME}
365 83f0f95a 2022-09-29 op #define HAVE_GETPROGNAME ${HAVE_GETPROGNAME}
366 83f0f95a 2022-09-29 op #define HAVE_IMSG ${HAVE_IMSG}
367 83f0f95a 2022-09-29 op #define HAVE_LIBEVENT ${HAVE_LIBEVENT}
368 83f0f95a 2022-09-29 op #define HAVE_LIBEVENT2 ${HAVE_LIBEVENT2}
369 83f0f95a 2022-09-29 op #define HAVE_PLEDGE ${HAVE_PLEDGE}
370 83f0f95a 2022-09-29 op #define HAVE_REALLOCARRAY ${HAVE_REALLOCARRAY}
371 83f0f95a 2022-09-29 op #define HAVE_RECALLOCARRAY ${HAVE_RECALLOCARRAY}
372 83f0f95a 2022-09-29 op #define HAVE_SETGROUPS ${HAVE_SETGROUPS}
373 83f0f95a 2022-09-29 op #define HAVE_SETPROCTITLE ${HAVE_SETPROCTITLE}
374 e2764fac 2022-09-30 op #define HAVE_SETRESGID ${HAVE_SETRESGID}
375 e2764fac 2022-09-30 op #define HAVE_SETRESUID ${HAVE_SETRESUID}
376 83f0f95a 2022-09-29 op #define HAVE_STRLCAT ${HAVE_STRLCAT}
377 83f0f95a 2022-09-29 op #define HAVE_STRLCPY ${HAVE_STRLCPY}
378 83f0f95a 2022-09-29 op #define HAVE_STRTONUM ${HAVE_STRTONUM}
379 83f0f95a 2022-09-29 op #define HAVE_SYS_QUEUE ${HAVE_SYS_QUEUE}
380 83f0f95a 2022-09-29 op #define HAVE_SYS_TREE ${HAVE_SYS_TREE}
381 83f0f95a 2022-09-29 op #define HAVE_UNVEIL ${HAVE_UNVEIL}
382 83f0f95a 2022-09-29 op #define HAVE_VASPRINTF ${HAVE_VASPRINTF}
383 83f0f95a 2022-09-29 op #define HAVE___PROGNAME ${HAVE___PROGNAME}
388 83f0f95a 2022-09-29 op exec > config.mk
389 83f0f95a 2022-09-29 op echo "config.mk: writing..." >&2
393 83f0f95a 2022-09-29 op CFLAGS= ${CFLAGS}
394 83f0f95a 2022-09-29 op LIBS= ${LIBS}
395 83f0f95a 2022-09-29 op LDFLAGS= ${LDFLAGS}
396 83f0f95a 2022-09-29 op YACC= ${YACC}
398 83f0f95a 2022-09-29 op COMPATS= ${COMPATS}
400 83f0f95a 2022-09-29 op INSTALL= install
401 83f0f95a 2022-09-29 op INSTALL_PROGRAM=\${INSTALL} -m 0555
402 83f0f95a 2022-09-29 op INSTALL_LIB= \${INSTALL} -m 0444
403 83f0f95a 2022-09-29 op INSTALL_MAN= \${INSTALL} -m 0444
404 83f0f95a 2022-09-29 op INSTALL_DATA= \${INSTALL} -m 0444
408 83f0f95a 2022-09-29 op echo "done!" >&2
411 83f0f95a 2022-09-29 op echo "Now run \`make' to compile." >&2