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=
164 # singletest name var extra-cflags extra-libs msg
167 if [ -z "$msg" ]; then
170 elif [ -n "$4" ]; then
173 elif [ "$msg" = no ]; then
179 $CC tests/${1}.c -Werror $3 -o test-$1 $LDFLAGS $4
181 if $CC tests/${1}.c -Werror $3 -o test-$1 $LDFLAGS $4 >&3 2>&3; then
182 rm -f test-${1} test-${1}.d
184 echo "${1}: $CC$msg succeeded" >&3
191 echo "${1}: $CC$msg failed with $?" >&3
200 if singletest "$1" "$2" "${CFLAGS}" "${LIBS}" no; then
205 if [ -f compat/${1}.c ]; then
206 COMPATS="compat/${1}.c $COMPATS"
213 # runtest name var extra-cflags extra-libs pkgconfig-name
215 if singletest "$1" "$2" "" ""; then
220 if [ -n "$3" -o -n "$4" ]; then
221 echo "retrying with ${3+$3 }$4" >&3
222 if singletest "$1" "$2" "$3" "$4"; then
226 if [ -n "${4}" ]; then
234 if [ -n "$5" -a -n "$pkgconfig" ]; then
235 if $pkgconfig "$5"; then
236 cflags="$($pkgconfig --cflags "$5")"
237 ldflags="$($pkgconfig --libs "$5")"
238 echo "retrying with pkg-config" >&3
239 if singletest "$1" "$2" "$3" "$cflags" "$ldflags"; then
240 CFLAGS="$CFLAGS $cflags"
241 LIBS="$LIBS $ldflags"
248 if [ -f compat/${1}.c ]; then
249 COMPATS="compat/${1}.c $COMPATS"
256 if singletest MMD _MMD -MMD >/dev/null; then
257 CFLAGS="${CFLAGS} -MMD"
258 echo "adding -MMD to CFLAGS" >&2
259 echo "adding -MMD to CFLAGS" >&3
262 runtest accept4 ACCEPT4 -D_GNU_SOURCE || true
263 runtest asr_run ASR_RUN "" "-lasr" || true
264 runtest err ERR || true
265 runtest freezero FREEZERO || true
266 runtest getdtablecount GETDTABLECOUNT || true
267 runtest getdtablesize GETDTABLESIZE || true
268 runtest getexecname GETEXECNAME || true
269 runtest getprogname GETPROGNAME || true
270 runtest imsg IMSG "" "-lutil" libimsg || true
271 runtest libevent LIBEVENT "" "-levent" libevent_core || true
272 runtest libtls LIBTLS "" "-ltls" libtls || true
273 runtest pledge PLEDGE || true
274 runtest reallocarray REALLOCARRAY -D_OPENBSD_SOURCE || true
275 runtest recallocarray RECALLOCARRAY -D_OPENBSD_SOURCE || true
276 runtest setgroups SETGROUPS -D_BSD_SOURCE || true
277 runtest setproctitle SETPROCTITLE || true
278 runtest setresgid SETRESGID -D_GNU_SOURCE || true
279 runtest setresuid SETRESUID -D_GNU_SOURCE || true
280 runtest strlcat STRLCAT || true
281 runtest strlcpy STRLCPY || true
282 runtest strtonum STRTONUM || true
283 runtest sys_queue SYS_QUEUE || true
284 runtest sys_tree SYS_TREE || true
285 runtest unveil UNVEIL || true
286 runtest vasprintf VASPRINTF -D_GNU_SOURCE || true
287 runtest __progname __PROGNAME || true
289 deptest bufferevent_read_pressure_cb BEV_READ_PRESSURE || true
290 deptest event_asr_run EVENT_ASR_RUN || true
291 deptest libevent2 LIBEVENT2 || true
295 if [ "${HAVE_ACCEPT4}" -eq 0 ]; then
296 echo "Fatal: missing accept4(2)" >&2
297 echo "Fatal: missing accept4(2)" >&3
301 if [ "${HAVE_ASR_RUN}" -eq 0 ]; then
302 echo "Fatal: missing libasr" >&2
303 echo "Fatal: missing libasr" >&3
307 if [ "${HAVE_LIBEVENT}" -eq 0 ]; then
308 echo "Fatal: missing libevent" >&2
309 echo "Fatal: missing libevent" >&3
313 if [ "${HAVE_LIBTLS}" -eq 0 ]; then
314 echo "Fatal: missing libtls" >&2
315 echo "Fatal: missing libtls" >&3
319 if [ "${HAVE_SETGROUPS}" -eq 0 ]; then
320 echo "Fatal: missing setgroups(2)" >&2
321 echo "Fatal: missing setgroups(2)" >&3
325 # things we can provide by ourselves:
327 if [ "${HAVE_IMSG}" -eq 0 ]; then
328 CFLAGS="-I compat/imsg ${CFLAGS}"
329 COMPATS="compat/imsg/imsg.c compat/imsg/imsg-buffer.c ${COMPATS}"
332 if [ "${HAVE_SYS_QUEUE}" -eq 0 -o "${HAVE_SYS_TREE}" -eq 0 ]; then
333 CFLAGS="-I compat/sys ${CFLAGS}"
336 if [ -n "${COMPATS}" ]; then
337 CFLAGS="-I compat/ ${CFLAGS}"
341 echo "config.h: writing..." >&2
348 # error "Do not use C++: this is a C application."
351 #define HAVE_ACCEPT4 ${HAVE_ACCEPT4}
352 #define HAVE_ASR_RUN ${HAVE_ASR_RUN}
353 #define HAVE_BUFFEREVENT_READ_PRESSURE_CB ${HAVE_BUFFEREVENT_READ_PRESSURE_CB}
354 #define HAVE_ERR ${HAVE_ERR}
355 #define HAVE_EVENT_ASR_RUN ${HAVE_EVENT_ASR_RUN}
356 #define HAVE_FREEZERO ${HAVE_FREEZERO}
357 #define HAVE_GETDTABLECOUNT ${HAVE_GETDTABLECOUNT}
358 #define HAVE_GETDTABLESIZE ${HAVE_GETDTABLESIZE}
359 #define HAVE_GETEXECNAME ${HAVE_GETEXECNAME}
360 #define HAVE_GETPROGNAME ${HAVE_GETPROGNAME}
361 #define HAVE_IMSG ${HAVE_IMSG}
362 #define HAVE_LIBEVENT ${HAVE_LIBEVENT}
363 #define HAVE_LIBEVENT2 ${HAVE_LIBEVENT2}
364 #define HAVE_PLEDGE ${HAVE_PLEDGE}
365 #define HAVE_REALLOCARRAY ${HAVE_REALLOCARRAY}
366 #define HAVE_RECALLOCARRAY ${HAVE_RECALLOCARRAY}
367 #define HAVE_SETGROUPS ${HAVE_SETGROUPS}
368 #define HAVE_SETPROCTITLE ${HAVE_SETPROCTITLE}
369 #define HAVE_SETRESGID ${HAVE_SETRESGID}
370 #define HAVE_SETRESUID ${HAVE_SETRESUID}
371 #define HAVE_STRLCAT ${HAVE_STRLCAT}
372 #define HAVE_STRLCPY ${HAVE_STRLCPY}
373 #define HAVE_STRTONUM ${HAVE_STRTONUM}
374 #define HAVE_SYS_QUEUE ${HAVE_SYS_QUEUE}
375 #define HAVE_SYS_TREE ${HAVE_SYS_TREE}
376 #define HAVE_UNVEIL ${HAVE_UNVEIL}
377 #define HAVE_VASPRINTF ${HAVE_VASPRINTF}
378 #define HAVE___PROGNAME ${HAVE___PROGNAME}
384 echo "config.mk: writing..." >&2
396 INSTALL_PROGRAM=\${INSTALL} -m 0555
397 INSTALL_LIB= \${INSTALL} -m 0444
398 INSTALL_MAN= \${INSTALL} -m 0444
399 INSTALL_DATA= \${INSTALL} -m 0444
406 echo "Now run \`make' to compile." >&2