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 # Override gotd's empty_path location.
28 AC_ARG_WITH([gotd-empty-path],
29 [AS_HELP_STRING([--with-gotd-empty-path],
32 [GOTD_EMPTY_PATHC=$withval]
34 AC_SUBST(GOTD_EMPTY_PATHC)
36 # Override where git's libexec helpers are located for gitwrapper.
37 AC_ARG_WITH([gitwrapper-git-libexec-path],
38 [AS_HELP_STRING([--with-gitwrapper-git-libexec-path],
39 [git libexec path for gitwrapper])
41 [GITWRAPPER_LIBEXEC_PATHC=$withval]
43 AC_SUBST(GITWRAPPER_LIBEXEC_PATHC)
45 # When CFLAGS isn't set at this stage and gcc is detected by the macro below,
46 # autoconf will automatically use CFLAGS="-O2 -g". Prevent that by using an
50 # Save user CPPFLAGS, CFLAGS and LDFLAGS. We need to change them because
51 # AC_CHECK_HEADER doesn't give us any other way to update the include
52 # paths. But for Makefile.am we want to use AM_CPPFLAGS and friends.
53 SAVED_CFLAGS="$CFLAGS"
54 SAVED_CPPFLAGS="$CPPFLAGS"
55 SAVED_LDFLAGS="$LDFLAGS"
60 # Checks for programs.
66 if test -z "$YACC"; then
74 if test "$YACC_OVERRIDE" = "yes"; then
75 AC_MSG_NOTICE("Using YACC set from environment: $YACC")
78 # Checks for header files.
113 AC_CHECK_DECL([F_CLOSEM],
115 AC_DEFINE([HAVE_FCNTL_CLOSEM], [1],
116 [Use F_CLOSEM fcntl for closefrom]),
123 AC_MSG_CHECKING([for /proc/pid/fd directory])
124 if test -d "/proc/$$/fd" ; then
125 AC_DEFINE([HAVE_PROC_PID], [1], [Define if you have /proc/$pid/fd])
131 AC_MSG_CHECKING([whether program_invocation_short_name is defined])
132 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
135 program_invocation_short_name = "test";
138 AC_DEFINE([HAVE_PROGRAM_INVOCATION_SHORT_NAME], [1],
139 [Define if program_invocation_short_name is defined])
144 # Look for prctl(PR_SET_NAME).
147 [AC_DEFINE([HAVE_PR_SET_NAME], [1], [Define if PR_SET_NAME is defined])],
149 [#include <sys/prctl.h>]
152 AM_CONDITIONAL([HAVE_SHA2], [test "x$ac_cv_header_sha2_h" = xyes])
154 AC_CACHE_CHECK([whether getopt has optreset support],
155 ac_cv_have_getopt_optreset, [
156 AC_LINK_IFELSE([AC_LANG_PROGRAM([[ #include <getopt.h> ]],
157 [[ extern int optreset; optreset = 0; ]])],
158 [ ac_cv_have_getopt_optreset="yes" ],
159 [ ac_cv_have_getopt_optreset="no"
163 AM_CONDITIONAL([HAVE_GETOPT], [test "x$ac_cv_have_getopt_optreset" = "xyes"])
164 if test "x$ac_cv_have_getopt_optreset" = "xyes" ; then
165 AC_DEFINE([HAVE_GETOPT_OPTRESET], [1],
166 [Define if your getopt(3) defines and uses optreset])
169 AC_CHECK_MEMBERS([struct pollfd.fd], [], [], [[
170 #include <sys/types.h>
174 #ifdef HAVE_SYS_POLL_H
175 #include <sys/poll.h>
179 # Checks for typ edefs, structures, and compiler characteristics.
180 AC_CHECK_HEADER_STDBOOL
193 # Check for ifgroupreq which is only available on BSD.
194 AC_CHECK_TYPES([struct ifgroupreq])
196 # Check for sockaddr_storage. On some systems, ss_len is filled out, although
197 # this is not mandated by POSIX, and hence systems such as linux, don't have
199 AC_CHECK_TYPES([struct sockaddr_storage], [], [], [
200 #include <sys/types.h>
201 #include <sys/socket.h>
204 # Same thing as sockaddr_storage above, only now check if the member exists in
205 # the struct as well.
206 AC_CHECK_MEMBERS([struct sockaddr_storage.ss_len], , ,
208 #include <netinet/in.h>
209 #include <sys/socket.h> ]
212 AC_CHECK_MEMBERS([struct sockaddr.sa_len], , ,
214 #include <netinet/in.h>
215 #include <sys/socket.h> ]
218 # Both checks above will result in:
220 # HAVE_STRUCT_SOCKADDR_AS_LEN
223 # Either being defined or not.
225 # Look for library needed for flock.
226 AC_SEARCH_LIBS(flock, bsd)
228 # Checks for library functions.
231 AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK
273 AM_CONDITIONAL([HAVE_SETPROCTITLE], [test "x$ac_cv_func_setproctitle" = xyes])
275 if test "x$ac_cv_func_sysconf" = xyes; then
276 AC_DEFINE([HAVE_SYSCONF], [1], [Define to 1 if sysconf() present])
280 AC_CHECK_FUNCS([SipHash])
281 AM_CONDITIONAL([HAVE_SIPHASH], [test "x$ac_cv_func_SipHash" = xyes])
283 # Check for functions with a compatibility implementation.
302 AM_CONDITIONAL([HAVE_CLOSEFROM], [test "x$ac_cv_func_closefrom" = xyes])
304 # Always use our getopt because 1) glibc's doesn't enforce argument order 2)
305 # musl does not set optarg to NULL for flags without arguments (although it is
306 # not required to, but it is helpful) 3) there are probably other weird
310 # Check for b64_ntop. If we have b64_ntop, we assume b64_pton as well.
311 AC_MSG_CHECKING(for b64_ntop)
312 AC_LINK_IFELSE([AC_LANG_PROGRAM(
314 #include <sys/types.h>
315 #include <netinet/in.h>
319 b64_ntop(NULL, 0, NULL, 0);
324 AC_MSG_RESULT($found_b64_ntop)
326 if test "x$found_b64_ntop" = xno; then
327 AC_MSG_CHECKING(for b64_ntop with -lresolv)
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"
344 if test "x$found_b64_ntop" = xno; then
345 AC_MSG_CHECKING(for b64_ntop with -lnetwork)
346 LIBS="-lresolv -lnetwork"
347 AC_LINK_IFELSE([AC_LANG_PROGRAM(
349 #include <sys/types.h>
350 #include <netinet/in.h>
354 b64_ntop(NULL, 0, NULL, 0);
359 AC_MSG_RESULT($found_b64_ntop)
360 libresolv_LIBS="$LIBS"
363 AM_CONDITIONAL([HAVE_B64], [test "x$found_b64_ntop" = xyes])
364 if test "x$found_b64_ntop" = xyes; then
365 AC_DEFINE([HAVE_B64_NTOP], [1], [define if b64_ntop is present])
366 AC_SUBST(libresolv_LIBS)
371 # Check the platform we're compiling on.
372 AC_MSG_CHECKING(platform)
379 AC_MSG_RESULT(freebsd)
383 AC_MSG_RESULT(darwin)
387 AC_MSG_RESULT(netbsd)
391 AC_MSG_RESULT(openbsd)
395 AC_MSG_RESULT(dragonfly)
396 PLATFORM=dragonflybsd
399 AC_MSG_RESULT(unknown)
404 AM_CONDITIONAL([HOST_FREEBSD], [test "$PLATFORM" = "freebsd"])
405 AM_CONDITIONAL([HOST_LINUX], [test "$PLATFORM" = "linux"])
406 AM_CONDITIONAL([HOST_DARWIN], [test "$PLATFORM" = "darwin"])
407 AM_CONDITIONAL([HOST_NETBSD], [test "$PLATFORM" = "netbsd"])
408 AM_CONDITIONAL([HOST_OPENBSD], [test "$PLATFORM" = "openbsd"])
409 AM_CONDITIONAL([HOST_DRAGONFLYBSD], [test "$PLATFORM" = "dragonflybsd"])
411 # On OpenBSD, these functions are already defined, yet looking for them in
412 # this way on OpenBSD breaks <sha2.h> inclusion.
413 # FIXME: this needs addressing.
414 if test "x$PLATFORM" != "xopenbsd"; then
423 if test "YACC_OVERRIDE" = "yes" && test -n "$YACC" \
424 && ! command -v "$YACC" >/dev/null 2>&1; then
425 AC_MSG_ERROR("yacc not found: $YACC")
428 if test x"$PLATFORM" = "xdarwin"; then
429 # Check for and/or set HOMEBREW_PREFIX. brew is a common way of
430 # installing applications. The other is MacPorts.
432 # Before Apple Silicon existed (M1 onward), the paths for applications
433 # installed via homebrew was typically /usr/local. However, with M1
434 # onward, this changed to a different path.
436 # Rather than hardcode this, check for HOMEBREW_PREFIX in the
437 # environment if it's already set, and use it. Otherwise, check for
438 # brew(1) and use that. If that fails, default to /usr/local
440 # This also means that MacPorts should continue to work.
442 # But with MacPorts, we should also check --prefix, and use that if it
445 # In both cases, the variable HOMEBREW_PREFIX is used for both.
449 if test -z "$HOMEBREW_PREFIX" -o "$HOMEBREW_PREFIX" = "NONE"; then
450 # HOMEBREW_PREFIX not set, check for brew(1)
451 if command -v brew >/dev/null 2>&1; then
452 AC_MSG_NOTICE("HOMEBREW_PREFIX set via 'brew --prefix'")
453 export HOMEBREW_PREFIX="$(brew --prefix)"
456 if test -z "$HOMEBREW_PREFIX" -o "$HOMEBREW_PREFIX" = "NONE"
459 if test -z "${prefix}" -o "${prefix}" = "NONE"; then
460 export HOMEBREW_PREFIX="/usr/local"
461 HB_PREFIX="/usr/local"
462 AC_MSG_NOTICE("HOMEBREW_PREFIX defaulting to $HB_PREFIX")
464 HB_PREFIX="$(eval echo ${prefix})"
465 if test "$HB_PREFIX" = "NONE"; then
466 HB_PREFIX="/opt/local"
468 AC_MSG_NOTICE("HOMEBREW_PREFIX using --prefix")
470 export HOMEBREW_PREFIX="$HB_PREFIX"
475 AC_MSG_NOTICE("HOMEBREW_PREFIX determined as: $HOMEBREW_PREFIX")
477 if test "$YACC_OVERRIDE" = "no" && \
478 ! test -x "${HOMEBREW_PREFIX}/opt/bison/bin/bison"; then
480 "***********************************************************
481 GNU Bison not found: ${HOMEBREW_PREFIX}/opt/bison/bin/bison
482 ***********************************************************
484 Falling back to checking either /usr/local or \${prefix}"
488 AC_MSG_WARN("Trying ${HB_PREFIX}/opt/bison/bin/bison")
489 if test -x "${HB_PREFIX}/opt/bison/bin/bison"; then
490 export HOMEBREW_PREFIX="/usr/local"
492 GNUBISON="${HB_PREFIX}/opt/bison/bin/bison"
495 if test "$FOUND_BISON" = "no"; then
496 HB_PREFIX="/opt/local"
497 AC_MSG_WARN("Trying ${HB_PREFIX}/bin/bison")
499 if test -x "${HB_PREFIX}/bin/bison"; then
500 export HOMEBREW_PREFIX="${HB_PREFIX}"
501 GNUBISON="${HB_PREFIX}/bin/bison"
507 GNUBISON="${HOMEBREW_PREFIX}/opt/bison/bin/bison"
510 if test "$FOUND_BISON" = "no" && test "$YACC_OVERRIDE" = "no"; then
511 AC_MSG_ERROR("*** Couldn't find GNU BISON ***")
514 # Override YACC here to point to the GNU version of bison.
515 if test "$YACC_OVERRIDE" = "yes"; then
516 export YACC="$YACC -y"
518 AC_MSG_NOTICE("Found GNU Bison as: $GNUBISON")
519 export YACC="${GNUBISON} -y"
521 export LDFLAGS="-L${HOMEBREW_PREFIX}/opt/ncurses/lib -L${HOMEBREW_PREFIX}/opt/openssl@3/lib $LDFLAGS"
522 export CPPFLAGS="-I${HOMEBREW_PREFIX}/opt/ncurses/include -I${HOMEBREW_PREFIX}/opt/openssl@3/include $CPPFLAGS"
523 export PKG_CONFIG_PATH="${HOMEBREW_PREFIX}/opt/ncurses/lib/pkgconfig"
524 export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:${HOMEBREW_PREFIX}/opt/openssl@3/lib/pkgconfig"
527 # Landlock detection.
528 AC_MSG_CHECKING([for landlock])
529 AM_CONDITIONAL([HAVE_LINUX_LANDLOCK],
530 [test "x$ac_cv_header_linux_landlock_h" = "xyes"])
531 if test "x$ac_cv_header_linux_landlock_h" = "xyes"; then
537 # Clang sanitizers wrap reallocarray even if it isn't available on the target
538 # system. When compiled it always returns NULL and crashes the program. To
539 # detect this we need a more complicated test.
540 AC_MSG_CHECKING([for working reallocarray])
541 AC_RUN_IFELSE([AC_LANG_PROGRAM(
542 [#include <stdlib.h>],
543 [return (reallocarray(NULL, 1, 1) == NULL);]
546 [AC_LIBOBJ(reallocarray) AC_MSG_RESULT([no])],
547 [AC_LIBOBJ(reallocarray) AC_MSG_RESULT([no])]
549 AC_MSG_CHECKING([for working recallocarray])
550 AC_RUN_IFELSE([AC_LANG_PROGRAM(
551 [#include <stdlib.h>],
552 [return (recallocarray(NULL, 1, 1, 1) == NULL);]
555 [AC_LIBOBJ(recallocarray) AC_MSG_RESULT([no])],
556 [AC_LIBOBJ(recallocarray) AC_MSG_RESULT([no])]
559 # Look for imsg_init in libutil.
560 AC_SEARCH_LIBS(imsg_init, util, found_imsg_init=yes, found_imsg_init=no)
561 AM_CONDITIONAL([HAVE_IMSG], [test "x$found_imsg_init" = "xyes"])
562 if test "x$found_imsg_init" = "xyes"; then
563 AC_DEFINE([HAVE_IMSG], [1], [Define to 1 if imsg is declared in libutil])
564 libutil_LIBS="$ac_cv_search_imsg_init"
565 AC_SUBST(libutil_LIBS)
568 # libevent (for gotwebd). Lifted from tmux.
569 # Look for libevent. Try libevent_core or libevent with pkg-config first then
570 # look for the library.
574 [libevent_core >= 2],
576 libevent_CFLAGS="$LIBEVENT_CORE_CFLAGS"
577 libevent_LIBS="$LIBEVENT_CORE_LIBS"
578 AC_SUBST(libevent_CFLAGS)
579 AC_SUBST(libevent_LIBS)
584 if test x$found_libevent = xno; then
589 libevent_CFLAGS="$LIBEVENT_CFLAGS"
590 libevent_LIBS="$LIBEVENT_LIBS"
591 AC_SUBST(libevent_CFLAGS)
592 AC_SUBST(libevent_LIBS)
598 if test x$found_libevent = xno; then
601 [event_core event event-1.4],
606 if test "x$found_libevent" = "xyes"; then
607 libevent_LIBS="$ac_cv_search_event_init"
608 AC_SUBST(libevent_LIBS)
612 if test x$found_libevent = xno; then
615 AC_DEFINE([HAVE_EVENT2_EVENT_H], [1], [libevent2 has event.h]),
619 AC_DEFINE([HAVE_EVENT_H], [0], [libevent]),
626 if test "x$found_libevent" = xno; then
627 AC_MSG_ERROR("libevent not found")
630 AC_CHECK_FUNC([uuid_create], [found_uuid=yes], [found_uuid=no])
632 # Don't define HAVE_BSD_UUID on darwin (Apple) as this breaks the BSD API.
633 # Instead, use the UUID implementation wrapper that's in compat/ plus uuid
635 if test "x$found_uuid" = "xyes" -a "x$PLATFORM" != "darwin"; then
636 AC_DEFINE([HAVE_BSD_UUID], [1], [BSD UUID])
642 libuuid_CFLAGS="$LIBUUID_CFLAGS"
643 libuuid_LIBS="$LIBUUID_LIBS"
644 AC_SUBST(libuuid_CFLAGS)
645 AC_SUBST(libuuid_LIBS)
653 if test "x$found_libuuid" = "xno"; then
661 if test "x$found_libuuid" = "xno"; then
662 AC_MSG_ERROR("*** couldn't find uuid ***")
669 zlib_CFLAGS="$ZLIB_CFLAGS"
670 zlib_LIBS="$ZLIB_LIBS"
671 AC_SUBST(zlib_CFLAGS)
680 if test "x$found_zlib" = "xno"; then
687 if test "x$found_zlib" = "xno"; then
688 AC_MSG_ERROR("*** couldn't find zlib ***")
691 if test "$PLATFORM" = "linux"; then
696 libbsd_CFLAGS="$LIBBSD_CFLAGS"
697 libbsd_LIBS="$LIBBSD_LIBS"
698 AC_SUBST(libbsd_CFLAGS)
699 AC_SUBST(libbsd_LIBS)
700 AC_DEFINE([HAVE_LIBBSD], [1], [BSD UUID])
703 AC_MSG_ERROR("*** couldn't find libbsd-overlay via pkg-config")
708 # Add LIBBSD_{CFLAGS,LIBS} to the environment here, as libbsd puts its
709 # header files in a non-standard location, which means the overlay for
710 # <sys/tree.h> and <sys/queue.h> won't be found.
711 CFLAGS="$CFLAGS $LIBBSD_CFLAGS"
712 LIBS="$LIBS $LIBBSD_LIBS"
718 libmd_CFLAGS="$LIBMD_CFLAGS"
719 libmd_LIBS="$LIBMD_LIBS"
720 AC_SUBST(libmd_CFLAGS)
724 CFLAGS="$CFLAGS $LIBMD_CFLAGS"
725 LIBS="$LIBS $LIBMD_LIBS"
729 # Look for a suitable queue.h. We hope libbsd is enough, but that is missing
735 [#include <sys/queue.h>]
741 [#include <sys/queue.h>]
747 [#include <sys/queue.h>]
750 if test "x$found_queue_h" = xyes; then
751 AC_DEFINE([HAVE_QUEUE_H], [1], [sys/queue.h])
753 AC_MSG_ERROR("*** sys/queue.h missing key defines ***)
758 found_sys_tree_h=yes,
760 [#include <sys/tree.h>]
763 if test "x$found_sys_tree_h" = xyes; then
764 AC_DEFINE([HAVE_TREE_H], [1], [sys/tree.h])
766 AC_MSG_NOTICE("Using compat/tree.h")
769 # Look for __progname.
770 AC_MSG_CHECKING(for __progname)
771 AC_LINK_IFELSE([AC_LANG_SOURCE(
775 extern char *__progname;
777 const char *cp = __progname;
782 [AC_DEFINE([HAVE___PROGNAME], [1], [___progname]) AC_MSG_RESULT(yes)],
789 LIBPANELW_LIBS="$LIBPANELW_LIBS"
794 if test "x$found_panel" = "xno"; then
799 LIBPANELW_LIBS="$LIBPANELW_LIBS"
806 if test "x$found_panel" = "xno"; then
811 LIBPANELW_LIBS="$LIBPANELW_LIBS"
818 if test "x$found_panel" = "xno"; then
819 AC_CHECK_LIB(panelw, update_panels, [],
820 AC_MSG_ERROR([ "*** panelw not found for ncurses. ***"]),
832 if test "x$found_ncurses" = xyes; then
833 libncurses_CFLAGS="$LIBNCURSES_CFLAGS $LIBTINFO_CFLAGS $LIBPANELW_CFLAGS"
834 libncurses_LIBS="$LIBNCURSES_LIBS $LIBTINFO_LIBS $LIBPANELW_LIBS"
835 AC_SUBST(libncurses_CFLAGS)
836 AC_SUBST(libncurses_LIBS)
843 if test "x$found_ncurses" = xyes; then
846 libncurses_CFLAGS="$LIBPANELW_CFLAGS $LIBPANEL_CFLAGS"
847 libncurses_LIBS="$LIBPANELW_LIBS -lncursesw"
848 AC_SUBST(libncurses_CFLAGS)
849 AC_SUBST(libncurses_LIBS)
853 if test "x$found_ncurses" = xyes; then
854 AC_DEFINE([HAVE_NCURSES_H], [1], [NCurses])
856 # No ncurses, try curses.
866 if test "x$found_curses" = xyes; then
867 libncurses_CFLAGS="$LIBPANELW_CFLAGS $LIBPANEL_CFLAGS"
868 libncurses_LIBS="$LIBPANELW_LIBS -lncursesw -lpanelw"
869 AC_SUBST(libncurses_CFLAGS)
870 AC_SUBST(libncurses_LIBS)
871 AC_DEFINE([HAVE_CURSES_H], [1], [Curses_h])
873 AC_MSG_ERROR("curses not found")
877 # Save our CFLAGS/CPPFLAGS/LDFLAGS for the Makefile and restore the old user
879 AC_SUBST(AM_CPPFLAGS)
880 CPPFLAGS="$SAVED_CPPFLAGS"
882 CFLAGS="$SAVED_CFLAGS"
884 LDFLAGS="$SAVED_LDFLAGS"
886 # LIBS is designed to accumulate library dependencies as checks for them are
887 # peformed, so that this can be included directly to ld(1).
889 # However, this hinders the splitting up of the library dependencies so that
890 # they're targetted just where they're needed. Flatting LIBS here ensures
891 # that this happens appropriately.
894 AH_BOTTOM([#include "got_compat2.h"])
896 AM_CONDITIONAL([GOTD_ENABLED], [test "x$enable_gotd" = xyes])
898 AC_CONFIG_FILES([Makefile
902 libexec/got-read-tree/Makefile
903 libexec/got-fetch-pack/Makefile
904 libexec/got-index-pack/Makefile
905 libexec/got-read-blob/Makefile
906 libexec/got-read-commit/Makefile
907 libexec/got-read-gitconfig/Makefile
908 libexec/got-read-gotconfig/Makefile
909 libexec/got-read-object/Makefile
910 libexec/got-read-pack/Makefile
911 libexec/got-read-patch/Makefile
912 libexec/got-read-tag/Makefile
913 libexec/got-send-pack/Makefile
918 Makefile.common:Makefile.common.in])
920 if test "x$enable_gotd" = "xyes"; then
921 AC_CONFIG_FILES([gitwrapper/Makefile])
922 AC_CONFIG_FILES([gotd/Makefile])
923 AC_CONFIG_FILES([gotsh/Makefile])
924 AC_CONFIG_FILES([gotctl/Makefile])
929 executables="$(eval echo ${exec_prefix}/bin)"
930 helpers="$(eval echo ${libexecdir})"
931 manpages="$(eval echo ${mandir})"
932 gotdep="$GOTD_EMPTY_PATHC"
933 gotgwlep="$GITWRAPPER_LIBEXEC_PATHC"
935 if test -z "$enable_gotd"; then
941 if test -z "$gotdep"; then
945 if test -z "$gotgwlep"; then
950 Configured got-portable with:
955 Executables: ${executables}
959 Empty Path: ${gotdep}
960 Gitwrapper: ${gotgwlep}
962 Man pages: ${manpages}