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"
32 # Checks for programs.
43 # Checks for header files.
70 # Checks for typ edefs, structures, and compiler characteristics.
71 AC_CHECK_HEADER_STDBOOL
84 # Check for ifgroupreq which is only available on BSD.
85 AC_CHECK_TYPES([struct ifgroupreq])
87 # Check for sockaddr_storage. On some systems, ss_len is filled out, although
88 # this is not mandated by POSIX, and hence systems such as linux, don't have
90 AC_CHECK_TYPES([struct sockaddr_storage], [], [], [
91 #include <sys/types.h>
92 #include <sys/socket.h>
95 # Same thing as sockaddr_storage above, only now check if the member exists in
97 AC_CHECK_MEMBERS([struct sockaddr_storage.ss_len], , ,
99 #include <netinet/in.h>
100 #include <sys/socket.h> ]
103 AC_CHECK_MEMBERS([struct sockaddr.sa_len], , ,
105 #include <netinet/in.h>
106 #include <sys/socket.h> ]
109 # Both checks above will result in:
111 # HAVE_STRUCT_SOCKADDR_AS_LEN
114 # Either being defined or not.
116 # Look for library needed for flock.
117 AC_SEARCH_LIBS(flock, bsd)
119 # Checks for library functions.
122 AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK
163 AM_CONDITIONAL([HAVE_SETPROCTITLE], [test "x$ac_cv_func_setproctitle" = xyes])
164 AM_CONDITIONAL([HAVE_SETRESGID], [test "x$ac_cv_func_setresgid" = xyes])
165 AM_CONDITIONAL([HAVE_SETRESUID], [test "x$ac_cv_func_setresuid" = xyes])
168 AC_CHECK_FUNCS([SipHash])
169 AM_CONDITIONAL([HAVE_SIPHASH], [test "x$ac_cv_func_SipHash" = xyes])
171 # Check for functions with a compatibility implementation.
190 # Always use our getopt because 1) glibc's doesn't enforce argument order 2)
191 # musl does not set optarg to NULL for flags without arguments (although it is
192 # not required to, but it is helpful) 3) there are probably other weird
196 # Check the platform we're compiling on.
197 AC_MSG_CHECKING(platform)
204 AC_MSG_RESULT(freebsd)
208 AC_MSG_RESULT(darwin)
212 AC_MSG_RESULT(netbsd)
216 AC_MSG_RESULT(dragonfly)
217 PLATFORM=dragonflybsd
220 AC_MSG_RESULT(unknown)
225 AM_CONDITIONAL([HOST_FREEBSD], [test "$PLATFORM" = "freebsd"])
226 AM_CONDITIONAL([HOST_LINUX], [test "$PLATFORM" = "linux"])
227 AM_CONDITIONAL([HOST_DARWIN], [test "$PLATFORM" = "darwin"])
228 AM_CONDITIONAL([HOST_NETBSD], [test "$PLATFORM" = "netbsd"])
229 AM_CONDITIONAL([HOST_DRAGONFLYBSD], [test "$PLATFORM" = "dragonflybsd"])
231 if test x"$PLATFORM" = "xdarwin"; then
232 # Check for and/or set HOMEBREW_PREFIX. brew is a common way of
233 # installing applications. The other is MacPorts.
235 # Before Apple Silicon existed (M1 onward), the paths for applications
236 # installed via homebrew was typically /usr/local. However, with M1
237 # onward, this changed to a different path.
239 # Rather than hardcode this, check for HOMEBREW_PREFIX in the
240 # environment if it's already set, and use it. Otherwise, check for
241 # brew(1) and use that. If that fails, default to /usr/local
243 # This also means that MacPorts should continue to work.
245 # But with MacPorts, we should also check --prefix, and use that if it
248 # In both cases, the variable HOMEBREW_PREFIX is used for both.
252 if test -z "$HOMEBREW_PREFIX" -o "$HOMEBREW_PREFIX" = "NONE"; then
253 # HOMEBREW_PREFIX not set, check for brew(1)
254 if command -v brew >/dev/null 2>&1; then
255 AC_MSG_NOTICE("HOMEBREW_PREFIX set via 'brew --prefix'")
256 export HOMEBREW_PREFIX="$(brew --prefix)"
259 if test -z "$HOMEBREW_PREFIX" -o "$HOMEBREW_PREFIX" = "NONE"
262 if test -z "${prefix}" -o "${prefix}" = "NONE"; then
263 export HOMEBREW_PREFIX="/usr/local"
264 HB_PREFIX="/usr/local"
265 AC_MSG_NOTICE("HOMEBREW_PREFIX defaulting to $HB_PREFIX")
267 HB_PREFIX="$(eval echo ${prefix})"
268 if test "$HB_PREFIX" = "NONE"; then
269 HB_PREFIX="/opt/local"
271 AC_MSG_NOTICE("HOMEBREW_PREFIX using --prefix")
273 export HOMEBREW_PREFIX="$HB_PREFIX"
278 AC_MSG_NOTICE("HOMEBREW_PREFIX determined as: $HOMEBREW_PREFIX")
280 if ! test -x "${HOMEBREW_PREFIX}/opt/bison/bin/bison"; then
282 "***********************************************************
283 GNU Bison not found: ${HOMEBREW_PREFIX}/opt/bison/bin/bison
284 ***********************************************************
286 Falling back to checking either /usr/local or \${prefix}"
290 AC_MSG_WARN("Trying ${HB_PREFIX}/opt/bison/bin/bison")
291 if test -x "${HB_PREFIX}/opt/bison/bin/bison"; then
292 export HOMEBREW_PREFIX="/usr/local"
294 GNUBISON="${HB_PREFIX}/opt/bison/bin/bison"
297 if test "$FOUND_BISON" = "no"; then
298 HB_PREFIX="/opt/local"
299 AC_MSG_WARN("Trying ${HB_PREFIX}/bin/bison")
301 if test -x "${HB_PREFIX}/bin/bison"; then
302 export HOMEBREW_PREFIX="${HB_PREFIX}"
303 GNUBISON="${HB_PREFIX}/bin/bison"
309 GNUBISON="${HOMEBREW_PREFIX}/opt/bison/bin/bison"
312 if test "$FOUND_BISON" = "no"; then
313 AC_MSG_ERROR("*** Couldn't find GNU BISON ***")
316 AC_MSG_NOTICE("Found GNU Bison as: $GNUBISON")
318 # Override YACC here to point to the GNU version of bison.
319 export YACC="${GNUBISON} -y"
320 export LDFLAGS="-L${HOMEBREW_PREFIX}/opt/ncurses/lib -L${HOMEBREW_PREFIX}/opt/openssl@3/lib $LDFLAGS"
321 export CPPFLAGS="-I${HOMEBREW_PREFIX}/opt/ncurses/include -I${HOMEBREW_PREFIX}/opt/openssl@3/include $CPPFLAGS"
322 export PKG_CONFIG_PATH="${HOMEBREW_PREFIX}/opt/ncurses/lib/pkgconfig"
323 export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:${HOMEBREW_PREFIX}/opt/openssl@3/lib/pkgconfig"
326 # Landlock detection.
327 AC_MSG_CHECKING([for landlock])
328 AM_CONDITIONAL([HAVE_LINUX_LANDLOCK],
329 [test "x$ac_cv_header_linux_landlock_h" = "xyes"])
330 if test "x$ac_cv_header_linux_landlock_h" = "xyes"; then
336 # Clang sanitizers wrap reallocarray even if it isn't available on the target
337 # system. When compiled it always returns NULL and crashes the program. To
338 # detect this we need a more complicated test.
339 AC_MSG_CHECKING([for working reallocarray])
340 AC_RUN_IFELSE([AC_LANG_PROGRAM(
341 [#include <stdlib.h>],
342 [return (reallocarray(NULL, 1, 1) == NULL);]
345 [AC_LIBOBJ(reallocarray) AC_MSG_RESULT([no])],
346 [AC_LIBOBJ(reallocarray) AC_MSG_RESULT([no])]
348 AC_MSG_CHECKING([for working recallocarray])
349 AC_RUN_IFELSE([AC_LANG_PROGRAM(
350 [#include <stdlib.h>],
351 [return (recallocarray(NULL, 1, 1, 1) == NULL);]
354 [AC_LIBOBJ(recallocarray) AC_MSG_RESULT([no])],
355 [AC_LIBOBJ(recallocarray) AC_MSG_RESULT([no])]
358 # Look for imsg_init in libutil.
359 AC_SEARCH_LIBS(imsg_init, util, found_imsg_init=yes, found_imsg_init=no)
360 AM_CONDITIONAL([HAVE_IMSG], [test "x$found_imsg_init" = "xyes"])
361 if test "x$found_imsg_init" = xno; then
363 AC_LIBOBJ(imsg-buffer)
366 # libevent (for gotwebd). Lifted from tmux.
367 # Look for libevent. Try libevent_core or libevent with pkg-config first then
368 # look for the library.
371 [libevent_core >= 2],
373 AM_CPPFLAGS="$LIBEVENT_CORE_CFLAGS $AM_CPPFLAGS"
374 CPPFLAGS="$AM_CPPFLAGS $SAVED_CPPFLAGS"
375 LIBS="$LIBEVENT_CORE_LIBS $LIBS"
380 if test x$found_libevent = xno; then
385 AM_CPPFLAGS="$LIBEVENT_CFLAGS $AM_CPPFLAGS"
386 CPPFLAGS="$AM_CPPFLAGS $SAVED_CPPFLAGS"
387 LIBS="$LIBEVENT_LIBS $LIBS"
393 if test x$found_libevent = xno; then
396 [event_core event event-1.4],
403 AC_DEFINE(HAVE_EVENT2_EVENT_H),
407 AC_DEFINE(HAVE_EVENT_H),
412 if test "x$found_libevent" = xno; then
413 AC_MSG_ERROR("libevent not found")
416 # libcrypto (via libssl for SHA information)
421 AM_CFLAGS="$LIBCRYPTO_CFLAGS $AM_CFLAGS"
422 CFLAGS="$AM_CFLAGS $SAVED_CFLAGS"
423 LIBS="$LIBCRYPTO_LIBS $LIBS"
431 if test "x$found_libcrypto" = "xyes"; then
432 AC_DEFINE(HAVE_LIBCRYPTO)
435 AC_SEARCH_LIBS(uuid_create, , AC_DEFINE(HAVE_BSD_UUID))
436 AC_SEARCH_LIBS(uuid_create, found_uuid=no, found_uuid=yes)
437 AC_SEARCH_LIBS(mergesort, , AC_DEFINE(HAVE_BSD_MERGESORT))
439 # Don't define HAVE_BSD_UUID on darwin (Apple) as this breaks the BSD API.
440 # Instead, use the UUID implementation wrapper that's in compat/ plus uuid
442 if test "x$found_uuid" = "xyes" -a "x$PLATFORM" != "darwin"; then
443 AC_DEFINE(HAVE_BSD_UUID)
449 AM_CFLAGS="$LIBUUID_CFLAGS $AM_CFLAGS"
450 CFLAGS="$AM_CFLAGS $SAVED_CFLAGS"
451 LIBS="$LIBUUID_LIBS $LIBS"
459 if test "x$found_libuuid" = "xno"; then
467 if test "x$found_libuuid" = "xno"; then
468 AC_MSG_ERROR("*** couldn't find uuid ***")
475 AM_CFLAGS="$ZLIB_CFLAGS $AM_CFLAGS"
476 CFLAGS="$AM_CFLAGS $SAVED_CFLAGS"
477 LIBS="$ZLIB_LIBS $LIBS"
485 if test "x$found_zlib" = "xno"; then
492 if test "x$found_zlib" = "xno"; then
493 AC_MSG_ERROR("*** couldn't find zlib ***")
496 if test "$PLATFORM" = "linux"; then
501 AM_CFLAGS="$LIBMD_CFLAGS $AM_CFLAGS"
502 CFLAGS="$AM_CFLAGS $SAVED_CFLAGS"
503 LIBS="$LIBMD_LIBS $LIBS"
506 AC_MSG_ERROR("*** couldn't find libmd via pkg-config")
513 AM_CFLAGS="$LIBBSD_CFLAGS $AM_CFLAGS"
514 CFLAGS="$AM_CFLAGS $SAVED_CFLAGS"
515 LIBS="$LIBBSD_LIBS $LIBS"
517 AC_DEFINE(HAVE_LIBBSD)
520 AC_MSG_ERROR("*** couldn't find libbsd-overlay via pkg-config")
526 # Look for a suitable queue.h. We hope libbsd is enough, but that is missing
532 [#include <sys/queue.h>]
538 [#include <sys/queue.h>]
544 [#include <sys/queue.h>]
547 if test "x$found_queue_h" = xyes; then
548 AC_DEFINE(HAVE_QUEUE_H)
550 AC_MSG_ERROR("*** sys/queue.h missing key defines ***)
555 found_sys_tree_h=yes,
557 [#include <sys/tree.h>]
560 if test "x$found_sys_tree_h" = xyes; then
561 AC_DEFINE(HAVE_TREE_H)
563 AC_MSG_NOTICE("Using compat/tree.h")
566 # Look for __progname.
567 AC_MSG_CHECKING(for __progname)
568 AC_LINK_IFELSE([AC_LANG_SOURCE(
572 extern char *__progname;
574 const char *cp = __progname;
579 [AC_DEFINE(HAVE___PROGNAME) AC_MSG_RESULT(yes)],
603 if test "x$found_panel" = "xno"; then
604 AC_CHECK_LIB(panelw, update_panels, [],
605 AC_MSG_ERROR([ "*** panelw not found for ncurses. ***"]),
609 LIBPANELW_LIBS="-lpanelw"
618 if test "x$found_ncurses" = xyes; then
619 AM_CFLAGS="$LIBNCURSES_CFLAGS $LIBTINFO_CFLAGS $LIBPANELW_CFLAGS $AM_CFLAGS"
620 CFLAGS="$LIBNCURSES_CFLAGS $LIBTINFO_CFLAGS $LIBPANELW_CFLAGS $CFLAGS"
621 LIBS="$LIBNCURSES_LIBS $LIBTINFO_LIBS $LIBPANELW_LIBS $LIBS"
629 if test "x$found_ncurses" = xyes; then
632 AM_CFLAGS="$LIBPANELW_CFLAGS $AM_CFLAGS"
633 CFLAGS="$LIBPANEL_CFLAGS $CFLAGS"
634 LIBS="$LIBS -lncursesw $LIBPANELW_LIBS",
639 if test "x$found_ncurses" = xyes; then
640 AC_DEFINE(HAVE_NCURSES_H)
642 # No ncurses, try curses.
653 if test "x$found_curses" = xyes; then
654 AM_CFLAGS="$LIBPANELW_CFLAGS $AM_CFLAGS"
655 CFLAGS="$LIBPANEL_CFLAGS $CFLAGS"
656 LIBS="$LIBS -lcursesw $LIBPANELW_LIBS"
657 AC_DEFINE(HAVE_CURSES_H)
659 AC_MSG_ERROR("curses not found")
663 # Save our CFLAGS/CPPFLAGS/LDFLAGS for the Makefile and restore the old user
665 AC_SUBST(AM_CPPFLAGS)
666 CPPFLAGS="$SAVED_CPPFLAGS"
668 CFLAGS="$SAVED_CFLAGS"
670 LDFLAGS="$SAVED_LDFLAGS"
672 AC_CONFIG_FILES([Makefile
675 libexec/got-read-tree/Makefile
676 libexec/got-fetch-pack/Makefile
677 libexec/got-index-pack/Makefile
678 libexec/got-read-blob/Makefile
679 libexec/got-read-commit/Makefile
680 libexec/got-read-gitconfig/Makefile
681 libexec/got-read-gotconfig/Makefile
682 libexec/got-read-object/Makefile
683 libexec/got-read-pack/Makefile
684 libexec/got-read-patch/Makefile
685 libexec/got-read-tag/Makefile
686 libexec/got-send-pack/Makefile
691 Makefile.common:Makefile.common.in])
694 executables="$(eval echo ${exec_prefix}/bin)"
695 helpers="$(eval echo ${libexecdir})"
696 manpages="$(eval echo ${mandir})"
699 Configured got-portable with:
704 Executables: ${executables}
706 Man pages: ${manpages}