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=
162 # singletest name var extra-cflags extra-libs msg
165 if [ -z "$msg" ]; then
168 elif [ -n "$4" ]; then
171 elif [ "$msg" = no ]; then
177 $CC tests/${1}.c -Werror $3 -o test-$1 $LDFLAGS $4
179 if $CC tests/${1}.c -Werror $3 -o test-$1 $LDFLAGS $4 >&3 2>&3; then
180 rm -f test-${1} test-${1}.d
182 echo "${1}: $CC$msg succeeded" >&3
189 echo "${1}: $CC$msg failed with $?" >&3
198 if singletest "$1" "$2" "${CFLAGS}" "${LIBS}" no; then
203 if [ -f compat/${1}.c ]; then
204 COMPATS="compat/${1}.c $COMPATS"
211 # runtest name var extra-cflags extra-libs pkgconfig-name
213 if singletest "$1" "$2" "" ""; then
218 if [ -n "$3" -o -n "$4" ]; then
219 echo "retrying with ${3+$3 }$4" >&3
220 if singletest "$1" "$2" "$3" "$4"; then
224 if [ -n "${4}" ]; then
232 if [ -n "$5" -a -n "$pkgconfig" ]; then
233 if $pkgconfig "$5"; then
234 cflags="$($pkgconfig --cflags "$5")"
235 ldflags="$($pkgconfig --libs "$5")"
236 echo "retrying with pkg-config" >&3
237 if singletest "$1" "$2" "$3" "$cflags" "$ldflags"; then
238 CFLAGS="$CFLAGS $cflags"
239 LIBS="$LIBS $ldflags"
246 if [ -f compat/${1}.c ]; then
247 COMPATS="compat/${1}.c $COMPATS"
254 if runtest MMD _MMD -MMD >/dev/null; then
255 echo "adding -MMD to CFLAGS" >&2
256 echo "adding -MMD to CFLAGS" >&3
259 runtest accept4 ACCEPT4 -D_GNU_SOURCE || true
260 runtest asr_run ASR_RUN "" "-lasr" || true
261 runtest err ERR || true
262 runtest freezero FREEZERO || true
263 runtest getdtablecount GETDTABLECOUNT || true
264 runtest getdtablesize GETDTABLESIZE || true
265 runtest getexecname GETEXECNAME || true
266 runtest getprogname GETPROGNAME || true
267 runtest imsg IMSG "" "-lutil" libimsg || true
268 runtest libevent LIBEVENT "" "-levent" libevent_core || true
269 runtest libtls LIBTLS "" "-ltls" libtls || true
270 runtest pledge PLEDGE || true
271 runtest reallocarray REALLOCARRAY -D_OPENBSD_SOURCE || true
272 runtest recallocarray RECALLOCARRAY -D_OPENBSD_SOURCE || true
273 runtest setgroups SETGROUPS -D_BSD_SOURCE || true
274 runtest setproctitle SETPROCTITLE || true
275 runtest strlcat STRLCAT || true
276 runtest strlcpy STRLCPY || true
277 runtest strtonum STRTONUM || true
278 runtest sys_queue SYS_QUEUE || true
279 runtest sys_tree SYS_TREE || true
280 runtest unveil UNVEIL || true
281 runtest vasprintf VASPRINTF -D_GNU_SOURCE || true
282 runtest __progname __PROGNAME || true
284 deptest bufferevent_read_pressure_cb BEV_READ_PRESSURE || true
285 deptest event_asr_run EVENT_ASR_RUN || true
286 deptest libevent2 LIBEVENT2 || true
290 if [ "${HAVE_ACCEPT4}" -eq 0 ]; then
291 echo "Fatal: missing accept4(2)" >&2
292 echo "Fatal: missing accept4(2)" >&3
296 if [ "${HAVE_ASR_RUN}" -eq 0 ]; then
297 echo "Fatal: missing libasr" >&2
298 echo "Fatal: missing libasr" >&3
302 if [ "${HAVE_LIBEVENT}" -eq 0 ]; then
303 echo "Fatal: missing libevent" >&2
304 echo "Fatal: missing libevent" >&3
308 if [ "${HAVE_LIBTLS}" -eq 0 ]; then
309 echo "Fatal: missing libtls" >&2
310 echo "Fatal: missing libtls" >&3
314 if [ "${HAVE_SETGROUPS}" -eq 0 ]; then
315 echo "Fatal: missing setgroups(2)" >&2
316 echo "Fatal: missing setgroups(2)" >&3
320 # things we can provide by ourselves:
322 if [ "${HAVE_IMSG}" -eq 0 ]; then
323 CFLAGS="-I compat/imsg ${CFLAGS}"
324 COMPATS="compat/imsg/imsg.c compat/imsg/imsg-buffer.c ${COMPATS}"
327 if [ "${HAVE_SYS_QUEUE}" -eq 0 -o "${HAVE_SYS_TREE}" -eq 0 ]; then
328 CFLAGS="-I compat/sys ${CFLAGS}"
331 if [ -n "${COMPATS}" ]; then
332 CFLAGS="-I compat/ ${CFLAGS}"
336 echo "config.h: writing..." >&2
343 # error "Do not use C++: this is a C application."
346 #define HAVE_ACCEPT4 ${HAVE_ACCEPT4}
347 #define HAVE_ASR_RUN ${HAVE_ASR_RUN}
348 #define HAVE_BUFFEREVENT_READ_PRESSURE_CB ${HAVE_BUFFEREVENT_READ_PRESSURE_CB}
349 #define HAVE_ERR ${HAVE_ERR}
350 #define HAVE_EVENT_ASR_RUN ${HAVE_EVENT_ASR_RUN}
351 #define HAVE_FREEZERO ${HAVE_FREEZERO}
352 #define HAVE_GETDTABLECOUNT ${HAVE_GETDTABLECOUNT}
353 #define HAVE_GETDTABLESIZE ${HAVE_GETDTABLESIZE}
354 #define HAVE_GETEXECNAME ${HAVE_GETEXECNAME}
355 #define HAVE_GETPROGNAME ${HAVE_GETPROGNAME}
356 #define HAVE_IMSG ${HAVE_IMSG}
357 #define HAVE_LIBEVENT ${HAVE_LIBEVENT}
358 #define HAVE_LIBEVENT2 ${HAVE_LIBEVENT2}
359 #define HAVE_PLEDGE ${HAVE_PLEDGE}
360 #define HAVE_REALLOCARRAY ${HAVE_REALLOCARRAY}
361 #define HAVE_RECALLOCARRAY ${HAVE_RECALLOCARRAY}
362 #define HAVE_SETGROUPS ${HAVE_SETGROUPS}
363 #define HAVE_SETPROCTITLE ${HAVE_SETPROCTITLE}
364 #define HAVE_STRLCAT ${HAVE_STRLCAT}
365 #define HAVE_STRLCPY ${HAVE_STRLCPY}
366 #define HAVE_STRTONUM ${HAVE_STRTONUM}
367 #define HAVE_SYS_QUEUE ${HAVE_SYS_QUEUE}
368 #define HAVE_SYS_TREE ${HAVE_SYS_TREE}
369 #define HAVE_UNVEIL ${HAVE_UNVEIL}
370 #define HAVE_VASPRINTF ${HAVE_VASPRINTF}
371 #define HAVE___PROGNAME ${HAVE___PROGNAME}
377 echo "config.mk: writing..." >&2
389 INSTALL_PROGRAM=\${INSTALL} -m 0555
390 INSTALL_LIB= \${INSTALL} -m 0444
391 INSTALL_MAN= \${INSTALL} -m 0444
392 INSTALL_DATA= \${INSTALL} -m 0444
399 echo "Now run \`make' to compile." >&2