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