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, chec for
238 # brew(1) and use that. If that fails, default to /usr/local
240 # This also means that MacPorts should continue to work.
241 if test -z "$HOMEBREW_PREFIX"; then
242 # HOMEBREW_PREFIX not set, check for brew(1)
243 if test -x command -v brew >/dev/null 2>&1; then
244 export HOMEBREW_PREFIX="$(brew --prefix)"
247 export HOMEBREW_PREFIX="/usr/local"
251 if ! test -x "${HOMEBREW_PREFIX}/opt/bison/bin/bison"; then
252 AC_MSG_ERROR("GNU Bison not found")
255 # Override YACC here to point to the GNU version of bison.
256 export YACC="${HOMEBREW_PREFIX}/opt/bison/bin/bison -y"
257 export LDFLAGS="-L${HOMEBREW_PREFIX}/opt/ncurses/lib -L${HOMEBREW_PREFI}/opt/openssl@3/lib $LDFLAGS"
258 export CPPFLAGS="-I${HOMEBREW_PREFIX}/opt/ncurses/include -I${HOMEBREW_PREFIX}/opt/openssl@3/include $CPPFLAGS"
259 export PKG_CONFIG_PATH="${HOMEBREW_PREFIX}/opt/ncurses/lib/pkgconfig"
260 export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:${HOMEBREW_PREFIX}/opt/openssl@3/lib/pkgconfig"
263 # Landlock detection.
264 AC_MSG_CHECKING([for landlock])
265 AM_CONDITIONAL([HAVE_LINUX_LANDLOCK],
266 [test "x$ac_cv_header_linux_landlock_h" = "xyes"])
267 if test "x$ac_cv_header_linux_landlock_h" = "xyes"; then
273 # Clang sanitizers wrap reallocarray even if it isn't available on the target
274 # system. When compiled it always returns NULL and crashes the program. To
275 # detect this we need a more complicated test.
276 AC_MSG_CHECKING([for working reallocarray])
277 AC_RUN_IFELSE([AC_LANG_PROGRAM(
278 [#include <stdlib.h>],
279 [return (reallocarray(NULL, 1, 1) == NULL);]
282 [AC_LIBOBJ(reallocarray) AC_MSG_RESULT([no])],
283 [AC_LIBOBJ(reallocarray) AC_MSG_RESULT([no])]
285 AC_MSG_CHECKING([for working recallocarray])
286 AC_RUN_IFELSE([AC_LANG_PROGRAM(
287 [#include <stdlib.h>],
288 [return (recallocarray(NULL, 1, 1, 1) == NULL);]
291 [AC_LIBOBJ(recallocarray) AC_MSG_RESULT([no])],
292 [AC_LIBOBJ(recallocarray) AC_MSG_RESULT([no])]
295 # Look for imsg_init in libutil.
296 AC_SEARCH_LIBS(imsg_init, util, found_imsg_init=yes, found_imsg_init=no)
297 if test "x$found_imsg_init" = xyes; then
301 AC_LIBOBJ(imsg-buffer)
304 # libevent (for gotwebd). Lifted from tmux.
305 # Look for libevent. Try libevent_core or libevent with pkg-config first then
306 # look for the library.
309 [libevent_core >= 2],
311 AM_CPPFLAGS="$LIBEVENT_CORE_CFLAGS $AM_CPPFLAGS"
312 CPPFLAGS="$AM_CPPFLAGS $SAVED_CPPFLAGS"
313 LIBS="$LIBEVENT_CORE_LIBS $LIBS"
318 if test x$found_libevent = xno; then
323 AM_CPPFLAGS="$LIBEVENT_CFLAGS $AM_CPPFLAGS"
324 CPPFLAGS="$AM_CPPFLAGS $SAVED_CPPFLAGS"
325 LIBS="$LIBEVENT_LIBS $LIBS"
331 if test x$found_libevent = xno; then
334 [event_core event event-1.4],
341 AC_DEFINE(HAVE_EVENT2_EVENT_H),
345 AC_DEFINE(HAVE_EVENT_H),
350 if test "x$found_libevent" = xno; then
351 AC_MSG_ERROR("libevent not found")
354 # libcrypto (via libssl for SHA information)
359 AM_CFLAGS="$LIBCRYPTO_CFLAGS $AM_CFLAGS"
360 CFLAGS="$AM_CFLAGS $SAVED_CFLAGS"
361 LIBS="$LIBCRYPTO_LIBS $LIBS"
369 if test "x$found_libcrypto" = "xyes"; then
370 AC_DEFINE(HAVE_LIBCRYPTO)
373 AC_SEARCH_LIBS(uuid_create, , AC_DEFINE(HAVE_BSD_UUID))
374 AC_SEARCH_LIBS(uuid_create, found_uuid=no, found_uuid=yes)
375 AC_SEARCH_LIBS(mergesort, , AC_DEFINE(HAVE_BSD_MERGESORT))
377 # Don't define HAVE_BSD_UUID on darwin (Apple) as this breaks the BSD API.
378 # Instead, use the UUID implementation wrapper that's in compat/ plus uuid
380 if test "x$found_uuid" = "xyes" -a "x$PLATFORM" != "darwin"; then
381 AC_DEFINE(HAVE_BSD_UUID)
387 AM_CFLAGS="$LIBUUID_CFLAGS $AM_CFLAGS"
388 CFLAGS="$AM_CFLAGS $SAVED_CFLAGS"
389 LIBS="$LIBUUID_LIBS $LIBS"
397 if test "x$found_libuuid" = "xno"; then
405 if test "x$found_libuuid" = "xno"; then
406 AC_MSG_ERROR("*** couldn't find uuid ***")
413 AM_CFLAGS="$ZLIB_CFLAGS $AM_CFLAGS"
414 CFLAGS="$AM_CFLAGS $SAVED_CFLAGS"
415 LIBS="$ZLIB_LIBS $LIBS"
423 if test "x$found_zlib" = "xno"; then
430 if test "x$found_zlib" = "xno"; then
431 AC_MSG_ERROR("*** couldn't find zlib ***")
434 if test "$PLATFORM" = "linux"; then
439 AM_CFLAGS="$LIBMD_CFLAGS $AM_CFLAGS"
440 CFLAGS="$AM_CFLAGS $SAVED_CFLAGS"
441 LIBS="$LIBMD_LIBS $LIBS"
444 AC_MSG_ERROR("*** couldn't find libmd via pkg-config")
451 AM_CFLAGS="$LIBBSD_CFLAGS $AM_CFLAGS"
452 CFLAGS="$AM_CFLAGS $SAVED_CFLAGS"
453 LIBS="$LIBBSD_LIBS $LIBS"
455 AC_DEFINE(HAVE_LIBBSD)
458 AC_MSG_ERROR("*** couldn't find libbsd-overlay via pkg-config")
464 # Look for a suitable queue.h. We hope libbsd is enough, but that is missing
470 [#include <sys/queue.h>]
476 [#include <sys/queue.h>]
482 [#include <sys/queue.h>]
485 if test "x$found_queue_h" = xyes; then
486 AC_DEFINE(HAVE_QUEUE_H)
488 AC_MSG_ERROR("*** sys/queue.h missing key defines ***)
492 # Look for __progname.
493 AC_MSG_CHECKING(for __progname)
494 AC_LINK_IFELSE([AC_LANG_SOURCE(
498 extern char *__progname;
500 const char *cp = __progname;
505 [AC_DEFINE(HAVE___PROGNAME) AC_MSG_RESULT(yes)],
529 if test "x$found_panel" = "xno"; then
530 AC_CHECK_LIB(panelw, update_panels,,
531 AC_MSG_ERROR([ "*** panelw not found for ncurses. ***"])
534 LIBPANELW_LIBS="-lpanelw"
543 if test "x$found_ncurses" = xyes; then
544 AM_CFLAGS="$LIBNCURSES_CFLAGS $LIBTINFO_CFLAGS $LIBPANELW_CFLAGS $AM_CFLAGS"
545 CFLAGS="$LIBNCURSES_CFLAGS $LIBTINFO_CFLAGS $LIBPANELW_CFLAGS $CFLAGS"
546 LIBS="$LIBNCURSES_LIBS $LIBTINFO_LIBS $LIBPANELW_LIBS $LIBS"
554 if test "x$found_ncurses" = xyes; then
557 AM_CFLAGS="$LIBPANELW_CFLAGS $AM_CFLAGS"
558 CFLAGS="$LIBPANEL_CFLAGS $CFLAGS"
559 LIBS="$LIBS -lncursesw $LIBPANELW_LIBS",
564 if test "x$found_ncurses" = xyes; then
565 AC_DEFINE(HAVE_NCURSES_H)
567 # No ncurses, try curses.
578 if test "x$found_curses" = xyes; then
579 AM_CFLAGS="$LIBPANELW_CFLAGS $AM_CFLAGS"
580 CFLAGS="$LIBPANEL_CFLAGS $CFLAGS"
581 LIBS="$LIBS -lcursesw $LIBPANELW_LIBS"
582 AC_DEFINE(HAVE_CURSES_H)
584 AC_MSG_ERROR("curses not found")
588 # Save our CFLAGS/CPPFLAGS/LDFLAGS for the Makefile and restore the old user
590 AC_SUBST(AM_CPPFLAGS)
591 CPPFLAGS="$SAVED_CPPFLAGS"
593 CFLAGS="$SAVED_CFLAGS"
595 LDFLAGS="$SAVED_LDFLAGS"
597 AC_CONFIG_FILES([Makefile
600 libexec/got-read-tree/Makefile
601 libexec/got-fetch-pack/Makefile
602 libexec/got-index-pack/Makefile
603 libexec/got-read-blob/Makefile
604 libexec/got-read-commit/Makefile
605 libexec/got-read-gitconfig/Makefile
606 libexec/got-read-gotconfig/Makefile
607 libexec/got-read-object/Makefile
608 libexec/got-read-pack/Makefile
609 libexec/got-read-patch/Makefile
610 libexec/got-read-tag/Makefile
611 libexec/got-send-pack/Makefile
616 Makefile.common:Makefile.common.in])
619 executables="$(eval echo ${exec_prefix}/bin)"
620 helpers="$(eval echo ${libexecdir})"
621 manpages="$(eval echo ${mandir})"
624 Configured got-portable with:
629 Executables: ${executables}
631 Man pages: ${manpages}