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 # When CFLAGS isn't set at this stage and gcc is detected by the macro below,
26 # autoconf will automatically use CFLAGS="-O2 -g". Prevent that by using an
30 # Save user CPPFLAGS, CFLAGS and LDFLAGS. We need to change them because
31 # AC_CHECK_HEADER doesn't give us any other way to update the include
32 # paths. But for Makefile.am we want to use AM_CPPFLAGS and friends.
33 SAVED_CFLAGS="$CFLAGS"
34 SAVED_CPPFLAGS="$CPPFLAGS"
35 SAVED_LDFLAGS="$LDFLAGS"
40 # Checks for programs.
46 if test -z "$YACC"; then
54 if test "$YACC_OVERRIDE" = "yes"; then
55 AC_MSG_NOTICE("Using YACC set from environment: $YACC")
58 # Checks for header files.
93 AC_CHECK_DECL([F_CLOSEM],
95 AC_DEFINE([HAVE_FCNTL_CLOSEM], [1],
96 [Use F_CLOSEM fcntl for closefrom]),
103 AC_MSG_CHECKING([for /proc/pid/fd directory])
104 if test -d "/proc/$$/fd" ; then
105 AC_DEFINE([HAVE_PROC_PID], [1], [Define if you have /proc/$pid/fd])
111 AC_MSG_CHECKING([whether program_invocation_short_name is defined])
112 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
115 program_invocation_short_name = "test";
118 AC_DEFINE([HAVE_PROGRAM_INVOCATION_SHORT_NAME], [1],
119 [Define if program_invocation_short_name is defined])
124 # Look for prctl(PR_SET_NAME).
127 [AC_DEFINE([HAVE_PR_SET_NAME], [1], [Define if PR_SET_NAME is defined])],
129 [#include <sys/prctl.h>]
132 AM_CONDITIONAL([HAVE_SHA2], [test "x$ac_cv_header_sha2_h" = xyes])
134 AC_CACHE_CHECK([whether getopt has optreset support],
135 ac_cv_have_getopt_optreset, [
136 AC_LINK_IFELSE([AC_LANG_PROGRAM([[ #include <getopt.h> ]],
137 [[ extern int optreset; optreset = 0; ]])],
138 [ ac_cv_have_getopt_optreset="yes" ],
139 [ ac_cv_have_getopt_optreset="no"
143 AM_CONDITIONAL([HAVE_GETOPT], [test "x$ac_cv_have_getopt_optreset" = "xyes"])
144 if test "x$ac_cv_have_getopt_optreset" = "xyes" ; then
145 AC_DEFINE([HAVE_GETOPT_OPTRESET], [1],
146 [Define if your getopt(3) defines and uses optreset])
149 AC_CHECK_MEMBERS([struct pollfd.fd], [], [], [[
150 #include <sys/types.h>
154 #ifdef HAVE_SYS_POLL_H
155 #include <sys/poll.h>
159 # Checks for typ edefs, structures, and compiler characteristics.
160 AC_CHECK_HEADER_STDBOOL
173 # Check for ifgroupreq which is only available on BSD.
174 AC_CHECK_TYPES([struct ifgroupreq])
176 # Check for sockaddr_storage. On some systems, ss_len is filled out, although
177 # this is not mandated by POSIX, and hence systems such as linux, don't have
179 AC_CHECK_TYPES([struct sockaddr_storage], [], [], [
180 #include <sys/types.h>
181 #include <sys/socket.h>
184 # Same thing as sockaddr_storage above, only now check if the member exists in
185 # the struct as well.
186 AC_CHECK_MEMBERS([struct sockaddr_storage.ss_len], , ,
188 #include <netinet/in.h>
189 #include <sys/socket.h> ]
192 AC_CHECK_MEMBERS([struct sockaddr.sa_len], , ,
194 #include <netinet/in.h>
195 #include <sys/socket.h> ]
198 # Both checks above will result in:
200 # HAVE_STRUCT_SOCKADDR_AS_LEN
203 # Either being defined or not.
205 # Look for library needed for flock.
206 AC_SEARCH_LIBS(flock, bsd)
208 # Checks for library functions.
211 AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK
253 AM_CONDITIONAL([HAVE_SETPROCTITLE], [test "x$ac_cv_func_setproctitle" = xyes])
255 if test "x$ac_cv_func_sysconf" = xyes; then
256 AC_DEFINE([HAVE_SYSCONF], [1], [Define to 1 if sysconf() present])
260 AC_CHECK_FUNCS([SipHash])
261 AM_CONDITIONAL([HAVE_SIPHASH], [test "x$ac_cv_func_SipHash" = xyes])
263 # Check for functions with a compatibility implementation.
282 AM_CONDITIONAL([HAVE_CLOSEFROM], [test "x$ac_cv_func_closefrom" = xyes])
284 # Always use our getopt because 1) glibc's doesn't enforce argument order 2)
285 # musl does not set optarg to NULL for flags without arguments (although it is
286 # not required to, but it is helpful) 3) there are probably other weird
290 # Check for b64_ntop. If we have b64_ntop, we assume b64_pton as well.
291 AC_MSG_CHECKING(for b64_ntop)
292 AC_LINK_IFELSE([AC_LANG_PROGRAM(
294 #include <sys/types.h>
295 #include <netinet/in.h>
299 b64_ntop(NULL, 0, NULL, 0);
304 AC_MSG_RESULT($found_b64_ntop)
306 if test "x$found_b64_ntop" = xno; then
307 AC_MSG_CHECKING(for b64_ntop with -lresolv)
309 AC_LINK_IFELSE([AC_LANG_PROGRAM(
311 #include <sys/types.h>
312 #include <netinet/in.h>
316 b64_ntop(NULL, 0, NULL, 0);
321 AC_MSG_RESULT($found_b64_ntop)
322 libresolv_LIBS="$LIBS"
324 if test "x$found_b64_ntop" = xno; then
325 AC_MSG_CHECKING(for b64_ntop with -lnetwork)
326 LIBS="-lresolv -lnetwork"
327 AC_LINK_IFELSE([AC_LANG_PROGRAM(
329 #include <sys/types.h>
330 #include <netinet/in.h>
334 b64_ntop(NULL, 0, NULL, 0);
339 AC_MSG_RESULT($found_b64_ntop)
340 libresolv_LIBS="$LIBS"
343 AM_CONDITIONAL([HAVE_B64], [test "x$found_b64_ntop" = xyes])
344 if test "x$found_b64_ntop" = xyes; then
345 AC_DEFINE([HAVE_B64_NTOP], [1], [define if b64_ntop is present])
346 AC_SUBST(libresolv_LIBS)
351 # Check the platform we're compiling on.
352 AC_MSG_CHECKING(platform)
359 AC_MSG_RESULT(freebsd)
363 AC_MSG_RESULT(darwin)
367 AC_MSG_RESULT(netbsd)
371 AC_MSG_RESULT(openbsd)
375 AC_MSG_RESULT(dragonfly)
376 PLATFORM=dragonflybsd
379 AC_MSG_RESULT(unknown)
384 AM_CONDITIONAL([HOST_FREEBSD], [test "$PLATFORM" = "freebsd"])
385 AM_CONDITIONAL([HOST_LINUX], [test "$PLATFORM" = "linux"])
386 AM_CONDITIONAL([HOST_DARWIN], [test "$PLATFORM" = "darwin"])
387 AM_CONDITIONAL([HOST_NETBSD], [test "$PLATFORM" = "netbsd"])
388 AM_CONDITIONAL([HOST_OPENBSD], [test "$PLATFORM" = "openbsd"])
389 AM_CONDITIONAL([HOST_DRAGONFLYBSD], [test "$PLATFORM" = "dragonflybsd"])
391 # On OpenBSD, these functions are already defined, yet looking for them in
392 # this way on OpenBSD breaks <sha2.h> inclusion.
393 # FIXME: this needs addressing.
394 if test "x$PLATFORM" != "xopenbsd"; then
403 if test "YACC_OVERRIDE" = "yes" && test -n "$YACC" \
404 && ! command -v "$YACC" >/dev/null 2>&1; then
405 AC_MSG_ERROR("yacc not found: $YACC")
408 if test x"$PLATFORM" = "xdarwin"; then
409 # Check for and/or set HOMEBREW_PREFIX. brew is a common way of
410 # installing applications. The other is MacPorts.
412 # Before Apple Silicon existed (M1 onward), the paths for applications
413 # installed via homebrew was typically /usr/local. However, with M1
414 # onward, this changed to a different path.
416 # Rather than hardcode this, check for HOMEBREW_PREFIX in the
417 # environment if it's already set, and use it. Otherwise, check for
418 # brew(1) and use that. If that fails, default to /usr/local
420 # This also means that MacPorts should continue to work.
422 # But with MacPorts, we should also check --prefix, and use that if it
425 # In both cases, the variable HOMEBREW_PREFIX is used for both.
429 if test -z "$HOMEBREW_PREFIX" -o "$HOMEBREW_PREFIX" = "NONE"; then
430 # HOMEBREW_PREFIX not set, check for brew(1)
431 if command -v brew >/dev/null 2>&1; then
432 AC_MSG_NOTICE("HOMEBREW_PREFIX set via 'brew --prefix'")
433 export HOMEBREW_PREFIX="$(brew --prefix)"
436 if test -z "$HOMEBREW_PREFIX" -o "$HOMEBREW_PREFIX" = "NONE"
439 if test -z "${prefix}" -o "${prefix}" = "NONE"; then
440 export HOMEBREW_PREFIX="/usr/local"
441 HB_PREFIX="/usr/local"
442 AC_MSG_NOTICE("HOMEBREW_PREFIX defaulting to $HB_PREFIX")
444 HB_PREFIX="$(eval echo ${prefix})"
445 if test "$HB_PREFIX" = "NONE"; then
446 HB_PREFIX="/opt/local"
448 AC_MSG_NOTICE("HOMEBREW_PREFIX using --prefix")
450 export HOMEBREW_PREFIX="$HB_PREFIX"
455 AC_MSG_NOTICE("HOMEBREW_PREFIX determined as: $HOMEBREW_PREFIX")
457 if test "$YACC_OVERRIDE" = "no" && \
458 ! test -x "${HOMEBREW_PREFIX}/opt/bison/bin/bison"; then
460 "***********************************************************
461 GNU Bison not found: ${HOMEBREW_PREFIX}/opt/bison/bin/bison
462 ***********************************************************
464 Falling back to checking either /usr/local or \${prefix}"
468 AC_MSG_WARN("Trying ${HB_PREFIX}/opt/bison/bin/bison")
469 if test -x "${HB_PREFIX}/opt/bison/bin/bison"; then
470 export HOMEBREW_PREFIX="/usr/local"
472 GNUBISON="${HB_PREFIX}/opt/bison/bin/bison"
475 if test "$FOUND_BISON" = "no"; then
476 HB_PREFIX="/opt/local"
477 AC_MSG_WARN("Trying ${HB_PREFIX}/bin/bison")
479 if test -x "${HB_PREFIX}/bin/bison"; then
480 export HOMEBREW_PREFIX="${HB_PREFIX}"
481 GNUBISON="${HB_PREFIX}/bin/bison"
487 GNUBISON="${HOMEBREW_PREFIX}/opt/bison/bin/bison"
490 if test "$FOUND_BISON" = "no" && test "$YACC_OVERRIDE" = "no"; then
491 AC_MSG_ERROR("*** Couldn't find GNU BISON ***")
494 # Override YACC here to point to the GNU version of bison.
495 if test "$YACC_OVERRIDE" = "yes"; then
496 export YACC="$YACC -y"
498 AC_MSG_NOTICE("Found GNU Bison as: $GNUBISON")
499 export YACC="${GNUBISON} -y"
501 export LDFLAGS="-L${HOMEBREW_PREFIX}/opt/ncurses/lib -L${HOMEBREW_PREFIX}/opt/openssl@3/lib $LDFLAGS"
502 export CPPFLAGS="-I${HOMEBREW_PREFIX}/opt/ncurses/include -I${HOMEBREW_PREFIX}/opt/openssl@3/include $CPPFLAGS"
503 export PKG_CONFIG_PATH="${HOMEBREW_PREFIX}/opt/ncurses/lib/pkgconfig"
504 export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:${HOMEBREW_PREFIX}/opt/openssl@3/lib/pkgconfig"
507 # Landlock detection.
508 AC_MSG_CHECKING([for landlock])
509 AM_CONDITIONAL([HAVE_LINUX_LANDLOCK],
510 [test "x$ac_cv_header_linux_landlock_h" = "xyes"])
511 if test "x$ac_cv_header_linux_landlock_h" = "xyes"; then
517 # Clang sanitizers wrap reallocarray even if it isn't available on the target
518 # system. When compiled it always returns NULL and crashes the program. To
519 # detect this we need a more complicated test.
520 AC_MSG_CHECKING([for working reallocarray])
521 AC_RUN_IFELSE([AC_LANG_PROGRAM(
522 [#include <stdlib.h>],
523 [return (reallocarray(NULL, 1, 1) == NULL);]
526 [AC_LIBOBJ(reallocarray) AC_MSG_RESULT([no])],
527 [AC_LIBOBJ(reallocarray) AC_MSG_RESULT([no])]
529 AC_MSG_CHECKING([for working recallocarray])
530 AC_RUN_IFELSE([AC_LANG_PROGRAM(
531 [#include <stdlib.h>],
532 [return (recallocarray(NULL, 1, 1, 1) == NULL);]
535 [AC_LIBOBJ(recallocarray) AC_MSG_RESULT([no])],
536 [AC_LIBOBJ(recallocarray) AC_MSG_RESULT([no])]
539 # Look for imsg_init in libutil.
540 AC_SEARCH_LIBS(imsg_init, util, found_imsg_init=yes, found_imsg_init=no)
541 AM_CONDITIONAL([HAVE_IMSG], [test "x$found_imsg_init" = "xyes"])
542 if test "x$found_imsg_init" = "xyes"; then
543 AC_DEFINE([HAVE_IMSG], [1], [Define to 1 if imsg is declared in libutil])
544 libutil_LIBS="$ac_cv_search_imsg_init"
545 AC_SUBST(libutil_LIBS)
548 # libevent (for gotwebd). Lifted from tmux.
549 # Look for libevent. Try libevent_core or libevent with pkg-config first then
550 # look for the library.
554 [libevent_core >= 2],
556 libevent_CFLAGS="$LIBEVENT_CORE_CFLAGS"
557 libevent_LIBS="$LIBEVENT_CORE_LIBS"
558 AC_SUBST(libevent_CFLAGS)
559 AC_SUBST(libevent_LIBS)
564 if test x$found_libevent = xno; then
569 libevent_CFLAGS="$LIBEVENT_CFLAGS"
570 libevent_LIBS="$LIBEVENT_LIBS"
571 AC_SUBST(libevent_CFLAGS)
572 AC_SUBST(libevent_LIBS)
578 if test x$found_libevent = xno; then
581 [event_core event event-1.4],
586 if test "x$found_libevent" = "xyes"; then
587 libevent_LIBS="$ac_cv_search_event_init"
588 AC_SUBST(libevent_LIBS)
592 if test x$found_libevent = xno; then
595 AC_DEFINE([HAVE_EVENT2_EVENT_H], [1], [libevent2 has event.h]),
599 AC_DEFINE([HAVE_EVENT_H], [0], [libevent]),
606 if test "x$found_libevent" = xno; then
607 AC_MSG_ERROR("libevent not found")
610 AC_CHECK_FUNC([uuid_create], [found_uuid=yes], [found_uuid=no])
612 # Don't define HAVE_BSD_UUID on darwin (Apple) as this breaks the BSD API.
613 # Instead, use the UUID implementation wrapper that's in compat/ plus uuid
615 if test "x$found_uuid" = "xyes" -a "x$PLATFORM" != "darwin"; then
616 AC_DEFINE([HAVE_BSD_UUID], [1], [BSD UUID])
622 libuuid_CFLAGS="$LIBUUID_CFLAGS"
623 libuuid_LIBS="$LIBUUID_LIBS"
624 AC_SUBST(libuuid_CFLAGS)
625 AC_SUBST(libuuid_LIBS)
633 if test "x$found_libuuid" = "xno"; then
641 if test "x$found_libuuid" = "xno"; then
642 AC_MSG_ERROR("*** couldn't find uuid ***")
649 zlib_CFLAGS="$ZLIB_CFLAGS"
650 zlib_LIBS="$ZLIB_LIBS"
651 AC_SUBST(zlib_CFLAGS)
660 if test "x$found_zlib" = "xno"; then
667 if test "x$found_zlib" = "xno"; then
668 AC_MSG_ERROR("*** couldn't find zlib ***")
671 if test "$PLATFORM" = "linux"; then
676 libbsd_CFLAGS="$LIBBSD_CFLAGS"
677 libbsd_LIBS="$LIBBSD_LIBS"
678 AC_SUBST(libbsd_CFLAGS)
679 AC_SUBST(libbsd_LIBS)
680 AC_DEFINE([HAVE_LIBBSD], [1], [BSD UUID])
683 AC_MSG_ERROR("*** couldn't find libbsd-overlay via pkg-config")
688 # Add LIBBSD_{CFLAGS,LIBS} to the environment here, as libbsd puts its
689 # header files in a non-standard location, which means the overlay for
690 # <sys/tree.h> and <sys/queue.h> won't be found.
691 CFLAGS="$CFLAGS $LIBBSD_CFLAGS"
692 LIBS="$LIBS $LIBBSD_LIBS"
698 libmd_CFLAGS="$LIBMD_CFLAGS"
699 libmd_LIBS="$LIBMD_LIBS"
700 AC_SUBST(libmd_CFLAGS)
704 CFLAGS="$CFLAGS $LIBMD_CFLAGS"
705 LIBS="$LIBS $LIBMD_LIBS"
709 # Look for a suitable queue.h. We hope libbsd is enough, but that is missing
715 [#include <sys/queue.h>]
721 [#include <sys/queue.h>]
727 [#include <sys/queue.h>]
730 if test "x$found_queue_h" = xyes; then
731 AC_DEFINE([HAVE_QUEUE_H], [1], [sys/queue.h])
733 AC_MSG_ERROR("*** sys/queue.h missing key defines ***)
738 found_sys_tree_h=yes,
740 [#include <sys/tree.h>]
743 if test "x$found_sys_tree_h" = xyes; then
744 AC_DEFINE([HAVE_TREE_H], [1], [sys/tree.h])
746 AC_MSG_NOTICE("Using compat/tree.h")
749 # Look for __progname.
750 AC_MSG_CHECKING(for __progname)
751 AC_LINK_IFELSE([AC_LANG_SOURCE(
755 extern char *__progname;
757 const char *cp = __progname;
762 [AC_DEFINE([HAVE___PROGNAME], [1], [___progname]) AC_MSG_RESULT(yes)],
769 LIBPANELW_LIBS="$LIBPANELW_LIBS"
774 if test "x$found_panel" = "xno"; then
779 LIBPANELW_LIBS="$LIBPANELW_LIBS"
786 if test "x$found_panel" = "xno"; then
791 LIBPANELW_LIBS="$LIBPANELW_LIBS"
798 if test "x$found_panel" = "xno"; then
799 AC_CHECK_LIB(panelw, update_panels, [],
800 AC_MSG_ERROR([ "*** panelw not found for ncurses. ***"]),
812 if test "x$found_ncurses" = xyes; then
813 libncurses_CFLAGS="$LIBNCURSES_CFLAGS $LIBTINFO_CFLAGS $LIBPANELW_CFLAGS"
814 libncurses_LIBS="$LIBNCURSES_LIBS $LIBTINFO_LIBS $LIBPANELW_LIBS"
815 AC_SUBST(libncurses_CFLAGS)
816 AC_SUBST(libncurses_LIBS)
823 if test "x$found_ncurses" = xyes; then
826 libncurses_CFLAGS="$LIBPANELW_CFLAGS $LIBPANEL_CFLAGS"
827 libncurses_LIBS="$LIBPANELW_LIBS -lncursesw"
828 AC_SUBST(libncurses_CFLAGS)
829 AC_SUBST(libncurses_LIBS)
833 if test "x$found_ncurses" = xyes; then
834 AC_DEFINE([HAVE_NCURSES_H], [1], [NCurses])
836 # No ncurses, try curses.
846 if test "x$found_curses" = xyes; then
847 libncurses_CFLAGS="$LIBPANELW_CFLAGS $LIBPANEL_CFLAGS"
848 libncurses_LIBS="$LIBPANELW_LIBS -lncursesw -lpanelw"
849 AC_SUBST(libncurses_CFLAGS)
850 AC_SUBST(libncurses_LIBS)
851 AC_DEFINE([HAVE_CURSES_H], [1], [Curses_h])
853 AC_MSG_ERROR("curses not found")
857 # Save our CFLAGS/CPPFLAGS/LDFLAGS for the Makefile and restore the old user
859 AC_SUBST(AM_CPPFLAGS)
860 CPPFLAGS="$SAVED_CPPFLAGS"
862 CFLAGS="$SAVED_CFLAGS"
864 LDFLAGS="$SAVED_LDFLAGS"
866 # LIBS is designed to accumulate library dependencies as checks for them are
867 # peformed, so that this can be included directly to ld(1).
869 # However, this hinders the splitting up of the library dependencies so that
870 # they're targetted just where they're needed. Flatting LIBS here ensures
871 # that this happens appropriately.
874 AH_BOTTOM([#include "got_compat2.h"])
876 AC_CONFIG_FILES([Makefile
880 libexec/got-read-tree/Makefile
881 libexec/got-fetch-pack/Makefile
882 libexec/got-index-pack/Makefile
883 libexec/got-read-blob/Makefile
884 libexec/got-read-commit/Makefile
885 libexec/got-read-gitconfig/Makefile
886 libexec/got-read-gotconfig/Makefile
887 libexec/got-read-object/Makefile
888 libexec/got-read-pack/Makefile
889 libexec/got-read-patch/Makefile
890 libexec/got-read-tag/Makefile
891 libexec/got-send-pack/Makefile
896 Makefile.common:Makefile.common.in])
899 executables="$(eval echo ${exec_prefix}/bin)"
900 helpers="$(eval echo ${libexecdir})"
901 manpages="$(eval echo ${mandir})"
904 Configured got-portable with:
909 Executables: ${executables}
913 Man pages: ${manpages}