CHANGES for 0.93
[got-portable.git] / configure.ac
blob24fac9fc2983a5613885c8e2154d8af4ce715c4f
1 # Process this file with autoconf to produce a configure script.
3 AC_PREREQ([2.69])
4 AC_INIT([got-portable],
5         m4_esyscmd_s(util/got-portable-ver.sh),
6         [thomas@xteddy.org])
7 AC_CONFIG_AUX_DIR(etc)
8 AC_CONFIG_SRCDIR([lib/rcsutil.h])
9 AM_INIT_AUTOMAKE([foreign subdir-objects])
11 AC_CONFIG_HEADERS([include/got_compat.h])
13 AC_DEFINE_UNQUOTED(VERSION, $VERSION)
14 AC_SUBST(VERSION)
15 AC_SUBST(GOT_RELEASE)
17 AC_DEFINE_UNQUOTED([GOT_VERSION], VERSION, [GoT version string])
18 AC_DEFINE_UNQUOTED([GOT_VERSION_NUMBER], VERSION, [Got version number])
20 AC_USE_SYSTEM_EXTENSIONS
21 AC_CANONICAL_HOST
23 AC_CONFIG_SUBDIRS([template])
24 AC_ARG_ENABLE([gotd],
25         AS_HELP_STRING([--enable gotd], [build gotd and gotsh]))
27 # Override gotd's empty_path location.
28 AC_ARG_WITH([gotd-empty-path],
29             [AS_HELP_STRING([--with-gotd-empty-path],
30                             [gotd empty path])
31             ],
32             [GOTD_EMPTY_PATHC=$withval]
33             [])
34 AC_SUBST(GOTD_EMPTY_PATHC)
36 # Override where git's libexec helpers are located for gitwrapper.
37 AC_ARG_WITH([gitwrapper-git-libexec-path],
38             [AS_HELP_STRING([--with-gitwrapper-git-libexec-path],
39                             [git libexec path for gitwrapper])
40             ],
41             [GITWRAPPER_LIBEXEC_PATHC=$withval]
42             [])
43 AC_SUBST(GITWRAPPER_LIBEXEC_PATHC)
45 # When CFLAGS isn't set at this stage and gcc is detected by the macro below,
46 # autoconf will automatically use CFLAGS="-O2 -g". Prevent that by using an
47 # empty default.
48 : ${CFLAGS=""}
50 # Save user CPPFLAGS, CFLAGS and LDFLAGS. We need to change them because
51 # AC_CHECK_HEADER doesn't give us any other way to update the include
52 # paths. But for Makefile.am we want to use AM_CPPFLAGS and friends.
53 SAVED_CFLAGS="$CFLAGS"
54 SAVED_CPPFLAGS="$CPPFLAGS"
55 SAVED_LDFLAGS="$LDFLAGS"
57 # YACC override
58 YACC_OVERRIDE="yes"
60 # Checks for programs.
61 AC_PROG_CC
62 AC_PROG_CPP
63 AC_PROG_INSTALL
64 AC_PROG_LN_S
65 AC_PROG_MAKE_SET
66 if test -z "$YACC"; then
67 YACC_OVERRIDE="no"
68 AC_PROG_YACC
70 AM_PROG_AR
71 AC_PROG_RANLIB
72 PKG_PROG_PKG_CONFIG
74 if test "$YACC_OVERRIDE" = "yes"; then
75         AC_MSG_NOTICE("Using YACC set from environment: $YACC")
78 # Checks for header files.
79 AC_CHECK_HEADERS([ \
80         fcntl.h \
81         getopt.h \
82         langinfo.h \
83         libutil.h \
84         limits.h \
85         linux/landlock.h \
86         locale.h \
87         netdb.h \
88         netinet/in.h \
89         paths.h \
90         poll.h \
91         sha.h \
92         sha1.h \
93         sha2.h \
94         sha256.h \
95         stddef.h \
96         stdint.h \
97         stdlib.h \
98         string.h \
99         sys/ioctl.h \
100         sys/param.h \
101         sys/poll.h \
102         sys/queue.h \
103         sys/select.h \
104         sys/socket.h \
105         sys/time.h \
106         sys/tree.h \
107         util.h \
108         unistd.h \
109         wchar.h \
112 AC_HEADER_DIRENT
113 AC_CHECK_DECL([F_CLOSEM],
114               HAVE_FCNTL_CLOSEM
115               AC_DEFINE([HAVE_FCNTL_CLOSEM], [1],
116                         [Use F_CLOSEM fcntl for closefrom]),
117                         [],
118                         [#include <limits.h>
119                          #include <fcntl.h>
120                         ]
123 AC_MSG_CHECKING([for /proc/pid/fd directory])
124 if test -d "/proc/$$/fd" ; then
125         AC_DEFINE([HAVE_PROC_PID], [1], [Define if you have /proc/$pid/fd])
126         AC_MSG_RESULT([yes])
127 else
128         AC_MSG_RESULT([no])
131 AC_MSG_CHECKING([whether program_invocation_short_name is defined])
132 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
133         #include <argp.h>
134 ]], [[
135         program_invocation_short_name = "test";
136 ]])], [
137         AC_MSG_RESULT([yes])
138         AC_DEFINE([HAVE_PROGRAM_INVOCATION_SHORT_NAME], [1],
139                 [Define if program_invocation_short_name is defined])
140 ], [
141         AC_MSG_RESULT([no])
144 # Look for prctl(PR_SET_NAME).
145 AC_CHECK_DECL(
146         [PR_SET_NAME],
147         [AC_DEFINE([HAVE_PR_SET_NAME], [1], [Define if PR_SET_NAME is defined])],
148         [],
149         [#include <sys/prctl.h>]
152 AM_CONDITIONAL([HAVE_SHA2], [test "x$ac_cv_header_sha2_h" = xyes])
154 AC_CACHE_CHECK([whether getopt has optreset support],
155                 ac_cv_have_getopt_optreset, [
156         AC_LINK_IFELSE([AC_LANG_PROGRAM([[ #include <getopt.h> ]],
157                 [[ extern int optreset; optreset = 0; ]])],
158         [ ac_cv_have_getopt_optreset="yes" ],
159         [ ac_cv_have_getopt_optreset="no"
160         ])
163 AM_CONDITIONAL([HAVE_GETOPT], [test "x$ac_cv_have_getopt_optreset" = "xyes"])
164 if test "x$ac_cv_have_getopt_optreset" = "xyes" ; then
165         AC_DEFINE([HAVE_GETOPT_OPTRESET], [1],
166                 [Define if your getopt(3) defines and uses optreset])
169 AC_CHECK_MEMBERS([struct pollfd.fd], [], [], [[
170 #include <sys/types.h>
171 #ifdef HAVE_POLL_H
172 #include <poll.h>
173 #endif
174 #ifdef HAVE_SYS_POLL_H
175 #include <sys/poll.h>
176 #endif
179 # Checks for typ edefs, structures, and compiler characteristics.
180 AC_CHECK_HEADER_STDBOOL
181 AC_C_INLINE
182 AC_TYPE_INT64_T
183 AC_TYPE_MODE_T
184 AC_TYPE_OFF_T
185 AC_TYPE_PID_T
186 AC_TYPE_SIZE_T
187 AC_TYPE_SSIZE_T
188 AC_TYPE_UINT16_T
189 AC_TYPE_UINT32_T
190 AC_TYPE_UINT64_T
191 AC_TYPE_UINT8_T
193 # Check for ifgroupreq which is only available on BSD.
194 AC_CHECK_TYPES([struct ifgroupreq])
196 # Check for sockaddr_storage.  On some systems, ss_len is filled out, although
197 # this is not mandated by POSIX, and hence systems such as linux, don't have
198 # it.
199 AC_CHECK_TYPES([struct sockaddr_storage], [], [], [
200 #include <sys/types.h>
201 #include <sys/socket.h>
204 # Same thing as sockaddr_storage above, only now check if the member exists in
205 # the struct as well.
206 AC_CHECK_MEMBERS([struct sockaddr_storage.ss_len], , ,
207         [ #include <netdb.h>
208           #include <netinet/in.h>
209           #include <sys/socket.h> ]
212 AC_CHECK_MEMBERS([struct sockaddr.sa_len], , ,
213         [ #include <netdb.h>
214           #include <netinet/in.h>
215           #include <sys/socket.h> ]
218 # Both checks above will result in:
220 # HAVE_STRUCT_SOCKADDR_AS_LEN
221 # SS_LEN
223 # Either being defined or not.
225 # Look for library needed for flock.
226 AC_SEARCH_LIBS(flock, bsd)
228 # Checks for library functions.
229 AC_FUNC_FORK
230 AC_FUNC_FSEEKO
231 AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK
232 AC_FUNC_MALLOC
233 AC_FUNC_MMAP
234 AC_FUNC_REALLOC
235 AC_FUNC_STRERROR_R
236 AC_FUNC_STRNLEN
237 AC_CHECK_FUNCS([ \
238         dup2 \
239         flock \
240         getcwd \
241         localtime_r \
242         memchr \
243         memmove \
244         memset \
245         mergesort \
246         mkdir \
247         munmap \
248         nl_langinfo \
249         realpath \
250         regcomp \
251         rmdir \
252         setlocale \
253         socket \
254         setresgid \
255         setresuid \
256         setproctitle \
257         strcasecmp \
258         strchr \
259         strcspn \
260         strdup \
261         strerror \
262         strncasecmp \
263         strndup \
264         strrchr \
265         strspn \
266         strstr \
267         strtol \
268         strtoul \
269         sysconf \
270         wcwidth \
273 AM_CONDITIONAL([HAVE_SETPROCTITLE], [test "x$ac_cv_func_setproctitle" = xyes])
275 if test "x$ac_cv_func_sysconf" = xyes; then
276         AC_DEFINE([HAVE_SYSCONF], [1], [Define to 1 if sysconf() present])
279 # Siphash support.
280 AC_CHECK_FUNCS([SipHash])
281 AM_CONDITIONAL([HAVE_SIPHASH], [test "x$ac_cv_func_SipHash" = xyes])
283 # Check for functions with a compatibility implementation.
284 AC_REPLACE_FUNCS([ \
285         asprintf \
286         closefrom \
287         explicit_bzero \
288         fmt_scaled \
289         freezero \
290         getdtablecount \
291         getline \
292         getprogname \
293         recallocarray \
294         reallocarray \
295         strlcat \
296         strlcpy \
297         strndup \
298         strnlen \
299         strsep \
300         strtonum \
302 AM_CONDITIONAL([HAVE_CLOSEFROM], [test "x$ac_cv_func_closefrom" = xyes])
304 # Always use our getopt because 1) glibc's doesn't enforce argument order 2)
305 # musl does not set optarg to NULL for flags without arguments (although it is
306 # not required to, but it is helpful) 3) there are probably other weird
307 # implementations.
308 AC_LIBOBJ(getopt)
310 # Check for b64_ntop. If we have b64_ntop, we assume b64_pton as well.
311 AC_MSG_CHECKING(for b64_ntop)
312         AC_LINK_IFELSE([AC_LANG_PROGRAM(
313         [
314                 #include <sys/types.h>
315                 #include <netinet/in.h>
316                 #include <resolv.h>
317         ],
318         [
319                 b64_ntop(NULL, 0, NULL, 0);
320         ])],
321         found_b64_ntop=yes,
322         found_b64_ntop=no
324 AC_MSG_RESULT($found_b64_ntop)
325 libresolv_LIBS=""
326 if test "x$found_b64_ntop" = xno; then
327         AC_MSG_CHECKING(for b64_ntop with -lresolv)
328         LIBS="-lresolv"
329         AC_LINK_IFELSE([AC_LANG_PROGRAM(
330                 [
331                         #include <sys/types.h>
332                         #include <netinet/in.h>
333                         #include <resolv.h>
334                 ],
335                 [
336                         b64_ntop(NULL, 0, NULL, 0);
337                 ])],
338                 found_b64_ntop=yes,
339                 found_b64_ntop=no
340         )
341         AC_MSG_RESULT($found_b64_ntop)
342         libresolv_LIBS="$LIBS"
344 if test "x$found_b64_ntop" = xno; then
345         AC_MSG_CHECKING(for b64_ntop with -lnetwork)
346         LIBS="-lresolv -lnetwork"
347         AC_LINK_IFELSE([AC_LANG_PROGRAM(
348                 [
349                         #include <sys/types.h>
350                         #include <netinet/in.h>
351                         #include <resolv.h>
352                 ],
353                 [
354                         b64_ntop(NULL, 0, NULL, 0);
355                 ])],
356                 found_b64_ntop=yes,
357                 found_b64_ntop=no
358         )
359         AC_MSG_RESULT($found_b64_ntop)
360         libresolv_LIBS="$LIBS"
363 AM_CONDITIONAL([HAVE_B64], [test "x$found_b64_ntop" = xyes])
364 if test "x$found_b64_ntop" = xyes; then
365         AC_DEFINE([HAVE_B64_NTOP], [1], [define if b64_ntop is present])
366         AC_SUBST(libresolv_LIBS)
367 else
368         AC_LIBOBJ(base64)
371 # Check the platform we're compiling on.
372 AC_MSG_CHECKING(platform)
373 case "$host_os" in
374         *linux*)
375                 AC_MSG_RESULT(linux)
376                 PLATFORM=linux
377                 ;;
378         *freebsd*)
379                 AC_MSG_RESULT(freebsd)
380                 PLATFORM=freebsd
381                 ;;
382         *darwin*)
383                 AC_MSG_RESULT(darwin)
384                 PLATFORM=darwin
385                 ;;
386         *netbsd*)
387                 AC_MSG_RESULT(netbsd)
388                 PLATFORM=netbsd
389                 ;;
390         *openbsd*)
391                 AC_MSG_RESULT(openbsd)
392                 PLATFORM=openbsd
393                 ;;
394         *dragonfly*)
395                 AC_MSG_RESULT(dragonfly)
396                 PLATFORM=dragonflybsd
397                 ;;
398         *)
399                 AC_MSG_RESULT(unknown)
400                 PLATFORM=unknown
401                 ;;
402 esac
403 AC_SUBST(PLATFORM)
404 AM_CONDITIONAL([HOST_FREEBSD], [test "$PLATFORM" = "freebsd"])
405 AM_CONDITIONAL([HOST_LINUX], [test "$PLATFORM" = "linux"])
406 AM_CONDITIONAL([HOST_DARWIN], [test "$PLATFORM" = "darwin"])
407 AM_CONDITIONAL([HOST_NETBSD], [test "$PLATFORM" = "netbsd"])
408 AM_CONDITIONAL([HOST_OPENBSD], [test "$PLATFORM" = "openbsd"])
409 AM_CONDITIONAL([HOST_DRAGONFLYBSD], [test "$PLATFORM" = "dragonflybsd"])
411 # On OpenBSD, these functions are already defined, yet looking for them in
412 # this way on OpenBSD breaks <sha2.h> inclusion.
413 # FIXME: this needs addressing.
414 if test "x$PLATFORM" != "xopenbsd"; then
415         AC_CHECK_FUNCS([ \
416                 SHA256Update \
417                 SHA384Update \
418                 SHA512Update \
419         ])
422 # Look for yacc.
423 if test "YACC_OVERRIDE" = "yes" && test -n "$YACC" \
424         && ! command -v "$YACC" >/dev/null 2>&1; then
425         AC_MSG_ERROR("yacc not found: $YACC")
428 if test x"$PLATFORM" = "xdarwin"; then
429         # Check for and/or set HOMEBREW_PREFIX.  brew is a common way of
430         # installing applications.  The other is MacPorts.
431         #
432         # Before Apple Silicon existed (M1 onward), the paths for applications
433         # installed via homebrew was typically /usr/local.  However, with M1
434         # onward, this changed to a different path.
435         #
436         # Rather than hardcode this, check for HOMEBREW_PREFIX in the
437         # environment if it's already set, and use it.  Otherwise, check for
438         # brew(1) and use that.  If that fails, default to /usr/local
439         #
440         # This also means that MacPorts should continue to work.
441         #
442         # But with MacPorts, we should also check --prefix, and use that if it
443         # has been supplied.
444         #
445         # In both cases, the variable HOMEBREW_PREFIX is used for both.
446         HB_PREFIX=""
447         FOUND_BISON="no"
448         GNUBISON=""
449         if test -z "$HOMEBREW_PREFIX" -o "$HOMEBREW_PREFIX" = "NONE"; then
450                 # HOMEBREW_PREFIX not set, check for brew(1)
451                 if command -v brew >/dev/null 2>&1; then
452                         AC_MSG_NOTICE("HOMEBREW_PREFIX set via 'brew --prefix'")
453                         export HOMEBREW_PREFIX="$(brew --prefix)"
454                 fi
456                 if test -z "$HOMEBREW_PREFIX" -o "$HOMEBREW_PREFIX" = "NONE"
457                 then
458                         # Default.
459                         if test -z "${prefix}" -o "${prefix}" = "NONE"; then
460                                 export HOMEBREW_PREFIX="/usr/local"
461                                 HB_PREFIX="/usr/local"
462                                 AC_MSG_NOTICE("HOMEBREW_PREFIX defaulting to $HB_PREFIX")
463                         else
464                                 HB_PREFIX="$(eval echo ${prefix})"
465                                 if test "$HB_PREFIX" = "NONE"; then
466                                         HB_PREFIX="/opt/local"
467                                 else
468                                         AC_MSG_NOTICE("HOMEBREW_PREFIX using --prefix")
469                                 fi
470                                 export HOMEBREW_PREFIX="$HB_PREFIX"
471                         fi
472                 fi
473         fi
475         AC_MSG_NOTICE("HOMEBREW_PREFIX determined as: $HOMEBREW_PREFIX")
477         if test "$YACC_OVERRIDE" = "no" && \
478                 ! test -x "${HOMEBREW_PREFIX}/opt/bison/bin/bison"; then
479                 AC_MSG_WARN([
480                              "***********************************************************
481                              GNU Bison not found: ${HOMEBREW_PREFIX}/opt/bison/bin/bison
482                              ***********************************************************
484                              Falling back to checking either /usr/local or \${prefix}"
485                 ])
487                 FOUND_BISON="no"
488                 AC_MSG_WARN("Trying ${HB_PREFIX}/opt/bison/bin/bison")
489                 if test -x "${HB_PREFIX}/opt/bison/bin/bison"; then
490                         export HOMEBREW_PREFIX="/usr/local"
491                         FOUND_BISON="yes"
492                         GNUBISON="${HB_PREFIX}/opt/bison/bin/bison"
493                 fi
495                 if test "$FOUND_BISON" = "no"; then
496                         HB_PREFIX="/opt/local"
497                         AC_MSG_WARN("Trying ${HB_PREFIX}/bin/bison")
499                         if test -x "${HB_PREFIX}/bin/bison"; then
500                                 export HOMEBREW_PREFIX="${HB_PREFIX}"
501                                 GNUBISON="${HB_PREFIX}/bin/bison"
502                                 FOUND_BISON="yes"
503                         fi
504                 fi
505         else
506                 FOUND_BISON="yes"
507                 GNUBISON="${HOMEBREW_PREFIX}/opt/bison/bin/bison"
508         fi
510         if test "$FOUND_BISON" = "no" && test "$YACC_OVERRIDE" = "no"; then
511                 AC_MSG_ERROR("*** Couldn't find GNU BISON ***")
512         fi
514         # Override YACC here to point to the GNU version of bison.
515         if test "$YACC_OVERRIDE" = "yes"; then
516                 export YACC="$YACC -y"
517         else
518                 AC_MSG_NOTICE("Found GNU Bison as: $GNUBISON")
519                 export YACC="${GNUBISON} -y"
520         fi
521         export LDFLAGS="-L${HOMEBREW_PREFIX}/opt/ncurses/lib -L${HOMEBREW_PREFIX}/opt/openssl@3/lib $LDFLAGS"
522         export CPPFLAGS="-I${HOMEBREW_PREFIX}/opt/ncurses/include -I${HOMEBREW_PREFIX}/opt/openssl@3/include $CPPFLAGS"
523         export PKG_CONFIG_PATH="${HOMEBREW_PREFIX}/opt/ncurses/lib/pkgconfig"
524         export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:${HOMEBREW_PREFIX}/opt/openssl@3/lib/pkgconfig"
527 # Landlock detection.
528 AC_MSG_CHECKING([for landlock])
529 AM_CONDITIONAL([HAVE_LINUX_LANDLOCK],
530     [test "x$ac_cv_header_linux_landlock_h" = "xyes"])
531 if test "x$ac_cv_header_linux_landlock_h" = "xyes"; then
532         AC_MSG_RESULT(yes)
533 else
534         AC_MSG_RESULT(no)
537 # Clang sanitizers wrap reallocarray even if it isn't available on the target
538 # system. When compiled it always returns NULL and crashes the program. To
539 # detect this we need a more complicated test.
540 AC_MSG_CHECKING([for working reallocarray])
541 AC_RUN_IFELSE([AC_LANG_PROGRAM(
542                 [#include <stdlib.h>],
543                 [return (reallocarray(NULL, 1, 1) == NULL);]
544         )],
545         AC_MSG_RESULT(yes),
546         [AC_LIBOBJ(reallocarray) AC_MSG_RESULT([no])],
547         [AC_LIBOBJ(reallocarray) AC_MSG_RESULT([no])]
549 AC_MSG_CHECKING([for working recallocarray])
550 AC_RUN_IFELSE([AC_LANG_PROGRAM(
551                 [#include <stdlib.h>],
552                 [return (recallocarray(NULL, 1, 1, 1) == NULL);]
553         )],
554         AC_MSG_RESULT(yes),
555         [AC_LIBOBJ(recallocarray) AC_MSG_RESULT([no])],
556         [AC_LIBOBJ(recallocarray) AC_MSG_RESULT([no])]
559 # Look for imsg_init in libutil.
560 AC_SEARCH_LIBS(imsg_init, util, found_imsg_init=yes, found_imsg_init=no)
561 AM_CONDITIONAL([HAVE_IMSG], [test "x$found_imsg_init" = "xyes"])
562 if test "x$found_imsg_init" = "xyes"; then
563         AC_DEFINE([HAVE_IMSG], [1], [Define to 1 if imsg is declared in libutil])
564         libutil_LIBS="$ac_cv_search_imsg_init"
565         AC_SUBST(libutil_LIBS)
568 # libevent (for gotwebd).  Lifted from tmux.
569 # Look for libevent. Try libevent_core or libevent with pkg-config first then
570 # look for the library.
571 found_libevent=no
572 PKG_CHECK_MODULES(
573         LIBEVENT_CORE,
574         [libevent_core >= 2],
575         [
576                 libevent_CFLAGS="$LIBEVENT_CORE_CFLAGS"
577                 libevent_LIBS="$LIBEVENT_CORE_LIBS"
578                 AC_SUBST(libevent_CFLAGS)
579                 AC_SUBST(libevent_LIBS)
580                 found_libevent=yes
581         ],
582         found_libevent=no
584 if test x$found_libevent = xno; then
585         PKG_CHECK_MODULES(
586                 LIBEVENT,
587                 [libevent >= 2],
588                 [
589                         libevent_CFLAGS="$LIBEVENT_CFLAGS"
590                         libevent_LIBS="$LIBEVENT_LIBS"
591                         AC_SUBST(libevent_CFLAGS)
592                         AC_SUBST(libevent_LIBS)
593                         found_libevent=yes
594                 ],
595                 found_libevent=no
596         )
598 if test x$found_libevent = xno; then
599         AC_SEARCH_LIBS(
600                 event_init,
601                 [event_core event event-1.4],
602                 found_libevent=yes,
603                 found_libevent=no
604         )
606         if test "x$found_libevent" = "xyes"; then
607                 libevent_LIBS="$ac_cv_search_event_init"
608                 AC_SUBST(libevent_LIBS)
609         fi
612 if test x$found_libevent = xno; then
613 AC_CHECK_HEADER(
614         event2/event.h,
615         AC_DEFINE([HAVE_EVENT2_EVENT_H], [1], [libevent2 has event.h]),
616         [
617                 AC_CHECK_HEADER(
618                         event.h,
619                         AC_DEFINE([HAVE_EVENT_H], [0], [libevent]),
620                         found_libevent=no
621                 )
622         ]
626 if test "x$found_libevent" = xno; then
627         AC_MSG_ERROR("libevent not found")
630 AC_CHECK_FUNC([uuid_create], [found_uuid=yes], [found_uuid=no])
632 # Don't define HAVE_BSD_UUID on darwin (Apple) as this breaks the BSD API.
633 # Instead, use the UUID implementation wrapper that's in compat/ plus uuid
634 # ossp
635 if test "x$found_uuid" = "xyes" -a "x$PLATFORM" != "darwin"; then
636         AC_DEFINE([HAVE_BSD_UUID], [1], [BSD UUID])
637 else
638         PKG_CHECK_MODULES(
639                 LIBUUID,
640                 uuid,
641                 [
642                         libuuid_CFLAGS="$LIBUUID_CFLAGS"
643                         libuuid_LIBS="$LIBUUID_LIBS"
644                         AC_SUBST(libuuid_CFLAGS)
645                         AC_SUBST(libuuid_LIBS)
646                         found_libuuid=yes
647                 ],
648                 [
649                         found_libuuid=no
650                 ]
651         )
653         if test "x$found_libuuid" = "xno"; then
654                 AC_CHECK_HEADER(
655                         uuid.h,
656                         found_libuuid=yes,
657                         found_libuuid=no)
658         fi
661 if test "x$found_libuuid" = "xno"; then
662         AC_MSG_ERROR("*** couldn't find uuid ***")
665 PKG_CHECK_MODULES(
666         ZLIB,
667         zlib,
668         [
669                 zlib_CFLAGS="$ZLIB_CFLAGS"
670                 zlib_LIBS="$ZLIB_LIBS"
671                 AC_SUBST(zlib_CFLAGS)
672                 AC_SUBST(zlib_LIBS)
673                 found_zlib=yes
674         ],
675         [
676                 found_zlib=no
677         ]
680 if test "x$found_zlib" = "xno"; then
681         AC_CHECK_HEADER(
682                 zlib.h,
683                 ,
684                 found_zlib=no)
687 if test "x$found_zlib" = "xno"; then
688         AC_MSG_ERROR("*** couldn't find zlib ***")
691 if test "$PLATFORM" = "linux"; then
692         PKG_CHECK_MODULES(
693                 LIBBSD,
694                 libbsd-overlay,
695                 [
696                         libbsd_CFLAGS="$LIBBSD_CFLAGS"
697                         libbsd_LIBS="$LIBBSD_LIBS"
698                         AC_SUBST(libbsd_CFLAGS)
699                         AC_SUBST(libbsd_LIBS)
700                         AC_DEFINE([HAVE_LIBBSD], [1], [BSD UUID])
701                 ],
702                 [
703                         AC_MSG_ERROR("*** couldn't find libbsd-overlay via pkg-config")
704                 ]
706         )
708         # Add LIBBSD_{CFLAGS,LIBS} to the environment here, as libbsd puts its
709         # header files in a non-standard location, which means the overlay for
710         # <sys/tree.h> and <sys/queue.h> won't be found.
711         CFLAGS="$CFLAGS $LIBBSD_CFLAGS"
712         LIBS="$LIBS $LIBBSD_LIBS"
714         PKG_CHECK_MODULES(
715                 LIBMD,
716                 libmd,
717                 [
718                      libmd_CFLAGS="$LIBMD_CFLAGS"
719                      libmd_LIBS="$LIBMD_LIBS"
720                      AC_SUBST(libmd_CFLAGS)
721                      AC_SUBST(libmd_LIBS)
722                 ], []
723         )
724         CFLAGS="$CFLAGS $LIBMD_CFLAGS"
725         LIBS="$LIBS $LIBMD_LIBS"
729 # Look for a suitable queue.h.  We hope libbsd is enough, but that is missing
730 # some declarations.
731 AC_CHECK_DECL(
732         TAILQ_CONCAT,
733         found_queue_h=yes,
734         found_queue_h=no,
735         [#include <sys/queue.h>]
737 AC_CHECK_DECL(
738         TAILQ_PREV,
739         ,
740         found_queue_h=no,
741         [#include <sys/queue.h>]
743 AC_CHECK_DECL(
744         TAILQ_FOREACH_SAFE,
745         ,
746         found_queue_h=no,
747         [#include <sys/queue.h>]
750 if test "x$found_queue_h" = xyes; then
751         AC_DEFINE([HAVE_QUEUE_H], [1], [sys/queue.h])
752 else
753         AC_MSG_ERROR("*** sys/queue.h missing key defines ***)
756 AC_CHECK_DECL(
757         RB_GENERATE_STATIC,
758         found_sys_tree_h=yes,
759         found_sys_tree_h=no,
760         [#include <sys/tree.h>]
763 if test "x$found_sys_tree_h" = xyes; then
764         AC_DEFINE([HAVE_TREE_H], [1], [sys/tree.h])
765 else
766         AC_MSG_NOTICE("Using compat/tree.h")
769 # Look for __progname.
770 AC_MSG_CHECKING(for __progname)
771 AC_LINK_IFELSE([AC_LANG_SOURCE(
772         [
773                 #include <stdio.h>
774                 #include <stdlib.h>
775                 extern char *__progname;
776                 int main(void) {
777                         const char *cp = __progname;
778                         printf("%s\n", cp);
779                         exit(0);
780                 }
781         ])],
782         [AC_DEFINE([HAVE___PROGNAME], [1], [___progname]) AC_MSG_RESULT(yes)],
783         [AC_MSG_RESULT(no)]
786 PKG_CHECK_MODULES(
787         LIBPANELW,
788         panelw,
789         LIBPANELW_LIBS="$LIBPANELW_LIBS"
790         found_panel=yes,
791         found_panel=no
794 if test "x$found_panel" = "xno"; then
795 PKG_CHECK_MODULES(
796         LIBPANELW,
797         gnupanelw,
798         [
799                 LIBPANELW_LIBS="$LIBPANELW_LIBS"
800                 found_panel=yes
801         ],
802         found_panel=no
806 if test "x$found_panel" = "xno"; then
807 PKG_CHECK_MODULES(
808         LIBPANELW,
809         panel,
810         [
811                 LIBPANELW_LIBS="$LIBPANELW_LIBS"
812                 found_panel=yes
813         ],
814         found_panel=no
818 if test "x$found_panel" = "xno"; then
819         AC_CHECK_LIB(panelw, update_panels, [],
820                 AC_MSG_ERROR([ "*** panelw not found for ncurses. ***"]),
821                 [-lncurses]
822         )
826 PKG_CHECK_MODULES(
827         LIBNCURSES,
828         ncursesw,
829         found_ncurses=yes,
830         found_ncurses=no
832 if test "x$found_ncurses" = xyes; then
833         libncurses_CFLAGS="$LIBNCURSES_CFLAGS $LIBTINFO_CFLAGS $LIBPANELW_CFLAGS"
834         libncurses_LIBS="$LIBNCURSES_LIBS $LIBTINFO_LIBS $LIBPANELW_LIBS"
835         AC_SUBST(libncurses_CFLAGS)
836         AC_SUBST(libncurses_LIBS)
837 else
838         AC_SEARCH_LIBS(
839                 setupterm,
840                 found_ncurses=yes,
841                 found_ncurses=no
842         )
843         if test "x$found_ncurses" = xyes; then
844                 AC_CHECK_HEADER(
845                         ncurses.h,
846                         libncurses_CFLAGS="$LIBPANELW_CFLAGS $LIBPANEL_CFLAGS"
847                         libncurses_LIBS="$LIBPANELW_LIBS -lncursesw"
848                         AC_SUBST(libncurses_CFLAGS)
849                         AC_SUBST(libncurses_LIBS)
850                 )
851         fi
853 if test "x$found_ncurses" = xyes; then
854         AC_DEFINE([HAVE_NCURSES_H], [1], [NCurses])
855 else
856         # No ncurses, try curses.
857         AC_CHECK_FUNC(
858                 setupterm,
859                 found_curses=yes,
860                 found_curses=no
861         )
862         AC_CHECK_HEADER(
863                 curses.h,
864                 found_curses=yes,
865                 found_curses=no)
866         if test "x$found_curses" = xyes; then
867                 libncurses_CFLAGS="$LIBPANELW_CFLAGS $LIBPANEL_CFLAGS"
868                 libncurses_LIBS="$LIBPANELW_LIBS -lncursesw -lpanelw"
869                 AC_SUBST(libncurses_CFLAGS)
870                 AC_SUBST(libncurses_LIBS)
871                 AC_DEFINE([HAVE_CURSES_H], [1], [Curses_h])
872         else
873                 AC_MSG_ERROR("curses not found")
874         fi
877 # Save our CFLAGS/CPPFLAGS/LDFLAGS for the Makefile and restore the old user
878 # variables.
879 AC_SUBST(AM_CPPFLAGS)
880 CPPFLAGS="$SAVED_CPPFLAGS"
881 AC_SUBST(AM_CFLAGS)
882 CFLAGS="$SAVED_CFLAGS"
883 AC_SUBST(AM_LDFLAGS)
884 LDFLAGS="$SAVED_LDFLAGS"
886 # LIBS is designed to accumulate library dependencies as checks for them are
887 # peformed, so that this can be included directly to ld(1).
889 # However, this hinders the splitting up of the library dependencies so that
890 # they're targetted just where they're needed.  Flatting LIBS here ensures
891 # that this happens appropriately.
892 LIBS=""
894 AH_BOTTOM([#include "got_compat2.h"])
896 AM_CONDITIONAL([GOTD_ENABLED], [test "x$enable_gotd" = xyes])
898 AC_CONFIG_FILES([Makefile
899                  compat/Makefile
900                  cvg/Makefile
901                  libexec/Makefile
902                  libexec/got-read-tree/Makefile
903                  libexec/got-fetch-pack/Makefile
904                  libexec/got-index-pack/Makefile
905                  libexec/got-read-blob/Makefile
906                  libexec/got-read-commit/Makefile
907                  libexec/got-read-gitconfig/Makefile
908                  libexec/got-read-gotconfig/Makefile
909                  libexec/got-read-object/Makefile
910                  libexec/got-read-pack/Makefile
911                  libexec/got-read-patch/Makefile
912                  libexec/got-read-tag/Makefile
913                  libexec/got-send-pack/Makefile
914                  got/Makefile
915                  gotadmin/Makefile
916                  gotwebd/Makefile
917                  tog/Makefile
918                  Makefile.common:Makefile.common.in])
920 if test "x$enable_gotd" = "xyes"; then
921         AC_CONFIG_FILES([gitwrapper/Makefile])
922         AC_CONFIG_FILES([gotd/Makefile])
923         AC_CONFIG_FILES([gotsh/Makefile])
924         AC_CONFIG_FILES([gotctl/Makefile])
927 AC_OUTPUT
929 executables="$(eval echo ${exec_prefix}/bin)"
930 helpers="$(eval echo ${libexecdir})"
931 manpages="$(eval echo ${mandir})"
932 gotdep="$GOTD_EMPTY_PATHC"
933 gotgwlep="$GITWRAPPER_LIBEXEC_PATHC"
935 if test -z "$enable_gotd"; then
936         enable_gotd="no"
937         gotdep="N/A"
938         gotgwlep="N/A"
941 if test -z "$gotdep"; then
942         gotdep="N/A"
945 if test -z "$gotgwlep"; then
946         gotgwlep="N/A"
949 echo "
950 Configured got-portable with:
952  Version:      $VERSION
954  Prefix:           ${prefix}
955  Executables:      ${executables}
956  Bison:            $YACC
957  CFlags:           $CFLAGS
958  Gotd:             ${enable_gotd}
959    Empty Path:     ${gotdep}
960    Gitwrapper:     ${gotgwlep}
961  Helpers:          ${helpers}
962  Man pages:        ${manpages}