Blob


1 # Process this file with autoconf to produce a configure script.
3 AC_PREREQ([2.69])
4 AC_INIT([got-portable],
5 m4_esyscmd_s(util/got-portable-ver.sh),
6 [thomas@xteddy.org])
7 AC_CONFIG_AUX_DIR(etc)
8 AC_CONFIG_SRCDIR([lib/rcsutil.h])
9 AM_INIT_AUTOMAKE([foreign subdir-objects])
11 AC_CONFIG_HEADERS([include/got_compat.h])
13 AC_DEFINE_UNQUOTED(VERSION, $VERSION)
14 AC_SUBST(VERSION)
15 AC_SUBST(GOT_RELEASE)
17 AC_DEFINE_UNQUOTED([GOT_VERSION], VERSION, [GoT version string])
18 AC_DEFINE_UNQUOTED([GOT_VERSION_NUMBER], VERSION, [Got version number])
20 AC_USE_SYSTEM_EXTENSIONS
21 AC_CANONICAL_HOST
23 AC_CONFIG_SUBDIRS([template])
24 AC_ARG_ENABLE([gotd],
25 AS_HELP_STRING([--enable gotd], [build gotd and gotsh]))
27 # When CFLAGS isn't set at this stage and gcc is detected by the macro below,
28 # autoconf will automatically use CFLAGS="-O2 -g". Prevent that by using an
29 # empty default.
30 : ${CFLAGS=""}
32 # Save user CPPFLAGS, CFLAGS and LDFLAGS. We need to change them because
33 # AC_CHECK_HEADER doesn't give us any other way to update the include
34 # paths. But for Makefile.am we want to use AM_CPPFLAGS and friends.
35 SAVED_CFLAGS="$CFLAGS"
36 SAVED_CPPFLAGS="$CPPFLAGS"
37 SAVED_LDFLAGS="$LDFLAGS"
39 # YACC override
40 YACC_OVERRIDE="yes"
42 # Checks for programs.
43 AC_PROG_CC
44 AC_PROG_CPP
45 AC_PROG_INSTALL
46 AC_PROG_LN_S
47 AC_PROG_MAKE_SET
48 if test -z "$YACC"; then
49 YACC_OVERRIDE="no"
50 AC_PROG_YACC
51 fi
52 AM_PROG_AR
53 AC_PROG_RANLIB
54 PKG_PROG_PKG_CONFIG
56 if test "$YACC_OVERRIDE" = "yes"; then
57 AC_MSG_NOTICE("Using YACC set from environment: $YACC")
58 fi
60 # Checks for header files.
61 AC_CHECK_HEADERS([ \
62 fcntl.h \
63 getopt.h \
64 langinfo.h \
65 libutil.h \
66 limits.h \
67 linux/landlock.h \
68 locale.h \
69 netdb.h \
70 netinet/in.h \
71 paths.h \
72 poll.h \
73 sha.h \
74 sha1.h \
75 sha2.h \
76 sha256.h \
77 stddef.h \
78 stdint.h \
79 stdlib.h \
80 string.h \
81 sys/ioctl.h \
82 sys/param.h \
83 sys/poll.h \
84 sys/queue.h \
85 sys/select.h \
86 sys/socket.h \
87 sys/time.h \
88 sys/tree.h \
89 util.h \
90 unistd.h \
91 wchar.h \
92 ])
94 AC_HEADER_DIRENT
95 AC_CHECK_DECL([F_CLOSEM],
96 HAVE_FCNTL_CLOSEM
97 AC_DEFINE([HAVE_FCNTL_CLOSEM], [1],
98 [Use F_CLOSEM fcntl for closefrom]),
99 [],
100 [#include <limits.h>
101 #include <fcntl.h>
105 AC_MSG_CHECKING([for /proc/pid/fd directory])
106 if test -d "/proc/$$/fd" ; then
107 AC_DEFINE([HAVE_PROC_PID], [1], [Define if you have /proc/$pid/fd])
108 AC_MSG_RESULT([yes])
109 else
110 AC_MSG_RESULT([no])
111 fi
113 AC_MSG_CHECKING([whether program_invocation_short_name is defined])
114 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
115 #include <argp.h>
116 ]], [[
117 program_invocation_short_name = "test";
118 ]])], [
119 AC_MSG_RESULT([yes])
120 AC_DEFINE([HAVE_PROGRAM_INVOCATION_SHORT_NAME], [1],
121 [Define if program_invocation_short_name is defined])
122 ], [
123 AC_MSG_RESULT([no])
124 ])
126 # Look for prctl(PR_SET_NAME).
127 AC_CHECK_DECL(
128 [PR_SET_NAME],
129 [AC_DEFINE([HAVE_PR_SET_NAME], [1], [Define if PR_SET_NAME is defined])],
130 [],
131 [#include <sys/prctl.h>]
134 AM_CONDITIONAL([HAVE_SHA2], [test "x$ac_cv_header_sha2_h" = xyes])
136 AC_CACHE_CHECK([whether getopt has optreset support],
137 ac_cv_have_getopt_optreset, [
138 AC_LINK_IFELSE([AC_LANG_PROGRAM([[ #include <getopt.h> ]],
139 [[ extern int optreset; optreset = 0; ]])],
140 [ ac_cv_have_getopt_optreset="yes" ],
141 [ ac_cv_have_getopt_optreset="no"
142 ])
143 ])
145 AM_CONDITIONAL([HAVE_GETOPT], [test "x$ac_cv_have_getopt_optreset" = "xyes"])
146 if test "x$ac_cv_have_getopt_optreset" = "xyes" ; then
147 AC_DEFINE([HAVE_GETOPT_OPTRESET], [1],
148 [Define if your getopt(3) defines and uses optreset])
149 fi
151 AC_CHECK_MEMBERS([struct pollfd.fd], [], [], [[
152 #include <sys/types.h>
153 #ifdef HAVE_POLL_H
154 #include <poll.h>
155 #endif
156 #ifdef HAVE_SYS_POLL_H
157 #include <sys/poll.h>
158 #endif
159 ]])
161 # Checks for typ edefs, structures, and compiler characteristics.
162 AC_CHECK_HEADER_STDBOOL
163 AC_C_INLINE
164 AC_TYPE_INT64_T
165 AC_TYPE_MODE_T
166 AC_TYPE_OFF_T
167 AC_TYPE_PID_T
168 AC_TYPE_SIZE_T
169 AC_TYPE_SSIZE_T
170 AC_TYPE_UINT16_T
171 AC_TYPE_UINT32_T
172 AC_TYPE_UINT64_T
173 AC_TYPE_UINT8_T
175 # Check for ifgroupreq which is only available on BSD.
176 AC_CHECK_TYPES([struct ifgroupreq])
178 # Check for sockaddr_storage. On some systems, ss_len is filled out, although
179 # this is not mandated by POSIX, and hence systems such as linux, don't have
180 # it.
181 AC_CHECK_TYPES([struct sockaddr_storage], [], [], [
182 #include <sys/types.h>
183 #include <sys/socket.h>
184 ])
186 # Same thing as sockaddr_storage above, only now check if the member exists in
187 # the struct as well.
188 AC_CHECK_MEMBERS([struct sockaddr_storage.ss_len], , ,
189 [ #include <netdb.h>
190 #include <netinet/in.h>
191 #include <sys/socket.h> ]
194 AC_CHECK_MEMBERS([struct sockaddr.sa_len], , ,
195 [ #include <netdb.h>
196 #include <netinet/in.h>
197 #include <sys/socket.h> ]
200 # Both checks above will result in:
202 # HAVE_STRUCT_SOCKADDR_AS_LEN
203 # SS_LEN
205 # Either being defined or not.
207 # Look for library needed for flock.
208 AC_SEARCH_LIBS(flock, bsd)
210 # Checks for library functions.
211 AC_FUNC_FORK
212 AC_FUNC_FSEEKO
213 AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK
214 AC_FUNC_MALLOC
215 AC_FUNC_MMAP
216 AC_FUNC_REALLOC
217 AC_FUNC_STRERROR_R
218 AC_FUNC_STRNLEN
219 AC_CHECK_FUNCS([ \
220 dup2 \
221 flock \
222 getcwd \
223 localtime_r \
224 memchr \
225 memmove \
226 memset \
227 mergesort \
228 mkdir \
229 munmap \
230 nl_langinfo \
231 realpath \
232 regcomp \
233 rmdir \
234 setlocale \
235 socket \
236 setresgid \
237 setresuid \
238 setproctitle \
239 strcasecmp \
240 strchr \
241 strcspn \
242 strdup \
243 strerror \
244 strncasecmp \
245 strndup \
246 strrchr \
247 strspn \
248 strstr \
249 strtol \
250 strtoul \
251 sysconf \
252 wcwidth \
253 ])
255 AM_CONDITIONAL([HAVE_SETPROCTITLE], [test "x$ac_cv_func_setproctitle" = xyes])
257 if test "x$ac_cv_func_sysconf" = xyes; then
258 AC_DEFINE([HAVE_SYSCONF], [1], [Define to 1 if sysconf() present])
259 fi
261 # Siphash support.
262 AC_CHECK_FUNCS([SipHash])
263 AM_CONDITIONAL([HAVE_SIPHASH], [test "x$ac_cv_func_SipHash" = xyes])
265 # Check for functions with a compatibility implementation.
266 AC_REPLACE_FUNCS([ \
267 asprintf \
268 closefrom \
269 explicit_bzero \
270 fmt_scaled \
271 freezero \
272 getdtablecount \
273 getline \
274 getprogname \
275 recallocarray \
276 reallocarray \
277 strlcat \
278 strlcpy \
279 strndup \
280 strnlen \
281 strsep \
282 strtonum \
283 ])
284 AM_CONDITIONAL([HAVE_CLOSEFROM], [test "x$ac_cv_func_closefrom" = xyes])
286 # Always use our getopt because 1) glibc's doesn't enforce argument order 2)
287 # musl does not set optarg to NULL for flags without arguments (although it is
288 # not required to, but it is helpful) 3) there are probably other weird
289 # implementations.
290 AC_LIBOBJ(getopt)
292 # Check for b64_ntop. If we have b64_ntop, we assume b64_pton as well.
293 AC_MSG_CHECKING(for b64_ntop)
294 AC_LINK_IFELSE([AC_LANG_PROGRAM(
296 #include <sys/types.h>
297 #include <netinet/in.h>
298 #include <resolv.h>
299 ],
301 b64_ntop(NULL, 0, NULL, 0);
302 ])],
303 found_b64_ntop=yes,
304 found_b64_ntop=no
306 AC_MSG_RESULT($found_b64_ntop)
307 libresolv_LIBS=""
308 if test "x$found_b64_ntop" = xno; then
309 AC_MSG_CHECKING(for b64_ntop with -lresolv)
310 LIBS="-lresolv"
311 AC_LINK_IFELSE([AC_LANG_PROGRAM(
313 #include <sys/types.h>
314 #include <netinet/in.h>
315 #include <resolv.h>
316 ],
318 b64_ntop(NULL, 0, NULL, 0);
319 ])],
320 found_b64_ntop=yes,
321 found_b64_ntop=no
323 AC_MSG_RESULT($found_b64_ntop)
324 libresolv_LIBS="$LIBS"
325 fi
326 if test "x$found_b64_ntop" = xno; then
327 AC_MSG_CHECKING(for b64_ntop with -lnetwork)
328 LIBS="-lresolv -lnetwork"
329 AC_LINK_IFELSE([AC_LANG_PROGRAM(
331 #include <sys/types.h>
332 #include <netinet/in.h>
333 #include <resolv.h>
334 ],
336 b64_ntop(NULL, 0, NULL, 0);
337 ])],
338 found_b64_ntop=yes,
339 found_b64_ntop=no
341 AC_MSG_RESULT($found_b64_ntop)
342 libresolv_LIBS="$LIBS"
343 fi
345 AM_CONDITIONAL([HAVE_B64], [test "x$found_b64_ntop" = xyes])
346 if test "x$found_b64_ntop" = xyes; then
347 AC_DEFINE([HAVE_B64_NTOP], [1], [define if b64_ntop is present])
348 AC_SUBST(libresolv_LIBS)
349 else
350 AC_LIBOBJ(base64)
351 fi
353 # Check the platform we're compiling on.
354 AC_MSG_CHECKING(platform)
355 case "$host_os" in
356 *linux*)
357 AC_MSG_RESULT(linux)
358 PLATFORM=linux
359 ;;
360 *freebsd*)
361 AC_MSG_RESULT(freebsd)
362 PLATFORM=freebsd
363 ;;
364 *darwin*)
365 AC_MSG_RESULT(darwin)
366 PLATFORM=darwin
367 ;;
368 *netbsd*)
369 AC_MSG_RESULT(netbsd)
370 PLATFORM=netbsd
371 ;;
372 *openbsd*)
373 AC_MSG_RESULT(openbsd)
374 PLATFORM=openbsd
375 ;;
376 *dragonfly*)
377 AC_MSG_RESULT(dragonfly)
378 PLATFORM=dragonflybsd
379 ;;
380 *)
381 AC_MSG_RESULT(unknown)
382 PLATFORM=unknown
383 ;;
384 esac
385 AC_SUBST(PLATFORM)
386 AM_CONDITIONAL([HOST_FREEBSD], [test "$PLATFORM" = "freebsd"])
387 AM_CONDITIONAL([HOST_LINUX], [test "$PLATFORM" = "linux"])
388 AM_CONDITIONAL([HOST_DARWIN], [test "$PLATFORM" = "darwin"])
389 AM_CONDITIONAL([HOST_NETBSD], [test "$PLATFORM" = "netbsd"])
390 AM_CONDITIONAL([HOST_OPENBSD], [test "$PLATFORM" = "openbsd"])
391 AM_CONDITIONAL([HOST_DRAGONFLYBSD], [test "$PLATFORM" = "dragonflybsd"])
393 # On OpenBSD, these functions are already defined, yet looking for them in
394 # this way on OpenBSD breaks <sha2.h> inclusion.
395 # FIXME: this needs addressing.
396 if test "x$PLATFORM" != "xopenbsd"; then
397 AC_CHECK_FUNCS([ \
398 SHA256Update \
399 SHA384Update \
400 SHA512Update \
401 ])
402 fi
404 # Look for yacc.
405 if test "YACC_OVERRIDE" = "yes" && test -n "$YACC" \
406 && ! command -v "$YACC" >/dev/null 2>&1; then
407 AC_MSG_ERROR("yacc not found: $YACC")
408 fi
410 if test x"$PLATFORM" = "xdarwin"; then
411 # Check for and/or set HOMEBREW_PREFIX. brew is a common way of
412 # installing applications. The other is MacPorts.
414 # Before Apple Silicon existed (M1 onward), the paths for applications
415 # installed via homebrew was typically /usr/local. However, with M1
416 # onward, this changed to a different path.
418 # Rather than hardcode this, check for HOMEBREW_PREFIX in the
419 # environment if it's already set, and use it. Otherwise, check for
420 # brew(1) and use that. If that fails, default to /usr/local
422 # This also means that MacPorts should continue to work.
424 # But with MacPorts, we should also check --prefix, and use that if it
425 # has been supplied.
427 # In both cases, the variable HOMEBREW_PREFIX is used for both.
428 HB_PREFIX=""
429 FOUND_BISON="no"
430 GNUBISON=""
431 if test -z "$HOMEBREW_PREFIX" -o "$HOMEBREW_PREFIX" = "NONE"; then
432 # HOMEBREW_PREFIX not set, check for brew(1)
433 if command -v brew >/dev/null 2>&1; then
434 AC_MSG_NOTICE("HOMEBREW_PREFIX set via 'brew --prefix'")
435 export HOMEBREW_PREFIX="$(brew --prefix)"
436 fi
438 if test -z "$HOMEBREW_PREFIX" -o "$HOMEBREW_PREFIX" = "NONE"
439 then
440 # Default.
441 if test -z "${prefix}" -o "${prefix}" = "NONE"; then
442 export HOMEBREW_PREFIX="/usr/local"
443 HB_PREFIX="/usr/local"
444 AC_MSG_NOTICE("HOMEBREW_PREFIX defaulting to $HB_PREFIX")
445 else
446 HB_PREFIX="$(eval echo ${prefix})"
447 if test "$HB_PREFIX" = "NONE"; then
448 HB_PREFIX="/opt/local"
449 else
450 AC_MSG_NOTICE("HOMEBREW_PREFIX using --prefix")
451 fi
452 export HOMEBREW_PREFIX="$HB_PREFIX"
453 fi
454 fi
455 fi
457 AC_MSG_NOTICE("HOMEBREW_PREFIX determined as: $HOMEBREW_PREFIX")
459 if test "$YACC_OVERRIDE" = "no" && \
460 ! test -x "${HOMEBREW_PREFIX}/opt/bison/bin/bison"; then
461 AC_MSG_WARN([
462 "***********************************************************
463 GNU Bison not found: ${HOMEBREW_PREFIX}/opt/bison/bin/bison
464 ***********************************************************
466 Falling back to checking either /usr/local or \${prefix}"
467 ])
469 FOUND_BISON="no"
470 AC_MSG_WARN("Trying ${HB_PREFIX}/opt/bison/bin/bison")
471 if test -x "${HB_PREFIX}/opt/bison/bin/bison"; then
472 export HOMEBREW_PREFIX="/usr/local"
473 FOUND_BISON="yes"
474 GNUBISON="${HB_PREFIX}/opt/bison/bin/bison"
475 fi
477 if test "$FOUND_BISON" = "no"; then
478 HB_PREFIX="/opt/local"
479 AC_MSG_WARN("Trying ${HB_PREFIX}/bin/bison")
481 if test -x "${HB_PREFIX}/bin/bison"; then
482 export HOMEBREW_PREFIX="${HB_PREFIX}"
483 GNUBISON="${HB_PREFIX}/bin/bison"
484 FOUND_BISON="yes"
485 fi
486 fi
487 else
488 FOUND_BISON="yes"
489 GNUBISON="${HOMEBREW_PREFIX}/opt/bison/bin/bison"
490 fi
492 if test "$FOUND_BISON" = "no" && test "$YACC_OVERRIDE" = "no"; then
493 AC_MSG_ERROR("*** Couldn't find GNU BISON ***")
494 fi
496 # Override YACC here to point to the GNU version of bison.
497 if test "$YACC_OVERRIDE" = "yes"; then
498 export YACC="$YACC -y"
499 else
500 AC_MSG_NOTICE("Found GNU Bison as: $GNUBISON")
501 export YACC="${GNUBISON} -y"
502 fi
503 export LDFLAGS="-L${HOMEBREW_PREFIX}/opt/ncurses/lib -L${HOMEBREW_PREFIX}/opt/openssl@3/lib $LDFLAGS"
504 export CPPFLAGS="-I${HOMEBREW_PREFIX}/opt/ncurses/include -I${HOMEBREW_PREFIX}/opt/openssl@3/include $CPPFLAGS"
505 export PKG_CONFIG_PATH="${HOMEBREW_PREFIX}/opt/ncurses/lib/pkgconfig"
506 export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:${HOMEBREW_PREFIX}/opt/openssl@3/lib/pkgconfig"
507 fi
509 # Landlock detection.
510 AC_MSG_CHECKING([for landlock])
511 AM_CONDITIONAL([HAVE_LINUX_LANDLOCK],
512 [test "x$ac_cv_header_linux_landlock_h" = "xyes"])
513 if test "x$ac_cv_header_linux_landlock_h" = "xyes"; then
514 AC_MSG_RESULT(yes)
515 else
516 AC_MSG_RESULT(no)
517 fi
519 # Clang sanitizers wrap reallocarray even if it isn't available on the target
520 # system. When compiled it always returns NULL and crashes the program. To
521 # detect this we need a more complicated test.
522 AC_MSG_CHECKING([for working reallocarray])
523 AC_RUN_IFELSE([AC_LANG_PROGRAM(
524 [#include <stdlib.h>],
525 [return (reallocarray(NULL, 1, 1) == NULL);]
526 )],
527 AC_MSG_RESULT(yes),
528 [AC_LIBOBJ(reallocarray) AC_MSG_RESULT([no])],
529 [AC_LIBOBJ(reallocarray) AC_MSG_RESULT([no])]
531 AC_MSG_CHECKING([for working recallocarray])
532 AC_RUN_IFELSE([AC_LANG_PROGRAM(
533 [#include <stdlib.h>],
534 [return (recallocarray(NULL, 1, 1, 1) == NULL);]
535 )],
536 AC_MSG_RESULT(yes),
537 [AC_LIBOBJ(recallocarray) AC_MSG_RESULT([no])],
538 [AC_LIBOBJ(recallocarray) AC_MSG_RESULT([no])]
541 # Look for imsg_init in libutil.
542 AC_SEARCH_LIBS(imsg_init, util, found_imsg_init=yes, found_imsg_init=no)
543 AM_CONDITIONAL([HAVE_IMSG], [test "x$found_imsg_init" = "xyes"])
544 if test "x$found_imsg_init" = "xyes"; then
545 AC_DEFINE([HAVE_IMSG], [1], [Define to 1 if imsg is declared in libutil])
546 libutil_LIBS="$ac_cv_search_imsg_init"
547 AC_SUBST(libutil_LIBS)
548 fi
550 # libevent (for gotwebd). Lifted from tmux.
551 # Look for libevent. Try libevent_core or libevent with pkg-config first then
552 # look for the library.
553 found_libevent=no
554 PKG_CHECK_MODULES(
555 LIBEVENT_CORE,
556 [libevent_core >= 2],
558 libevent_CFLAGS="$LIBEVENT_CORE_CFLAGS"
559 libevent_LIBS="$LIBEVENT_CORE_LIBS"
560 AC_SUBST(libevent_CFLAGS)
561 AC_SUBST(libevent_LIBS)
562 found_libevent=yes
563 ],
564 found_libevent=no
566 if test x$found_libevent = xno; then
567 PKG_CHECK_MODULES(
568 LIBEVENT,
569 [libevent >= 2],
571 libevent_CFLAGS="$LIBEVENT_CFLAGS"
572 libevent_LIBS="$LIBEVENT_LIBS"
573 AC_SUBST(libevent_CFLAGS)
574 AC_SUBST(libevent_LIBS)
575 found_libevent=yes
576 ],
577 found_libevent=no
579 fi
580 if test x$found_libevent = xno; then
581 AC_SEARCH_LIBS(
582 event_init,
583 [event_core event event-1.4],
584 found_libevent=yes,
585 found_libevent=no
588 if test "x$found_libevent" = "xyes"; then
589 libevent_LIBS="$ac_cv_search_event_init"
590 AC_SUBST(libevent_LIBS)
591 fi
592 fi
594 if test x$found_libevent = xno; then
595 AC_CHECK_HEADER(
596 event2/event.h,
597 AC_DEFINE([HAVE_EVENT2_EVENT_H], [1], [libevent2 has event.h]),
599 AC_CHECK_HEADER(
600 event.h,
601 AC_DEFINE([HAVE_EVENT_H], [0], [libevent]),
602 found_libevent=no
606 fi
608 if test "x$found_libevent" = xno; then
609 AC_MSG_ERROR("libevent not found")
610 fi
612 AC_CHECK_FUNC([uuid_create], [found_uuid=yes], [found_uuid=no])
614 # Don't define HAVE_BSD_UUID on darwin (Apple) as this breaks the BSD API.
615 # Instead, use the UUID implementation wrapper that's in compat/ plus uuid
616 # ossp
617 if test "x$found_uuid" = "xyes" -a "x$PLATFORM" != "darwin"; then
618 AC_DEFINE([HAVE_BSD_UUID], [1], [BSD UUID])
619 else
620 PKG_CHECK_MODULES(
621 LIBUUID,
622 uuid,
624 libuuid_CFLAGS="$LIBUUID_CFLAGS"
625 libuuid_LIBS="$LIBUUID_LIBS"
626 AC_SUBST(libuuid_CFLAGS)
627 AC_SUBST(libuuid_LIBS)
628 found_libuuid=yes
629 ],
631 found_libuuid=no
635 if test "x$found_libuuid" = "xno"; then
636 AC_CHECK_HEADER(
637 uuid.h,
638 found_libuuid=yes,
639 found_libuuid=no)
640 fi
641 fi
643 if test "x$found_libuuid" = "xno"; then
644 AC_MSG_ERROR("*** couldn't find uuid ***")
645 fi
647 PKG_CHECK_MODULES(
648 ZLIB,
649 zlib,
651 zlib_CFLAGS="$ZLIB_CFLAGS"
652 zlib_LIBS="$ZLIB_LIBS"
653 AC_SUBST(zlib_CFLAGS)
654 AC_SUBST(zlib_LIBS)
655 found_zlib=yes
656 ],
658 found_zlib=no
662 if test "x$found_zlib" = "xno"; then
663 AC_CHECK_HEADER(
664 zlib.h,
666 found_zlib=no)
667 fi
669 if test "x$found_zlib" = "xno"; then
670 AC_MSG_ERROR("*** couldn't find zlib ***")
671 fi
673 if test "$PLATFORM" = "linux"; then
674 PKG_CHECK_MODULES(
675 LIBBSD,
676 libbsd-overlay,
678 libbsd_CFLAGS="$LIBBSD_CFLAGS"
679 libbsd_LIBS="$LIBBSD_LIBS"
680 AC_SUBST(libbsd_CFLAGS)
681 AC_SUBST(libbsd_LIBS)
682 AC_DEFINE([HAVE_LIBBSD], [1], [BSD UUID])
683 ],
685 AC_MSG_ERROR("*** couldn't find libbsd-overlay via pkg-config")
690 # Add LIBBSD_{CFLAGS,LIBS} to the environment here, as libbsd puts its
691 # header files in a non-standard location, which means the overlay for
692 # <sys/tree.h> and <sys/queue.h> won't be found.
693 CFLAGS="$CFLAGS $LIBBSD_CFLAGS"
694 LIBS="$LIBS $LIBBSD_LIBS"
696 PKG_CHECK_MODULES(
697 LIBMD,
698 libmd,
700 libmd_CFLAGS="$LIBMD_CFLAGS"
701 libmd_LIBS="$LIBMD_LIBS"
702 AC_SUBST(libmd_CFLAGS)
703 AC_SUBST(libmd_LIBS)
704 ], []
706 CFLAGS="$CFLAGS $LIBMD_CFLAGS"
707 LIBS="$LIBS $LIBMD_LIBS"
709 fi
711 # Look for a suitable queue.h. We hope libbsd is enough, but that is missing
712 # some declarations.
713 AC_CHECK_DECL(
714 TAILQ_CONCAT,
715 found_queue_h=yes,
716 found_queue_h=no,
717 [#include <sys/queue.h>]
719 AC_CHECK_DECL(
720 TAILQ_PREV,
722 found_queue_h=no,
723 [#include <sys/queue.h>]
725 AC_CHECK_DECL(
726 TAILQ_FOREACH_SAFE,
728 found_queue_h=no,
729 [#include <sys/queue.h>]
732 if test "x$found_queue_h" = xyes; then
733 AC_DEFINE([HAVE_QUEUE_H], [1], [sys/queue.h])
734 else
735 AC_MSG_ERROR("*** sys/queue.h missing key defines ***)
736 fi
738 AC_CHECK_DECL(
739 RB_GENERATE_STATIC,
740 found_sys_tree_h=yes,
741 found_sys_tree_h=no,
742 [#include <sys/tree.h>]
745 if test "x$found_sys_tree_h" = xyes; then
746 AC_DEFINE([HAVE_TREE_H], [1], [sys/tree.h])
747 else
748 AC_MSG_NOTICE("Using compat/tree.h")
749 fi
751 # Look for __progname.
752 AC_MSG_CHECKING(for __progname)
753 AC_LINK_IFELSE([AC_LANG_SOURCE(
755 #include <stdio.h>
756 #include <stdlib.h>
757 extern char *__progname;
758 int main(void) {
759 const char *cp = __progname;
760 printf("%s\n", cp);
761 exit(0);
763 ])],
764 [AC_DEFINE([HAVE___PROGNAME], [1], [___progname]) AC_MSG_RESULT(yes)],
765 [AC_MSG_RESULT(no)]
768 PKG_CHECK_MODULES(
769 LIBPANELW,
770 panelw,
771 LIBPANELW_LIBS="$LIBPANELW_LIBS"
772 found_panel=yes,
773 found_panel=no
776 if test "x$found_panel" = "xno"; then
777 PKG_CHECK_MODULES(
778 LIBPANELW,
779 gnupanelw,
781 LIBPANELW_LIBS="$LIBPANELW_LIBS"
782 found_panel=yes
783 ],
784 found_panel=no
786 fi
788 if test "x$found_panel" = "xno"; then
789 PKG_CHECK_MODULES(
790 LIBPANELW,
791 panel,
793 LIBPANELW_LIBS="$LIBPANELW_LIBS"
794 found_panel=yes
795 ],
796 found_panel=no
798 fi
800 if test "x$found_panel" = "xno"; then
801 AC_CHECK_LIB(panelw, update_panels, [],
802 AC_MSG_ERROR([ "*** panelw not found for ncurses. ***"]),
803 [-lncurses]
806 fi
808 PKG_CHECK_MODULES(
809 LIBNCURSES,
810 ncursesw,
811 found_ncurses=yes,
812 found_ncurses=no
814 if test "x$found_ncurses" = xyes; then
815 libncurses_CFLAGS="$LIBNCURSES_CFLAGS $LIBTINFO_CFLAGS $LIBPANELW_CFLAGS"
816 libncurses_LIBS="$LIBNCURSES_LIBS $LIBTINFO_LIBS $LIBPANELW_LIBS"
817 AC_SUBST(libncurses_CFLAGS)
818 AC_SUBST(libncurses_LIBS)
819 else
820 AC_SEARCH_LIBS(
821 setupterm,
822 found_ncurses=yes,
823 found_ncurses=no
825 if test "x$found_ncurses" = xyes; then
826 AC_CHECK_HEADER(
827 ncurses.h,
828 libncurses_CFLAGS="$LIBPANELW_CFLAGS $LIBPANEL_CFLAGS"
829 libncurses_LIBS="$LIBPANELW_LIBS -lncursesw"
830 AC_SUBST(libncurses_CFLAGS)
831 AC_SUBST(libncurses_LIBS)
833 fi
834 fi
835 if test "x$found_ncurses" = xyes; then
836 AC_DEFINE([HAVE_NCURSES_H], [1], [NCurses])
837 else
838 # No ncurses, try curses.
839 AC_CHECK_FUNC(
840 setupterm,
841 found_curses=yes,
842 found_curses=no
844 AC_CHECK_HEADER(
845 curses.h,
846 found_curses=yes,
847 found_curses=no)
848 if test "x$found_curses" = xyes; then
849 libncurses_CFLAGS="$LIBPANELW_CFLAGS $LIBPANEL_CFLAGS"
850 libncurses_LIBS="$LIBPANELW_LIBS -lncursesw -lpanelw"
851 AC_SUBST(libncurses_CFLAGS)
852 AC_SUBST(libncurses_LIBS)
853 AC_DEFINE([HAVE_CURSES_H], [1], [Curses_h])
854 else
855 AC_MSG_ERROR("curses not found")
856 fi
857 fi
859 # Save our CFLAGS/CPPFLAGS/LDFLAGS for the Makefile and restore the old user
860 # variables.
861 AC_SUBST(AM_CPPFLAGS)
862 CPPFLAGS="$SAVED_CPPFLAGS"
863 AC_SUBST(AM_CFLAGS)
864 CFLAGS="$SAVED_CFLAGS"
865 AC_SUBST(AM_LDFLAGS)
866 LDFLAGS="$SAVED_LDFLAGS"
868 # LIBS is designed to accumulate library dependencies as checks for them are
869 # peformed, so that this can be included directly to ld(1).
871 # However, this hinders the splitting up of the library dependencies so that
872 # they're targetted just where they're needed. Flatting LIBS here ensures
873 # that this happens appropriately.
874 LIBS=""
876 AH_BOTTOM([#include "got_compat2.h"])
878 AM_CONDITIONAL([GOTD_ENABLED], [test "x$enable_gotd" = xyes])
880 AC_CONFIG_FILES([Makefile
881 compat/Makefile
882 cvg/Makefile
883 libexec/Makefile
884 libexec/got-read-tree/Makefile
885 libexec/got-fetch-pack/Makefile
886 libexec/got-index-pack/Makefile
887 libexec/got-read-blob/Makefile
888 libexec/got-read-commit/Makefile
889 libexec/got-read-gitconfig/Makefile
890 libexec/got-read-gotconfig/Makefile
891 libexec/got-read-object/Makefile
892 libexec/got-read-pack/Makefile
893 libexec/got-read-patch/Makefile
894 libexec/got-read-tag/Makefile
895 libexec/got-send-pack/Makefile
896 got/Makefile
897 gotadmin/Makefile
898 gotwebd/Makefile
899 tog/Makefile
900 Makefile.common:Makefile.common.in])
902 if test "x$enable_gotd" = "xyes"; then
903 AC_CONFIG_FILES([gotd/Makefile])
904 AC_CONFIG_FILES([gotsh/Makefile])
905 AC_CONFIG_FILES([gotctl/Makefile])
906 fi
908 AC_OUTPUT
910 executables="$(eval echo ${exec_prefix}/bin)"
911 helpers="$(eval echo ${libexecdir})"
912 manpages="$(eval echo ${mandir})"
914 if test -z "$enable_gotd"; then
915 enable_gotd="no"
916 fi
918 echo "
919 Configured got-portable with:
921 Version: $VERSION
923 Prefix: ${prefix}
924 Executables: ${executables}
925 Bison: $YACC
926 CFlags: $CFLAGS
927 Gotd: ${enable_gotd}
928 Helpers: ${helpers}
929 Man pages: ${manpages}