use a bloom filter to avoid pointless pack index searches
[got-portable.git] / configure.ac
blob08aa688aa34a9e48edcc75a77151729fe8409ac4
1 # Process this file with autoconf to produce a configure script.
3 AC_PREREQ([2.69])
4 AC_INIT([got-portable], [0.61], [thomas@xteddy.org])
5 AC_CONFIG_AUX_DIR(etc)
6 AC_CONFIG_SRCDIR([lib/rcsutil.h])
7 AM_INIT_AUTOMAKE([foreign subdir-objects])
9 GOT_RELEASE=No
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         locale.h \
46         netdb.h \
47         netinet/in.h \
48         paths.h \
49         stddef.h \
50         stdint.h \
51         stdlib.h \
52         string.h \
53         sys/ioctl.h \
54         sys/param.h \
55         sys/socket.h \
56         sys/time.h \
57         sys/tree.h \
58         util.h \
59         unistd.h \
60         wchar.h \
63 # Checks for typ edefs, structures, and compiler characteristics.
64 AC_CHECK_HEADER_STDBOOL
65 AC_C_INLINE
66 AC_TYPE_INT64_T
67 AC_TYPE_MODE_T
68 AC_TYPE_OFF_T
69 AC_TYPE_PID_T
70 AC_TYPE_SIZE_T
71 AC_TYPE_SSIZE_T
72 AC_TYPE_UINT16_T
73 AC_TYPE_UINT32_T
74 AC_TYPE_UINT64_T
75 AC_TYPE_UINT8_T
77 # Look for library needed for flock.
78 AC_SEARCH_LIBS(flock, bsd)
80 # Checks for library functions.
81 AC_FUNC_FORK
82 AC_FUNC_FSEEKO
83 AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK
84 AC_FUNC_MALLOC
85 AC_FUNC_MMAP
86 AC_FUNC_REALLOC
87 AC_FUNC_STRERROR_R
88 AC_FUNC_STRNLEN
89 AC_CHECK_FUNCS([ \
90         dup2 \
91         flock \
92         getcwd \
93         localtime_r \
94         memchr \
95         memmove \
96         memset \
97         mkdir \
98         munmap \
99         nl_langinfo \
100         realpath \
101         regcomp \
102         rmdir \
103         setlocale \
104         socket \
105         strcasecmp \
106         strchr \
107         strcspn \
108         strdup \
109         strerror \
110         strlcpy \
111         strncasecmp \
112         strndup \
113         strrchr \
114         strspn \
115         strstr \
116         strtol \
117         strtoul \
118         wcwidth \
121 # Check for functions with a compatibility implementation.
122 AC_REPLACE_FUNCS([ \
123         asprintf \
124         closefrom \
125         explicit_bzero \
126         fmt_scaled \
127         freezero \
128         getdtablecount \
129         getline \
130         getprogname \
131         recallocarray \
132         reallocarray \
133         strlcat \
134         strlcpy \
135         strndup \
136         strsep \
137         strtonum \
140 # Always use our getopt because 1) glibc's doesn't enforce argument order 2)
141 # musl does not set optarg to NULL for flags without arguments (although it is
142 # not required to, but it is helpful) 3) there are probably other weird
143 # implementations.
144 AC_LIBOBJ(getopt)
146 # Check the platform we're compiling on.
147 AC_MSG_CHECKING(platform)
148 case "$host_os" in
149         *linux*)
150                 AC_MSG_RESULT(linux)
151                 PLATFORM=linux
152                 ;;
153         *freebsd*)
154                 AC_MSG_RESULT(freebsd)
155                 PLATFORM=freebsd
156                 ;;
157         *)
158                 AC_MSG_RESULT(unknown)
159                 PLATFORM=unknown
160                 ;;
161 esac
162 AC_SUBST(PLATFORM)
163 AM_CONDITIONAL([HOST_FREEBSD], [test "$PLATFORM" = "freebsd"])
164 AM_CONDITIONAL([HOST_LINUX], [test "$PLATFORM" = "linux"])
166 # Clang sanitizers wrap reallocarray even if it isn't available on the target
167 # system. When compiled it always returns NULL and crashes the program. To
168 # detect this we need a more complicated test.
169 AC_MSG_CHECKING([for working reallocarray])
170 AC_RUN_IFELSE([AC_LANG_PROGRAM(
171                 [#include <stdlib.h>],
172                 [return (reallocarray(NULL, 1, 1) == NULL);]
173         )],
174         AC_MSG_RESULT(yes),
175         [AC_LIBOBJ(reallocarray) AC_MSG_RESULT([no])]
177 AC_MSG_CHECKING([for working recallocarray])
178 AC_RUN_IFELSE([AC_LANG_PROGRAM(
179                 [#include <stdlib.h>],
180                 [return (recallocarray(NULL, 1, 1, 1) == NULL);]
181         )],
182         AC_MSG_RESULT(yes),
183         [AC_LIBOBJ(recallocarray) AC_MSG_RESULT([no])]
186 # Look for imsg_init in libutil.
187 AC_SEARCH_LIBS(imsg_init, util, found_imsg_init=yes, found_imsg_init=no)
188 if test "x$found_imsg_init" = xyes; then
189         AC_DEFINE(HAVE_IMSG)
190 else
191         AC_LIBOBJ(imsg)
192         AC_LIBOBJ(imsg-buffer)
195 # libcrypto (via libssl for SHA information)
196 PKG_CHECK_MODULES(
197         LIBCRYPTO,
198         libcrypto,
199         [
200                 AM_CFLAGS="$LIBCRYPTO_CFLAGS $AM_CFLAGS"
201                 CFLAGS="$AM_CFLAGS $SAVED_CFLAGS"
202                 LIBS="$LIBCRYPTO_LIBS $LIBS"
203                 found_libcrypto=yes
204         ],
205         [
206                 found_libcrypto=no
207         ]
210 if test "x$found_libcrypto" = "xyes"; then
211         AC_DEFINE(HAVE_LIBCRYPTO)
214 AC_SEARCH_LIBS(uuid_create, , AC_DEFINE(HAVE_BSD_UUID))
215 AC_SEARCH_LIBS(uuid_create, found_uuid=no, found_uuid=yes)
216 AC_SEARCH_LIBS(mergesort, , AC_DEFINE(HAVE_BSD_MERGESORT))
218 if test "x$found_uuid" = "xyes"; then
219         AC_DEFINE(HAVE_BSD_UUID)
220 else
221         PKG_CHECK_MODULES(
222                 LIBUUID,
223                 uuid,
224                 [
225                         AM_CFLAGS="$LIBUUID_CFLAGS $AM_CFLAGS"
226                         CFLAGS="$AM_CFLAGS $SAVED_CFLAGS"
227                         LIBS="$LIBUUID_LIBS $LIBS"
228                         found_libuuid=yes
229                 ],
230                 [
231                         found_libuuid=no
232                 ]
233         )
235         if test "x$found_libuuid" = "xno"; then
236                 AC_CHECK_HEADER(
237                         uuid.h,
238                         found_libuuid=yes,
239                         found_libuuid=no)
240         fi
243 if test "x$found_libuuid" = "xno"; then
244         AC_MSG_ERROR("*** couldn't find uuid ***")
247 PKG_CHECK_MODULES(
248         ZLIB,
249         zlib,
250         [
251                 AM_CFLAGS="$ZLIB_CFLAGS $AM_CFLAGS"
252                 CFLAGS="$AM_CFLAGS $SAVED_CFLAGS"
253                 LIBS="$ZLIB_LIBS $LIBS"
254                 found_zlib=yes
255         ],
256         [
257                 found_zlib=no
258         ]
261 if test "x$found_zlib" = "xno"; then
262         AC_CHECK_HEADER(
263                 zlib.h,
264                 ,
265                 found_zlib=no)
268 if test "x$found_zlib" = "xno"; then
269         AC_MSG_ERROR("*** couldn't find zlib ***")
272 if test "$PLATFORM" = "linux"; then
273         PKG_CHECK_MODULES(
274                 LIBMD,
275                 libmd,
276                 [
277                         AM_CFLAGS="$LIBMD_CFLAGS $AM_CFLAGS"
278                         CFLAGS="$AM_CFLAGS $SAVED_CFLAGS"
279                         LIBS="$LIBMD_LIBS $LIBS"
280                 ],
281                 [
282                         AC_MSG_ERROR("*** couldn't find libmd via pkg-config")
283                 ]
284         )
285         PKG_CHECK_MODULES(
286                 LIBBSD,
287                 libbsd-overlay,
288                 [
289                         AM_CFLAGS="$LIBBSD_CFLAGS $AM_CFLAGS"
290                         CFLAGS="$AM_CFLAGS $SAVED_CFLAGS"
291                         LIBS="$LIBBSD_LIBS $LIBS"
292                         found_libbsd=yes
293                         AC_DEFINE(HAVE_LIBBSD)
294                 ],
295                 []
296         )
299 # Look for a suitable queue.h.  We hope libbsd is enough, but that is missing
300 # SIMPLEQ.
301 AC_CHECK_DECL(
302         SIMPLEQ_INIT,
303         found_queue_h=yes,
304         found_queue_h=no,
305         [#include <sys/queue.h>]
307 AC_CHECK_DECL(
308         TAILQ_CONCAT,
309         found_queue_h=yes,
310         found_queue_h=no,
311         [#include <sys/queue.h>]
313 AC_CHECK_DECL(
314         TAILQ_PREV,
315         found_queue_h=yes,
316         found_queue_h=no,
317         [#include <sys/queue.h>]
319 AC_CHECK_DECL(
320         TAILQ_REPLACE,
321         found_queue_h=yes,
322         found_queue_h=no,
323         [#include <sys/queue.h>]
325 AC_CHECK_DECL(
326         SIMPLEQ_ENTRY,
327         ,
328         found_queue_h=no,
329         [#include <sys/queue.h>]
331 AC_CHECK_DECL(
332         TAILQ_FOREACH_SAFE,
333         ,
334         found_queue_h=no,
335         [#include <sys/queue.h>]
337 if test "x$found_queue_h" = xyes; then
338         AC_DEFINE(HAVE_QUEUE_H)
341 # Look for __progname.
342 AC_MSG_CHECKING(for __progname)
343 AC_LINK_IFELSE([AC_LANG_SOURCE(
344         [
345                 #include <stdio.h>
346                 #include <stdlib.h>
347                 extern char *__progname;
348                 int main(void) {
349                         const char *cp = __progname;
350                         printf("%s\n", cp);
351                         exit(0);
352                 }
353         ])],
354         [AC_DEFINE(HAVE___PROGNAME) AC_MSG_RESULT(yes)],
355         AC_MSG_RESULT(no)
358 if test "$PLATFORM" = "linux"; then
359         PKG_CHECK_MODULES(
360                 LIBPANELW,
361                 panelw,
362                 found_panel=yes,
363                 AC_MSG_ERROR("*** couldn't find -lpanel from ncurses")
364         )
365 else
366         AC_CHECK_LIB(panelw, update_panels,,
367                 AC_MSG_ERROR([ "*** panelw not found for ncurses. ***"])
368         )
370         LIBPANELW_LIBS="-lpanelw"
373 PKG_CHECK_MODULES(
374         LIBNCURSES,
375         ncursesw,
376         found_ncurses=yes,
377         found_ncurses=no
379 if test "x$found_ncurses" = xyes; then
380         AM_CFLAGS="$LIBNCURSES_CFLAGS $LIBTINFO_CFLAGS $LIBPANELW_CFLAGS $AM_CFLAGS"
381         CFLAGS="$LIBNCURSES_CFLAGS $LIBTINFO_CFLAGS $LIBPANELW_CFLAGS $CFLAGS"
382         LIBS="$LIBNCURSES_LIBS $LIBTINFO_LIBS $LIBPANELW_LIBS $LIBS"
383 else
384         AC_CHECK_LIB(
385                 ncursesw,
386                 setupterm,
387                 found_ncurses=yes,
388                 found_ncurses=no
389         )
390         if test "x$found_ncurses" = xyes; then
391                 AC_CHECK_HEADER(
392                         ncurses.h,
393                         AM_CFLAGS="$LIBPANELW_CFLAGS $AM_CFLAGS"
394                         CFLAGS="$LIBPANEL_CFLAGS $CFLAGS"
395                         LIBS="$LIBS -lncursesw $LIBPANELW_LIBS",
396                         found_ncurses=no
397                 )
398         fi
400 if test "x$found_ncurses" = xyes; then
401         AC_DEFINE(HAVE_NCURSES_H)
402 else
403         # No ncurses, try curses.
404         AC_CHECK_LIB(
405                 cursesw,
406                 setupterm,
407                 found_curses=yes,
408                 found_curses=no
409         )
410         AC_CHECK_HEADER(
411                 curses.h,
412                 ,
413                 found_curses=no)
414         if test "x$found_curses" = xyes; then
415                 AM_CFLAGS="$LIBPANELW_CFLAGS $AM_CFLAGS"
416                 CFLAGS="$LIBPANEL_CFLAGS $CFLAGS"
417                 LIBS="$LIBS -lcursesw $LIBPANELW_LIBS"
418                 AC_DEFINE(HAVE_CURSES_H)
419         else
420                 AC_MSG_ERROR("curses not found")
421         fi
424 # Save our CFLAGS/CPPFLAGS/LDFLAGS for the Makefile and restore the old user
425 # variables.
426 AC_SUBST(AM_CPPFLAGS)
427 CPPFLAGS="$SAVED_CPPFLAGS"
428 AC_SUBST(AM_CFLAGS)
429 CFLAGS="$SAVED_CFLAGS"
430 AC_SUBST(AM_LDFLAGS)
431 LDFLAGS="$SAVED_LDFLAGS"
433 AC_CONFIG_FILES([Makefile
434                  compat/Makefile
435                  libexec/Makefile
436                  libexec/got-read-tree/Makefile
437                  libexec/got-fetch-pack/Makefile
438                  libexec/got-index-pack/Makefile
439                  libexec/got-read-blob/Makefile
440                  libexec/got-read-commit/Makefile
441                  libexec/got-read-gitconfig/Makefile
442                  libexec/got-read-gotconfig/Makefile
443                  libexec/got-read-object/Makefile
444                  libexec/got-read-pack/Makefile
445                  libexec/got-read-tag/Makefile
446                  libexec/got-send-pack/Makefile
447                  got/Makefile
448                  gotadmin/Makefile
449                  tog/Makefile
450                  Makefile.common:Makefile.common.in])
451 AC_OUTPUT
453 #                tog/GNUMakefile])
454 #                regress/GNUMakefile
455 #                regress/cmdline/GNUMakefile
456 #                regress/delta/GNUMakefile
457 #                regress/fetch/GNUMakefile
458 #                regress/idset/GNUMakefile
459 #                regress/path/GNUMakefile
460 #                 gotweb/GNUMakefile
461 #                 gotweb/libexec/GNUMakefile
462 #                 gotweb/libexec/got-read-blob/GNUMakefile
463 #                 gotweb/libexec/got-read-commit/GNUMakefile
464 #                 gotweb/libexec/got-read-gitconfig/GNUMakefile
465 #                 gotweb/libexec/got-read-gotconfig/GNUMakefile
466 #                 gotweb/libexec/got-read-object/GNUMakefile
467 #                 gotweb/libexec/got-read-pack/GNUMakefile
468 #                 gotweb/libexec/got-read-tag/GNUMakefile
469 #                 gotweb/libexec/got-read-tree/GNUMakefile