Blob


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])
25 # When CFLAGS isn't set at this stage and gcc is detected by the macro below,
26 # autoconf will automatically use CFLAGS="-O2 -g". Prevent that by using an
27 # empty default.
28 : ${CFLAGS=""}
30 # Save user CPPFLAGS, CFLAGS and LDFLAGS. We need to change them because
31 # AC_CHECK_HEADER doesn't give us any other way to update the include
32 # paths. But for Makefile.am we want to use AM_CPPFLAGS and friends.
33 SAVED_CFLAGS="$CFLAGS"
34 SAVED_CPPFLAGS="$CPPFLAGS"
35 SAVED_LDFLAGS="$LDFLAGS"
37 # YACC override
38 YACC_OVERRIDE="yes"
40 # Checks for programs.
41 AC_PROG_CC
42 AC_PROG_CPP
43 AC_PROG_INSTALL
44 AC_PROG_LN_S
45 AC_PROG_MAKE_SET
46 if test -z "$YACC"; then
47 YACC_OVERRIDE="no"
48 AC_PROG_YACC
49 fi
50 AM_PROG_AR
51 AC_PROG_RANLIB
52 PKG_PROG_PKG_CONFIG
54 if test "$YACC_OVERRIDE" = "yes"; then
55 AC_MSG_NOTICE("Using YACC set from environment: $YACC")
56 fi
58 # Checks for header files.
59 AC_CHECK_HEADERS([ \
60 fcntl.h \
61 langinfo.h \
62 libutil.h \
63 limits.h \
64 linux/landlock.h \
65 locale.h \
66 netdb.h \
67 netinet/in.h \
68 paths.h \
69 poll.h \
70 sha.h \
71 sha1.h \
72 sha2.h \
73 sha256.h \
74 stddef.h \
75 stdint.h \
76 stdlib.h \
77 string.h \
78 sys/ioctl.h \
79 sys/param.h \
80 sys/poll.h \
81 sys/queue.h \
82 sys/select.h \
83 sys/socket.h \
84 sys/time.h \
85 sys/tree.h \
86 util.h \
87 unistd.h \
88 wchar.h \
89 ])
91 AC_HEADER_DIRENT
92 AC_CHECK_DECL([F_CLOSEM],
93 HAVE_FCNTL_CLOSEM
94 AC_DEFINE([HAVE_FCNTL_CLOSEM], [1],
95 [Use F_CLOSEM fcntl for closefrom]),
96 [],
97 [#include <limits.h>
98 #include <fcntl.h>
99 ]
102 AC_MSG_CHECKING([for /proc/pid/fd directory])
103 if test -d "/proc/$$/fd" ; then
104 AC_DEFINE([HAVE_PROC_PID], [1], [Define if you have /proc/$pid/fd])
105 AC_MSG_RESULT([yes])
106 else
107 AC_MSG_RESULT([no])
108 fi
110 AC_MSG_CHECKING([whether program_invocation_short_name is defined])
111 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
112 #include <argp.h>
113 ]], [[
114 program_invocation_short_name = "test";
115 ]])], [
116 AC_MSG_RESULT([yes])
117 AC_DEFINE([HAVE_PROGRAM_INVOCATION_SHORT_NAME], [1],
118 [Define if program_invocation_short_name is defined])
119 ], [
120 AC_MSG_RESULT([no])
121 ])
123 # Look for prctl(PR_SET_NAME).
124 AC_CHECK_DECL(
125 [PR_SET_NAME],
126 [AC_DEFINE([HAVE_PR_SET_NAME], [1], [Define if PR_SET_NAME is defined])],
127 [],
128 [#include <sys/prctl.h>]
131 AM_CONDITIONAL([HAVE_SHA2], [test "x$ac_cv_header_sha2_h" = xyes])
133 AC_CHECK_MEMBERS([struct pollfd.fd], [], [], [[
134 #include <sys/types.h>
135 #ifdef HAVE_POLL_H
136 #include <poll.h>
137 #endif
138 #ifdef HAVE_SYS_POLL_H
139 #include <sys/poll.h>
140 #endif
141 ]])
143 # Checks for typ edefs, structures, and compiler characteristics.
144 AC_CHECK_HEADER_STDBOOL
145 AC_C_INLINE
146 AC_TYPE_INT64_T
147 AC_TYPE_MODE_T
148 AC_TYPE_OFF_T
149 AC_TYPE_PID_T
150 AC_TYPE_SIZE_T
151 AC_TYPE_SSIZE_T
152 AC_TYPE_UINT16_T
153 AC_TYPE_UINT32_T
154 AC_TYPE_UINT64_T
155 AC_TYPE_UINT8_T
157 # Check for ifgroupreq which is only available on BSD.
158 AC_CHECK_TYPES([struct ifgroupreq])
160 # Check for sockaddr_storage. On some systems, ss_len is filled out, although
161 # this is not mandated by POSIX, and hence systems such as linux, don't have
162 # it.
163 AC_CHECK_TYPES([struct sockaddr_storage], [], [], [
164 #include <sys/types.h>
165 #include <sys/socket.h>
166 ])
168 # Same thing as sockaddr_storage above, only now check if the member exists in
169 # the struct as well.
170 AC_CHECK_MEMBERS([struct sockaddr_storage.ss_len], , ,
171 [ #include <netdb.h>
172 #include <netinet/in.h>
173 #include <sys/socket.h> ]
176 AC_CHECK_MEMBERS([struct sockaddr.sa_len], , ,
177 [ #include <netdb.h>
178 #include <netinet/in.h>
179 #include <sys/socket.h> ]
182 # Both checks above will result in:
184 # HAVE_STRUCT_SOCKADDR_AS_LEN
185 # SS_LEN
187 # Either being defined or not.
189 # Look for library needed for flock.
190 AC_SEARCH_LIBS(flock, bsd)
192 # Checks for library functions.
193 AC_FUNC_FORK
194 AC_FUNC_FSEEKO
195 AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK
196 AC_FUNC_MALLOC
197 AC_FUNC_MMAP
198 AC_FUNC_REALLOC
199 AC_FUNC_STRERROR_R
200 AC_FUNC_STRNLEN
201 AC_CHECK_FUNCS([ \
202 dup2 \
203 flock \
204 getcwd \
205 localtime_r \
206 memchr \
207 memmove \
208 memset \
209 mergesort \
210 mkdir \
211 munmap \
212 nl_langinfo \
213 realpath \
214 regcomp \
215 rmdir \
216 setlocale \
217 socket \
218 setresgid \
219 setresuid \
220 setproctitle \
221 strcasecmp \
222 strchr \
223 strcspn \
224 strdup \
225 strerror \
226 strncasecmp \
227 strndup \
228 strrchr \
229 strspn \
230 strstr \
231 strtol \
232 strtoul \
233 sysconf \
234 wcwidth \
235 ])
237 AM_CONDITIONAL([HAVE_SETPROCTITLE], [test "x$ac_cv_func_setproctitle" = xyes])
239 if test "x$ac_cv_func_sysconf" = xyes; then
240 AC_DEFINE([HAVE_SYSCONF], [1], [Define to 1 if sysconf() present])
241 fi
243 # Siphash support.
244 AC_CHECK_FUNCS([SipHash])
245 AM_CONDITIONAL([HAVE_SIPHASH], [test "x$ac_cv_func_SipHash" = xyes])
247 # Check for functions with a compatibility implementation.
248 AC_REPLACE_FUNCS([ \
249 asprintf \
250 closefrom \
251 explicit_bzero \
252 fmt_scaled \
253 freezero \
254 getdtablecount \
255 getline \
256 getprogname \
257 recallocarray \
258 reallocarray \
259 strlcat \
260 strlcpy \
261 strndup \
262 strnlen \
263 strsep \
264 strtonum \
265 ])
266 AM_CONDITIONAL([HAVE_CLOSEFROM], [test "x$ac_cv_func_closefrom" = xyes])
268 # Always use our getopt because 1) glibc's doesn't enforce argument order 2)
269 # musl does not set optarg to NULL for flags without arguments (although it is
270 # not required to, but it is helpful) 3) there are probably other weird
271 # implementations.
272 AC_LIBOBJ(getopt)
274 # Check for b64_ntop. If we have b64_ntop, we assume b64_pton as well.
275 AC_MSG_CHECKING(for b64_ntop)
276 AC_LINK_IFELSE([AC_LANG_PROGRAM(
278 #include <sys/types.h>
279 #include <netinet/in.h>
280 #include <resolv.h>
281 ],
283 b64_ntop(NULL, 0, NULL, 0);
284 ])],
285 found_b64_ntop=yes,
286 found_b64_ntop=no
288 AC_MSG_RESULT($found_b64_ntop)
289 libresolv_LIBS=""
290 if test "x$found_b64_ntop" = xno; then
291 AC_MSG_CHECKING(for b64_ntop with -lresolv)
292 LIBS="-lresolv"
293 AC_LINK_IFELSE([AC_LANG_PROGRAM(
295 #include <sys/types.h>
296 #include <netinet/in.h>
297 #include <resolv.h>
298 ],
300 b64_ntop(NULL, 0, NULL, 0);
301 ])],
302 found_b64_ntop=yes,
303 found_b64_ntop=no
305 AC_MSG_RESULT($found_b64_ntop)
306 libresolv_LIBS="$LIBS"
307 fi
308 if test "x$found_b64_ntop" = xno; then
309 AC_MSG_CHECKING(for b64_ntop with -lnetwork)
310 LIBS="-lresolv -lnetwork"
311 AC_LINK_IFELSE([AC_LANG_PROGRAM(
313 #include <sys/types.h>
314 #include <netinet/in.h>
315 #include <resolv.h>
316 ],
318 b64_ntop(NULL, 0, NULL, 0);
319 ])],
320 found_b64_ntop=yes,
321 found_b64_ntop=no
323 AC_MSG_RESULT($found_b64_ntop)
324 libresolv_LIBS="$LIBS"
325 fi
327 AM_CONDITIONAL([HAVE_B64], [test "x$found_b64_ntop" = xyes])
328 if test "x$found_b64_ntop" = xyes; then
329 AC_DEFINE([HAVE_B64_NTOP], [1], [define if b64_ntop is present])
330 AC_SUBST(libresolv_LIBS)
331 else
332 AC_LIBOBJ(base64)
333 fi
335 # Check the platform we're compiling on.
336 AC_MSG_CHECKING(platform)
337 case "$host_os" in
338 *linux*)
339 AC_MSG_RESULT(linux)
340 PLATFORM=linux
341 ;;
342 *freebsd*)
343 AC_MSG_RESULT(freebsd)
344 PLATFORM=freebsd
345 ;;
346 *darwin*)
347 AC_MSG_RESULT(darwin)
348 PLATFORM=darwin
349 ;;
350 *netbsd*)
351 AC_MSG_RESULT(netbsd)
352 PLATFORM=netbsd
353 ;;
354 *openbsd*)
355 AC_MSG_RESULT(openbsd)
356 PLATFORM=openbsd
357 ;;
358 *dragonfly*)
359 AC_MSG_RESULT(dragonfly)
360 PLATFORM=dragonflybsd
361 ;;
362 *)
363 AC_MSG_RESULT(unknown)
364 PLATFORM=unknown
365 ;;
366 esac
367 AC_SUBST(PLATFORM)
368 AM_CONDITIONAL([HOST_FREEBSD], [test "$PLATFORM" = "freebsd"])
369 AM_CONDITIONAL([HOST_LINUX], [test "$PLATFORM" = "linux"])
370 AM_CONDITIONAL([HOST_DARWIN], [test "$PLATFORM" = "darwin"])
371 AM_CONDITIONAL([HOST_NETBSD], [test "$PLATFORM" = "netbsd"])
372 AM_CONDITIONAL([HOST_OPENBSD], [test "$PLATFORM" = "openbsd"])
373 AM_CONDITIONAL([HOST_DRAGONFLYBSD], [test "$PLATFORM" = "dragonflybsd"])
375 # On OpenBSD, these functions are already defined, yet looking for them in
376 # this way on OpenBSD breaks <sha2.h> inclusion.
377 # FIXME: this needs addressing.
378 if test "x$PLATFORM" != "xopenbsd"; then
379 AC_CHECK_FUNCS([ \
380 SHA256Update \
381 SHA384Update \
382 SHA512Update \
383 ])
384 fi
386 # Look for yacc.
387 if test "YACC_OVERRIDE" = "yes" && test -n "$YACC" \
388 && ! command -v "$YACC" >/dev/null 2>&1; then
389 AC_MSG_ERROR("yacc not found: $YACC")
390 fi
392 if test x"$PLATFORM" = "xdarwin"; then
393 # Check for and/or set HOMEBREW_PREFIX. brew is a common way of
394 # installing applications. The other is MacPorts.
396 # Before Apple Silicon existed (M1 onward), the paths for applications
397 # installed via homebrew was typically /usr/local. However, with M1
398 # onward, this changed to a different path.
400 # Rather than hardcode this, check for HOMEBREW_PREFIX in the
401 # environment if it's already set, and use it. Otherwise, check for
402 # brew(1) and use that. If that fails, default to /usr/local
404 # This also means that MacPorts should continue to work.
406 # But with MacPorts, we should also check --prefix, and use that if it
407 # has been supplied.
409 # In both cases, the variable HOMEBREW_PREFIX is used for both.
410 HB_PREFIX=""
411 FOUND_BISON="no"
412 GNUBISON=""
413 if test -z "$HOMEBREW_PREFIX" -o "$HOMEBREW_PREFIX" = "NONE"; then
414 # HOMEBREW_PREFIX not set, check for brew(1)
415 if command -v brew >/dev/null 2>&1; then
416 AC_MSG_NOTICE("HOMEBREW_PREFIX set via 'brew --prefix'")
417 export HOMEBREW_PREFIX="$(brew --prefix)"
418 fi
420 if test -z "$HOMEBREW_PREFIX" -o "$HOMEBREW_PREFIX" = "NONE"
421 then
422 # Default.
423 if test -z "${prefix}" -o "${prefix}" = "NONE"; then
424 export HOMEBREW_PREFIX="/usr/local"
425 HB_PREFIX="/usr/local"
426 AC_MSG_NOTICE("HOMEBREW_PREFIX defaulting to $HB_PREFIX")
427 else
428 HB_PREFIX="$(eval echo ${prefix})"
429 if test "$HB_PREFIX" = "NONE"; then
430 HB_PREFIX="/opt/local"
431 else
432 AC_MSG_NOTICE("HOMEBREW_PREFIX using --prefix")
433 fi
434 export HOMEBREW_PREFIX="$HB_PREFIX"
435 fi
436 fi
437 fi
439 AC_MSG_NOTICE("HOMEBREW_PREFIX determined as: $HOMEBREW_PREFIX")
441 if test "$YACC_OVERRIDE" = "no" && \
442 ! test -x "${HOMEBREW_PREFIX}/opt/bison/bin/bison"; then
443 AC_MSG_WARN([
444 "***********************************************************
445 GNU Bison not found: ${HOMEBREW_PREFIX}/opt/bison/bin/bison
446 ***********************************************************
448 Falling back to checking either /usr/local or \${prefix}"
449 ])
451 FOUND_BISON="no"
452 AC_MSG_WARN("Trying ${HB_PREFIX}/opt/bison/bin/bison")
453 if test -x "${HB_PREFIX}/opt/bison/bin/bison"; then
454 export HOMEBREW_PREFIX="/usr/local"
455 FOUND_BISON="yes"
456 GNUBISON="${HB_PREFIX}/opt/bison/bin/bison"
457 fi
459 if test "$FOUND_BISON" = "no"; then
460 HB_PREFIX="/opt/local"
461 AC_MSG_WARN("Trying ${HB_PREFIX}/bin/bison")
463 if test -x "${HB_PREFIX}/bin/bison"; then
464 export HOMEBREW_PREFIX="${HB_PREFIX}"
465 GNUBISON="${HB_PREFIX}/bin/bison"
466 FOUND_BISON="yes"
467 fi
468 fi
469 else
470 FOUND_BISON="yes"
471 GNUBISON="${HOMEBREW_PREFIX}/opt/bison/bin/bison"
472 fi
474 if test "$FOUND_BISON" = "no" && test "$YACC_OVERRIDE" = "no"; then
475 AC_MSG_ERROR("*** Couldn't find GNU BISON ***")
476 fi
478 # Override YACC here to point to the GNU version of bison.
479 if test "$YACC_OVERRIDE" = "yes"; then
480 export YACC="$YACC -y"
481 else
482 AC_MSG_NOTICE("Found GNU Bison as: $GNUBISON")
483 export YACC="${GNUBISON} -y"
484 fi
485 export LDFLAGS="-L${HOMEBREW_PREFIX}/opt/ncurses/lib -L${HOMEBREW_PREFIX}/opt/openssl@3/lib $LDFLAGS"
486 export CPPFLAGS="-I${HOMEBREW_PREFIX}/opt/ncurses/include -I${HOMEBREW_PREFIX}/opt/openssl@3/include $CPPFLAGS"
487 export PKG_CONFIG_PATH="${HOMEBREW_PREFIX}/opt/ncurses/lib/pkgconfig"
488 export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:${HOMEBREW_PREFIX}/opt/openssl@3/lib/pkgconfig"
489 fi
491 # Landlock detection.
492 AC_MSG_CHECKING([for landlock])
493 AM_CONDITIONAL([HAVE_LINUX_LANDLOCK],
494 [test "x$ac_cv_header_linux_landlock_h" = "xyes"])
495 if test "x$ac_cv_header_linux_landlock_h" = "xyes"; then
496 AC_MSG_RESULT(yes)
497 else
498 AC_MSG_RESULT(no)
499 fi
501 # Clang sanitizers wrap reallocarray even if it isn't available on the target
502 # system. When compiled it always returns NULL and crashes the program. To
503 # detect this we need a more complicated test.
504 AC_MSG_CHECKING([for working reallocarray])
505 AC_RUN_IFELSE([AC_LANG_PROGRAM(
506 [#include <stdlib.h>],
507 [return (reallocarray(NULL, 1, 1) == NULL);]
508 )],
509 AC_MSG_RESULT(yes),
510 [AC_LIBOBJ(reallocarray) AC_MSG_RESULT([no])],
511 [AC_LIBOBJ(reallocarray) AC_MSG_RESULT([no])]
513 AC_MSG_CHECKING([for working recallocarray])
514 AC_RUN_IFELSE([AC_LANG_PROGRAM(
515 [#include <stdlib.h>],
516 [return (recallocarray(NULL, 1, 1, 1) == NULL);]
517 )],
518 AC_MSG_RESULT(yes),
519 [AC_LIBOBJ(recallocarray) AC_MSG_RESULT([no])],
520 [AC_LIBOBJ(recallocarray) AC_MSG_RESULT([no])]
523 # Look for imsg_init in libutil.
524 AC_SEARCH_LIBS(imsg_init, util, found_imsg_init=yes, found_imsg_init=no)
525 AM_CONDITIONAL([HAVE_IMSG], [test "x$found_imsg_init" = "xyes"])
526 if test "x$found_imsg_init" = "xyes"; then
527 AC_DEFINE([HAVE_IMSG], [1], [Define to 1 if imsg is declared in libutil])
528 libutil_LIBS="$ac_cv_search_imsg_init"
529 AC_SUBST(libutil_LIBS)
530 fi
532 # libevent (for gotwebd). Lifted from tmux.
533 # Look for libevent. Try libevent_core or libevent with pkg-config first then
534 # look for the library.
535 found_libevent=no
536 PKG_CHECK_MODULES(
537 LIBEVENT_CORE,
538 [libevent_core >= 2],
540 libevent_CFLAGS="$LIBEVENT_CORE_CFLAGS"
541 libevent_LIBS="$LIBEVENT_CORE_LIBS"
542 AC_SUBST(libevent_CFLAGS)
543 AC_SUBST(libevent_LIBS)
544 found_libevent=yes
545 ],
546 found_libevent=no
548 if test x$found_libevent = xno; then
549 PKG_CHECK_MODULES(
550 LIBEVENT,
551 [libevent >= 2],
553 libevent_CFLAGS="$LIBEVENT_CFLAGS"
554 libevent_LIBS="$LIBEVENT_LIBS"
555 AC_SUBST(libevent_CFLAGS)
556 AC_SUBST(libevent_LIBS)
557 found_libevent=yes
558 ],
559 found_libevent=no
561 fi
562 if test x$found_libevent = xno; then
563 AC_SEARCH_LIBS(
564 event_init,
565 [event_core event event-1.4],
566 found_libevent=yes,
567 found_libevent=no
570 if test "x$found_libevent" = "xyes"; then
571 libevent_LIBS="$ac_cv_search_event_init"
572 AC_SUBST(libevent_LIBS)
573 fi
574 fi
576 if test x$found_libevent = xno; then
577 AC_CHECK_HEADER(
578 event2/event.h,
579 AC_DEFINE([HAVE_EVENT2_EVENT_H], [1], [libevent2 has event.h]),
581 AC_CHECK_HEADER(
582 event.h,
583 AC_DEFINE([HAVE_EVENT_H], [0], [libevent]),
584 found_libevent=no
588 fi
590 if test "x$found_libevent" = xno; then
591 AC_MSG_ERROR("libevent not found")
592 fi
594 AC_CHECK_FUNC([uuid_create], [found_uuid=yes], [found_uuid=no])
596 # Don't define HAVE_BSD_UUID on darwin (Apple) as this breaks the BSD API.
597 # Instead, use the UUID implementation wrapper that's in compat/ plus uuid
598 # ossp
599 if test "x$found_uuid" = "xyes" -a "x$PLATFORM" != "darwin"; then
600 AC_DEFINE([HAVE_BSD_UUID], [1], [BSD UUID])
601 else
602 PKG_CHECK_MODULES(
603 LIBUUID,
604 uuid,
606 libuuid_CFLAGS="$LIBUUID_CFLAGS"
607 libuuid_LIBS="$LIBUUID_LIBS"
608 AC_SUBST(libuuid_CFLAGS)
609 AC_SUBST(libuuid_LIBS)
610 found_libuuid=yes
611 ],
613 found_libuuid=no
617 if test "x$found_libuuid" = "xno"; then
618 AC_CHECK_HEADER(
619 uuid.h,
620 found_libuuid=yes,
621 found_libuuid=no)
622 fi
623 fi
625 if test "x$found_libuuid" = "xno"; then
626 AC_MSG_ERROR("*** couldn't find uuid ***")
627 fi
629 PKG_CHECK_MODULES(
630 ZLIB,
631 zlib,
633 zlib_CFLAGS="$ZLIB_CFLAGS"
634 zlib_LIBS="$ZLIB_LIBS"
635 AC_SUBST(zlib_CFLAGS)
636 AC_SUBST(zlib_LIBS)
637 found_zlib=yes
638 ],
640 found_zlib=no
644 if test "x$found_zlib" = "xno"; then
645 AC_CHECK_HEADER(
646 zlib.h,
648 found_zlib=no)
649 fi
651 if test "x$found_zlib" = "xno"; then
652 AC_MSG_ERROR("*** couldn't find zlib ***")
653 fi
655 if test "$PLATFORM" = "linux"; then
656 PKG_CHECK_MODULES(
657 LIBBSD,
658 libbsd-overlay,
660 libbsd_CFLAGS="$LIBBSD_CFLAGS"
661 libbsd_LIBS="$LIBBSD_LIBS"
662 AC_SUBST(libbsd_CFLAGS)
663 AC_SUBST(libbsd_LIBS)
664 AC_DEFINE([HAVE_LIBBSD], [1], [BSD UUID])
665 ],
667 AC_MSG_ERROR("*** couldn't find libbsd-overlay via pkg-config")
672 # Add LIBBSD_{CFLAGS,LIBS} to the environment here, as libbsd puts its
673 # header files in a non-standard location, which means the overlay for
674 # <sys/tree.h> and <sys/queue.h> won't be found.
675 CFLAGS="$CFLAGS $LIBBSD_CFLAGS"
676 LIBS="$LIBS $LIBBSD_LIBS"
677 fi
679 # Look for a suitable queue.h. We hope libbsd is enough, but that is missing
680 # some declarations.
681 AC_CHECK_DECL(
682 TAILQ_CONCAT,
683 found_queue_h=yes,
684 found_queue_h=no,
685 [#include <sys/queue.h>]
687 AC_CHECK_DECL(
688 TAILQ_PREV,
690 found_queue_h=no,
691 [#include <sys/queue.h>]
693 AC_CHECK_DECL(
694 TAILQ_FOREACH_SAFE,
696 found_queue_h=no,
697 [#include <sys/queue.h>]
700 if test "x$found_queue_h" = xyes; then
701 AC_DEFINE([HAVE_QUEUE_H], [1], [sys/queue.h])
702 else
703 AC_MSG_ERROR("*** sys/queue.h missing key defines ***)
704 fi
706 AC_CHECK_DECL(
707 RB_GENERATE_STATIC,
708 found_sys_tree_h=yes,
709 found_sys_tree_h=no,
710 [#include <sys/tree.h>]
713 if test "x$found_sys_tree_h" = xyes; then
714 AC_DEFINE([HAVE_TREE_H], [1], [sys/tree.h])
715 else
716 AC_MSG_NOTICE("Using compat/tree.h")
717 fi
719 # Look for __progname.
720 AC_MSG_CHECKING(for __progname)
721 AC_LINK_IFELSE([AC_LANG_SOURCE(
723 #include <stdio.h>
724 #include <stdlib.h>
725 extern char *__progname;
726 int main(void) {
727 const char *cp = __progname;
728 printf("%s\n", cp);
729 exit(0);
731 ])],
732 [AC_DEFINE([HAVE___PROGNAME], [1], [___progname]) AC_MSG_RESULT(yes)],
733 [AC_MSG_RESULT(no)]
736 PKG_CHECK_MODULES(
737 LIBPANELW,
738 panelw,
739 LIBPANELW_LIBS="$LIBPANELW_LIBS"
740 found_panel=yes,
741 found_panel=no
744 if test "x$found_panel" = "xno"; then
745 PKG_CHECK_MODULES(
746 LIBPANELW,
747 gnupanelw,
749 LIBPANELW_LIBS="$LIBPANELW_LIBS"
750 found_panel=yes
751 ],
752 found_panel=no
754 fi
756 if test "x$found_panel" = "xno"; then
757 PKG_CHECK_MODULES(
758 LIBPANELW,
759 panel,
761 LIBPANELW_LIBS="$LIBPANELW_LIBS"
762 found_panel=yes
763 ],
764 found_panel=no
766 fi
768 if test "x$found_panel" = "xno"; then
769 AC_CHECK_LIB(panelw, update_panels, [],
770 AC_MSG_ERROR([ "*** panelw not found for ncurses. ***"]),
771 [-lncurses]
774 fi
776 PKG_CHECK_MODULES(
777 LIBNCURSES,
778 ncursesw,
779 found_ncurses=yes,
780 found_ncurses=no
782 if test "x$found_ncurses" = xyes; then
783 libncurses_CFLAGS="$LIBNCURSES_CFLAGS $LIBTINFO_CFLAGS $LIBPANELW_CFLAGS"
784 libncurses_LIBS="$LIBNCURSES_LIBS $LIBTINFO_LIBS $LIBPANELW_LIBS"
785 AC_SUBST(libncurses_CFLAGS)
786 AC_SUBST(libncurses_LIBS)
787 else
788 AC_SEARCH_LIBS(
789 setupterm,
790 found_ncurses=yes,
791 found_ncurses=no
793 if test "x$found_ncurses" = xyes; then
794 AC_CHECK_HEADER(
795 ncurses.h,
796 libncurses_CFLAGS="$LIBPANELW_CFLAGS $LIBPANEL_CFLAGS"
797 libncurses_LIBS="$LIBPANELW_LIBS -lncursesw"
798 AC_SUBST(libncurses_CFLAGS)
799 AC_SUBST(libncurses_LIBS)
801 fi
802 fi
803 if test "x$found_ncurses" = xyes; then
804 AC_DEFINE([HAVE_NCURSES_H], [1], [NCurses])
805 else
806 # No ncurses, try curses.
807 AC_CHECK_FUNC(
808 setupterm,
809 found_curses=yes,
810 found_curses=no
812 AC_CHECK_HEADER(
813 curses.h,
814 found_curses=yes,
815 found_curses=no)
816 if test "x$found_curses" = xyes; then
817 libncurses_CFLAGS="$LIBPANELW_CFLAGS $LIBPANEL_CFLAGS"
818 libncurses_LIBS="$LIBPANELW_LIBS -lncursesw -lpanelw"
819 AC_SUBST(libncurses_CFLAGS)
820 AC_SUBST(libncurses_LIBS)
821 AC_DEFINE([HAVE_CURSES_H], [1], [Curses_h])
822 else
823 AC_MSG_ERROR("curses not found")
824 fi
825 fi
827 # Save our CFLAGS/CPPFLAGS/LDFLAGS for the Makefile and restore the old user
828 # variables.
829 AC_SUBST(AM_CPPFLAGS)
830 CPPFLAGS="$SAVED_CPPFLAGS"
831 AC_SUBST(AM_CFLAGS)
832 CFLAGS="$SAVED_CFLAGS"
833 AC_SUBST(AM_LDFLAGS)
834 LDFLAGS="$SAVED_LDFLAGS"
836 # LIBS is designed to accumulate library dependencies as checks for them are
837 # peformed, so that this can be included directly to ld(1).
839 # However, this hinders the splitting up of the library dependencies so that
840 # they're targetted just where they're needed. Flatting LIBS here ensures
841 # that this happens appropriately.
842 LIBS=""
844 AH_BOTTOM([#include "got_compat2.h"])
846 AC_CONFIG_FILES([Makefile
847 compat/Makefile
848 libexec/Makefile
849 libexec/got-read-tree/Makefile
850 libexec/got-fetch-pack/Makefile
851 libexec/got-index-pack/Makefile
852 libexec/got-read-blob/Makefile
853 libexec/got-read-commit/Makefile
854 libexec/got-read-gitconfig/Makefile
855 libexec/got-read-gotconfig/Makefile
856 libexec/got-read-object/Makefile
857 libexec/got-read-pack/Makefile
858 libexec/got-read-patch/Makefile
859 libexec/got-read-tag/Makefile
860 libexec/got-send-pack/Makefile
861 got/Makefile
862 gotadmin/Makefile
863 gotwebd/Makefile
864 tog/Makefile
865 Makefile.common:Makefile.common.in])
866 AC_OUTPUT
868 executables="$(eval echo ${exec_prefix}/bin)"
869 helpers="$(eval echo ${libexecdir})"
870 manpages="$(eval echo ${mandir})"
872 echo "
873 Configured got-portable with:
875 Version: $VERSION
877 Prefix: ${prefix}
878 Executables: ${executables}
879 Bison: $YACC
880 CFlags: $CFLAGS
881 Helpers: ${helpers}
882 Man pages: ${manpages}