remove git-repository(5) format details from gotadmin cleanup docs
[got-portable.git] / configure.ac
blob11c980256f2b2e1e96780971d892ff5e672f13f5
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 AC_CHECK_DECL(
277         RB_GENERATE_STATIC,
278         found_sys_tree_h=yes,
279         found_sys_tree_h=no,
280         [#include <sys/tree.h>]
283 AM_CONDITIONAL([HAVE_SETPROCTITLE], [test "x$ac_cv_func_setproctitle" = xyes])
285 if test "x$ac_cv_func_sysconf" = xyes; then
286         AC_DEFINE([HAVE_SYSCONF], [1], [Define to 1 if sysconf() present])
289 # Siphash support.
290 AC_CHECK_FUNCS([SipHash])
291 AM_CONDITIONAL([HAVE_SIPHASH], [test "x$ac_cv_func_SipHash" = xyes])
293 # Check for functions with a compatibility implementation.
294 AC_REPLACE_FUNCS([ \
295         asprintf \
296         closefrom \
297         explicit_bzero \
298         fmt_scaled \
299         freezero \
300         getdtablecount \
301         getline \
302         getprogname \
303         recallocarray \
304         reallocarray \
305         strlcat \
306         strlcpy \
307         strndup \
308         strnlen \
309         strsep \
310         strtonum \
312 AM_CONDITIONAL([HAVE_CLOSEFROM], [test "x$ac_cv_func_closefrom" = xyes])
314 # Always use our getopt because 1) glibc's doesn't enforce argument order 2)
315 # musl does not set optarg to NULL for flags without arguments (although it is
316 # not required to, but it is helpful) 3) there are probably other weird
317 # implementations.
318 AC_LIBOBJ(getopt)
320 # Check for b64_ntop. If we have b64_ntop, we assume b64_pton as well.
321 AC_MSG_CHECKING(for b64_ntop)
322         AC_LINK_IFELSE([AC_LANG_PROGRAM(
323         [
324                 #include <sys/types.h>
325                 #include <netinet/in.h>
326                 #include <resolv.h>
327         ],
328         [
329                 b64_ntop(NULL, 0, NULL, 0);
330         ])],
331         found_b64_ntop=yes,
332         found_b64_ntop=no
334 AC_MSG_RESULT($found_b64_ntop)
335 libresolv_LIBS=""
336 if test "x$found_b64_ntop" = xno; then
337         AC_MSG_CHECKING(for b64_ntop with -lresolv)
338         LIBS="-lresolv"
339         AC_LINK_IFELSE([AC_LANG_PROGRAM(
340                 [
341                         #include <sys/types.h>
342                         #include <netinet/in.h>
343                         #include <resolv.h>
344                 ],
345                 [
346                         b64_ntop(NULL, 0, NULL, 0);
347                 ])],
348                 found_b64_ntop=yes,
349                 found_b64_ntop=no
350         )
351         AC_MSG_RESULT($found_b64_ntop)
352         libresolv_LIBS="$LIBS"
354 if test "x$found_b64_ntop" = xno; then
355         AC_MSG_CHECKING(for b64_ntop with -lnetwork)
356         LIBS="-lresolv -lnetwork"
357         AC_LINK_IFELSE([AC_LANG_PROGRAM(
358                 [
359                         #include <sys/types.h>
360                         #include <netinet/in.h>
361                         #include <resolv.h>
362                 ],
363                 [
364                         b64_ntop(NULL, 0, NULL, 0);
365                 ])],
366                 found_b64_ntop=yes,
367                 found_b64_ntop=no
368         )
369         AC_MSG_RESULT($found_b64_ntop)
370         libresolv_LIBS="$LIBS"
373 AM_CONDITIONAL([HAVE_B64], [test "x$found_b64_ntop" = xyes])
374 if test "x$found_b64_ntop" = xyes; then
375         AC_DEFINE([HAVE_B64_NTOP], [1], [define if b64_ntop is present])
376         AC_SUBST(libresolv_LIBS)
377 else
378         AC_LIBOBJ(base64)
381 # Check the platform we're compiling on.
382 AC_MSG_CHECKING(platform)
383 case "$host_os" in
384         *linux*)
385                 AC_MSG_RESULT(linux)
386                 PLATFORM=linux
387                 ;;
388         *freebsd*)
389                 AC_MSG_RESULT(freebsd)
390                 PLATFORM=freebsd
391                 ;;
392         *darwin*)
393                 AC_MSG_RESULT(darwin)
394                 PLATFORM=darwin
395                 ;;
396         *netbsd*)
397                 AC_MSG_RESULT(netbsd)
398                 PLATFORM=netbsd
399                 ;;
400         *openbsd*)
401                 AC_MSG_RESULT(openbsd)
402                 PLATFORM=openbsd
403                 ;;
404         *dragonfly*)
405                 AC_MSG_RESULT(dragonfly)
406                 PLATFORM=dragonflybsd
407                 ;;
408         *)
409                 AC_MSG_RESULT(unknown)
410                 PLATFORM=unknown
411                 ;;
412 esac
413 AC_SUBST(PLATFORM)
414 AM_CONDITIONAL([HOST_FREEBSD], [test "$PLATFORM" = "freebsd"])
415 AM_CONDITIONAL([HOST_LINUX], [test "$PLATFORM" = "linux"])
416 AM_CONDITIONAL([HOST_DARWIN], [test "$PLATFORM" = "darwin"])
417 AM_CONDITIONAL([HOST_NETBSD], [test "$PLATFORM" = "netbsd"])
418 AM_CONDITIONAL([HOST_OPENBSD], [test "$PLATFORM" = "openbsd"])
419 AM_CONDITIONAL([HOST_DRAGONFLYBSD], [test "$PLATFORM" = "dragonflybsd"])
421 # On OpenBSD, these functions are already defined, yet looking for them in
422 # this way on OpenBSD breaks <sha2.h> inclusion.
423 # FIXME: this needs addressing.
424 if test "x$PLATFORM" != "xopenbsd"; then
425         AC_CHECK_FUNCS([SHA256Update])
428 # Look for yacc.
429 if test "YACC_OVERRIDE" = "yes" && test -n "$YACC" \
430         && ! command -v "$YACC" >/dev/null 2>&1; then
431         AC_MSG_ERROR("yacc not found: $YACC")
434 if test x"$PLATFORM" = "xdarwin"; then
435         # Check for and/or set HOMEBREW_PREFIX.  brew is a common way of
436         # installing applications.  The other is MacPorts.
437         #
438         # Before Apple Silicon existed (M1 onward), the paths for applications
439         # installed via homebrew was typically /usr/local.  However, with M1
440         # onward, this changed to a different path.
441         #
442         # Rather than hardcode this, check for HOMEBREW_PREFIX in the
443         # environment if it's already set, and use it.  Otherwise, check for
444         # brew(1) and use that.  If that fails, default to /usr/local
445         #
446         # This also means that MacPorts should continue to work.
447         #
448         # But with MacPorts, we should also check --prefix, and use that if it
449         # has been supplied.
450         #
451         # In both cases, the variable HOMEBREW_PREFIX is used for both.
452         HB_PREFIX=""
453         FOUND_BISON="no"
454         GNUBISON=""
455         if test -z "$HOMEBREW_PREFIX" -o "$HOMEBREW_PREFIX" = "NONE"; then
456                 # HOMEBREW_PREFIX not set, check for brew(1)
457                 if command -v brew >/dev/null 2>&1; then
458                         AC_MSG_NOTICE("HOMEBREW_PREFIX set via 'brew --prefix'")
459                         export HOMEBREW_PREFIX="$(brew --prefix)"
460                 fi
462                 if test -z "$HOMEBREW_PREFIX" -o "$HOMEBREW_PREFIX" = "NONE"
463                 then
464                         # Default.
465                         if test -z "${prefix}" -o "${prefix}" = "NONE"; then
466                                 export HOMEBREW_PREFIX="/usr/local"
467                                 HB_PREFIX="/usr/local"
468                                 AC_MSG_NOTICE("HOMEBREW_PREFIX defaulting to $HB_PREFIX")
469                         else
470                                 HB_PREFIX="$(eval echo ${prefix})"
471                                 if test "$HB_PREFIX" = "NONE"; then
472                                         HB_PREFIX="/opt/local"
473                                 else
474                                         AC_MSG_NOTICE("HOMEBREW_PREFIX using --prefix")
475                                 fi
476                                 export HOMEBREW_PREFIX="$HB_PREFIX"
477                         fi
478                 fi
479         fi
481         AC_MSG_NOTICE("HOMEBREW_PREFIX determined as: $HOMEBREW_PREFIX")
483         if test "$YACC_OVERRIDE" = "no" && \
484                 ! test -x "${HOMEBREW_PREFIX}/opt/bison/bin/bison"; then
485                 AC_MSG_WARN([
486                              "***********************************************************
487                              GNU Bison not found: ${HOMEBREW_PREFIX}/opt/bison/bin/bison
488                              ***********************************************************
490                              Falling back to checking either /usr/local or \${prefix}"
491                 ])
493                 FOUND_BISON="no"
494                 AC_MSG_WARN("Trying ${HB_PREFIX}/opt/bison/bin/bison")
495                 if test -x "${HB_PREFIX}/opt/bison/bin/bison"; then
496                         export HOMEBREW_PREFIX="/usr/local"
497                         FOUND_BISON="yes"
498                         GNUBISON="${HB_PREFIX}/opt/bison/bin/bison"
499                 fi
501                 if test "$FOUND_BISON" = "no"; then
502                         HB_PREFIX="/opt/local"
503                         AC_MSG_WARN("Trying ${HB_PREFIX}/bin/bison")
505                         if test -x "${HB_PREFIX}/bin/bison"; then
506                                 export HOMEBREW_PREFIX="${HB_PREFIX}"
507                                 GNUBISON="${HB_PREFIX}/bin/bison"
508                                 FOUND_BISON="yes"
509                         fi
510                 fi
511         else
512                 FOUND_BISON="yes"
513                 GNUBISON="${HOMEBREW_PREFIX}/opt/bison/bin/bison"
514         fi
516         if test "$FOUND_BISON" = "no" && test "$YACC_OVERRIDE" = "no"; then
517                 AC_MSG_ERROR("*** Couldn't find GNU BISON ***")
518         fi
520         # Override YACC here to point to the GNU version of bison.
521         if test "$YACC_OVERRIDE" = "yes"; then
522                 export YACC="$YACC -y"
523         else
524                 AC_MSG_NOTICE("Found GNU Bison as: $GNUBISON")
525                 export YACC="${GNUBISON} -y"
526         fi
527         export LDFLAGS="-L${HOMEBREW_PREFIX}/opt/ncurses/lib -L${HOMEBREW_PREFIX}/opt/openssl@3/lib $LDFLAGS"
528         export CPPFLAGS="-I${HOMEBREW_PREFIX}/opt/ncurses/include -I${HOMEBREW_PREFIX}/opt/openssl@3/include $CPPFLAGS"
529         export PKG_CONFIG_PATH="${HOMEBREW_PREFIX}/opt/ncurses/lib/pkgconfig"
530         export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:${HOMEBREW_PREFIX}/opt/openssl@3/lib/pkgconfig"
533 # Landlock detection.
534 AC_MSG_CHECKING([for landlock])
535 AM_CONDITIONAL([HAVE_LINUX_LANDLOCK],
536     [test "x$ac_cv_header_linux_landlock_h" = "xyes"])
537 if test "x$ac_cv_header_linux_landlock_h" = "xyes"; then
538         AC_MSG_RESULT(yes)
539 else
540         AC_MSG_RESULT(no)
543 # Clang sanitizers wrap reallocarray even if it isn't available on the target
544 # system. When compiled it always returns NULL and crashes the program. To
545 # detect this we need a more complicated test.
546 AC_MSG_CHECKING([for working reallocarray])
547 AC_RUN_IFELSE([AC_LANG_PROGRAM(
548                 [#include <stdlib.h>],
549                 [return (reallocarray(NULL, 1, 1) == NULL);]
550         )],
551         AC_MSG_RESULT(yes),
552         [AC_LIBOBJ(reallocarray) AC_MSG_RESULT([no])],
553         [AC_LIBOBJ(reallocarray) AC_MSG_RESULT([no])]
555 AC_MSG_CHECKING([for working recallocarray])
556 AC_RUN_IFELSE([AC_LANG_PROGRAM(
557                 [#include <stdlib.h>],
558                 [return (recallocarray(NULL, 1, 1, 1) == NULL);]
559         )],
560         AC_MSG_RESULT(yes),
561         [AC_LIBOBJ(recallocarray) AC_MSG_RESULT([no])],
562         [AC_LIBOBJ(recallocarray) AC_MSG_RESULT([no])]
565 # Look for imsg_init in libutil.
566 AC_SEARCH_LIBS(imsg_init, util, found_imsg_init=yes, found_imsg_init=no)
567 AM_CONDITIONAL([HAVE_IMSG], [test "x$found_imsg_init" = "xyes"])
568 if test "x$found_imsg_init" = "xyes"; then
569         AC_DEFINE([HAVE_IMSG], [1], [Define to 1 if imsg is declared in libutil])
570         libutil_LIBS="$ac_cv_search_imsg_init"
571         AC_SUBST(libutil_LIBS)
574 # libevent (for gotwebd).  Lifted from tmux.
575 # Look for libevent. Try libevent_core or libevent with pkg-config first then
576 # look for the library.
577 found_libevent=no
578 PKG_CHECK_MODULES(
579         LIBEVENT_CORE,
580         [libevent_core >= 2],
581         [
582                 libevent_CFLAGS="$LIBEVENT_CORE_CFLAGS"
583                 libevent_LIBS="$LIBEVENT_CORE_LIBS"
584                 AC_SUBST(libevent_CFLAGS)
585                 AC_SUBST(libevent_LIBS)
586                 found_libevent=yes
587         ],
588         found_libevent=no
590 if test x$found_libevent = xno; then
591         PKG_CHECK_MODULES(
592                 LIBEVENT,
593                 [libevent >= 2],
594                 [
595                         libevent_CFLAGS="$LIBEVENT_CFLAGS"
596                         libevent_LIBS="$LIBEVENT_LIBS"
597                         AC_SUBST(libevent_CFLAGS)
598                         AC_SUBST(libevent_LIBS)
599                         found_libevent=yes
600                 ],
601                 found_libevent=no
602         )
604 if test x$found_libevent = xno; then
605         AC_SEARCH_LIBS(
606                 event_init,
607                 [event_core event event-1.4],
608                 found_libevent=yes,
609                 found_libevent=no
610         )
612         if test "x$found_libevent" = "xyes"; then
613                 libevent_LIBS="$ac_cv_search_event_init"
614                 AC_SUBST(libevent_LIBS)
615         fi
618 if test x$found_libevent = xno; then
619 AC_CHECK_HEADER(
620         event2/event.h,
621         AC_DEFINE([HAVE_EVENT2_EVENT_H], [1], [libevent2 has event.h]),
622         [
623                 AC_CHECK_HEADER(
624                         event.h,
625                         AC_DEFINE([HAVE_EVENT_H], [0], [libevent]),
626                         found_libevent=no
627                 )
628         ]
632 if test "x$found_libevent" = xno; then
633         AC_MSG_ERROR("libevent not found")
636 AC_CHECK_FUNC([uuid_create], [found_uuid=yes], [found_uuid=no])
638 # Don't define HAVE_BSD_UUID on darwin (Apple) as this breaks the BSD API.
639 # Instead, use the UUID implementation wrapper that's in compat/ plus uuid
640 # ossp
641 if test "x$found_uuid" = "xyes" -a "x$PLATFORM" != "darwin"; then
642         AC_DEFINE([HAVE_BSD_UUID], [1], [BSD UUID])
643 else
644         PKG_CHECK_MODULES(
645                 LIBUUID,
646                 uuid,
647                 [
648                         libuuid_CFLAGS="$LIBUUID_CFLAGS"
649                         libuuid_LIBS="$LIBUUID_LIBS"
650                         AC_SUBST(libuuid_CFLAGS)
651                         AC_SUBST(libuuid_LIBS)
652                         found_libuuid=yes
653                 ],
654                 [
655                         found_libuuid=no
656                 ]
657         )
659         if test "x$found_libuuid" = "xno"; then
660                 AC_CHECK_HEADER(
661                         uuid.h,
662                         found_libuuid=yes,
663                         found_libuuid=no)
664         fi
667 if test "x$found_libuuid" = "xno"; then
668         AC_MSG_ERROR("*** couldn't find uuid ***")
671 PKG_CHECK_MODULES(
672         ZLIB,
673         zlib,
674         [
675                 zlib_CFLAGS="$ZLIB_CFLAGS"
676                 zlib_LIBS="$ZLIB_LIBS"
677                 AC_SUBST(zlib_CFLAGS)
678                 AC_SUBST(zlib_LIBS)
679                 found_zlib=yes
680         ],
681         [
682                 found_zlib=no
683         ]
686 if test "x$found_zlib" = "xno"; then
687         AC_CHECK_HEADER(
688                 zlib.h,
689                 ,
690                 found_zlib=no)
693 if test "x$found_zlib" = "xno"; then
694         AC_MSG_ERROR("*** couldn't find zlib ***")
697 if test "$PLATFORM" = "linux"; then
698         PKG_CHECK_MODULES(
699                 LIBBSD,
700                 libbsd-overlay,
701                 [
702                         libbsd_CFLAGS="$LIBBSD_CFLAGS"
703                         libbsd_LIBS="$LIBBSD_LIBS"
704                         AC_SUBST(libbsd_CFLAGS)
705                         AC_SUBST(libbsd_LIBS)
706                         AC_DEFINE([HAVE_LIBBSD], [1], [BSD UUID])
707                         AC_DEFINE([HAVE_TREE_H], [test x"$found_sys_tree_h" = "xyes"], [HAVE_TREE_H])
708                 ],
709                 [
710                         AC_MSG_ERROR("*** couldn't find libbsd-overlay via pkg-config")
711                 ]
713         )
715         # Add LIBBSD_{CFLAGS,LIBS} to the environment here, as libbsd puts its
716         # header files in a non-standard location, which means the overlay for
717         # <sys/tree.h> and <sys/queue.h> won't be found.
718         CFLAGS="$CFLAGS $LIBBSD_CFLAGS"
719         LIBS="$LIBS $LIBBSD_LIBS"
721         PKG_CHECK_MODULES(
722                 LIBMD,
723                 libmd,
724                 [
725                      libmd_CFLAGS="$LIBMD_CFLAGS"
726                      libmd_LIBS="$LIBMD_LIBS"
727                      AC_SUBST(libmd_CFLAGS)
728                      AC_SUBST(libmd_LIBS)
729                 ], []
730         )
731         CFLAGS="$CFLAGS $LIBMD_CFLAGS"
732         LIBS="$LIBS $LIBMD_LIBS"
736 # Look for a suitable queue.h.  We hope libbsd is enough, but that is missing
737 # some declarations.
738 AC_CHECK_DECL(
739         TAILQ_CONCAT,
740         found_queue_h=yes,
741         found_queue_h=no,
742         [#include <sys/queue.h>]
744 AC_CHECK_DECL(
745         TAILQ_PREV,
746         ,
747         found_queue_h=no,
748         [#include <sys/queue.h>]
750 AC_CHECK_DECL(
751         TAILQ_FOREACH_SAFE,
752         ,
753         found_queue_h=no,
754         [#include <sys/queue.h>]
757 if test "x$found_queue_h" = xyes; then
758         AC_DEFINE([HAVE_QUEUE_H], [1], [sys/queue.h])
759 else
760         AC_MSG_ERROR("*** sys/queue.h missing key defines ***)
763 # Look for crypto (part of openssl)
764 # Note:  libcrypto (via openssl) has a .pc file in pretty-much all distros and
765 # BSDs which we support.
766 PKG_CHECK_MODULES(
767         LIBCRYPTO,
768         [libcrypto],
769         [
770                 libcrypto_CFLAGS="$LIBCRYPTO_CFLAGS"
771                 libcrypto_LIBS="$LIBCRYPTO_LIBS"
772                 AC_SUBST(libcrypto_CFLAGS)
773                 AC_SUBST(libcrypto_LIBS)
774         ],
775         AC_MSG_ERROR(["*** Couldn't find libcrypto ***"])
778 if test "x$PLATFORM" != "xopenbsd"; then
779 PKG_CHECK_MODULES(
780         LIBTLS,
781         [libtls],
782         [
783                 libtls_CFLAGS="$LIBTLS_CFLAGS"
784                 libtls_LIBS="$LIBTLS_LIBS"
785                 AC_SUBST(libtls_CFLAGS)
786                 AC_SUBST(libtls_LIBS)
787         ],
788         AC_MSG_ERROR(["*** Couldn't find libtls ***"])
792 # Look for __progname.
793 AC_MSG_CHECKING(for __progname)
794 AC_LINK_IFELSE([AC_LANG_SOURCE(
795         [
796                 #include <stdio.h>
797                 #include <stdlib.h>
798                 extern char *__progname;
799                 int main(void) {
800                         const char *cp = __progname;
801                         printf("%s\n", cp);
802                         exit(0);
803                 }
804         ])],
805         [AC_DEFINE([HAVE___PROGNAME], [1], [___progname]) AC_MSG_RESULT(yes)],
806         [AC_MSG_RESULT(no)]
809 PKG_CHECK_MODULES(
810         LIBPANELW,
811         panelw,
812         LIBPANELW_LIBS="$LIBPANELW_LIBS"
813         found_panel=yes,
814         found_panel=no
817 if test "x$found_panel" = "xno"; then
818 PKG_CHECK_MODULES(
819         LIBPANELW,
820         gnupanelw,
821         [
822                 LIBPANELW_LIBS="$LIBPANELW_LIBS"
823                 found_panel=yes
824         ],
825         found_panel=no
829 if test "x$found_panel" = "xno"; then
830 PKG_CHECK_MODULES(
831         LIBPANELW,
832         panel,
833         [
834                 LIBPANELW_LIBS="$LIBPANELW_LIBS"
835                 found_panel=yes
836         ],
837         found_panel=no
841 if test "x$found_panel" = "xno"; then
842         AC_CHECK_LIB(panelw, update_panels, [],
843                 AC_MSG_ERROR([ "*** panelw not found for ncurses. ***"]),
844                 [-lncurses]
845         )
849 PKG_CHECK_MODULES(
850         LIBNCURSES,
851         ncursesw,
852         found_ncurses=yes,
853         found_ncurses=no
855 if test "x$found_ncurses" = xyes; then
856         libncurses_CFLAGS="$LIBNCURSES_CFLAGS $LIBTINFO_CFLAGS $LIBPANELW_CFLAGS"
857         libncurses_LIBS="$LIBNCURSES_LIBS $LIBTINFO_LIBS $LIBPANELW_LIBS"
858         AC_SUBST(libncurses_CFLAGS)
859         AC_SUBST(libncurses_LIBS)
860 else
861         AC_SEARCH_LIBS(
862                 setupterm,
863                 found_ncurses=yes,
864                 found_ncurses=no
865         )
866         if test "x$found_ncurses" = xyes; then
867                 AC_CHECK_HEADER(
868                         ncurses.h,
869                         libncurses_CFLAGS="$LIBPANELW_CFLAGS $LIBPANEL_CFLAGS"
870                         libncurses_LIBS="$LIBPANELW_LIBS -lncursesw"
871                         AC_SUBST(libncurses_CFLAGS)
872                         AC_SUBST(libncurses_LIBS)
873                 )
874         fi
876 if test "x$found_ncurses" = xyes; then
877         AC_DEFINE([HAVE_NCURSES_H], [1], [NCurses])
878 else
879         # No ncurses, try curses.
880         AC_CHECK_FUNC(
881                 setupterm,
882                 found_curses=yes,
883                 found_curses=no
884         )
885         AC_CHECK_HEADER(
886                 curses.h,
887                 found_curses=yes,
888                 found_curses=no)
889         if test "x$found_curses" = xyes; then
890                 libncurses_CFLAGS="$LIBPANELW_CFLAGS $LIBPANEL_CFLAGS"
891                 libncurses_LIBS="$LIBPANELW_LIBS -lncursesw -lpanelw"
892                 AC_SUBST(libncurses_CFLAGS)
893                 AC_SUBST(libncurses_LIBS)
894                 AC_DEFINE([HAVE_CURSES_H], [1], [Curses_h])
895         else
896                 AC_MSG_ERROR("curses not found")
897         fi
900 # Save our CFLAGS/CPPFLAGS/LDFLAGS for the Makefile and restore the old user
901 # variables.
902 AC_SUBST(AM_CPPFLAGS)
903 CPPFLAGS="$SAVED_CPPFLAGS"
904 AC_SUBST(AM_CFLAGS)
905 CFLAGS="$SAVED_CFLAGS"
906 AC_SUBST(AM_LDFLAGS)
907 LDFLAGS="$SAVED_LDFLAGS"
909 # LIBS is designed to accumulate library dependencies as checks for them are
910 # peformed, so that this can be included directly to ld(1).
912 # However, this hinders the splitting up of the library dependencies so that
913 # they're targetted just where they're needed.  Flatting LIBS here ensures
914 # that this happens appropriately.
915 LIBS=""
917 AH_BOTTOM([#include "got_compat2.h"])
919 AM_CONDITIONAL([CVG_ENABLED], [test "x$enable_cvg" = xyes])
921 AC_CONFIG_FILES([Makefile
922                  compat/Makefile
923                  gitwrapper/Makefile
924                  got/Makefile
925                  gotadmin/Makefile
926                  gotctl/Makefile
927                  gotd/Makefile
928                  gotd/libexec/Makefile
929                  gotd/libexec/got-notify-email/Makefile
930                  gotd/libexec/got-notify-http/Makefile
931                  gotsh/Makefile
932                  gotwebd/Makefile
933                  libexec/Makefile
934                  libexec/got-fetch-http/Makefile
935                  libexec/got-fetch-pack/Makefile
936                  libexec/got-index-pack/Makefile
937                  libexec/got-read-blob/Makefile
938                  libexec/got-read-commit/Makefile
939                  libexec/got-read-gitconfig/Makefile
940                  libexec/got-read-gotconfig/Makefile
941                  libexec/got-read-object/Makefile
942                  libexec/got-read-pack/Makefile
943                  libexec/got-read-patch/Makefile
944                  libexec/got-read-tag/Makefile
945                  libexec/got-read-tree/Makefile
946                  libexec/got-send-pack/Makefile
947                  tog/Makefile
948                  Makefile.common:Makefile.common.in])
950 if test "x$enable_cvg" = "xyes"; then
951         AC_CONFIG_FILES([cvg/Makefile])
954 AC_OUTPUT
956 executables="$(eval echo ${exec_prefix}/bin)"
957 helpers="$(eval echo ${libexecdir})"
958 manpages="$(eval echo ${mandir})"
959 gotdep="$GOTD_EMPTY_PATHC"
960 gotgwlep="$GITWRAPPER_LIBEXEC_PATHC"
962 if test -z "$enable_cvg"; then
963         enable_cvg="no"
966 if test -z "$gotdep"; then
967         gotdep="N/A"
970 if test -z "$gotgwlep"; then
971         gotgwlep="N/A"
974 echo "
975 Configured got-portable with:
977  Version:      $VERSION
979  Prefix:           ${prefix}
980  Executables:      ${executables}
981  Bison:            $YACC
982  CFlags:           $CFLAGS
983  cvg:              ${enable_cvg}
984  Gotd:
985    Empty Path:     ${gotdep}
986    Gitwrapper:     ${gotgwlep}
987  Helpers:          ${helpers}
988  Man pages:        ${manpages}