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_sha2_h" = xyes; then
88 if test "x$ac_cv_header_sha256_h" = xyes; then
89 AC_DEFINE(HAVE_SHA256)
92 # Check for SHA1_DIGEST_LENGTH
93 if test "x$ac_cv_header_sha_h" = xyes; then
94 AC_CHECK_DECL([SHA_DIGEST_LENGTH],
95 [AC_DEFINE(HAVE_SHA_AS_SHA1)],
96 [AC_DEFINE(NEEDS_SHA1_DEFS)],
100 if test "x$ac_cv_header_sha1_h" = xyes; then
101 AC_CHECK_DECL([SHA_DIGEST_LENGTH],
102 [AC_DEFINE(HAVE_SHA1_AS_SHA1)],
103 [AC_DEFINE(NEEDS_SHA1_DEFS)],
107 if test "x$ac_cv_header_sha_h" = xno || test "x$ac_cv_header_sha1_h" = xno
109 AC_DEFINE(NEEDS_SHA1_DEFS)
112 # Checks for typ edefs, structures, and compiler characteristics.
113 AC_CHECK_HEADER_STDBOOL
126 # Check for ifgroupreq which is only available on BSD.
127 AC_CHECK_TYPES([struct ifgroupreq])
129 # Check for sockaddr_storage. On some systems, ss_len is filled out, although
130 # this is not mandated by POSIX, and hence systems such as linux, don't have
132 AC_CHECK_TYPES([struct sockaddr_storage], [], [], [
133 #include <sys/types.h>
134 #include <sys/socket.h>
137 # Same thing as sockaddr_storage above, only now check if the member exists in
138 # the struct as well.
139 AC_CHECK_MEMBERS([struct sockaddr_storage.ss_len], , ,
141 #include <netinet/in.h>
142 #include <sys/socket.h> ]
145 AC_CHECK_MEMBERS([struct sockaddr.sa_len], , ,
147 #include <netinet/in.h>
148 #include <sys/socket.h> ]
151 # Both checks above will result in:
153 # HAVE_STRUCT_SOCKADDR_AS_LEN
156 # Either being defined or not.
158 # Look for library needed for flock.
159 AC_SEARCH_LIBS(flock, bsd)
161 # Checks for library functions.
164 AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK
205 AM_CONDITIONAL([HAVE_SETPROCTITLE], [test "x$ac_cv_func_setproctitle" = xyes])
206 AM_CONDITIONAL([HAVE_SETRESGID], [test "x$ac_cv_func_setresgid" = xyes])
207 AM_CONDITIONAL([HAVE_SETRESUID], [test "x$ac_cv_func_setresuid" = xyes])
210 AC_CHECK_FUNCS([SipHash])
211 AM_CONDITIONAL([HAVE_SIPHASH], [test "x$ac_cv_func_SipHash" = xyes])
213 # Check for functions with a compatibility implementation.
232 # Always use our getopt because 1) glibc's doesn't enforce argument order 2)
233 # musl does not set optarg to NULL for flags without arguments (although it is
234 # not required to, but it is helpful) 3) there are probably other weird
238 # Check the platform we're compiling on.
239 AC_MSG_CHECKING(platform)
246 AC_MSG_RESULT(freebsd)
250 AC_MSG_RESULT(darwin)
254 AC_MSG_RESULT(netbsd)
258 AC_MSG_RESULT(dragonfly)
259 PLATFORM=dragonflybsd
262 AC_MSG_RESULT(unknown)
267 AM_CONDITIONAL([HOST_FREEBSD], [test "$PLATFORM" = "freebsd"])
268 AM_CONDITIONAL([HOST_LINUX], [test "$PLATFORM" = "linux"])
269 AM_CONDITIONAL([HOST_DARWIN], [test "$PLATFORM" = "darwin"])
270 AM_CONDITIONAL([HOST_NETBSD], [test "$PLATFORM" = "netbsd"])
271 AM_CONDITIONAL([HOST_DRAGONFLYBSD], [test "$PLATFORM" = "dragonflybsd"])
274 if test "YACC_OVERRIDE" = "yes" && test -n "$YACC" \
275 && ! command -v "$YACC" >/dev/null 2>&1; then
276 AC_MSG_ERROR("yacc not found: $YACC")
279 if test x"$PLATFORM" = "xdarwin"; then
280 # Check for and/or set HOMEBREW_PREFIX. brew is a common way of
281 # installing applications. The other is MacPorts.
283 # Before Apple Silicon existed (M1 onward), the paths for applications
284 # installed via homebrew was typically /usr/local. However, with M1
285 # onward, this changed to a different path.
287 # Rather than hardcode this, check for HOMEBREW_PREFIX in the
288 # environment if it's already set, and use it. Otherwise, check for
289 # brew(1) and use that. If that fails, default to /usr/local
291 # This also means that MacPorts should continue to work.
293 # But with MacPorts, we should also check --prefix, and use that if it
296 # In both cases, the variable HOMEBREW_PREFIX is used for both.
300 if test -z "$HOMEBREW_PREFIX" -o "$HOMEBREW_PREFIX" = "NONE"; then
301 # HOMEBREW_PREFIX not set, check for brew(1)
302 if command -v brew >/dev/null 2>&1; then
303 AC_MSG_NOTICE("HOMEBREW_PREFIX set via 'brew --prefix'")
304 export HOMEBREW_PREFIX="$(brew --prefix)"
307 if test -z "$HOMEBREW_PREFIX" -o "$HOMEBREW_PREFIX" = "NONE"
310 if test -z "${prefix}" -o "${prefix}" = "NONE"; then
311 export HOMEBREW_PREFIX="/usr/local"
312 HB_PREFIX="/usr/local"
313 AC_MSG_NOTICE("HOMEBREW_PREFIX defaulting to $HB_PREFIX")
315 HB_PREFIX="$(eval echo ${prefix})"
316 if test "$HB_PREFIX" = "NONE"; then
317 HB_PREFIX="/opt/local"
319 AC_MSG_NOTICE("HOMEBREW_PREFIX using --prefix")
321 export HOMEBREW_PREFIX="$HB_PREFIX"
326 AC_MSG_NOTICE("HOMEBREW_PREFIX determined as: $HOMEBREW_PREFIX")
328 if test "$YACC_OVERRIDE" = "no" && \
329 ! test -x "${HOMEBREW_PREFIX}/opt/bison/bin/bison"; then
331 "***********************************************************
332 GNU Bison not found: ${HOMEBREW_PREFIX}/opt/bison/bin/bison
333 ***********************************************************
335 Falling back to checking either /usr/local or \${prefix}"
339 AC_MSG_WARN("Trying ${HB_PREFIX}/opt/bison/bin/bison")
340 if test -x "${HB_PREFIX}/opt/bison/bin/bison"; then
341 export HOMEBREW_PREFIX="/usr/local"
343 GNUBISON="${HB_PREFIX}/opt/bison/bin/bison"
346 if test "$FOUND_BISON" = "no"; then
347 HB_PREFIX="/opt/local"
348 AC_MSG_WARN("Trying ${HB_PREFIX}/bin/bison")
350 if test -x "${HB_PREFIX}/bin/bison"; then
351 export HOMEBREW_PREFIX="${HB_PREFIX}"
352 GNUBISON="${HB_PREFIX}/bin/bison"
358 GNUBISON="${HOMEBREW_PREFIX}/opt/bison/bin/bison"
361 if test "$FOUND_BISON" = "no" && test "$YACC_OVERRIDE" = "no"; then
362 AC_MSG_ERROR("*** Couldn't find GNU BISON ***")
365 # Override YACC here to point to the GNU version of bison.
366 if test "$YACC_OVERRIDE" = "yes"; then
367 export YACC="$YACC -y"
369 AC_MSG_NOTICE("Found GNU Bison as: $GNUBISON")
370 export YACC="${GNUBISON} -y"
372 export LDFLAGS="-L${HOMEBREW_PREFIX}/opt/ncurses/lib -L${HOMEBREW_PREFIX}/opt/openssl@3/lib $LDFLAGS"
373 export CPPFLAGS="-I${HOMEBREW_PREFIX}/opt/ncurses/include -I${HOMEBREW_PREFIX}/opt/openssl@3/include $CPPFLAGS"
374 export PKG_CONFIG_PATH="${HOMEBREW_PREFIX}/opt/ncurses/lib/pkgconfig"
375 export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:${HOMEBREW_PREFIX}/opt/openssl@3/lib/pkgconfig"
378 # Landlock detection.
379 AC_MSG_CHECKING([for landlock])
380 AM_CONDITIONAL([HAVE_LINUX_LANDLOCK],
381 [test "x$ac_cv_header_linux_landlock_h" = "xyes"])
382 if test "x$ac_cv_header_linux_landlock_h" = "xyes"; then
388 # Clang sanitizers wrap reallocarray even if it isn't available on the target
389 # system. When compiled it always returns NULL and crashes the program. To
390 # detect this we need a more complicated test.
391 AC_MSG_CHECKING([for working reallocarray])
392 AC_RUN_IFELSE([AC_LANG_PROGRAM(
393 [#include <stdlib.h>],
394 [return (reallocarray(NULL, 1, 1) == NULL);]
397 [AC_LIBOBJ(reallocarray) AC_MSG_RESULT([no])],
398 [AC_LIBOBJ(reallocarray) AC_MSG_RESULT([no])]
400 AC_MSG_CHECKING([for working recallocarray])
401 AC_RUN_IFELSE([AC_LANG_PROGRAM(
402 [#include <stdlib.h>],
403 [return (recallocarray(NULL, 1, 1, 1) == NULL);]
406 [AC_LIBOBJ(recallocarray) AC_MSG_RESULT([no])],
407 [AC_LIBOBJ(recallocarray) AC_MSG_RESULT([no])]
410 # Look for imsg_init in libutil.
411 AC_SEARCH_LIBS(imsg_init, util, found_imsg_init=yes, found_imsg_init=no)
412 AM_CONDITIONAL([HAVE_IMSG], [test "x$found_imsg_init" = "xyes"])
413 if test "x$found_imsg_init" = xno; then
415 AC_LIBOBJ(imsg-buffer)
418 # libevent (for gotwebd). Lifted from tmux.
419 # Look for libevent. Try libevent_core or libevent with pkg-config first then
420 # look for the library.
423 [libevent_core >= 2],
425 AM_CPPFLAGS="$LIBEVENT_CORE_CFLAGS $AM_CPPFLAGS"
426 CPPFLAGS="$AM_CPPFLAGS $SAVED_CPPFLAGS"
427 LIBS="$LIBEVENT_CORE_LIBS $LIBS"
432 if test x$found_libevent = xno; then
437 AM_CPPFLAGS="$LIBEVENT_CFLAGS $AM_CPPFLAGS"
438 CPPFLAGS="$AM_CPPFLAGS $SAVED_CPPFLAGS"
439 LIBS="$LIBEVENT_LIBS $LIBS"
445 if test x$found_libevent = xno; then
448 [event_core event event-1.4],
455 AC_DEFINE(HAVE_EVENT2_EVENT_H),
459 AC_DEFINE(HAVE_EVENT_H),
464 if test "x$found_libevent" = xno; then
465 AC_MSG_ERROR("libevent not found")
468 # libcrypto (via libssl for SHA information)
473 AM_CFLAGS="$LIBCRYPTO_CFLAGS $AM_CFLAGS"
474 CFLAGS="$AM_CFLAGS $SAVED_CFLAGS"
475 LIBS="$LIBCRYPTO_LIBS $LIBS"
483 if test "x$found_libcrypto" = "xyes"; then
484 AC_DEFINE(HAVE_LIBCRYPTO)
487 AC_SEARCH_LIBS(uuid_create, , AC_DEFINE(HAVE_BSD_UUID))
488 AC_SEARCH_LIBS(uuid_create, found_uuid=no, found_uuid=yes)
489 AC_SEARCH_LIBS(mergesort, , AC_DEFINE(HAVE_BSD_MERGESORT))
491 # Don't define HAVE_BSD_UUID on darwin (Apple) as this breaks the BSD API.
492 # Instead, use the UUID implementation wrapper that's in compat/ plus uuid
494 if test "x$found_uuid" = "xyes" -a "x$PLATFORM" != "darwin"; then
495 AC_DEFINE(HAVE_BSD_UUID)
501 AM_CFLAGS="$LIBUUID_CFLAGS $AM_CFLAGS"
502 CFLAGS="$AM_CFLAGS $SAVED_CFLAGS"
503 LIBS="$LIBUUID_LIBS $LIBS"
511 if test "x$found_libuuid" = "xno"; then
519 if test "x$found_libuuid" = "xno"; then
520 AC_MSG_ERROR("*** couldn't find uuid ***")
527 AM_CFLAGS="$ZLIB_CFLAGS $AM_CFLAGS"
528 CFLAGS="$AM_CFLAGS $SAVED_CFLAGS"
529 LIBS="$ZLIB_LIBS $LIBS"
537 if test "x$found_zlib" = "xno"; then
544 if test "x$found_zlib" = "xno"; then
545 AC_MSG_ERROR("*** couldn't find zlib ***")
548 if test "$PLATFORM" = "linux"; then
553 AM_CFLAGS="$LIBMD_CFLAGS $AM_CFLAGS"
554 CFLAGS="$AM_CFLAGS $SAVED_CFLAGS"
555 LIBS="$LIBMD_LIBS $LIBS"
558 AC_MSG_ERROR("*** couldn't find libmd via pkg-config")
565 AM_CFLAGS="$LIBBSD_CFLAGS $AM_CFLAGS"
566 CFLAGS="$AM_CFLAGS $SAVED_CFLAGS"
567 LIBS="$LIBBSD_LIBS $LIBS"
569 AC_DEFINE(HAVE_LIBBSD)
572 AC_MSG_ERROR("*** couldn't find libbsd-overlay via pkg-config")
578 # Look for a suitable queue.h. We hope libbsd is enough, but that is missing
584 [#include <sys/queue.h>]
590 [#include <sys/queue.h>]
596 [#include <sys/queue.h>]
599 if test "x$found_queue_h" = xyes; then
600 AC_DEFINE(HAVE_QUEUE_H)
602 AC_MSG_ERROR("*** sys/queue.h missing key defines ***)
607 found_sys_tree_h=yes,
609 [#include <sys/tree.h>]
612 if test "x$found_sys_tree_h" = xyes; then
613 AC_DEFINE(HAVE_TREE_H)
615 AC_MSG_NOTICE("Using compat/tree.h")
618 # Look for __progname.
619 AC_MSG_CHECKING(for __progname)
620 AC_LINK_IFELSE([AC_LANG_SOURCE(
624 extern char *__progname;
626 const char *cp = __progname;
631 [AC_DEFINE(HAVE___PROGNAME) AC_MSG_RESULT(yes)],
655 if test "x$found_panel" = "xno"; then
656 AC_CHECK_LIB(panelw, update_panels, [],
657 AC_MSG_ERROR([ "*** panelw not found for ncurses. ***"]),
661 LIBPANELW_LIBS="-lpanelw"
670 if test "x$found_ncurses" = xyes; then
671 AM_CFLAGS="$LIBNCURSES_CFLAGS $LIBTINFO_CFLAGS $LIBPANELW_CFLAGS $AM_CFLAGS"
672 CFLAGS="$LIBNCURSES_CFLAGS $LIBTINFO_CFLAGS $LIBPANELW_CFLAGS $CFLAGS"
673 LIBS="$LIBNCURSES_LIBS $LIBTINFO_LIBS $LIBPANELW_LIBS $LIBS"
681 if test "x$found_ncurses" = xyes; then
684 AM_CFLAGS="$LIBPANELW_CFLAGS $AM_CFLAGS"
685 CFLAGS="$LIBPANEL_CFLAGS $CFLAGS"
686 LIBS="$LIBS -lncursesw $LIBPANELW_LIBS",
691 if test "x$found_ncurses" = xyes; then
692 AC_DEFINE(HAVE_NCURSES_H)
694 # No ncurses, try curses.
705 if test "x$found_curses" = xyes; then
706 AM_CFLAGS="$LIBPANELW_CFLAGS $AM_CFLAGS"
707 CFLAGS="$LIBPANEL_CFLAGS $CFLAGS"
708 LIBS="$LIBS -lcursesw $LIBPANELW_LIBS"
709 AC_DEFINE(HAVE_CURSES_H)
711 AC_MSG_ERROR("curses not found")
715 # Save our CFLAGS/CPPFLAGS/LDFLAGS for the Makefile and restore the old user
717 AC_SUBST(AM_CPPFLAGS)
718 CPPFLAGS="$SAVED_CPPFLAGS"
720 CFLAGS="$SAVED_CFLAGS"
722 LDFLAGS="$SAVED_LDFLAGS"
724 AC_CONFIG_FILES([Makefile
727 libexec/got-read-tree/Makefile
728 libexec/got-fetch-pack/Makefile
729 libexec/got-index-pack/Makefile
730 libexec/got-read-blob/Makefile
731 libexec/got-read-commit/Makefile
732 libexec/got-read-gitconfig/Makefile
733 libexec/got-read-gotconfig/Makefile
734 libexec/got-read-object/Makefile
735 libexec/got-read-pack/Makefile
736 libexec/got-read-patch/Makefile
737 libexec/got-read-tag/Makefile
738 libexec/got-send-pack/Makefile
743 Makefile.common:Makefile.common.in])
746 executables="$(eval echo ${exec_prefix}/bin)"
747 helpers="$(eval echo ${libexecdir})"
748 manpages="$(eval echo ${mandir})"
751 Configured got-portable with:
756 Executables: ${executables}
759 Man pages: ${manpages}