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