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.
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=
149 HAVE_MACHINE_ENDIAN=0
168 # singletest name var extra-cflags extra-libs msg
171 if [ -z "$msg" ]; then
174 elif [ -n "$4" ]; then
177 elif [ "$msg" = no ]; then
183 $CC tests/${1}.c -Werror $3 -o test-$1 $LDFLAGS $4
185 if $CC tests/${1}.c -Werror $3 -o test-$1 $LDFLAGS $4 >&3 2>&3; then
186 rm -f test-${1} test-${1}.d
188 echo "${1}: $CC$msg succeeded" >&3
195 echo "${1}: $CC$msg failed with $?" >&3
204 if singletest "$1" "$2" "${CFLAGS}" "${LIBS}" no; then
209 if [ -f compat/${1}.c ]; then
210 COMPATS="compat/${1}.c $COMPATS"
217 # runtest name var extra-cflags extra-libs pkgconfig-name
219 if singletest "$1" "$2" "" ""; then
224 if [ -n "$3" -o -n "$4" ]; then
225 echo "retrying with ${3+$3 }$4" >&3
226 if singletest "$1" "$2" "$3" "$4"; then
230 if [ -n "${4}" ]; then
238 if [ -n "$5" -a -n "$pkgconfig" ]; then
239 if $pkgconfig "$5"; then
240 cflags="$($pkgconfig --cflags "$5")"
241 ldflags="$($pkgconfig --libs "$5")"
242 echo "retrying with pkg-config" >&3
243 if singletest "$1" "$2" "$3" "$cflags" "$ldflags"; then
244 CFLAGS="$CFLAGS $cflags"
245 LIBS="$LIBS $ldflags"
252 if [ -f compat/${1}.c ]; then
253 COMPATS="compat/${1}.c $COMPATS"
260 if singletest MMD _MMD -MMD >/dev/null; then
261 CFLAGS="${CFLAGS} -MMD"
262 echo "adding -MMD to CFLAGS" >&2
263 echo "adding -MMD to CFLAGS" >&3
266 if ! singletest WAIT_ANY WAIT_ANY; then
267 CFLAGS="${CFLAGS} -DWAIT_ANY=-1"
270 runtest endian ENDIAN || \
271 runtest machine_endian MACHINE_ENDIAN || \
272 runtest sys_endian SYS_ENDIAN || true
274 if [ "${HAVE_ENDIAN}" -eq 0 -a \
275 "${HAVE_SYS_ENDIAN}" -eq 0 -a \
276 "${HAVE_MACHINE_ENDIAN}" -eq 0 ]; then
277 echo "FATAL: no endian header found" 1>&2
278 echo "FATAL: no endian header found" 1>&3
282 runtest accept4 ACCEPT4 -D_GNU_SOURCE || true
283 runtest asr_run ASR_RUN "" "-lasr" || true
284 runtest err ERR || true
285 runtest freezero FREEZERO || true
286 runtest getdtablecount GETDTABLECOUNT || true
287 runtest getdtablesize GETDTABLESIZE || true
288 runtest getexecname GETEXECNAME || true
289 runtest getprogname GETPROGNAME || true
290 runtest imsg IMSG "" "-lutil" libimsg || true
291 runtest libevent LIBEVENT "" "-levent" libevent_core || true
292 runtest libtls LIBTLS "" "-ltls" libtls || true
293 runtest pledge PLEDGE || true
294 runtest reallocarray REALLOCARRAY -D_OPENBSD_SOURCE || true
295 runtest recallocarray RECALLOCARRAY -D_OPENBSD_SOURCE || true
296 runtest setgroups SETGROUPS -D_BSD_SOURCE || true
297 runtest setproctitle SETPROCTITLE || true
298 runtest setresgid SETRESGID -D_GNU_SOURCE || true
299 runtest setresuid SETRESUID -D_GNU_SOURCE || true
300 runtest strlcat STRLCAT || true
301 runtest strlcpy STRLCPY || true
302 runtest strtonum STRTONUM || true
303 runtest sys_queue SYS_QUEUE || true
304 runtest sys_tree SYS_TREE || true
305 runtest unveil UNVEIL || true
306 runtest vasprintf VASPRINTF -D_GNU_SOURCE || true
307 runtest __progname __PROGNAME || true
309 deptest bufferevent_read_pressure_cb BEV_READ_PRESSURE || true
310 deptest event_asr_run EVENT_ASR_RUN || true
311 deptest libevent2 LIBEVENT2 || true
315 if [ "${HAVE_ACCEPT4}" -eq 0 ]; then
316 echo "Fatal: missing accept4(2)" >&2
317 echo "Fatal: missing accept4(2)" >&3
321 if [ "${HAVE_ASR_RUN}" -eq 0 ]; then
322 echo "Fatal: missing libasr" >&2
323 echo "Fatal: missing libasr" >&3
327 if [ "${HAVE_LIBEVENT}" -eq 0 ]; then
328 echo "Fatal: missing libevent" >&2
329 echo "Fatal: missing libevent" >&3
333 if [ "${HAVE_LIBTLS}" -eq 0 ]; then
334 echo "Fatal: missing libtls" >&2
335 echo "Fatal: missing libtls" >&3
339 if [ "${HAVE_SETGROUPS}" -eq 0 ]; then
340 echo "Fatal: missing setgroups(2)" >&2
341 echo "Fatal: missing setgroups(2)" >&3
345 # things we can provide by ourselves:
347 if [ "${HAVE_ENDIAN}" -eq 0 ]; then
348 CFLAGS="-I compat/endian ${CFLAGS}"
351 if [ "${HAVE_IMSG}" -eq 0 ]; then
352 CFLAGS="-I compat/imsg ${CFLAGS}"
353 COMPATS="compat/imsg/imsg.c compat/imsg/imsg-buffer.c ${COMPATS}"
356 if [ "${HAVE_SYS_QUEUE}" -eq 0 -o "${HAVE_SYS_TREE}" -eq 0 ]; then
357 CFLAGS="-I compat/sys ${CFLAGS}"
360 if [ -n "${COMPATS}" ]; then
361 CFLAGS="-I compat/ ${CFLAGS}"
365 echo "config.h: writing..." >&2
372 # error "Do not use C++: this is a C application."
375 #define HAVE_ACCEPT4 ${HAVE_ACCEPT4}
376 #define HAVE_ASR_RUN ${HAVE_ASR_RUN}
377 #define HAVE_BUFFEREVENT_READ_PRESSURE_CB ${HAVE_BUFFEREVENT_READ_PRESSURE_CB}
378 #define HAVE_ENDIAN ${HAVE_ENDIAN}
379 #define HAVE_ERR ${HAVE_ERR}
380 #define HAVE_EVENT_ASR_RUN ${HAVE_EVENT_ASR_RUN}
381 #define HAVE_FREEZERO ${HAVE_FREEZERO}
382 #define HAVE_GETDTABLECOUNT ${HAVE_GETDTABLECOUNT}
383 #define HAVE_GETDTABLESIZE ${HAVE_GETDTABLESIZE}
384 #define HAVE_GETEXECNAME ${HAVE_GETEXECNAME}
385 #define HAVE_GETPROGNAME ${HAVE_GETPROGNAME}
386 #define HAVE_IMSG ${HAVE_IMSG}
387 #define HAVE_LIBEVENT ${HAVE_LIBEVENT}
388 #define HAVE_LIBEVENT2 ${HAVE_LIBEVENT2}
389 #define HAVE_MACHINE_ENDIAN ${HAVE_MACHINE_ENDIAN}
390 #define HAVE_PLEDGE ${HAVE_PLEDGE}
391 #define HAVE_REALLOCARRAY ${HAVE_REALLOCARRAY}
392 #define HAVE_RECALLOCARRAY ${HAVE_RECALLOCARRAY}
393 #define HAVE_SETGROUPS ${HAVE_SETGROUPS}
394 #define HAVE_SETPROCTITLE ${HAVE_SETPROCTITLE}
395 #define HAVE_SETRESGID ${HAVE_SETRESGID}
396 #define HAVE_SETRESUID ${HAVE_SETRESUID}
397 #define HAVE_STRLCAT ${HAVE_STRLCAT}
398 #define HAVE_STRLCPY ${HAVE_STRLCPY}
399 #define HAVE_STRTONUM ${HAVE_STRTONUM}
400 #define HAVE_SYS_ENDIAN ${HAVE_SYS_ENDIAN}
401 #define HAVE_SYS_QUEUE ${HAVE_SYS_QUEUE}
402 #define HAVE_SYS_TREE ${HAVE_SYS_TREE}
403 #define HAVE_UNVEIL ${HAVE_UNVEIL}
404 #define HAVE_VASPRINTF ${HAVE_VASPRINTF}
405 #define HAVE___PROGNAME ${HAVE___PROGNAME}
411 echo "config.mk: writing..." >&2
423 INSTALL_PROGRAM=\${INSTALL} -m 0555
424 INSTALL_LIB= \${INSTALL} -m 0444
425 INSTALL_MAN= \${INSTALL} -m 0444
426 INSTALL_DATA= \${INSTALL} -m 0444
433 echo "Now run \`make' to compile." >&2