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_DEFINE_UNQUOTED(VERSION, "$VERSION")
12 AC_SUBST(VERSION)
13 AC_SUBST(GOT_RELEASE)
15 AC_CANONICAL_HOST
17 # When CFLAGS isn't set at this stage and gcc is detected by the macro below,
18 # autoconf will automatically use CFLAGS="-O2 -g". Prevent that by using an
19 # empty default.
20 : ${CFLAGS=""}
22 # Save user CPPFLAGS, CFLAGS and LDFLAGS. We need to change them because
23 # AC_CHECK_HEADER doesn't give us any other way to update the include
24 # paths. But for Makefile.am we want to use AM_CPPFLAGS and friends.
25 SAVED_CFLAGS="$CFLAGS"
26 SAVED_CPPFLAGS="$CPPFLAGS"
27 SAVED_LDFLAGS="$LDFLAGS"
29 # Checks for programs.
30 AC_PROG_CC
31 AC_PROG_CPP
32 AC_PROG_INSTALL
33 AC_PROG_LN_S
34 AC_PROG_MAKE_SET
35 AC_PROG_YACC
36 AC_PROG_RANLIB
37 PKG_PROG_PKG_CONFIG
38 AC_USE_SYSTEM_EXTENSIONS
40 # Checks for header files.
41 AC_CHECK_HEADERS([ \
42 fcntl.h \
43 langinfo.h \
44 limits.h \
45 linux/landlock.h \
46 locale.h \
47 netdb.h \
48 netinet/in.h \
49 paths.h \
50 poll.h \
51 stddef.h \
52 stdint.h \
53 stdlib.h \
54 string.h \
55 sys/ioctl.h \
56 sys/param.h \
57 sys/poll.h \
58 sys/queue.h \
59 sys/socket.h \
60 sys/time.h \
61 sys/tree.h \
62 util.h \
63 unistd.h \
64 wchar.h \
65 ])
67 # Checks for typ edefs, structures, and compiler characteristics.
68 AC_CHECK_HEADER_STDBOOL
69 AC_C_INLINE
70 AC_TYPE_INT64_T
71 AC_TYPE_MODE_T
72 AC_TYPE_OFF_T
73 AC_TYPE_PID_T
74 AC_TYPE_SIZE_T
75 AC_TYPE_SSIZE_T
76 AC_TYPE_UINT16_T
77 AC_TYPE_UINT32_T
78 AC_TYPE_UINT64_T
79 AC_TYPE_UINT8_T
81 # Check for ifgroupreq which is only available on BSD.
82 AC_CHECK_TYPES([struct ifgroupreq])
84 # Check for sockaddr_storage. On some systems, ss_len is filled out, although
85 # this is not mandated by POSIX, and hence systems such as linux, don't have
86 # it.
87 AC_CHECK_TYPES([struct sockaddr_storage], [], [], [
88 #include <sys/types.h>
89 #include <sys/socket.h>
90 ])
92 # Same thing as sockaddr_storage above, only now check if the member exists in
93 # the struct as well.
94 AC_CHECK_MEMBERS([struct sockaddr_storage.ss_len], , ,
95 [ #include <netdb.h>
96 #include <netinet/in.h>
97 #include <sys/socket.h> ]
98 )
100 AC_CHECK_MEMBERS([struct sockaddr.sa_len], , ,
101 [ #include <netdb.h>
102 #include <netinet/in.h>
103 #include <sys/socket.h> ]
106 # Both checks above will result in:
108 # HAVE_STRUCT_SOCKADDR_AS_LEN
109 # SS_LEN
111 # Either being defined or not.
113 # Look for library needed for flock.
114 AC_SEARCH_LIBS(flock, bsd)
116 # Checks for library functions.
117 AC_FUNC_FORK
118 AC_FUNC_FSEEKO
119 AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK
120 AC_FUNC_MALLOC
121 AC_FUNC_MMAP
122 AC_FUNC_REALLOC
123 AC_FUNC_STRERROR_R
124 AC_FUNC_STRNLEN
125 AC_CHECK_FUNCS([ \
126 dup2 \
127 flock \
128 getcwd \
129 localtime_r \
130 memchr \
131 memmove \
132 memset \
133 mkdir \
134 munmap \
135 nl_langinfo \
136 realpath \
137 regcomp \
138 rmdir \
139 setlocale \
140 socket \
141 setresgid \
142 setresuid \
143 setproctitle \
144 strcasecmp \
145 strchr \
146 strcspn \
147 strdup \
148 strerror \
149 strlcpy \
150 strncasecmp \
151 strndup \
152 strrchr \
153 strspn \
154 strstr \
155 strtol \
156 strtoul \
157 wcwidth \
158 ])
160 AM_CONDITIONAL([HAVE_SETPROCTITLE], [test "x$ac_cv_func_setproctitle" = xyes])
161 AM_CONDITIONAL([HAVE_SETRESGID], [test "x$ac_cv_func_setresgid" = xyes])
162 AM_CONDITIONAL([HAVE_SETRESUID], [test "x$ac_cv_func_setresuid" = xyes])
164 # Siphash support.
165 AC_CHECK_FUNCS([SipHash])
166 AM_CONDITIONAL([HAVE_SIPHASH], [test "x$ac_cv_func_SipHash" = xyes])
168 # Check for functions with a compatibility implementation.
169 AC_REPLACE_FUNCS([ \
170 asprintf \
171 closefrom \
172 explicit_bzero \
173 fmt_scaled \
174 freezero \
175 getdtablecount \
176 getline \
177 getprogname \
178 recallocarray \
179 reallocarray \
180 strlcat \
181 strlcpy \
182 strndup \
183 strsep \
184 strtonum \
185 ])
187 # Always use our getopt because 1) glibc's doesn't enforce argument order 2)
188 # musl does not set optarg to NULL for flags without arguments (although it is
189 # not required to, but it is helpful) 3) there are probably other weird
190 # implementations.
191 AC_LIBOBJ(getopt)
193 # Check the platform we're compiling on.
194 AC_MSG_CHECKING(platform)
195 case "$host_os" in
196 *linux*)
197 AC_MSG_RESULT(linux)
198 PLATFORM=linux
199 ;;
200 *freebsd*)
201 AC_MSG_RESULT(freebsd)
202 PLATFORM=freebsd
203 ;;
204 *darwin*)
205 AC_MSG_RESULT(darwin)
206 PLATFORM=darwin
207 ;;
208 *netbsd*)
209 AC_MSG_RESULT(netbsd)
210 PLATFORM=netbsd
211 ;;
212 *dragonfly*)
213 AC_MSG_RESULT(dragonfly)
214 PLATFORM=dragonflybsd
215 ;;
216 *)
217 AC_MSG_RESULT(unknown)
218 PLATFORM=unknown
219 ;;
220 esac
221 AC_SUBST(PLATFORM)
222 AM_CONDITIONAL([HOST_FREEBSD], [test "$PLATFORM" = "freebsd"])
223 AM_CONDITIONAL([HOST_LINUX], [test "$PLATFORM" = "linux"])
224 AM_CONDITIONAL([HOST_DARWIN], [test "$PLATFORM" = "darwin"])
225 AM_CONDITIONAL([HOST_NETBSD], [test "$PLATFORM" = "netbsd"])
226 AM_CONDITIONAL([HOST_DRAGONFLYBSD], [test "$PLATFORM" = "dragonflybsd"])
228 if test x"$PLATFORM" = "xdarwin"; then
229 # Check for and/or set HOMEBREW_PREFIX. brew is a common way of
230 # installing applications. The other is MacPorts.
232 # Before Apple Silicon existed (M1 onward), the paths for applications
233 # installed via homebrew was typically /usr/local. However, with M1
234 # onward, this changed to a different path.
236 # Rather than hardcode this, check for HOMEBREW_PREFIX in the
237 # environment if it's already set, and use it. Otherwise, chec for
238 # brew(1) and use that. If that fails, default to /usr/local
240 # This also means that MacPorts should continue to work.
241 if test -z "$HOMEBREW_PREFIX"; then
242 # HOMEBREW_PREFIX not set, check for brew(1)
243 if test -x command -v brew >/dev/null 2>&1; then
244 export HOMEBREW_PREFIX="$(brew --prefix)"
245 else
246 # Default.
247 export HOMEBREW_PREFIX="/usr/local"
248 fi
249 fi
251 if ! test -x "${HOMEBREW_PREFIX}/opt/bison/bin/bison"; then
252 AC_MSG_ERROR("GNU Bison not found")
253 fi
255 # Override YACC here to point to the GNU version of bison.
256 export YACC="${HOMEBREW_PREFIX}/opt/bison/bin/bison -y"
257 export LDFLAGS="-L${HOMEBREW_PREFIX}/opt/ncurses/lib -L${HOMEBREW_PREFI}/opt/openssl@3/lib $LDFLAGS"
258 export CPPFLAGS="-I${HOMEBREW_PREFIX}/opt/ncurses/include -I${HOMEBREW_PREFIX}/opt/openssl@3/include $CPPFLAGS"
259 export PKG_CONFIG_PATH="${HOMEBREW_PREFIX}/opt/ncurses/lib/pkgconfig"
260 export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:${HOMEBREW_PREFIX}/opt/openssl@3/lib/pkgconfig"
261 fi
263 # Landlock detection.
264 AC_MSG_CHECKING([for landlock])
265 AM_CONDITIONAL([HAVE_LINUX_LANDLOCK],
266 [test "x$ac_cv_header_linux_landlock_h" = "xyes"])
267 if test "x$ac_cv_header_linux_landlock_h" = "xyes"; then
268 AC_MSG_RESULT(yes)
269 else
270 AC_MSG_RESULT(no)
271 fi
273 # Clang sanitizers wrap reallocarray even if it isn't available on the target
274 # system. When compiled it always returns NULL and crashes the program. To
275 # detect this we need a more complicated test.
276 AC_MSG_CHECKING([for working reallocarray])
277 AC_RUN_IFELSE([AC_LANG_PROGRAM(
278 [#include <stdlib.h>],
279 [return (reallocarray(NULL, 1, 1) == NULL);]
280 )],
281 AC_MSG_RESULT(yes),
282 [AC_LIBOBJ(reallocarray) AC_MSG_RESULT([no])],
283 [AC_LIBOBJ(reallocarray) AC_MSG_RESULT([no])]
285 AC_MSG_CHECKING([for working recallocarray])
286 AC_RUN_IFELSE([AC_LANG_PROGRAM(
287 [#include <stdlib.h>],
288 [return (recallocarray(NULL, 1, 1, 1) == NULL);]
289 )],
290 AC_MSG_RESULT(yes),
291 [AC_LIBOBJ(recallocarray) AC_MSG_RESULT([no])],
292 [AC_LIBOBJ(recallocarray) AC_MSG_RESULT([no])]
295 # Look for imsg_init in libutil.
296 AC_SEARCH_LIBS(imsg_init, util, found_imsg_init=yes, found_imsg_init=no)
297 if test "x$found_imsg_init" = xyes; then
298 AC_DEFINE(HAVE_IMSG)
299 else
300 AC_LIBOBJ(imsg)
301 AC_LIBOBJ(imsg-buffer)
302 fi
304 # libevent (for gotwebd). Lifted from tmux.
305 # Look for libevent. Try libevent_core or libevent with pkg-config first then
306 # look for the library.
307 PKG_CHECK_MODULES(
308 LIBEVENT_CORE,
309 [libevent_core >= 2],
311 AM_CPPFLAGS="$LIBEVENT_CORE_CFLAGS $AM_CPPFLAGS"
312 CPPFLAGS="$AM_CPPFLAGS $SAVED_CPPFLAGS"
313 LIBS="$LIBEVENT_CORE_LIBS $LIBS"
314 found_libevent=yes
315 ],
316 found_libevent=no
318 if test x$found_libevent = xno; then
319 PKG_CHECK_MODULES(
320 LIBEVENT,
321 [libevent >= 2],
323 AM_CPPFLAGS="$LIBEVENT_CFLAGS $AM_CPPFLAGS"
324 CPPFLAGS="$AM_CPPFLAGS $SAVED_CPPFLAGS"
325 LIBS="$LIBEVENT_LIBS $LIBS"
326 found_libevent=yes
327 ],
328 found_libevent=no
330 fi
331 if test x$found_libevent = xno; then
332 AC_SEARCH_LIBS(
333 event_init,
334 [event_core event event-1.4],
335 found_libevent=yes,
336 found_libevent=no
338 fi
339 AC_CHECK_HEADER(
340 event2/event.h,
341 AC_DEFINE(HAVE_EVENT2_EVENT_H),
343 AC_CHECK_HEADER(
344 event.h,
345 AC_DEFINE(HAVE_EVENT_H),
346 found_libevent=no
350 if test "x$found_libevent" = xno; then
351 AC_MSG_ERROR("libevent not found")
352 fi
354 # libcrypto (via libssl for SHA information)
355 PKG_CHECK_MODULES(
356 LIBCRYPTO,
357 libcrypto,
359 AM_CFLAGS="$LIBCRYPTO_CFLAGS $AM_CFLAGS"
360 CFLAGS="$AM_CFLAGS $SAVED_CFLAGS"
361 LIBS="$LIBCRYPTO_LIBS $LIBS"
362 found_libcrypto=yes
363 ],
365 found_libcrypto=no
369 if test "x$found_libcrypto" = "xyes"; then
370 AC_DEFINE(HAVE_LIBCRYPTO)
371 fi
373 AC_SEARCH_LIBS(uuid_create, , AC_DEFINE(HAVE_BSD_UUID))
374 AC_SEARCH_LIBS(uuid_create, found_uuid=no, found_uuid=yes)
375 AC_SEARCH_LIBS(mergesort, , AC_DEFINE(HAVE_BSD_MERGESORT))
377 # Don't define HAVE_BSD_UUID on darwin (Apple) as this breaks the BSD API.
378 # Instead, use the UUID implementation wrapper that's in compat/ plus uuid
379 # ossp
380 if test "x$found_uuid" = "xyes" -a "x$PLATFORM" != "darwin"; then
381 AC_DEFINE(HAVE_BSD_UUID)
382 else
383 PKG_CHECK_MODULES(
384 LIBUUID,
385 uuid,
387 AM_CFLAGS="$LIBUUID_CFLAGS $AM_CFLAGS"
388 CFLAGS="$AM_CFLAGS $SAVED_CFLAGS"
389 LIBS="$LIBUUID_LIBS $LIBS"
390 found_libuuid=yes
391 ],
393 found_libuuid=no
397 if test "x$found_libuuid" = "xno"; then
398 AC_CHECK_HEADER(
399 uuid.h,
400 found_libuuid=yes,
401 found_libuuid=no)
402 fi
403 fi
405 if test "x$found_libuuid" = "xno"; then
406 AC_MSG_ERROR("*** couldn't find uuid ***")
407 fi
409 PKG_CHECK_MODULES(
410 ZLIB,
411 zlib,
413 AM_CFLAGS="$ZLIB_CFLAGS $AM_CFLAGS"
414 CFLAGS="$AM_CFLAGS $SAVED_CFLAGS"
415 LIBS="$ZLIB_LIBS $LIBS"
416 found_zlib=yes
417 ],
419 found_zlib=no
423 if test "x$found_zlib" = "xno"; then
424 AC_CHECK_HEADER(
425 zlib.h,
427 found_zlib=no)
428 fi
430 if test "x$found_zlib" = "xno"; then
431 AC_MSG_ERROR("*** couldn't find zlib ***")
432 fi
434 if test "$PLATFORM" = "linux"; then
435 PKG_CHECK_MODULES(
436 LIBMD,
437 libmd,
439 AM_CFLAGS="$LIBMD_CFLAGS $AM_CFLAGS"
440 CFLAGS="$AM_CFLAGS $SAVED_CFLAGS"
441 LIBS="$LIBMD_LIBS $LIBS"
442 ],
444 AC_MSG_ERROR("*** couldn't find libmd via pkg-config")
447 PKG_CHECK_MODULES(
448 LIBBSD,
449 libbsd-overlay,
451 AM_CFLAGS="$LIBBSD_CFLAGS $AM_CFLAGS"
452 CFLAGS="$AM_CFLAGS $SAVED_CFLAGS"
453 LIBS="$LIBBSD_LIBS $LIBS"
454 found_libbsd=yes
455 AC_DEFINE(HAVE_LIBBSD)
456 ],
458 AC_MSG_ERROR("*** couldn't find libbsd-overlay via pkg-config")
462 fi
464 # Look for a suitable queue.h. We hope libbsd is enough, but that is missing
465 # some declarations.
466 AC_CHECK_DECL(
467 TAILQ_CONCAT,
468 found_queue_h=yes,
469 found_queue_h=no,
470 [#include <sys/queue.h>]
472 AC_CHECK_DECL(
473 TAILQ_PREV,
475 found_queue_h=no,
476 [#include <sys/queue.h>]
478 AC_CHECK_DECL(
479 TAILQ_FOREACH_SAFE,
481 found_queue_h=no,
482 [#include <sys/queue.h>]
485 if test "x$found_queue_h" = xyes; then
486 AC_DEFINE(HAVE_QUEUE_H)
487 else
488 AC_MSG_ERROR("*** sys/queue.h missing key defines ***)
489 fi
492 # Look for __progname.
493 AC_MSG_CHECKING(for __progname)
494 AC_LINK_IFELSE([AC_LANG_SOURCE(
496 #include <stdio.h>
497 #include <stdlib.h>
498 extern char *__progname;
499 int main(void) {
500 const char *cp = __progname;
501 printf("%s\n", cp);
502 exit(0);
504 ])],
505 [AC_DEFINE(HAVE___PROGNAME) AC_MSG_RESULT(yes)],
506 AC_MSG_RESULT(no)
509 PKG_CHECK_MODULES(
510 LIBPANELW,
511 panelw,
512 found_panel=yes,
513 found_panel=no
516 PKG_CHECK_MODULES(
517 LIBPANELW,
518 gnupanelw,
519 found_panel=yes,
520 found_panel=no
523 PKG_CHECK_MODULES(
524 LIBPANELW,
525 panel,
526 found_panel=yes,
527 found_panel=no
529 if test "x$found_panel" = "xno"; then
530 AC_CHECK_LIB(panelw, update_panels,,
531 AC_MSG_ERROR([ "*** panelw not found for ncurses. ***"])
534 LIBPANELW_LIBS="-lpanelw"
535 fi
537 PKG_CHECK_MODULES(
538 LIBNCURSES,
539 ncursesw,
540 found_ncurses=yes,
541 found_ncurses=no
543 if test "x$found_ncurses" = xyes; then
544 AM_CFLAGS="$LIBNCURSES_CFLAGS $LIBTINFO_CFLAGS $LIBPANELW_CFLAGS $AM_CFLAGS"
545 CFLAGS="$LIBNCURSES_CFLAGS $LIBTINFO_CFLAGS $LIBPANELW_CFLAGS $CFLAGS"
546 LIBS="$LIBNCURSES_LIBS $LIBTINFO_LIBS $LIBPANELW_LIBS $LIBS"
547 else
548 AC_CHECK_LIB(
549 ncursesw,
550 setupterm,
551 found_ncurses=yes,
552 found_ncurses=no
554 if test "x$found_ncurses" = xyes; then
555 AC_CHECK_HEADER(
556 ncurses.h,
557 AM_CFLAGS="$LIBPANELW_CFLAGS $AM_CFLAGS"
558 CFLAGS="$LIBPANEL_CFLAGS $CFLAGS"
559 LIBS="$LIBS -lncursesw $LIBPANELW_LIBS",
560 found_ncurses=no
562 fi
563 fi
564 if test "x$found_ncurses" = xyes; then
565 AC_DEFINE(HAVE_NCURSES_H)
566 else
567 # No ncurses, try curses.
568 AC_CHECK_LIB(
569 cursesw,
570 setupterm,
571 found_curses=yes,
572 found_curses=no
574 AC_CHECK_HEADER(
575 curses.h,
577 found_curses=no)
578 if test "x$found_curses" = xyes; then
579 AM_CFLAGS="$LIBPANELW_CFLAGS $AM_CFLAGS"
580 CFLAGS="$LIBPANEL_CFLAGS $CFLAGS"
581 LIBS="$LIBS -lcursesw $LIBPANELW_LIBS"
582 AC_DEFINE(HAVE_CURSES_H)
583 else
584 AC_MSG_ERROR("curses not found")
585 fi
586 fi
588 # Save our CFLAGS/CPPFLAGS/LDFLAGS for the Makefile and restore the old user
589 # variables.
590 AC_SUBST(AM_CPPFLAGS)
591 CPPFLAGS="$SAVED_CPPFLAGS"
592 AC_SUBST(AM_CFLAGS)
593 CFLAGS="$SAVED_CFLAGS"
594 AC_SUBST(AM_LDFLAGS)
595 LDFLAGS="$SAVED_LDFLAGS"
597 AC_CONFIG_FILES([Makefile
598 compat/Makefile
599 libexec/Makefile
600 libexec/got-read-tree/Makefile
601 libexec/got-fetch-pack/Makefile
602 libexec/got-index-pack/Makefile
603 libexec/got-read-blob/Makefile
604 libexec/got-read-commit/Makefile
605 libexec/got-read-gitconfig/Makefile
606 libexec/got-read-gotconfig/Makefile
607 libexec/got-read-object/Makefile
608 libexec/got-read-pack/Makefile
609 libexec/got-read-patch/Makefile
610 libexec/got-read-tag/Makefile
611 libexec/got-send-pack/Makefile
612 got/Makefile
613 gotadmin/Makefile
614 gotwebd/Makefile
615 tog/Makefile
616 Makefile.common:Makefile.common.in])
617 AC_OUTPUT
619 executables="$(eval echo ${exec_prefix}/bin)"
620 helpers="$(eval echo ${libexecdir})"
621 manpages="$(eval echo ${mandir})"
623 echo "
624 Configured got-portable with:
626 Version: $VERSION
628 Prefix: ${prefix}
629 Executables: ${executables}
630 Helpers: ${helpers}
631 Man pages: ${manpages}