1 # Process this file with autoconf to produce a configure script.
4 AC_INIT([got-portable],
5 m4_esyscmd_s(util/got-portable-ver.sh),
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)
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
23 AC_CONFIG_SUBDIRS([template])
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
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"
42 # Checks for programs.
48 if test -z "$YACC"; then
56 if test "$YACC_OVERRIDE" = "yes"; then
57 AC_MSG_NOTICE("Using YACC set from environment: $YACC")
60 # Checks for header files.
95 AC_CHECK_DECL([F_CLOSEM],
97 AC_DEFINE([HAVE_FCNTL_CLOSEM], [1],
98 [Use F_CLOSEM fcntl for closefrom]),
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])
113 AC_MSG_CHECKING([whether program_invocation_short_name is defined])
114 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
117 program_invocation_short_name = "test";
120 AC_DEFINE([HAVE_PROGRAM_INVOCATION_SHORT_NAME], [1],
121 [Define if program_invocation_short_name is defined])
126 # Look for prctl(PR_SET_NAME).
129 [AC_DEFINE([HAVE_PR_SET_NAME], [1], [Define if PR_SET_NAME is defined])],
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"
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])
151 AC_CHECK_MEMBERS([struct pollfd.fd], [], [], [[
152 #include <sys/types.h>
156 #ifdef HAVE_SYS_POLL_H
157 #include <sys/poll.h>
161 # Checks for typ edefs, structures, and compiler characteristics.
162 AC_CHECK_HEADER_STDBOOL
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
181 AC_CHECK_TYPES([struct sockaddr_storage], [], [], [
182 #include <sys/types.h>
183 #include <sys/socket.h>
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], , ,
190 #include <netinet/in.h>
191 #include <sys/socket.h> ]
194 AC_CHECK_MEMBERS([struct sockaddr.sa_len], , ,
196 #include <netinet/in.h>
197 #include <sys/socket.h> ]
200 # Both checks above will result in:
202 # HAVE_STRUCT_SOCKADDR_AS_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.
213 AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK
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])
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.
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
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>
301 b64_ntop(NULL, 0, NULL, 0);
306 AC_MSG_RESULT($found_b64_ntop)
308 if test "x$found_b64_ntop" = xno; then
309 AC_MSG_CHECKING(for b64_ntop with -lresolv)
311 AC_LINK_IFELSE([AC_LANG_PROGRAM(
313 #include <sys/types.h>
314 #include <netinet/in.h>
318 b64_ntop(NULL, 0, NULL, 0);
323 AC_MSG_RESULT($found_b64_ntop)
324 libresolv_LIBS="$LIBS"
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>
336 b64_ntop(NULL, 0, NULL, 0);
341 AC_MSG_RESULT($found_b64_ntop)
342 libresolv_LIBS="$LIBS"
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)
353 # Check the platform we're compiling on.
354 AC_MSG_CHECKING(platform)
361 AC_MSG_RESULT(freebsd)
365 AC_MSG_RESULT(darwin)
369 AC_MSG_RESULT(netbsd)
373 AC_MSG_RESULT(openbsd)
377 AC_MSG_RESULT(dragonfly)
378 PLATFORM=dragonflybsd
381 AC_MSG_RESULT(unknown)
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
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")
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
427 # In both cases, the variable HOMEBREW_PREFIX is used for both.
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)"
438 if test -z "$HOMEBREW_PREFIX" -o "$HOMEBREW_PREFIX" = "NONE"
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")
446 HB_PREFIX="$(eval echo ${prefix})"
447 if test "$HB_PREFIX" = "NONE"; then
448 HB_PREFIX="/opt/local"
450 AC_MSG_NOTICE("HOMEBREW_PREFIX using --prefix")
452 export HOMEBREW_PREFIX="$HB_PREFIX"
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
462 "***********************************************************
463 GNU Bison not found: ${HOMEBREW_PREFIX}/opt/bison/bin/bison
464 ***********************************************************
466 Falling back to checking either /usr/local or \${prefix}"
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"
474 GNUBISON="${HB_PREFIX}/opt/bison/bin/bison"
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"
489 GNUBISON="${HOMEBREW_PREFIX}/opt/bison/bin/bison"
492 if test "$FOUND_BISON" = "no" && test "$YACC_OVERRIDE" = "no"; then
493 AC_MSG_ERROR("*** Couldn't find GNU BISON ***")
496 # Override YACC here to point to the GNU version of bison.
497 if test "$YACC_OVERRIDE" = "yes"; then
498 export YACC="$YACC -y"
500 AC_MSG_NOTICE("Found GNU Bison as: $GNUBISON")
501 export YACC="${GNUBISON} -y"
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"
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
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);]
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);]
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)
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.
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)
566 if test x$found_libevent = xno; then
571 libevent_CFLAGS="$LIBEVENT_CFLAGS"
572 libevent_LIBS="$LIBEVENT_LIBS"
573 AC_SUBST(libevent_CFLAGS)
574 AC_SUBST(libevent_LIBS)
580 if test x$found_libevent = xno; then
583 [event_core event event-1.4],
588 if test "x$found_libevent" = "xyes"; then
589 libevent_LIBS="$ac_cv_search_event_init"
590 AC_SUBST(libevent_LIBS)
594 if test x$found_libevent = xno; then
597 AC_DEFINE([HAVE_EVENT2_EVENT_H], [1], [libevent2 has event.h]),
601 AC_DEFINE([HAVE_EVENT_H], [0], [libevent]),
608 if test "x$found_libevent" = xno; then
609 AC_MSG_ERROR("libevent not found")
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
617 if test "x$found_uuid" = "xyes" -a "x$PLATFORM" != "darwin"; then
618 AC_DEFINE([HAVE_BSD_UUID], [1], [BSD UUID])
624 libuuid_CFLAGS="$LIBUUID_CFLAGS"
625 libuuid_LIBS="$LIBUUID_LIBS"
626 AC_SUBST(libuuid_CFLAGS)
627 AC_SUBST(libuuid_LIBS)
635 if test "x$found_libuuid" = "xno"; then
643 if test "x$found_libuuid" = "xno"; then
644 AC_MSG_ERROR("*** couldn't find uuid ***")
651 zlib_CFLAGS="$ZLIB_CFLAGS"
652 zlib_LIBS="$ZLIB_LIBS"
653 AC_SUBST(zlib_CFLAGS)
662 if test "x$found_zlib" = "xno"; then
669 if test "x$found_zlib" = "xno"; then
670 AC_MSG_ERROR("*** couldn't find zlib ***")
673 if test "$PLATFORM" = "linux"; then
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])
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"
700 libmd_CFLAGS="$LIBMD_CFLAGS"
701 libmd_LIBS="$LIBMD_LIBS"
702 AC_SUBST(libmd_CFLAGS)
706 CFLAGS="$CFLAGS $LIBMD_CFLAGS"
707 LIBS="$LIBS $LIBMD_LIBS"
711 # Look for a suitable queue.h. We hope libbsd is enough, but that is missing
717 [#include <sys/queue.h>]
723 [#include <sys/queue.h>]
729 [#include <sys/queue.h>]
732 if test "x$found_queue_h" = xyes; then
733 AC_DEFINE([HAVE_QUEUE_H], [1], [sys/queue.h])
735 AC_MSG_ERROR("*** sys/queue.h missing key defines ***)
740 found_sys_tree_h=yes,
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])
748 AC_MSG_NOTICE("Using compat/tree.h")
751 # Look for __progname.
752 AC_MSG_CHECKING(for __progname)
753 AC_LINK_IFELSE([AC_LANG_SOURCE(
757 extern char *__progname;
759 const char *cp = __progname;
764 [AC_DEFINE([HAVE___PROGNAME], [1], [___progname]) AC_MSG_RESULT(yes)],
771 LIBPANELW_LIBS="$LIBPANELW_LIBS"
776 if test "x$found_panel" = "xno"; then
781 LIBPANELW_LIBS="$LIBPANELW_LIBS"
788 if test "x$found_panel" = "xno"; then
793 LIBPANELW_LIBS="$LIBPANELW_LIBS"
800 if test "x$found_panel" = "xno"; then
801 AC_CHECK_LIB(panelw, update_panels, [],
802 AC_MSG_ERROR([ "*** panelw not found for ncurses. ***"]),
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)
825 if test "x$found_ncurses" = xyes; then
828 libncurses_CFLAGS="$LIBPANELW_CFLAGS $LIBPANEL_CFLAGS"
829 libncurses_LIBS="$LIBPANELW_LIBS -lncursesw"
830 AC_SUBST(libncurses_CFLAGS)
831 AC_SUBST(libncurses_LIBS)
835 if test "x$found_ncurses" = xyes; then
836 AC_DEFINE([HAVE_NCURSES_H], [1], [NCurses])
838 # No ncurses, try curses.
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])
855 AC_MSG_ERROR("curses not found")
859 # Save our CFLAGS/CPPFLAGS/LDFLAGS for the Makefile and restore the old user
861 AC_SUBST(AM_CPPFLAGS)
862 CPPFLAGS="$SAVED_CPPFLAGS"
864 CFLAGS="$SAVED_CFLAGS"
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.
876 AH_BOTTOM([#include "got_compat2.h"])
878 AM_CONDITIONAL([GOTD_ENABLED], [test "x$enable_gotd" = xyes])
880 AC_CONFIG_FILES([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
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])
910 executables="$(eval echo ${exec_prefix}/bin)"
911 helpers="$(eval echo ${libexecdir})"
912 manpages="$(eval echo ${mandir})"
914 if test -z "$enable_gotd"; then
919 Configured got-portable with:
924 Executables: ${executables}
929 Man pages: ${manpages}