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_DEFINE_UNQUOTED(VERSION, "$VERSION")
15 AC_USE_SYSTEM_EXTENSIONS
18 AC_CONFIG_SUBDIRS([template])
20 # When CFLAGS isn't set at this stage and gcc is detected by the macro below,
21 # autoconf will automatically use CFLAGS="-O2 -g". Prevent that by using an
25 # Save user CPPFLAGS, CFLAGS and LDFLAGS. We need to change them because
26 # AC_CHECK_HEADER doesn't give us any other way to update the include
27 # paths. But for Makefile.am we want to use AM_CPPFLAGS and friends.
28 SAVED_CFLAGS="$CFLAGS"
29 SAVED_CPPFLAGS="$CPPFLAGS"
30 SAVED_LDFLAGS="$LDFLAGS"
35 # Checks for programs.
41 if test -z "$YACC"; then
49 if test "$YACC_OVERRIDE" = "yes"; then
50 AC_MSG_NOTICE("Using YACC set from environment: $YACC")
53 # Checks for header files.
84 if test "x$ac_cv_header_sha256_h" = xyes; then
85 AC_DEFINE(HAVE_SHA256)
88 AM_CONDITIONAL([HAVE_SHA2], [test "x$ac_cv_header_sha2_h" = xyes])
90 # Check for SHA1_DIGEST_LENGTH
91 AC_CHECK_DECL([SHA1_DIGEST_LENGTH],
92 [AC_DEFINE(HAVE_SHA1_AS_SHA1)],
94 dnl maybe sha.h is available
95 AC_CHECK_DECL([SHA_DIGEST_LENGTH],
96 [AC_DEFINE(HAVE_SHA_AS_SHA1)],
101 #include <sys/types.h>
105 # Checks for typ edefs, structures, and compiler characteristics.
106 AC_CHECK_HEADER_STDBOOL
119 # Check for ifgroupreq which is only available on BSD.
120 AC_CHECK_TYPES([struct ifgroupreq])
122 # Check for sockaddr_storage. On some systems, ss_len is filled out, although
123 # this is not mandated by POSIX, and hence systems such as linux, don't have
125 AC_CHECK_TYPES([struct sockaddr_storage], [], [], [
126 #include <sys/types.h>
127 #include <sys/socket.h>
130 # Same thing as sockaddr_storage above, only now check if the member exists in
131 # the struct as well.
132 AC_CHECK_MEMBERS([struct sockaddr_storage.ss_len], , ,
134 #include <netinet/in.h>
135 #include <sys/socket.h> ]
138 AC_CHECK_MEMBERS([struct sockaddr.sa_len], , ,
140 #include <netinet/in.h>
141 #include <sys/socket.h> ]
144 # Both checks above will result in:
146 # HAVE_STRUCT_SOCKADDR_AS_LEN
149 # Either being defined or not.
151 # Look for library needed for flock.
152 AC_SEARCH_LIBS(flock, bsd)
154 # Checks for library functions.
157 AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK
198 AM_CONDITIONAL([HAVE_SETPROCTITLE], [test "x$ac_cv_func_setproctitle" = xyes])
199 AM_CONDITIONAL([HAVE_SETRESGID], [test "x$ac_cv_func_setresgid" = xyes])
200 AM_CONDITIONAL([HAVE_SETRESUID], [test "x$ac_cv_func_setresuid" = xyes])
203 AC_CHECK_FUNCS([SipHash])
204 AM_CONDITIONAL([HAVE_SIPHASH], [test "x$ac_cv_func_SipHash" = xyes])
206 # Check for functions with a compatibility implementation.
225 # Always use our getopt because 1) glibc's doesn't enforce argument order 2)
226 # musl does not set optarg to NULL for flags without arguments (although it is
227 # not required to, but it is helpful) 3) there are probably other weird
231 # Check the platform we're compiling on.
232 AC_MSG_CHECKING(platform)
239 AC_MSG_RESULT(freebsd)
243 AC_MSG_RESULT(darwin)
247 AC_MSG_RESULT(netbsd)
251 AC_MSG_RESULT(openbsd)
255 AC_MSG_RESULT(dragonfly)
256 PLATFORM=dragonflybsd
259 AC_MSG_RESULT(unknown)
264 AM_CONDITIONAL([HOST_FREEBSD], [test "$PLATFORM" = "freebsd"])
265 AM_CONDITIONAL([HOST_LINUX], [test "$PLATFORM" = "linux"])
266 AM_CONDITIONAL([HOST_DARWIN], [test "$PLATFORM" = "darwin"])
267 AM_CONDITIONAL([HOST_NETBSD], [test "$PLATFORM" = "netbsd"])
268 AM_CONDITIONAL([HOST_OPENBSD], [test "$PLATFORM" = "openbsd"])
269 AM_CONDITIONAL([HOST_DRAGONFLYBSD], [test "$PLATFORM" = "dragonflybsd"])
272 if test "YACC_OVERRIDE" = "yes" && test -n "$YACC" \
273 && ! command -v "$YACC" >/dev/null 2>&1; then
274 AC_MSG_ERROR("yacc not found: $YACC")
277 if test x"$PLATFORM" = "xdarwin"; then
278 # Check for and/or set HOMEBREW_PREFIX. brew is a common way of
279 # installing applications. The other is MacPorts.
281 # Before Apple Silicon existed (M1 onward), the paths for applications
282 # installed via homebrew was typically /usr/local. However, with M1
283 # onward, this changed to a different path.
285 # Rather than hardcode this, check for HOMEBREW_PREFIX in the
286 # environment if it's already set, and use it. Otherwise, check for
287 # brew(1) and use that. If that fails, default to /usr/local
289 # This also means that MacPorts should continue to work.
291 # But with MacPorts, we should also check --prefix, and use that if it
294 # In both cases, the variable HOMEBREW_PREFIX is used for both.
298 if test -z "$HOMEBREW_PREFIX" -o "$HOMEBREW_PREFIX" = "NONE"; then
299 # HOMEBREW_PREFIX not set, check for brew(1)
300 if command -v brew >/dev/null 2>&1; then
301 AC_MSG_NOTICE("HOMEBREW_PREFIX set via 'brew --prefix'")
302 export HOMEBREW_PREFIX="$(brew --prefix)"
305 if test -z "$HOMEBREW_PREFIX" -o "$HOMEBREW_PREFIX" = "NONE"
308 if test -z "${prefix}" -o "${prefix}" = "NONE"; then
309 export HOMEBREW_PREFIX="/usr/local"
310 HB_PREFIX="/usr/local"
311 AC_MSG_NOTICE("HOMEBREW_PREFIX defaulting to $HB_PREFIX")
313 HB_PREFIX="$(eval echo ${prefix})"
314 if test "$HB_PREFIX" = "NONE"; then
315 HB_PREFIX="/opt/local"
317 AC_MSG_NOTICE("HOMEBREW_PREFIX using --prefix")
319 export HOMEBREW_PREFIX="$HB_PREFIX"
324 AC_MSG_NOTICE("HOMEBREW_PREFIX determined as: $HOMEBREW_PREFIX")
326 if test "$YACC_OVERRIDE" = "no" && \
327 ! test -x "${HOMEBREW_PREFIX}/opt/bison/bin/bison"; then
329 "***********************************************************
330 GNU Bison not found: ${HOMEBREW_PREFIX}/opt/bison/bin/bison
331 ***********************************************************
333 Falling back to checking either /usr/local or \${prefix}"
337 AC_MSG_WARN("Trying ${HB_PREFIX}/opt/bison/bin/bison")
338 if test -x "${HB_PREFIX}/opt/bison/bin/bison"; then
339 export HOMEBREW_PREFIX="/usr/local"
341 GNUBISON="${HB_PREFIX}/opt/bison/bin/bison"
344 if test "$FOUND_BISON" = "no"; then
345 HB_PREFIX="/opt/local"
346 AC_MSG_WARN("Trying ${HB_PREFIX}/bin/bison")
348 if test -x "${HB_PREFIX}/bin/bison"; then
349 export HOMEBREW_PREFIX="${HB_PREFIX}"
350 GNUBISON="${HB_PREFIX}/bin/bison"
356 GNUBISON="${HOMEBREW_PREFIX}/opt/bison/bin/bison"
359 if test "$FOUND_BISON" = "no" && test "$YACC_OVERRIDE" = "no"; then
360 AC_MSG_ERROR("*** Couldn't find GNU BISON ***")
363 # Override YACC here to point to the GNU version of bison.
364 if test "$YACC_OVERRIDE" = "yes"; then
365 export YACC="$YACC -y"
367 AC_MSG_NOTICE("Found GNU Bison as: $GNUBISON")
368 export YACC="${GNUBISON} -y"
370 export LDFLAGS="-L${HOMEBREW_PREFIX}/opt/ncurses/lib -L${HOMEBREW_PREFIX}/opt/openssl@3/lib $LDFLAGS"
371 export CPPFLAGS="-I${HOMEBREW_PREFIX}/opt/ncurses/include -I${HOMEBREW_PREFIX}/opt/openssl@3/include $CPPFLAGS"
372 export PKG_CONFIG_PATH="${HOMEBREW_PREFIX}/opt/ncurses/lib/pkgconfig"
373 export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:${HOMEBREW_PREFIX}/opt/openssl@3/lib/pkgconfig"
376 # Landlock detection.
377 AC_MSG_CHECKING([for landlock])
378 AM_CONDITIONAL([HAVE_LINUX_LANDLOCK],
379 [test "x$ac_cv_header_linux_landlock_h" = "xyes"])
380 if test "x$ac_cv_header_linux_landlock_h" = "xyes"; then
386 # Clang sanitizers wrap reallocarray even if it isn't available on the target
387 # system. When compiled it always returns NULL and crashes the program. To
388 # detect this we need a more complicated test.
389 AC_MSG_CHECKING([for working reallocarray])
390 AC_RUN_IFELSE([AC_LANG_PROGRAM(
391 [#include <stdlib.h>],
392 [return (reallocarray(NULL, 1, 1) == NULL);]
395 [AC_LIBOBJ(reallocarray) AC_MSG_RESULT([no])],
396 [AC_LIBOBJ(reallocarray) AC_MSG_RESULT([no])]
398 AC_MSG_CHECKING([for working recallocarray])
399 AC_RUN_IFELSE([AC_LANG_PROGRAM(
400 [#include <stdlib.h>],
401 [return (recallocarray(NULL, 1, 1, 1) == NULL);]
404 [AC_LIBOBJ(recallocarray) AC_MSG_RESULT([no])],
405 [AC_LIBOBJ(recallocarray) AC_MSG_RESULT([no])]
408 # Look for imsg_init in libutil.
409 AC_SEARCH_LIBS(imsg_init, util, found_imsg_init=yes, found_imsg_init=no)
410 AM_CONDITIONAL([HAVE_IMSG], [test "x$found_imsg_init" = "xyes"])
411 if test "x$found_imsg_init" = xno; then
413 AC_LIBOBJ(imsg-buffer)
416 # libevent (for gotwebd). Lifted from tmux.
417 # Look for libevent. Try libevent_core or libevent with pkg-config first then
418 # look for the library.
421 [libevent_core >= 2],
423 AM_CPPFLAGS="$LIBEVENT_CORE_CFLAGS $AM_CPPFLAGS"
424 CPPFLAGS="$AM_CPPFLAGS $SAVED_CPPFLAGS"
425 LIBS="$LIBEVENT_CORE_LIBS $LIBS"
430 if test x$found_libevent = xno; then
435 AM_CPPFLAGS="$LIBEVENT_CFLAGS $AM_CPPFLAGS"
436 CPPFLAGS="$AM_CPPFLAGS $SAVED_CPPFLAGS"
437 LIBS="$LIBEVENT_LIBS $LIBS"
443 if test x$found_libevent = xno; then
446 [event_core event event-1.4],
453 AC_DEFINE(HAVE_EVENT2_EVENT_H),
457 AC_DEFINE(HAVE_EVENT_H),
462 if test "x$found_libevent" = xno; then
463 AC_MSG_ERROR("libevent not found")
466 # libcrypto (via libssl for SHA information)
471 AM_CFLAGS="$LIBCRYPTO_CFLAGS $AM_CFLAGS"
472 CFLAGS="$AM_CFLAGS $SAVED_CFLAGS"
473 LIBS="$LIBCRYPTO_LIBS $LIBS"
481 if test "x$found_libcrypto" = "xyes"; then
482 AC_DEFINE(HAVE_LIBCRYPTO)
485 AC_SEARCH_LIBS(uuid_create, , AC_DEFINE(HAVE_BSD_UUID))
486 AC_SEARCH_LIBS(uuid_create, found_uuid=no, found_uuid=yes)
487 AC_SEARCH_LIBS(mergesort, , AC_DEFINE(HAVE_BSD_MERGESORT))
489 # Don't define HAVE_BSD_UUID on darwin (Apple) as this breaks the BSD API.
490 # Instead, use the UUID implementation wrapper that's in compat/ plus uuid
492 if test "x$found_uuid" = "xyes" -a "x$PLATFORM" != "darwin"; then
493 AC_DEFINE(HAVE_BSD_UUID)
499 AM_CFLAGS="$LIBUUID_CFLAGS $AM_CFLAGS"
500 CFLAGS="$AM_CFLAGS $SAVED_CFLAGS"
501 LIBS="$LIBUUID_LIBS $LIBS"
509 if test "x$found_libuuid" = "xno"; then
517 if test "x$found_libuuid" = "xno"; then
518 AC_MSG_ERROR("*** couldn't find uuid ***")
525 AM_CFLAGS="$ZLIB_CFLAGS $AM_CFLAGS"
526 CFLAGS="$AM_CFLAGS $SAVED_CFLAGS"
527 LIBS="$ZLIB_LIBS $LIBS"
535 if test "x$found_zlib" = "xno"; then
542 if test "x$found_zlib" = "xno"; then
543 AC_MSG_ERROR("*** couldn't find zlib ***")
546 if test "$PLATFORM" = "linux"; then
551 AM_CFLAGS="$LIBMD_CFLAGS $AM_CFLAGS"
552 CFLAGS="$AM_CFLAGS $SAVED_CFLAGS"
553 LIBS="$LIBMD_LIBS $LIBS"
556 AC_MSG_ERROR("*** couldn't find libmd via pkg-config")
563 AM_CFLAGS="$LIBBSD_CFLAGS $AM_CFLAGS"
564 CFLAGS="$AM_CFLAGS $SAVED_CFLAGS"
565 LIBS="$LIBBSD_LIBS $LIBS"
566 AC_DEFINE(HAVE_LIBBSD)
569 AC_MSG_ERROR("*** couldn't find libbsd-overlay via pkg-config")
575 # Look for a suitable queue.h. We hope libbsd is enough, but that is missing
581 [#include <sys/queue.h>]
587 [#include <sys/queue.h>]
593 [#include <sys/queue.h>]
596 if test "x$found_queue_h" = xyes; then
597 AC_DEFINE(HAVE_QUEUE_H)
599 AC_MSG_ERROR("*** sys/queue.h missing key defines ***)
604 found_sys_tree_h=yes,
606 [#include <sys/tree.h>]
609 if test "x$found_sys_tree_h" = xyes; then
610 AC_DEFINE(HAVE_TREE_H)
612 AC_MSG_NOTICE("Using compat/tree.h")
615 # Look for __progname.
616 AC_MSG_CHECKING(for __progname)
617 AC_LINK_IFELSE([AC_LANG_SOURCE(
621 extern char *__progname;
623 const char *cp = __progname;
628 [AC_DEFINE(HAVE___PROGNAME) AC_MSG_RESULT(yes)],
652 if test "x$found_panel" = "xno"; then
653 AC_CHECK_LIB(panelw, update_panels, [],
654 AC_MSG_ERROR([ "*** panelw not found for ncurses. ***"]),
658 LIBPANELW_LIBS="-lpanelw"
667 if test "x$found_ncurses" = xyes; then
668 AM_CFLAGS="$LIBNCURSES_CFLAGS $LIBTINFO_CFLAGS $LIBPANELW_CFLAGS $AM_CFLAGS"
669 CFLAGS="$LIBNCURSES_CFLAGS $LIBTINFO_CFLAGS $LIBPANELW_CFLAGS $CFLAGS"
670 LIBS="$LIBNCURSES_LIBS $LIBTINFO_LIBS $LIBPANELW_LIBS $LIBS"
678 if test "x$found_ncurses" = xyes; then
681 AM_CFLAGS="$LIBPANELW_CFLAGS $AM_CFLAGS"
682 CFLAGS="$LIBPANEL_CFLAGS $CFLAGS"
683 LIBS="$LIBS -lncursesw $LIBPANELW_LIBS",
688 if test "x$found_ncurses" = xyes; then
689 AC_DEFINE(HAVE_NCURSES_H)
691 # No ncurses, try curses.
702 if test "x$found_curses" = xyes; then
703 AM_CFLAGS="$LIBPANELW_CFLAGS $AM_CFLAGS"
704 CFLAGS="$LIBPANEL_CFLAGS $CFLAGS"
705 LIBS="$LIBS -lcursesw $LIBPANELW_LIBS"
706 AC_DEFINE(HAVE_CURSES_H)
708 AC_MSG_ERROR("curses not found")
712 # Save our CFLAGS/CPPFLAGS/LDFLAGS for the Makefile and restore the old user
714 AC_SUBST(AM_CPPFLAGS)
715 CPPFLAGS="$SAVED_CPPFLAGS"
717 CFLAGS="$SAVED_CFLAGS"
719 LDFLAGS="$SAVED_LDFLAGS"
721 AC_CONFIG_FILES([Makefile
724 libexec/got-read-tree/Makefile
725 libexec/got-fetch-pack/Makefile
726 libexec/got-index-pack/Makefile
727 libexec/got-read-blob/Makefile
728 libexec/got-read-commit/Makefile
729 libexec/got-read-gitconfig/Makefile
730 libexec/got-read-gotconfig/Makefile
731 libexec/got-read-object/Makefile
732 libexec/got-read-pack/Makefile
733 libexec/got-read-patch/Makefile
734 libexec/got-read-tag/Makefile
735 libexec/got-send-pack/Makefile
740 Makefile.common:Makefile.common.in])
743 executables="$(eval echo ${exec_prefix}/bin)"
744 helpers="$(eval echo ${libexecdir})"
745 manpages="$(eval echo ${mandir})"
748 Configured got-portable with:
753 Executables: ${executables}
756 Man pages: ${manpages}