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 AM_CONDITIONAL([HAVE_IMSG], [test "x$found_imsg_init" = "xyes"])
359 if test "x$found_imsg_init" = xno; 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 ***)
553 found_sys_tree_h=yes,
555 [#include <sys/tree.h>]
558 if test "x$found_sys_tree_h" = xyes; then
559 AC_DEFINE(HAVE_TREE_H)
561 AC_MSG_NOTICE("Using compat/tree.h")
564 # Look for __progname.
565 AC_MSG_CHECKING(for __progname)
566 AC_LINK_IFELSE([AC_LANG_SOURCE(
570 extern char *__progname;
572 const char *cp = __progname;
577 [AC_DEFINE(HAVE___PROGNAME) AC_MSG_RESULT(yes)],
601 if test "x$found_panel" = "xno"; then
602 AC_CHECK_LIB(panelw, update_panels, [],
603 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}