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")
17 # When CFLAGS isn't set at this stage and gcc is detected by the macro below,
18 # autoconf will automatically use CFLAGS="-O2 -g". Prevent that by using an
22 # Save user CPPFLAGS, CFLAGS and LDFLAGS. We need to change them because
23 # AC_CHECK_HEADER doesn't give us any other way to update the include
24 # paths. But for Makefile.am we want to use AM_CPPFLAGS and friends.
25 SAVED_CFLAGS="$CFLAGS"
26 SAVED_CPPFLAGS="$CPPFLAGS"
27 SAVED_LDFLAGS="$LDFLAGS"
29 # Checks for programs.
38 AC_USE_SYSTEM_EXTENSIONS
40 # Checks for header files.
67 # Checks for typ edefs, structures, and compiler characteristics.
68 AC_CHECK_HEADER_STDBOOL
81 # Check for ifgroupreq which is only available on BSD.
82 AC_CHECK_TYPES([struct ifgroupreq])
84 # Check for sockaddr_storage. On some systems, ss_len is filled out, although
85 # this is not mandated by POSIX, and hence systems such as linux, don't have
87 AC_CHECK_TYPES([struct sockaddr_storage], [], [], [
88 #include <sys/types.h>
89 #include <sys/socket.h>
92 # Same thing as sockaddr_storage above, only now check if the member exists in
94 AC_CHECK_MEMBERS([struct sockaddr_storage.ss_len], , ,
96 #include <netinet/in.h>
97 #include <sys/socket.h> ]
100 AC_CHECK_MEMBERS([struct sockaddr.sa_len], , ,
102 #include <netinet/in.h>
103 #include <sys/socket.h> ]
106 # Both checks above will result in:
108 # HAVE_STRUCT_SOCKADDR_AS_LEN
111 # Either being defined or not.
113 # Look for library needed for flock.
114 AC_SEARCH_LIBS(flock, bsd)
116 # Checks for library functions.
119 AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK
160 AM_CONDITIONAL([HAVE_SETPROCTITLE], [test "x$ac_cv_func_setproctitle" = xyes])
161 AM_CONDITIONAL([HAVE_SETRESGID], [test "x$ac_cv_func_setresgid" = xyes])
162 AM_CONDITIONAL([HAVE_SETRESUID], [test "x$ac_cv_func_setresuid" = xyes])
165 AC_CHECK_FUNCS([SipHash])
166 AM_CONDITIONAL([HAVE_SIPHASH], [test "x$ac_cv_func_SipHash" = xyes])
168 # Check for functions with a compatibility implementation.
187 # Always use our getopt because 1) glibc's doesn't enforce argument order 2)
188 # musl does not set optarg to NULL for flags without arguments (although it is
189 # not required to, but it is helpful) 3) there are probably other weird
193 # Check the platform we're compiling on.
194 AC_MSG_CHECKING(platform)
201 AC_MSG_RESULT(freebsd)
205 AC_MSG_RESULT(darwin)
209 AC_MSG_RESULT(netbsd)
213 AC_MSG_RESULT(dragonfly)
214 PLATFORM=dragonflybsd
217 AC_MSG_RESULT(unknown)
222 AM_CONDITIONAL([HOST_FREEBSD], [test "$PLATFORM" = "freebsd"])
223 AM_CONDITIONAL([HOST_LINUX], [test "$PLATFORM" = "linux"])
224 AM_CONDITIONAL([HOST_DARWIN], [test "$PLATFORM" = "darwin"])
225 AM_CONDITIONAL([HOST_NETBSD], [test "$PLATFORM" = "netbsd"])
226 AM_CONDITIONAL([HOST_DRAGONFLYBSD], [test "$PLATFORM" = "dragonflybsd"])
228 if test x"$PLATFORM" = "xdarwin"; then
229 # Check for and/or set HOMEBREW_PREFIX. brew is a common way of
230 # installing applications. The other is MacPorts.
232 # Before Apple Silicon existed (M1 onward), the paths for applications
233 # installed via homebrew was typically /usr/local. However, with M1
234 # onward, this changed to a different path.
236 # Rather than hardcode this, check for HOMEBREW_PREFIX in the
237 # environment if it's already set, and use it. Otherwise, check for
238 # brew(1) and use that. If that fails, default to /usr/local
240 # This also means that MacPorts should continue to work.
242 # But with MacPorts, we should also check --prefix, and use that if it
245 # In both cases, the variable HOMEBREW_PREFIX is used for both.
249 if test -z "$HOMEBREW_PREFIX" -o "$HOMEBREW_PREFIX" = "NONE"; then
250 # HOMEBREW_PREFIX not set, check for brew(1)
251 if command -v brew >/dev/null 2>&1; then
252 AC_MSG_NOTICE("HOMEBREW_PREFIX set via 'brew --prefix'")
253 export HOMEBREW_PREFIX="$(brew --prefix)"
256 if test -z "$HOMEBREW_PREFIX" -o "$HOMEBREW_PREFIX" = "NONE"
259 if test -z "${prefix}" -o "${prefix}" = "NONE"; then
260 export HOMEBREW_PREFIX="/usr/local"
261 HB_PREFIX="/usr/local"
262 AC_MSG_NOTICE("HOMEBREW_PREFIX defaulting to $HB_PREFIX")
264 HB_PREFIX="$(eval echo ${prefix})"
265 if test "$HB_PREFIX" = "NONE"; then
266 HB_PREFIX="/opt/local"
268 AC_MSG_NOTICE("HOMEBREW_PREFIX using --prefix")
270 export HOMEBREW_PREFIX="$HB_PREFIX"
275 AC_MSG_NOTICE("HOMEBREW_PREFIX determined as: $HOMEBREW_PREFIX")
277 if ! test -x "${HOMEBREW_PREFIX}/opt/bison/bin/bison"; then
279 "***********************************************************
280 GNU Bison not found: ${HOMEBREW_PREFIX}/opt/bison/bin/bison
281 ***********************************************************
283 Falling back to checking either /usr/local or \${prefix}"
287 AC_MSG_WARN("Trying ${HB_PREFIX}/opt/bison/bin/bison")
288 if test -x "${HB_PREFIX}/opt/bison/bin/bison"; then
289 export HOMEBREW_PREFIX="/usr/local"
291 GNUBISON="${HB_PREFIX}/opt/bison/bin/bison"
294 if test "$FOUND_BISON" = "no"; then
295 HB_PREFIX="/opt/local"
296 AC_MSG_WARN("Trying ${HB_PREFIX}/bin/bison")
298 if test -x "${HB_PREFIX}/bin/bison"; then
299 export HOMEBREW_PREFIX="${HB_PREFIX}"
300 GNUBISON="${HB_PREFIX}/bin/bison"
306 GNUBISON="${HOMEBREW_PREFIX}/opt/bison/bin/bison"
309 if test "$FOUND_BISON" = "no"; then
310 AC_MSG_ERROR("*** Couldn't find GNU BISON ***")
313 AC_MSG_NOTICE("Found GNU Bison as: $GNUBISON")
315 # Override YACC here to point to the GNU version of bison.
316 export YACC="${GNUBISON} -y"
317 export LDFLAGS="-L${HOMEBREW_PREFIX}/opt/ncurses/lib -L${HOMEBREW_PREFIX}/opt/openssl@3/lib $LDFLAGS"
318 export CPPFLAGS="-I${HOMEBREW_PREFIX}/opt/ncurses/include -I${HOMEBREW_PREFIX}/opt/openssl@3/include $CPPFLAGS"
319 export PKG_CONFIG_PATH="${HOMEBREW_PREFIX}/opt/ncurses/lib/pkgconfig"
320 export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:${HOMEBREW_PREFIX}/opt/openssl@3/lib/pkgconfig"
323 # Landlock detection.
324 AC_MSG_CHECKING([for landlock])
325 AM_CONDITIONAL([HAVE_LINUX_LANDLOCK],
326 [test "x$ac_cv_header_linux_landlock_h" = "xyes"])
327 if test "x$ac_cv_header_linux_landlock_h" = "xyes"; then
333 # Clang sanitizers wrap reallocarray even if it isn't available on the target
334 # system. When compiled it always returns NULL and crashes the program. To
335 # detect this we need a more complicated test.
336 AC_MSG_CHECKING([for working reallocarray])
337 AC_RUN_IFELSE([AC_LANG_PROGRAM(
338 [#include <stdlib.h>],
339 [return (reallocarray(NULL, 1, 1) == NULL);]
342 [AC_LIBOBJ(reallocarray) AC_MSG_RESULT([no])],
343 [AC_LIBOBJ(reallocarray) AC_MSG_RESULT([no])]
345 AC_MSG_CHECKING([for working recallocarray])
346 AC_RUN_IFELSE([AC_LANG_PROGRAM(
347 [#include <stdlib.h>],
348 [return (recallocarray(NULL, 1, 1, 1) == NULL);]
351 [AC_LIBOBJ(recallocarray) AC_MSG_RESULT([no])],
352 [AC_LIBOBJ(recallocarray) AC_MSG_RESULT([no])]
355 # Look for imsg_init in libutil.
356 AC_SEARCH_LIBS(imsg_init, util, found_imsg_init=yes, found_imsg_init=no)
357 if test "x$found_imsg_init" = xyes; then
361 AC_LIBOBJ(imsg-buffer)
364 # libevent (for gotwebd). Lifted from tmux.
365 # Look for libevent. Try libevent_core or libevent with pkg-config first then
366 # look for the library.
369 [libevent_core >= 2],
371 AM_CPPFLAGS="$LIBEVENT_CORE_CFLAGS $AM_CPPFLAGS"
372 CPPFLAGS="$AM_CPPFLAGS $SAVED_CPPFLAGS"
373 LIBS="$LIBEVENT_CORE_LIBS $LIBS"
378 if test x$found_libevent = xno; then
383 AM_CPPFLAGS="$LIBEVENT_CFLAGS $AM_CPPFLAGS"
384 CPPFLAGS="$AM_CPPFLAGS $SAVED_CPPFLAGS"
385 LIBS="$LIBEVENT_LIBS $LIBS"
391 if test x$found_libevent = xno; then
394 [event_core event event-1.4],
401 AC_DEFINE(HAVE_EVENT2_EVENT_H),
405 AC_DEFINE(HAVE_EVENT_H),
410 if test "x$found_libevent" = xno; then
411 AC_MSG_ERROR("libevent not found")
414 # libcrypto (via libssl for SHA information)
419 AM_CFLAGS="$LIBCRYPTO_CFLAGS $AM_CFLAGS"
420 CFLAGS="$AM_CFLAGS $SAVED_CFLAGS"
421 LIBS="$LIBCRYPTO_LIBS $LIBS"
429 if test "x$found_libcrypto" = "xyes"; then
430 AC_DEFINE(HAVE_LIBCRYPTO)
433 AC_SEARCH_LIBS(uuid_create, , AC_DEFINE(HAVE_BSD_UUID))
434 AC_SEARCH_LIBS(uuid_create, found_uuid=no, found_uuid=yes)
435 AC_SEARCH_LIBS(mergesort, , AC_DEFINE(HAVE_BSD_MERGESORT))
437 # Don't define HAVE_BSD_UUID on darwin (Apple) as this breaks the BSD API.
438 # Instead, use the UUID implementation wrapper that's in compat/ plus uuid
440 if test "x$found_uuid" = "xyes" -a "x$PLATFORM" != "darwin"; then
441 AC_DEFINE(HAVE_BSD_UUID)
447 AM_CFLAGS="$LIBUUID_CFLAGS $AM_CFLAGS"
448 CFLAGS="$AM_CFLAGS $SAVED_CFLAGS"
449 LIBS="$LIBUUID_LIBS $LIBS"
457 if test "x$found_libuuid" = "xno"; then
465 if test "x$found_libuuid" = "xno"; then
466 AC_MSG_ERROR("*** couldn't find uuid ***")
473 AM_CFLAGS="$ZLIB_CFLAGS $AM_CFLAGS"
474 CFLAGS="$AM_CFLAGS $SAVED_CFLAGS"
475 LIBS="$ZLIB_LIBS $LIBS"
483 if test "x$found_zlib" = "xno"; then
490 if test "x$found_zlib" = "xno"; then
491 AC_MSG_ERROR("*** couldn't find zlib ***")
494 if test "$PLATFORM" = "linux"; then
499 AM_CFLAGS="$LIBMD_CFLAGS $AM_CFLAGS"
500 CFLAGS="$AM_CFLAGS $SAVED_CFLAGS"
501 LIBS="$LIBMD_LIBS $LIBS"
504 AC_MSG_ERROR("*** couldn't find libmd via pkg-config")
511 AM_CFLAGS="$LIBBSD_CFLAGS $AM_CFLAGS"
512 CFLAGS="$AM_CFLAGS $SAVED_CFLAGS"
513 LIBS="$LIBBSD_LIBS $LIBS"
515 AC_DEFINE(HAVE_LIBBSD)
518 AC_MSG_ERROR("*** couldn't find libbsd-overlay via pkg-config")
524 # Look for a suitable queue.h. We hope libbsd is enough, but that is missing
530 [#include <sys/queue.h>]
536 [#include <sys/queue.h>]
542 [#include <sys/queue.h>]
545 if test "x$found_queue_h" = xyes; then
546 AC_DEFINE(HAVE_QUEUE_H)
548 AC_MSG_ERROR("*** sys/queue.h missing key defines ***)
552 # Look for __progname.
553 AC_MSG_CHECKING(for __progname)
554 AC_LINK_IFELSE([AC_LANG_SOURCE(
558 extern char *__progname;
560 const char *cp = __progname;
565 [AC_DEFINE(HAVE___PROGNAME) AC_MSG_RESULT(yes)],
589 if test "x$found_panel" = "xno"; then
590 AC_CHECK_LIB(panelw, update_panels,,
591 AC_MSG_ERROR([ "*** panelw not found for ncurses. ***"])
594 LIBPANELW_LIBS="-lpanelw"
603 if test "x$found_ncurses" = xyes; then
604 AM_CFLAGS="$LIBNCURSES_CFLAGS $LIBTINFO_CFLAGS $LIBPANELW_CFLAGS $AM_CFLAGS"
605 CFLAGS="$LIBNCURSES_CFLAGS $LIBTINFO_CFLAGS $LIBPANELW_CFLAGS $CFLAGS"
606 LIBS="$LIBNCURSES_LIBS $LIBTINFO_LIBS $LIBPANELW_LIBS $LIBS"
614 if test "x$found_ncurses" = xyes; then
617 AM_CFLAGS="$LIBPANELW_CFLAGS $AM_CFLAGS"
618 CFLAGS="$LIBPANEL_CFLAGS $CFLAGS"
619 LIBS="$LIBS -lncursesw $LIBPANELW_LIBS",
624 if test "x$found_ncurses" = xyes; then
625 AC_DEFINE(HAVE_NCURSES_H)
627 # No ncurses, try curses.
638 if test "x$found_curses" = xyes; then
639 AM_CFLAGS="$LIBPANELW_CFLAGS $AM_CFLAGS"
640 CFLAGS="$LIBPANEL_CFLAGS $CFLAGS"
641 LIBS="$LIBS -lcursesw $LIBPANELW_LIBS"
642 AC_DEFINE(HAVE_CURSES_H)
644 AC_MSG_ERROR("curses not found")
648 # Save our CFLAGS/CPPFLAGS/LDFLAGS for the Makefile and restore the old user
650 AC_SUBST(AM_CPPFLAGS)
651 CPPFLAGS="$SAVED_CPPFLAGS"
653 CFLAGS="$SAVED_CFLAGS"
655 LDFLAGS="$SAVED_LDFLAGS"
657 AC_CONFIG_FILES([Makefile
660 libexec/got-read-tree/Makefile
661 libexec/got-fetch-pack/Makefile
662 libexec/got-index-pack/Makefile
663 libexec/got-read-blob/Makefile
664 libexec/got-read-commit/Makefile
665 libexec/got-read-gitconfig/Makefile
666 libexec/got-read-gotconfig/Makefile
667 libexec/got-read-object/Makefile
668 libexec/got-read-pack/Makefile
669 libexec/got-read-patch/Makefile
670 libexec/got-read-tag/Makefile
671 libexec/got-send-pack/Makefile
676 Makefile.common:Makefile.common.in])
679 executables="$(eval echo ${exec_prefix}/bin)"
680 helpers="$(eval echo ${libexecdir})"
681 manpages="$(eval echo ${mandir})"
684 Configured got-portable with:
689 Executables: ${executables}
691 Man pages: ${manpages}