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.
89 if test "x$ac_cv_header_sha256_h" = xyes; then
90 AC_DEFINE([HAVE_SHA256], [1], [SHA256 support])
93 AM_CONDITIONAL([HAVE_SHA2], [test "x$ac_cv_header_sha2_h" = xyes])
95 # Check for SHA1_DIGEST_LENGTH
96 AC_CHECK_DECL([SHA1_DIGEST_LENGTH],
97 [AC_DEFINE([HAVE_SHA1_AS_SHA1], [1], [SHA support is using SHA1])],
99 dnl maybe sha.h is available
100 AC_CHECK_DECL([SHA_DIGEST_LENGTH],
101 [AC_DEFINE([HAVE_SHA_AS_SHA1], [1],
102 [SHA support is using SHA])],
107 #include <sys/types.h>
111 # Checks for typ edefs, structures, and compiler characteristics.
112 AC_CHECK_HEADER_STDBOOL
125 # Check for ifgroupreq which is only available on BSD.
126 AC_CHECK_TYPES([struct ifgroupreq])
128 # Check for sockaddr_storage. On some systems, ss_len is filled out, although
129 # this is not mandated by POSIX, and hence systems such as linux, don't have
131 AC_CHECK_TYPES([struct sockaddr_storage], [], [], [
132 #include <sys/types.h>
133 #include <sys/socket.h>
136 # Same thing as sockaddr_storage above, only now check if the member exists in
137 # the struct as well.
138 AC_CHECK_MEMBERS([struct sockaddr_storage.ss_len], , ,
140 #include <netinet/in.h>
141 #include <sys/socket.h> ]
144 AC_CHECK_MEMBERS([struct sockaddr.sa_len], , ,
146 #include <netinet/in.h>
147 #include <sys/socket.h> ]
150 # Both checks above will result in:
152 # HAVE_STRUCT_SOCKADDR_AS_LEN
155 # Either being defined or not.
157 # Look for library needed for flock.
158 AC_SEARCH_LIBS(flock, bsd)
160 # Checks for library functions.
163 AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK
204 AM_CONDITIONAL([HAVE_SETPROCTITLE], [test "x$ac_cv_func_setproctitle" = xyes])
205 AM_CONDITIONAL([HAVE_SETRESGID], [test "x$ac_cv_func_setresgid" = xyes])
206 AM_CONDITIONAL([HAVE_SETRESUID], [test "x$ac_cv_func_setresuid" = xyes])
209 AC_CHECK_FUNCS([SipHash])
210 AM_CONDITIONAL([HAVE_SIPHASH], [test "x$ac_cv_func_SipHash" = xyes])
212 # Check for functions with a compatibility implementation.
230 AM_CONDITIONAL([HAVE_CLOSEFROM], [test "x$ac_cv_func_closefrom" = xyes])
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(openbsd)
262 AC_MSG_RESULT(dragonfly)
263 PLATFORM=dragonflybsd
266 AC_MSG_RESULT(unknown)
271 AM_CONDITIONAL([HOST_FREEBSD], [test "$PLATFORM" = "freebsd"])
272 AM_CONDITIONAL([HOST_LINUX], [test "$PLATFORM" = "linux"])
273 AM_CONDITIONAL([HOST_DARWIN], [test "$PLATFORM" = "darwin"])
274 AM_CONDITIONAL([HOST_NETBSD], [test "$PLATFORM" = "netbsd"])
275 AM_CONDITIONAL([HOST_OPENBSD], [test "$PLATFORM" = "openbsd"])
276 AM_CONDITIONAL([HOST_DRAGONFLYBSD], [test "$PLATFORM" = "dragonflybsd"])
279 if test "YACC_OVERRIDE" = "yes" && test -n "$YACC" \
280 && ! command -v "$YACC" >/dev/null 2>&1; then
281 AC_MSG_ERROR("yacc not found: $YACC")
284 if test x"$PLATFORM" = "xdarwin"; then
285 # Check for and/or set HOMEBREW_PREFIX. brew is a common way of
286 # installing applications. The other is MacPorts.
288 # Before Apple Silicon existed (M1 onward), the paths for applications
289 # installed via homebrew was typically /usr/local. However, with M1
290 # onward, this changed to a different path.
292 # Rather than hardcode this, check for HOMEBREW_PREFIX in the
293 # environment if it's already set, and use it. Otherwise, check for
294 # brew(1) and use that. If that fails, default to /usr/local
296 # This also means that MacPorts should continue to work.
298 # But with MacPorts, we should also check --prefix, and use that if it
301 # In both cases, the variable HOMEBREW_PREFIX is used for both.
305 if test -z "$HOMEBREW_PREFIX" -o "$HOMEBREW_PREFIX" = "NONE"; then
306 # HOMEBREW_PREFIX not set, check for brew(1)
307 if command -v brew >/dev/null 2>&1; then
308 AC_MSG_NOTICE("HOMEBREW_PREFIX set via 'brew --prefix'")
309 export HOMEBREW_PREFIX="$(brew --prefix)"
312 if test -z "$HOMEBREW_PREFIX" -o "$HOMEBREW_PREFIX" = "NONE"
315 if test -z "${prefix}" -o "${prefix}" = "NONE"; then
316 export HOMEBREW_PREFIX="/usr/local"
317 HB_PREFIX="/usr/local"
318 AC_MSG_NOTICE("HOMEBREW_PREFIX defaulting to $HB_PREFIX")
320 HB_PREFIX="$(eval echo ${prefix})"
321 if test "$HB_PREFIX" = "NONE"; then
322 HB_PREFIX="/opt/local"
324 AC_MSG_NOTICE("HOMEBREW_PREFIX using --prefix")
326 export HOMEBREW_PREFIX="$HB_PREFIX"
331 AC_MSG_NOTICE("HOMEBREW_PREFIX determined as: $HOMEBREW_PREFIX")
333 if test "$YACC_OVERRIDE" = "no" && \
334 ! test -x "${HOMEBREW_PREFIX}/opt/bison/bin/bison"; then
336 "***********************************************************
337 GNU Bison not found: ${HOMEBREW_PREFIX}/opt/bison/bin/bison
338 ***********************************************************
340 Falling back to checking either /usr/local or \${prefix}"
344 AC_MSG_WARN("Trying ${HB_PREFIX}/opt/bison/bin/bison")
345 if test -x "${HB_PREFIX}/opt/bison/bin/bison"; then
346 export HOMEBREW_PREFIX="/usr/local"
348 GNUBISON="${HB_PREFIX}/opt/bison/bin/bison"
351 if test "$FOUND_BISON" = "no"; then
352 HB_PREFIX="/opt/local"
353 AC_MSG_WARN("Trying ${HB_PREFIX}/bin/bison")
355 if test -x "${HB_PREFIX}/bin/bison"; then
356 export HOMEBREW_PREFIX="${HB_PREFIX}"
357 GNUBISON="${HB_PREFIX}/bin/bison"
363 GNUBISON="${HOMEBREW_PREFIX}/opt/bison/bin/bison"
366 if test "$FOUND_BISON" = "no" && test "$YACC_OVERRIDE" = "no"; then
367 AC_MSG_ERROR("*** Couldn't find GNU BISON ***")
370 # Override YACC here to point to the GNU version of bison.
371 if test "$YACC_OVERRIDE" = "yes"; then
372 export YACC="$YACC -y"
374 AC_MSG_NOTICE("Found GNU Bison as: $GNUBISON")
375 export YACC="${GNUBISON} -y"
377 export LDFLAGS="-L${HOMEBREW_PREFIX}/opt/ncurses/lib -L${HOMEBREW_PREFIX}/opt/openssl@3/lib $LDFLAGS"
378 export CPPFLAGS="-I${HOMEBREW_PREFIX}/opt/ncurses/include -I${HOMEBREW_PREFIX}/opt/openssl@3/include $CPPFLAGS"
379 export PKG_CONFIG_PATH="${HOMEBREW_PREFIX}/opt/ncurses/lib/pkgconfig"
380 export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:${HOMEBREW_PREFIX}/opt/openssl@3/lib/pkgconfig"
383 # Landlock detection.
384 AC_MSG_CHECKING([for landlock])
385 AM_CONDITIONAL([HAVE_LINUX_LANDLOCK],
386 [test "x$ac_cv_header_linux_landlock_h" = "xyes"])
387 if test "x$ac_cv_header_linux_landlock_h" = "xyes"; then
393 # Clang sanitizers wrap reallocarray even if it isn't available on the target
394 # system. When compiled it always returns NULL and crashes the program. To
395 # detect this we need a more complicated test.
396 AC_MSG_CHECKING([for working reallocarray])
397 AC_RUN_IFELSE([AC_LANG_PROGRAM(
398 [#include <stdlib.h>],
399 [return (reallocarray(NULL, 1, 1) == NULL);]
402 [AC_LIBOBJ(reallocarray) AC_MSG_RESULT([no])],
403 [AC_LIBOBJ(reallocarray) AC_MSG_RESULT([no])]
405 AC_MSG_CHECKING([for working recallocarray])
406 AC_RUN_IFELSE([AC_LANG_PROGRAM(
407 [#include <stdlib.h>],
408 [return (recallocarray(NULL, 1, 1, 1) == NULL);]
411 [AC_LIBOBJ(recallocarray) AC_MSG_RESULT([no])],
412 [AC_LIBOBJ(recallocarray) AC_MSG_RESULT([no])]
415 # Look for imsg_init in libutil.
416 AC_SEARCH_LIBS(imsg_init, util, found_imsg_init=yes, found_imsg_init=no)
417 AM_CONDITIONAL([HAVE_IMSG], [test "x$found_imsg_init" = "xyes"])
418 if test "x$found_imsg_init" = "xyes"; then
419 libutil_LIBS="$ac_cv_search_imsg_init"
420 AC_SUBST(libutil_LIBS)
423 AC_LIBOBJ(imsg-buffer)
426 # libevent (for gotwebd). Lifted from tmux.
427 # Look for libevent. Try libevent_core or libevent with pkg-config first then
428 # look for the library.
432 [libevent_core >= 2],
434 libevent_CFLAGS="$LIBEVENT_CORE_CFLAGS"
435 libevent_LIBS="$LIBEVENT_CORE_LIBS"
436 AC_SUBST(libevent_CFLAGS)
437 AC_SUBST(libevent_LIBS)
442 if test x$found_libevent = xno; then
447 libevent_CFLAGS="$LIBEVENT_CFLAGS"
448 libevent_LIBS="$LIBEVENT_LIBS"
449 AC_SUBST(libevent_CFLAGS)
450 AC_SUBST(libevent_LIBS)
456 if test x$found_libevent = xno; then
459 [event_core event event-1.4],
464 if test "x$found_libevent" = "xyes"; then
465 libevent_LIBS="$ac_cv_search_event_init"
466 AC_SUBST(libevent_LIBS)
470 if test x$found_libevent = xno; then
473 AC_DEFINE([HAVE_EVENT2_EVENT_H], [1], [libevent2 has event.h]),
477 AC_DEFINE([HAVE_EVENT_H], [0], [libevent]),
484 if test "x$found_libevent" = xno; then
485 AC_MSG_ERROR("libevent not found")
488 # libcrypto (via libssl for SHA information)
493 libcrypto_CFLAGS="$LIBCRYPTO_CORE_CFLAGS"
494 libcrypto_LIBS="$LIBCRYPTO_LIBS"
495 AC_SUBST(libcrypto_CFLAGS)
496 AC_SUBST(libcrypto_LIBS)
504 if test "x$found_libcrypto" = "xyes"; then
505 AC_DEFINE([HAVE_LIBCRYPTO], [1], [libcrypto])
508 AC_CHECK_FUNC([uuid_create], [found_uuid=yes], [found_uuid=no])
510 # Don't define HAVE_BSD_UUID on darwin (Apple) as this breaks the BSD API.
511 # Instead, use the UUID implementation wrapper that's in compat/ plus uuid
513 if test "x$found_uuid" = "xyes" -a "x$PLATFORM" != "darwin"; then
514 AC_DEFINE([HAVE_BSD_UUID], [1], [BSD UUID])
520 libuuid_CFLAGS="$LIBUUID_CFLAGS"
521 libuuid_LIBS="$LIBUUID_LIBS"
522 AC_SUBST(libuuid_CFLAGS)
523 AC_SUBST(libuuid_LIBS)
531 if test "x$found_libuuid" = "xno"; then
539 if test "x$found_libuuid" = "xno"; then
540 AC_MSG_ERROR("*** couldn't find uuid ***")
547 zlib_CFLAGS="$ZLIB_CFLAGS"
548 zlib_LIBS="$ZLIB_LIBS"
549 AC_SUBST(zlib_CFLAGS)
558 if test "x$found_zlib" = "xno"; then
565 if test "x$found_zlib" = "xno"; then
566 AC_MSG_ERROR("*** couldn't find zlib ***")
569 if test "$PLATFORM" = "linux"; then
574 libmd_CFLAGS="$LIBMD_CFLAGS"
575 libmd_LIBS="$LIBMD_LIBS"
576 AC_SUBST(libmd_CFLAGS)
580 AC_MSG_ERROR("*** couldn't find libmd via pkg-config")
587 libbsd_CFLAGS="$LIBBSD_CFLAGS"
588 libbsd_LIBS="$LIBBSD_LIBS"
589 AC_SUBST(libbsd_CFLAGS)
590 AC_SUBST(libbsd_LIBS)
591 AC_DEFINE([HAVE_LIBBSD], [1], [BSD UUID])
594 AC_MSG_ERROR("*** couldn't find libbsd-overlay via pkg-config")
599 # Add LIBBSD_{CFLAGS,LIBS} to the environment here, as libbsd puts its
600 # header files in a non-standard location, which means the overlay for
601 # <sys/tree.h> and <sys/queue.h> won't be found.
602 CFLAGS="$CFLAGS $LIBBSD_CFLAGS"
603 LIBS="$LIBS $LIBBSD_LIBS"
606 # Look for a suitable queue.h. We hope libbsd is enough, but that is missing
612 [#include <sys/queue.h>]
618 [#include <sys/queue.h>]
624 [#include <sys/queue.h>]
627 if test "x$found_queue_h" = xyes; then
628 AC_DEFINE([HAVE_QUEUE_H], [1], [sys/queue.h])
630 AC_MSG_ERROR("*** sys/queue.h missing key defines ***)
635 found_sys_tree_h=yes,
637 [#include <sys/tree.h>]
640 if test "x$found_sys_tree_h" = xyes; then
641 AC_DEFINE([HAVE_TREE_H], [1], [sys/tree.h])
643 AC_MSG_NOTICE("Using compat/tree.h")
646 # Look for __progname.
647 AC_MSG_CHECKING(for __progname)
648 AC_LINK_IFELSE([AC_LANG_SOURCE(
652 extern char *__progname;
654 const char *cp = __progname;
659 [AC_DEFINE([HAVE___PROGNAME], [1], [___progname]) AC_MSG_RESULT(yes)],
683 if test "x$found_panel" = "xno"; then
684 AC_CHECK_LIB(panelw, update_panels, [],
685 AC_MSG_ERROR([ "*** panelw not found for ncurses. ***"]),
689 LIBPANELW_LIBS="-lpanelw"
698 if test "x$found_ncurses" = xyes; then
699 libncurses_CFLAGS="$LIBNCURSES_CFLAGS $LIBTINFO_CFLAGS $LIBPANELW_CFLAGS"
700 libncurses_LIBS="$LIBNCURSES_LIBS $LIBTINFO_LIBS $LIBPANELW_LIBS"
701 AC_SUBST(libncurses_CFLAGS)
702 AC_SUBST(libncurses_LIBS)
709 if test "x$found_ncurses" = xyes; then
712 libncurses_CFLAGS="$LIBPANELW_CFLAGS $LIBPANEL_CFLAGS"
713 libncurses_LIBS="$LIBPANELW_LIBS -lncursesw"
714 AC_SUBST(libncurses_CFLAGS)
715 AC_SUBST(libncurses_LIBS)
719 if test "x$found_ncurses" = xyes; then
720 AC_DEFINE([HAVE_NCURSES_H], [1], [NCurses])
722 # No ncurses, try curses.
732 if test "x$found_curses" = xyes; then
733 libncurses_CFLAGS="$LIBPANELW_CFLAGS $LIBPANEL_CFLAGS"
734 libncurses_LIBS="$LIBPANELW_LIBS -lncursesw"
735 AC_SUBST(libncurses_CFLAGS)
736 AC_SUBST(libncurses_LIBS)
737 AC_DEFINE([HAVE_CURSES_H], [1], [Curses_h])
739 AC_MSG_ERROR("curses not found")
743 # Save our CFLAGS/CPPFLAGS/LDFLAGS for the Makefile and restore the old user
745 AC_SUBST(AM_CPPFLAGS)
746 CPPFLAGS="$SAVED_CPPFLAGS"
748 CFLAGS="$SAVED_CFLAGS"
750 LDFLAGS="$SAVED_LDFLAGS"
752 if test x"$PLATFORM" = "xopenbsd"; then
756 AH_BOTTOM([#include "got_compat2.h"])
758 AC_CONFIG_FILES([Makefile
761 libexec/got-read-tree/Makefile
762 libexec/got-fetch-pack/Makefile
763 libexec/got-index-pack/Makefile
764 libexec/got-read-blob/Makefile
765 libexec/got-read-commit/Makefile
766 libexec/got-read-gitconfig/Makefile
767 libexec/got-read-gotconfig/Makefile
768 libexec/got-read-object/Makefile
769 libexec/got-read-pack/Makefile
770 libexec/got-read-patch/Makefile
771 libexec/got-read-tag/Makefile
772 libexec/got-send-pack/Makefile
777 Makefile.common:Makefile.common.in])
780 executables="$(eval echo ${exec_prefix}/bin)"
781 helpers="$(eval echo ${libexecdir})"
782 manpages="$(eval echo ${mandir})"
785 Configured got-portable with:
790 Executables: ${executables}
794 Man pages: ${manpages}