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.
92 AC_CHECK_DECL([F_CLOSEM],
94 AC_DEFINE([HAVE_FCNTL_CLOSEM], [1],
95 [Use F_CLOSEM fcntl for closefrom]),
102 AC_MSG_CHECKING([for /proc/pid/fd directory])
103 if test -d "/proc/$$/fd" ; then
104 AC_DEFINE([HAVE_PROC_PID], [1], [Define if you have /proc/$pid/fd])
110 AC_MSG_CHECKING([whether program_invocation_short_name is defined])
111 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
114 program_invocation_short_name = "test";
117 AC_DEFINE([HAVE_PROGRAM_INVOCATION_SHORT_NAME], [1],
118 [Define if program_invocation_short_name is defined])
123 # Look for prctl(PR_SET_NAME).
126 [AC_DEFINE([HAVE_PR_SET_NAME], [1], [Define if PR_SET_NAME is defined])],
128 [#include <sys/prctl.h>]
131 AM_CONDITIONAL([HAVE_SHA2], [test "x$ac_cv_header_sha2_h" = xyes])
133 AC_CHECK_MEMBERS([struct pollfd.fd], [], [], [[
134 #include <sys/types.h>
138 #ifdef HAVE_SYS_POLL_H
139 #include <sys/poll.h>
143 # Checks for typ edefs, structures, and compiler characteristics.
144 AC_CHECK_HEADER_STDBOOL
157 # Check for ifgroupreq which is only available on BSD.
158 AC_CHECK_TYPES([struct ifgroupreq])
160 # Check for sockaddr_storage. On some systems, ss_len is filled out, although
161 # this is not mandated by POSIX, and hence systems such as linux, don't have
163 AC_CHECK_TYPES([struct sockaddr_storage], [], [], [
164 #include <sys/types.h>
165 #include <sys/socket.h>
168 # Same thing as sockaddr_storage above, only now check if the member exists in
169 # the struct as well.
170 AC_CHECK_MEMBERS([struct sockaddr_storage.ss_len], , ,
172 #include <netinet/in.h>
173 #include <sys/socket.h> ]
176 AC_CHECK_MEMBERS([struct sockaddr.sa_len], , ,
178 #include <netinet/in.h>
179 #include <sys/socket.h> ]
182 # Both checks above will result in:
184 # HAVE_STRUCT_SOCKADDR_AS_LEN
187 # Either being defined or not.
189 # Look for library needed for flock.
190 AC_SEARCH_LIBS(flock, bsd)
192 # Checks for library functions.
195 AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK
237 AM_CONDITIONAL([HAVE_SETPROCTITLE], [test "x$ac_cv_func_setproctitle" = xyes])
239 if test "x$ac_cv_func_sysconf" = xyes; then
240 AC_DEFINE([HAVE_SYSCONF], [1], [Define to 1 if sysconf() present])
244 AC_CHECK_FUNCS([SipHash])
245 AM_CONDITIONAL([HAVE_SIPHASH], [test "x$ac_cv_func_SipHash" = xyes])
247 # Check for functions with a compatibility implementation.
266 AM_CONDITIONAL([HAVE_CLOSEFROM], [test "x$ac_cv_func_closefrom" = xyes])
268 # Always use our getopt because 1) glibc's doesn't enforce argument order 2)
269 # musl does not set optarg to NULL for flags without arguments (although it is
270 # not required to, but it is helpful) 3) there are probably other weird
274 # Check for b64_ntop. If we have b64_ntop, we assume b64_pton as well.
275 AC_MSG_CHECKING(for b64_ntop)
276 AC_LINK_IFELSE([AC_LANG_PROGRAM(
278 #include <sys/types.h>
279 #include <netinet/in.h>
283 b64_ntop(NULL, 0, NULL, 0);
288 AC_MSG_RESULT($found_b64_ntop)
290 if test "x$found_b64_ntop" = xno; then
291 AC_MSG_CHECKING(for b64_ntop with -lresolv)
293 AC_LINK_IFELSE([AC_LANG_PROGRAM(
295 #include <sys/types.h>
296 #include <netinet/in.h>
300 b64_ntop(NULL, 0, NULL, 0);
305 AC_MSG_RESULT($found_b64_ntop)
306 libresolv_LIBS="$LIBS"
308 if test "x$found_b64_ntop" = xno; then
309 AC_MSG_CHECKING(for b64_ntop with -lnetwork)
310 LIBS="-lresolv -lnetwork"
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"
327 AM_CONDITIONAL([HAVE_B64], [test "x$found_b64_ntop" = xyes])
328 if test "x$found_b64_ntop" = xyes; then
329 AC_DEFINE([HAVE_B64_NTOP], [1], [define if b64_ntop is present])
330 AC_SUBST(libresolv_LIBS)
335 # Check the platform we're compiling on.
336 AC_MSG_CHECKING(platform)
343 AC_MSG_RESULT(freebsd)
347 AC_MSG_RESULT(darwin)
351 AC_MSG_RESULT(netbsd)
355 AC_MSG_RESULT(openbsd)
359 AC_MSG_RESULT(dragonfly)
360 PLATFORM=dragonflybsd
363 AC_MSG_RESULT(unknown)
368 AM_CONDITIONAL([HOST_FREEBSD], [test "$PLATFORM" = "freebsd"])
369 AM_CONDITIONAL([HOST_LINUX], [test "$PLATFORM" = "linux"])
370 AM_CONDITIONAL([HOST_DARWIN], [test "$PLATFORM" = "darwin"])
371 AM_CONDITIONAL([HOST_NETBSD], [test "$PLATFORM" = "netbsd"])
372 AM_CONDITIONAL([HOST_OPENBSD], [test "$PLATFORM" = "openbsd"])
373 AM_CONDITIONAL([HOST_DRAGONFLYBSD], [test "$PLATFORM" = "dragonflybsd"])
375 # On OpenBSD, these functions are already defined, yet looking for them in
376 # this way on OpenBSD breaks <sha2.h> inclusion.
377 # FIXME: this needs addressing.
378 if test "x$PLATFORM" != "xopenbsd"; then
387 if test "YACC_OVERRIDE" = "yes" && test -n "$YACC" \
388 && ! command -v "$YACC" >/dev/null 2>&1; then
389 AC_MSG_ERROR("yacc not found: $YACC")
392 if test x"$PLATFORM" = "xdarwin"; then
393 # Check for and/or set HOMEBREW_PREFIX. brew is a common way of
394 # installing applications. The other is MacPorts.
396 # Before Apple Silicon existed (M1 onward), the paths for applications
397 # installed via homebrew was typically /usr/local. However, with M1
398 # onward, this changed to a different path.
400 # Rather than hardcode this, check for HOMEBREW_PREFIX in the
401 # environment if it's already set, and use it. Otherwise, check for
402 # brew(1) and use that. If that fails, default to /usr/local
404 # This also means that MacPorts should continue to work.
406 # But with MacPorts, we should also check --prefix, and use that if it
409 # In both cases, the variable HOMEBREW_PREFIX is used for both.
413 if test -z "$HOMEBREW_PREFIX" -o "$HOMEBREW_PREFIX" = "NONE"; then
414 # HOMEBREW_PREFIX not set, check for brew(1)
415 if command -v brew >/dev/null 2>&1; then
416 AC_MSG_NOTICE("HOMEBREW_PREFIX set via 'brew --prefix'")
417 export HOMEBREW_PREFIX="$(brew --prefix)"
420 if test -z "$HOMEBREW_PREFIX" -o "$HOMEBREW_PREFIX" = "NONE"
423 if test -z "${prefix}" -o "${prefix}" = "NONE"; then
424 export HOMEBREW_PREFIX="/usr/local"
425 HB_PREFIX="/usr/local"
426 AC_MSG_NOTICE("HOMEBREW_PREFIX defaulting to $HB_PREFIX")
428 HB_PREFIX="$(eval echo ${prefix})"
429 if test "$HB_PREFIX" = "NONE"; then
430 HB_PREFIX="/opt/local"
432 AC_MSG_NOTICE("HOMEBREW_PREFIX using --prefix")
434 export HOMEBREW_PREFIX="$HB_PREFIX"
439 AC_MSG_NOTICE("HOMEBREW_PREFIX determined as: $HOMEBREW_PREFIX")
441 if test "$YACC_OVERRIDE" = "no" && \
442 ! test -x "${HOMEBREW_PREFIX}/opt/bison/bin/bison"; then
444 "***********************************************************
445 GNU Bison not found: ${HOMEBREW_PREFIX}/opt/bison/bin/bison
446 ***********************************************************
448 Falling back to checking either /usr/local or \${prefix}"
452 AC_MSG_WARN("Trying ${HB_PREFIX}/opt/bison/bin/bison")
453 if test -x "${HB_PREFIX}/opt/bison/bin/bison"; then
454 export HOMEBREW_PREFIX="/usr/local"
456 GNUBISON="${HB_PREFIX}/opt/bison/bin/bison"
459 if test "$FOUND_BISON" = "no"; then
460 HB_PREFIX="/opt/local"
461 AC_MSG_WARN("Trying ${HB_PREFIX}/bin/bison")
463 if test -x "${HB_PREFIX}/bin/bison"; then
464 export HOMEBREW_PREFIX="${HB_PREFIX}"
465 GNUBISON="${HB_PREFIX}/bin/bison"
471 GNUBISON="${HOMEBREW_PREFIX}/opt/bison/bin/bison"
474 if test "$FOUND_BISON" = "no" && test "$YACC_OVERRIDE" = "no"; then
475 AC_MSG_ERROR("*** Couldn't find GNU BISON ***")
478 # Override YACC here to point to the GNU version of bison.
479 if test "$YACC_OVERRIDE" = "yes"; then
480 export YACC="$YACC -y"
482 AC_MSG_NOTICE("Found GNU Bison as: $GNUBISON")
483 export YACC="${GNUBISON} -y"
485 export LDFLAGS="-L${HOMEBREW_PREFIX}/opt/ncurses/lib -L${HOMEBREW_PREFIX}/opt/openssl@3/lib $LDFLAGS"
486 export CPPFLAGS="-I${HOMEBREW_PREFIX}/opt/ncurses/include -I${HOMEBREW_PREFIX}/opt/openssl@3/include $CPPFLAGS"
487 export PKG_CONFIG_PATH="${HOMEBREW_PREFIX}/opt/ncurses/lib/pkgconfig"
488 export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:${HOMEBREW_PREFIX}/opt/openssl@3/lib/pkgconfig"
491 # Landlock detection.
492 AC_MSG_CHECKING([for landlock])
493 AM_CONDITIONAL([HAVE_LINUX_LANDLOCK],
494 [test "x$ac_cv_header_linux_landlock_h" = "xyes"])
495 if test "x$ac_cv_header_linux_landlock_h" = "xyes"; then
501 # Clang sanitizers wrap reallocarray even if it isn't available on the target
502 # system. When compiled it always returns NULL and crashes the program. To
503 # detect this we need a more complicated test.
504 AC_MSG_CHECKING([for working reallocarray])
505 AC_RUN_IFELSE([AC_LANG_PROGRAM(
506 [#include <stdlib.h>],
507 [return (reallocarray(NULL, 1, 1) == NULL);]
510 [AC_LIBOBJ(reallocarray) AC_MSG_RESULT([no])],
511 [AC_LIBOBJ(reallocarray) AC_MSG_RESULT([no])]
513 AC_MSG_CHECKING([for working recallocarray])
514 AC_RUN_IFELSE([AC_LANG_PROGRAM(
515 [#include <stdlib.h>],
516 [return (recallocarray(NULL, 1, 1, 1) == NULL);]
519 [AC_LIBOBJ(recallocarray) AC_MSG_RESULT([no])],
520 [AC_LIBOBJ(recallocarray) AC_MSG_RESULT([no])]
523 # Look for imsg_init in libutil.
524 AC_SEARCH_LIBS(imsg_init, util, found_imsg_init=yes, found_imsg_init=no)
525 AM_CONDITIONAL([HAVE_IMSG], [test "x$found_imsg_init" = "xyes"])
526 if test "x$found_imsg_init" = "xyes"; then
527 AC_DEFINE([HAVE_IMSG], [1], [Define to 1 if imsg is declared in libutil])
528 libutil_LIBS="$ac_cv_search_imsg_init"
529 AC_SUBST(libutil_LIBS)
532 # libevent (for gotwebd). Lifted from tmux.
533 # Look for libevent. Try libevent_core or libevent with pkg-config first then
534 # look for the library.
538 [libevent_core >= 2],
540 libevent_CFLAGS="$LIBEVENT_CORE_CFLAGS"
541 libevent_LIBS="$LIBEVENT_CORE_LIBS"
542 AC_SUBST(libevent_CFLAGS)
543 AC_SUBST(libevent_LIBS)
548 if test x$found_libevent = xno; then
553 libevent_CFLAGS="$LIBEVENT_CFLAGS"
554 libevent_LIBS="$LIBEVENT_LIBS"
555 AC_SUBST(libevent_CFLAGS)
556 AC_SUBST(libevent_LIBS)
562 if test x$found_libevent = xno; then
565 [event_core event event-1.4],
570 if test "x$found_libevent" = "xyes"; then
571 libevent_LIBS="$ac_cv_search_event_init"
572 AC_SUBST(libevent_LIBS)
576 if test x$found_libevent = xno; then
579 AC_DEFINE([HAVE_EVENT2_EVENT_H], [1], [libevent2 has event.h]),
583 AC_DEFINE([HAVE_EVENT_H], [0], [libevent]),
590 if test "x$found_libevent" = xno; then
591 AC_MSG_ERROR("libevent not found")
594 AC_CHECK_FUNC([uuid_create], [found_uuid=yes], [found_uuid=no])
596 # Don't define HAVE_BSD_UUID on darwin (Apple) as this breaks the BSD API.
597 # Instead, use the UUID implementation wrapper that's in compat/ plus uuid
599 if test "x$found_uuid" = "xyes" -a "x$PLATFORM" != "darwin"; then
600 AC_DEFINE([HAVE_BSD_UUID], [1], [BSD UUID])
606 libuuid_CFLAGS="$LIBUUID_CFLAGS"
607 libuuid_LIBS="$LIBUUID_LIBS"
608 AC_SUBST(libuuid_CFLAGS)
609 AC_SUBST(libuuid_LIBS)
617 if test "x$found_libuuid" = "xno"; then
625 if test "x$found_libuuid" = "xno"; then
626 AC_MSG_ERROR("*** couldn't find uuid ***")
633 zlib_CFLAGS="$ZLIB_CFLAGS"
634 zlib_LIBS="$ZLIB_LIBS"
635 AC_SUBST(zlib_CFLAGS)
644 if test "x$found_zlib" = "xno"; then
651 if test "x$found_zlib" = "xno"; then
652 AC_MSG_ERROR("*** couldn't find zlib ***")
655 if test "$PLATFORM" = "linux"; then
660 libbsd_CFLAGS="$LIBBSD_CFLAGS"
661 libbsd_LIBS="$LIBBSD_LIBS"
662 AC_SUBST(libbsd_CFLAGS)
663 AC_SUBST(libbsd_LIBS)
664 AC_DEFINE([HAVE_LIBBSD], [1], [BSD UUID])
667 AC_MSG_ERROR("*** couldn't find libbsd-overlay via pkg-config")
672 # Add LIBBSD_{CFLAGS,LIBS} to the environment here, as libbsd puts its
673 # header files in a non-standard location, which means the overlay for
674 # <sys/tree.h> and <sys/queue.h> won't be found.
675 CFLAGS="$CFLAGS $LIBBSD_CFLAGS"
676 LIBS="$LIBS $LIBBSD_LIBS"
679 # Look for a suitable queue.h. We hope libbsd is enough, but that is missing
685 [#include <sys/queue.h>]
691 [#include <sys/queue.h>]
697 [#include <sys/queue.h>]
700 if test "x$found_queue_h" = xyes; then
701 AC_DEFINE([HAVE_QUEUE_H], [1], [sys/queue.h])
703 AC_MSG_ERROR("*** sys/queue.h missing key defines ***)
708 found_sys_tree_h=yes,
710 [#include <sys/tree.h>]
713 if test "x$found_sys_tree_h" = xyes; then
714 AC_DEFINE([HAVE_TREE_H], [1], [sys/tree.h])
716 AC_MSG_NOTICE("Using compat/tree.h")
719 # Look for __progname.
720 AC_MSG_CHECKING(for __progname)
721 AC_LINK_IFELSE([AC_LANG_SOURCE(
725 extern char *__progname;
727 const char *cp = __progname;
732 [AC_DEFINE([HAVE___PROGNAME], [1], [___progname]) AC_MSG_RESULT(yes)],
739 LIBPANELW_LIBS="$LIBPANELW_LIBS"
744 if test "x$found_panel" = "xno"; then
749 LIBPANELW_LIBS="$LIBPANELW_LIBS"
756 if test "x$found_panel" = "xno"; then
761 LIBPANELW_LIBS="$LIBPANELW_LIBS"
768 if test "x$found_panel" = "xno"; then
769 AC_CHECK_LIB(panelw, update_panels, [],
770 AC_MSG_ERROR([ "*** panelw not found for ncurses. ***"]),
782 if test "x$found_ncurses" = xyes; then
783 libncurses_CFLAGS="$LIBNCURSES_CFLAGS $LIBTINFO_CFLAGS $LIBPANELW_CFLAGS"
784 libncurses_LIBS="$LIBNCURSES_LIBS $LIBTINFO_LIBS $LIBPANELW_LIBS"
785 AC_SUBST(libncurses_CFLAGS)
786 AC_SUBST(libncurses_LIBS)
793 if test "x$found_ncurses" = xyes; then
796 libncurses_CFLAGS="$LIBPANELW_CFLAGS $LIBPANEL_CFLAGS"
797 libncurses_LIBS="$LIBPANELW_LIBS -lncursesw"
798 AC_SUBST(libncurses_CFLAGS)
799 AC_SUBST(libncurses_LIBS)
803 if test "x$found_ncurses" = xyes; then
804 AC_DEFINE([HAVE_NCURSES_H], [1], [NCurses])
806 # No ncurses, try curses.
816 if test "x$found_curses" = xyes; then
817 libncurses_CFLAGS="$LIBPANELW_CFLAGS $LIBPANEL_CFLAGS"
818 libncurses_LIBS="$LIBPANELW_LIBS -lncursesw -lpanelw"
819 AC_SUBST(libncurses_CFLAGS)
820 AC_SUBST(libncurses_LIBS)
821 AC_DEFINE([HAVE_CURSES_H], [1], [Curses_h])
823 AC_MSG_ERROR("curses not found")
827 # Save our CFLAGS/CPPFLAGS/LDFLAGS for the Makefile and restore the old user
829 AC_SUBST(AM_CPPFLAGS)
830 CPPFLAGS="$SAVED_CPPFLAGS"
832 CFLAGS="$SAVED_CFLAGS"
834 LDFLAGS="$SAVED_LDFLAGS"
836 # LIBS is designed to accumulate library dependencies as checks for them are
837 # peformed, so that this can be included directly to ld(1).
839 # However, this hinders the splitting up of the library dependencies so that
840 # they're targetted just where they're needed. Flatting LIBS here ensures
841 # that this happens appropriately.
844 AH_BOTTOM([#include "got_compat2.h"])
846 AC_CONFIG_FILES([Makefile
849 libexec/got-read-tree/Makefile
850 libexec/got-fetch-pack/Makefile
851 libexec/got-index-pack/Makefile
852 libexec/got-read-blob/Makefile
853 libexec/got-read-commit/Makefile
854 libexec/got-read-gitconfig/Makefile
855 libexec/got-read-gotconfig/Makefile
856 libexec/got-read-object/Makefile
857 libexec/got-read-pack/Makefile
858 libexec/got-read-patch/Makefile
859 libexec/got-read-tag/Makefile
860 libexec/got-send-pack/Makefile
865 Makefile.common:Makefile.common.in])
868 executables="$(eval echo ${exec_prefix}/bin)"
869 helpers="$(eval echo ${libexecdir})"
870 manpages="$(eval echo ${mandir})"
873 Configured got-portable with:
878 Executables: ${executables}
882 Man pages: ${manpages}