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 # When CFLAGS isn't set at this stage and gcc is detected by the macro below,
19 # autoconf will automatically use CFLAGS="-O2 -g". Prevent that by using an
23 # Save user CPPFLAGS, CFLAGS and LDFLAGS. We need to change them because
24 # AC_CHECK_HEADER doesn't give us any other way to update the include
25 # paths. But for Makefile.am we want to use AM_CPPFLAGS and friends.
26 SAVED_CFLAGS="$CFLAGS"
27 SAVED_CPPFLAGS="$CPPFLAGS"
28 SAVED_LDFLAGS="$LDFLAGS"
30 # Checks for programs.
41 # Checks for header files.
68 # Checks for typ edefs, structures, and compiler characteristics.
69 AC_CHECK_HEADER_STDBOOL
82 # Check for ifgroupreq which is only available on BSD.
83 AC_CHECK_TYPES([struct ifgroupreq])
85 # Check for sockaddr_storage. On some systems, ss_len is filled out, although
86 # this is not mandated by POSIX, and hence systems such as linux, don't have
88 AC_CHECK_TYPES([struct sockaddr_storage], [], [], [
89 #include <sys/types.h>
90 #include <sys/socket.h>
93 # Same thing as sockaddr_storage above, only now check if the member exists in
95 AC_CHECK_MEMBERS([struct sockaddr_storage.ss_len], , ,
97 #include <netinet/in.h>
98 #include <sys/socket.h> ]
101 AC_CHECK_MEMBERS([struct sockaddr.sa_len], , ,
103 #include <netinet/in.h>
104 #include <sys/socket.h> ]
107 # Both checks above will result in:
109 # HAVE_STRUCT_SOCKADDR_AS_LEN
112 # Either being defined or not.
114 # Look for library needed for flock.
115 AC_SEARCH_LIBS(flock, bsd)
117 # Checks for library functions.
120 AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK
161 AM_CONDITIONAL([HAVE_SETPROCTITLE], [test "x$ac_cv_func_setproctitle" = xyes])
162 AM_CONDITIONAL([HAVE_SETRESGID], [test "x$ac_cv_func_setresgid" = xyes])
163 AM_CONDITIONAL([HAVE_SETRESUID], [test "x$ac_cv_func_setresuid" = xyes])
166 AC_CHECK_FUNCS([SipHash])
167 AM_CONDITIONAL([HAVE_SIPHASH], [test "x$ac_cv_func_SipHash" = xyes])
169 # Check for functions with a compatibility implementation.
188 # Always use our getopt because 1) glibc's doesn't enforce argument order 2)
189 # musl does not set optarg to NULL for flags without arguments (although it is
190 # not required to, but it is helpful) 3) there are probably other weird
194 # Check the platform we're compiling on.
195 AC_MSG_CHECKING(platform)
202 AC_MSG_RESULT(freebsd)
206 AC_MSG_RESULT(darwin)
210 AC_MSG_RESULT(netbsd)
214 AC_MSG_RESULT(dragonfly)
215 PLATFORM=dragonflybsd
218 AC_MSG_RESULT(unknown)
223 AM_CONDITIONAL([HOST_FREEBSD], [test "$PLATFORM" = "freebsd"])
224 AM_CONDITIONAL([HOST_LINUX], [test "$PLATFORM" = "linux"])
225 AM_CONDITIONAL([HOST_DARWIN], [test "$PLATFORM" = "darwin"])
226 AM_CONDITIONAL([HOST_NETBSD], [test "$PLATFORM" = "netbsd"])
227 AM_CONDITIONAL([HOST_DRAGONFLYBSD], [test "$PLATFORM" = "dragonflybsd"])
229 if test x"$PLATFORM" = "xdarwin"; then
230 # Check for and/or set HOMEBREW_PREFIX. brew is a common way of
231 # installing applications. The other is MacPorts.
233 # Before Apple Silicon existed (M1 onward), the paths for applications
234 # installed via homebrew was typically /usr/local. However, with M1
235 # onward, this changed to a different path.
237 # Rather than hardcode this, check for HOMEBREW_PREFIX in the
238 # environment if it's already set, and use it. Otherwise, check for
239 # brew(1) and use that. If that fails, default to /usr/local
241 # This also means that MacPorts should continue to work.
243 # But with MacPorts, we should also check --prefix, and use that if it
246 # In both cases, the variable HOMEBREW_PREFIX is used for both.
250 if test -z "$HOMEBREW_PREFIX" -o "$HOMEBREW_PREFIX" = "NONE"; then
251 # HOMEBREW_PREFIX not set, check for brew(1)
252 if command -v brew >/dev/null 2>&1; then
253 AC_MSG_NOTICE("HOMEBREW_PREFIX set via 'brew --prefix'")
254 export HOMEBREW_PREFIX="$(brew --prefix)"
257 if test -z "$HOMEBREW_PREFIX" -o "$HOMEBREW_PREFIX" = "NONE"
260 if test -z "${prefix}" -o "${prefix}" = "NONE"; then
261 export HOMEBREW_PREFIX="/usr/local"
262 HB_PREFIX="/usr/local"
263 AC_MSG_NOTICE("HOMEBREW_PREFIX defaulting to $HB_PREFIX")
265 HB_PREFIX="$(eval echo ${prefix})"
266 if test "$HB_PREFIX" = "NONE"; then
267 HB_PREFIX="/opt/local"
269 AC_MSG_NOTICE("HOMEBREW_PREFIX using --prefix")
271 export HOMEBREW_PREFIX="$HB_PREFIX"
276 AC_MSG_NOTICE("HOMEBREW_PREFIX determined as: $HOMEBREW_PREFIX")
278 if ! test -x "${HOMEBREW_PREFIX}/opt/bison/bin/bison"; then
280 "***********************************************************
281 GNU Bison not found: ${HOMEBREW_PREFIX}/opt/bison/bin/bison
282 ***********************************************************
284 Falling back to checking either /usr/local or \${prefix}"
288 AC_MSG_WARN("Trying ${HB_PREFIX}/opt/bison/bin/bison")
289 if test -x "${HB_PREFIX}/opt/bison/bin/bison"; then
290 export HOMEBREW_PREFIX="/usr/local"
292 GNUBISON="${HB_PREFIX}/opt/bison/bin/bison"
295 if test "$FOUND_BISON" = "no"; then
296 HB_PREFIX="/opt/local"
297 AC_MSG_WARN("Trying ${HB_PREFIX}/bin/bison")
299 if test -x "${HB_PREFIX}/bin/bison"; then
300 export HOMEBREW_PREFIX="${HB_PREFIX}"
301 GNUBISON="${HB_PREFIX}/bin/bison"
307 GNUBISON="${HOMEBREW_PREFIX}/opt/bison/bin/bison"
310 if test "$FOUND_BISON" = "no"; then
311 AC_MSG_ERROR("*** Couldn't find GNU BISON ***")
314 AC_MSG_NOTICE("Found GNU Bison as: $GNUBISON")
316 # Override YACC here to point to the GNU version of bison.
317 export YACC="${GNUBISON} -y"
318 export LDFLAGS="-L${HOMEBREW_PREFIX}/opt/ncurses/lib -L${HOMEBREW_PREFIX}/opt/openssl@3/lib $LDFLAGS"
319 export CPPFLAGS="-I${HOMEBREW_PREFIX}/opt/ncurses/include -I${HOMEBREW_PREFIX}/opt/openssl@3/include $CPPFLAGS"
320 export PKG_CONFIG_PATH="${HOMEBREW_PREFIX}/opt/ncurses/lib/pkgconfig"
321 export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:${HOMEBREW_PREFIX}/opt/openssl@3/lib/pkgconfig"
324 # Landlock detection.
325 AC_MSG_CHECKING([for landlock])
326 AM_CONDITIONAL([HAVE_LINUX_LANDLOCK],
327 [test "x$ac_cv_header_linux_landlock_h" = "xyes"])
328 if test "x$ac_cv_header_linux_landlock_h" = "xyes"; then
334 # Clang sanitizers wrap reallocarray even if it isn't available on the target
335 # system. When compiled it always returns NULL and crashes the program. To
336 # detect this we need a more complicated test.
337 AC_MSG_CHECKING([for working reallocarray])
338 AC_RUN_IFELSE([AC_LANG_PROGRAM(
339 [#include <stdlib.h>],
340 [return (reallocarray(NULL, 1, 1) == NULL);]
343 [AC_LIBOBJ(reallocarray) AC_MSG_RESULT([no])],
344 [AC_LIBOBJ(reallocarray) AC_MSG_RESULT([no])]
346 AC_MSG_CHECKING([for working recallocarray])
347 AC_RUN_IFELSE([AC_LANG_PROGRAM(
348 [#include <stdlib.h>],
349 [return (recallocarray(NULL, 1, 1, 1) == NULL);]
352 [AC_LIBOBJ(recallocarray) AC_MSG_RESULT([no])],
353 [AC_LIBOBJ(recallocarray) AC_MSG_RESULT([no])]
356 # Look for imsg_init in libutil.
357 AC_SEARCH_LIBS(imsg_init, util, found_imsg_init=yes, found_imsg_init=no)
358 if test "x$found_imsg_init" = xyes; then
362 AC_LIBOBJ(imsg-buffer)
365 # libevent (for gotwebd). Lifted from tmux.
366 # Look for libevent. Try libevent_core or libevent with pkg-config first then
367 # look for the library.
370 [libevent_core >= 2],
372 AM_CPPFLAGS="$LIBEVENT_CORE_CFLAGS $AM_CPPFLAGS"
373 CPPFLAGS="$AM_CPPFLAGS $SAVED_CPPFLAGS"
374 LIBS="$LIBEVENT_CORE_LIBS $LIBS"
379 if test x$found_libevent = xno; then
384 AM_CPPFLAGS="$LIBEVENT_CFLAGS $AM_CPPFLAGS"
385 CPPFLAGS="$AM_CPPFLAGS $SAVED_CPPFLAGS"
386 LIBS="$LIBEVENT_LIBS $LIBS"
392 if test x$found_libevent = xno; then
395 [event_core event event-1.4],
402 AC_DEFINE(HAVE_EVENT2_EVENT_H),
406 AC_DEFINE(HAVE_EVENT_H),
411 if test "x$found_libevent" = xno; then
412 AC_MSG_ERROR("libevent not found")
415 # libcrypto (via libssl for SHA information)
420 AM_CFLAGS="$LIBCRYPTO_CFLAGS $AM_CFLAGS"
421 CFLAGS="$AM_CFLAGS $SAVED_CFLAGS"
422 LIBS="$LIBCRYPTO_LIBS $LIBS"
430 if test "x$found_libcrypto" = "xyes"; then
431 AC_DEFINE(HAVE_LIBCRYPTO)
434 AC_SEARCH_LIBS(uuid_create, , AC_DEFINE(HAVE_BSD_UUID))
435 AC_SEARCH_LIBS(uuid_create, found_uuid=no, found_uuid=yes)
436 AC_SEARCH_LIBS(mergesort, , AC_DEFINE(HAVE_BSD_MERGESORT))
438 # Don't define HAVE_BSD_UUID on darwin (Apple) as this breaks the BSD API.
439 # Instead, use the UUID implementation wrapper that's in compat/ plus uuid
441 if test "x$found_uuid" = "xyes" -a "x$PLATFORM" != "darwin"; then
442 AC_DEFINE(HAVE_BSD_UUID)
448 AM_CFLAGS="$LIBUUID_CFLAGS $AM_CFLAGS"
449 CFLAGS="$AM_CFLAGS $SAVED_CFLAGS"
450 LIBS="$LIBUUID_LIBS $LIBS"
458 if test "x$found_libuuid" = "xno"; then
466 if test "x$found_libuuid" = "xno"; then
467 AC_MSG_ERROR("*** couldn't find uuid ***")
474 AM_CFLAGS="$ZLIB_CFLAGS $AM_CFLAGS"
475 CFLAGS="$AM_CFLAGS $SAVED_CFLAGS"
476 LIBS="$ZLIB_LIBS $LIBS"
484 if test "x$found_zlib" = "xno"; then
491 if test "x$found_zlib" = "xno"; then
492 AC_MSG_ERROR("*** couldn't find zlib ***")
495 if test "$PLATFORM" = "linux"; then
500 AM_CFLAGS="$LIBMD_CFLAGS $AM_CFLAGS"
501 CFLAGS="$AM_CFLAGS $SAVED_CFLAGS"
502 LIBS="$LIBMD_LIBS $LIBS"
505 AC_MSG_ERROR("*** couldn't find libmd via pkg-config")
512 AM_CFLAGS="$LIBBSD_CFLAGS $AM_CFLAGS"
513 CFLAGS="$AM_CFLAGS $SAVED_CFLAGS"
514 LIBS="$LIBBSD_LIBS $LIBS"
516 AC_DEFINE(HAVE_LIBBSD)
519 AC_MSG_ERROR("*** couldn't find libbsd-overlay via pkg-config")
525 # Look for a suitable queue.h. We hope libbsd is enough, but that is missing
531 [#include <sys/queue.h>]
537 [#include <sys/queue.h>]
543 [#include <sys/queue.h>]
546 if test "x$found_queue_h" = xyes; then
547 AC_DEFINE(HAVE_QUEUE_H)
549 AC_MSG_ERROR("*** sys/queue.h missing key defines ***)
554 found_sys_tree_h=yes,
556 [#include <sys/tree.h>]
559 if test "x$found_sys_tree_h" = xyes; then
560 AC_DEFINE(HAVE_TREE_H)
562 AC_MSG_NOTICE("Using compat/tree.h")
565 # Look for __progname.
566 AC_MSG_CHECKING(for __progname)
567 AC_LINK_IFELSE([AC_LANG_SOURCE(
571 extern char *__progname;
573 const char *cp = __progname;
578 [AC_DEFINE(HAVE___PROGNAME) AC_MSG_RESULT(yes)],
602 if test "x$found_panel" = "xno"; then
603 AC_CHECK_LIB(panelw, update_panels,,
604 AC_MSG_ERROR([ "*** panelw not found for ncurses. ***"])
607 LIBPANELW_LIBS="-lpanelw"
616 if test "x$found_ncurses" = xyes; then
617 AM_CFLAGS="$LIBNCURSES_CFLAGS $LIBTINFO_CFLAGS $LIBPANELW_CFLAGS $AM_CFLAGS"
618 CFLAGS="$LIBNCURSES_CFLAGS $LIBTINFO_CFLAGS $LIBPANELW_CFLAGS $CFLAGS"
619 LIBS="$LIBNCURSES_LIBS $LIBTINFO_LIBS $LIBPANELW_LIBS $LIBS"
627 if test "x$found_ncurses" = xyes; then
630 AM_CFLAGS="$LIBPANELW_CFLAGS $AM_CFLAGS"
631 CFLAGS="$LIBPANEL_CFLAGS $CFLAGS"
632 LIBS="$LIBS -lncursesw $LIBPANELW_LIBS",
637 if test "x$found_ncurses" = xyes; then
638 AC_DEFINE(HAVE_NCURSES_H)
640 # No ncurses, try curses.
651 if test "x$found_curses" = xyes; then
652 AM_CFLAGS="$LIBPANELW_CFLAGS $AM_CFLAGS"
653 CFLAGS="$LIBPANEL_CFLAGS $CFLAGS"
654 LIBS="$LIBS -lcursesw $LIBPANELW_LIBS"
655 AC_DEFINE(HAVE_CURSES_H)
657 AC_MSG_ERROR("curses not found")
661 # Save our CFLAGS/CPPFLAGS/LDFLAGS for the Makefile and restore the old user
663 AC_SUBST(AM_CPPFLAGS)
664 CPPFLAGS="$SAVED_CPPFLAGS"
666 CFLAGS="$SAVED_CFLAGS"
668 LDFLAGS="$SAVED_LDFLAGS"
670 AC_CONFIG_FILES([Makefile
673 libexec/got-read-tree/Makefile
674 libexec/got-fetch-pack/Makefile
675 libexec/got-index-pack/Makefile
676 libexec/got-read-blob/Makefile
677 libexec/got-read-commit/Makefile
678 libexec/got-read-gitconfig/Makefile
679 libexec/got-read-gotconfig/Makefile
680 libexec/got-read-object/Makefile
681 libexec/got-read-pack/Makefile
682 libexec/got-read-patch/Makefile
683 libexec/got-read-tag/Makefile
684 libexec/got-send-pack/Makefile
690 Makefile.common:Makefile.common.in])
693 executables="$(eval echo ${exec_prefix}/bin)"
694 helpers="$(eval echo ${libexecdir})"
695 manpages="$(eval echo ${mandir})"
698 Configured got-portable with:
703 Executables: ${executables}
705 Man pages: ${manpages}