autoconf: add wrapper script
[got-portable.git] / configure.ac
blob8d6fb79d27ab1875175458ba8995057718ec92d7
1 # Process this file with autoconf to produce a configure script.
3 AC_PREREQ([2.69])
4 AC_INIT([got-portable], [0.47], [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 # Clang sanitizers wrap reallocarray even if it isn't available on the target
147 # system. When compiled it always returns NULL and crashes the program. To
148 # detect this we need a more complicated test.
149 AC_MSG_CHECKING([for working reallocarray])
150 AC_RUN_IFELSE([AC_LANG_PROGRAM(
151                 [#include <stdlib.h>],
152                 [return (reallocarray(NULL, 1, 1) == NULL);]
153         )],
154         AC_MSG_RESULT(yes),
155         [AC_LIBOBJ(reallocarray) AC_MSG_RESULT([no])]
157 AC_MSG_CHECKING([for working recallocarray])
158 AC_RUN_IFELSE([AC_LANG_PROGRAM(
159                 [#include <stdlib.h>],
160                 [return (recallocarray(NULL, 1, 1, 1) == NULL);]
161         )],
162         AC_MSG_RESULT(yes),
163         [AC_LIBOBJ(recallocarray) AC_MSG_RESULT([no])]
166 # Look for imsg_init in libutil.
167 AC_SEARCH_LIBS(imsg_init, util, found_imsg_init=yes, found_imsg_init=no)
168 if test "x$found_imsg_init" = xyes; then
169         AC_DEFINE(HAVE_IMSG)
170 else
171         AC_LIBOBJ(imsg)
172         AC_LIBOBJ(imsg-buffer)
175 # libcrypto (via libssl for SHA information)
176 PKG_CHECK_MODULES(
177         LIBCRYPTO,
178         libcrypto,
179         [
180                 AM_CFLAGS="$LIBCRYTPO_CFLAGS $AM_CFLAGS"
181                 CFLAGS="$AM_CFLAGS $SAVED_CFLAGS"
182                 LIBS="$LIBCRYPTO_LIBS $LIBS"
183                 found_libcrypto=yes
184         ],
185         [
186                 AC_MSG_ERROR("*** couldn't find libcrypto via pkg-config")
187         ]
190 AC_SEARCH_LIBS(uuid_create, , AC_DEFINE(HAVE_BSD_UUID))
191 AC_SEARCH_LIBS(mergesort, , AC_DEFINE(HAVE_BSD_MERGESORT))
193 PKG_CHECK_MODULES(
194         LIBUUID,
195         uuid,
196         [
197                 AM_CFLAGS="$LIBUUID_CFLAGS $AM_CFLAGS"
198                 CFLAGS="$AM_CFLAGS $SAVED_CFLAGS"
199                 LIBS="$LIBUUID_LIBS $LIBS"
200                 found_libuuid=yes
201         ],
202         [
203                 AC_MSG_ERROR("*** couldn't find libuuid via pkg-config")
204         ]
208 PKG_CHECK_MODULES(
209         ZLIB,
210         zlib,
211         [
212                 AM_CFLAGS="$ZLIB_CFLAGS $AM_CFLAGS"
213                 CFLAGS="$AM_CFLAGS $SAVED_CFLAGS"
214                 LIBS="$ZLIB_LIBS $LIBS"
215                 found_zlib=yes
216         ],
217         [
218                 AC_MSG_ERROR("*** couldn't find zlib via pkg-config")
219         ]
222 PKG_CHECK_MODULES(
223         LIBMD,
224         libmd,
225         [
226                 AM_CFLAGS="$LIBMD_CFLAGS $AM_CFLAGS"
227                 CFLAGS="$AM_CFLAGS $SAVED_CFLAGS"
228                 LIBS="$LIBMD_LIBS $LIBS"
229         ],
230         [
231                 AC_MSG_ERROR("*** couldn't find libmd via pkg-config")
232         ]
234 # libmd (uuid)
235 # imsg
236 # libbsd (some portability gloop)
237 # lssl
238 # lz
239 # ldl *
240 # rdynamic *
242 # Check if libbsd is installed -- if we can use that version of sys/tree.h or
243 # our own if not.
244 PKG_CHECK_MODULES(
245         LIBBSD,
246         libbsd-overlay,
247         [
248                 AM_CFLAGS="$LIBBSD_CFLAGS $AM_CFLAGS"
249                 CFLAGS="$AM_CFLAGS $SAVED_CFLAGS"
250                 LIBS="$LIBBSD_LIBS $LIBS"
251                 found_libbsd=yes
252                 AC_DEFINE(HAVE_LIBBSD)
253         ],
254         []
257 # Look for a suitable queue.h.  We hope libbsd is enough, but that is missing
258 # SIMPLEQ.
259 AC_CHECK_DECL(
260         SIMPLEQ_INIT,
261         found_queue_h=yes,
262         found_queue_h=no,
263         [#include <sys/queue.h>]
265 AC_CHECK_DECL(
266         TAILQ_CONCAT,
267         found_queue_h=yes,
268         found_queue_h=no,
269         [#include <sys/queue.h>]
271 AC_CHECK_DECL(
272         TAILQ_PREV,
273         found_queue_h=yes,
274         found_queue_h=no,
275         [#include <sys/queue.h>]
277 AC_CHECK_DECL(
278         TAILQ_REPLACE,
279         found_queue_h=yes,
280         found_queue_h=no,
281         [#include <sys/queue.h>]
283 AC_CHECK_DECL(
284         SIMPLEQ_ENTRY,
285         ,
286         found_queue_h=no,
287         [#include <sys/queue.h>]
289 AC_CHECK_DECL(
290         TAILQ_FOREACH_SAFE,
291         ,
292         found_queue_h=no,
293         [#include <sys/queue.h>]
295 if test "x$found_queue_h" = xyes; then
296         AC_DEFINE(HAVE_QUEUE_H)
299 # Look for __progname.
300 AC_MSG_CHECKING(for __progname)
301 AC_LINK_IFELSE([AC_LANG_SOURCE(
302         [
303                 #include <stdio.h>
304                 #include <stdlib.h>
305                 extern char *__progname;
306                 int main(void) {
307                         const char *cp = __progname;
308                         printf("%s\n", cp);
309                         exit(0);
310                 }
311         ])],
312         [AC_DEFINE(HAVE___PROGNAME) AC_MSG_RESULT(yes)],
313         AC_MSG_RESULT(no)
316 PKG_CHECK_MODULES(
317         LIBPANELW,
318         panelw,
319         found_panel=yes,
320         AC_MSG_ERROR("*** couldn't find -lpanel from ncurses")
323 PKG_CHECK_MODULES(
324         LIBNCURSES,
325         ncursesw,
326         found_ncurses=yes,
327         found_ncurses=no
329 if test "x$found_ncurses" = xyes; then
330         AM_CFLAGS="$LIBNCURSES_CFLAGS $LIBTINFO_CFLAGS $LIBPANELW_CFLAGS $AM_CFLAGS"
331         CFLAGS="$LIBNCURSES_CFLAGS $LIBTINFO_CFLAGS $LIBPANELW_CFLAGS $CFLAGS"
332         LIBS="$LIBNCURSES_LIBS $LIBTINFO_LIBS $LIBPANELW_LIBS $LIBS"
333 else
334         AC_CHECK_LIB(
335                 ncursesw,
336                 setupterm,
337                 found_ncurses=yes,
338                 found_ncurses=no
339         )
340         if test "x$found_ncurses" = xyes; then
341                 AC_CHECK_HEADER(
342                         ncurses.h,
343                         AM_CFLAGS="$LIBPANELW_CFLAGS $AM_CFLAGS"
344                         CFLAGS="$LIBPANEL_CFLAGS $CFLAGS"
345                         LIBS="$LIBS -lncursesw $LIBPANELW_LIBS",
346                         found_ncurses=no
347                 )
348                 fi
350 if test "x$found_ncurses" = xyes; then
351         AC_DEFINE(HAVE_NCURSES_H)
352 else
353         # No ncurses, try curses.
354         AC_CHECK_LIB(
355                 cursesw,
356                 setupterm,
357                 found_curses=yes,
358                 found_curses=no
359         )
360         AC_CHECK_HEADER(
361                 curses.h,
362                 ,
363                 found_curses=no)
364         if test "x$found_curses" = xyes; then
365                 AM_CFLAGS="$LIBPANELW_CFLAGS $AM_CFLAGS"
366                 CFLAGS="$LIBPANEL_CFLAGS $CFLAGS"
367                 LIBS="$LIBS -lcursesw $LIBPANELW_LIBS"
368                 AC_DEFINE(HAVE_CURSES_H)
369         else
370                 AC_MSG_ERROR("curses not found")
371         fi
374 # Save our CFLAGS/CPPFLAGS/LDFLAGS for the Makefile and restore the old user
375 # variables.
376 AC_SUBST(AM_CPPFLAGS)
377 CPPFLAGS="$SAVED_CPPFLAGS"
378 AC_SUBST(AM_CFLAGS)
379 CFLAGS="$SAVED_CFLAGS"
380 AC_SUBST(AM_LDFLAGS)
381 LDFLAGS="$SAVED_LDFLAGS"
383 AC_CONFIG_FILES([Makefile
384                  compat/Makefile
385                  libexec/Makefile
386                  libexec/got-read-tree/Makefile
387                  libexec/got-fetch-pack/Makefile
388                  libexec/got-index-pack/Makefile
389                  libexec/got-read-blob/Makefile
390                  libexec/got-read-commit/Makefile
391                  libexec/got-read-gitconfig/Makefile
392                  libexec/got-read-gotconfig/Makefile
393                  libexec/got-read-object/Makefile
394                  libexec/got-read-pack/Makefile
395                  libexec/got-read-tag/Makefile
396                  libexec/got-send-pack/Makefile
397                  got/Makefile
398                  gotadmin/Makefile
399                  tog/Makefile])
400 AC_OUTPUT
402 #                tog/GNUMakefile])
403 #                regress/GNUMakefile
404 #                regress/cmdline/GNUMakefile
405 #                regress/delta/GNUMakefile
406 #                regress/fetch/GNUMakefile
407 #                regress/idset/GNUMakefile
408 #                regress/path/GNUMakefile
409 #                 gotweb/GNUMakefile
410 #                 gotweb/libexec/GNUMakefile
411 #                 gotweb/libexec/got-read-blob/GNUMakefile
412 #                 gotweb/libexec/got-read-commit/GNUMakefile
413 #                 gotweb/libexec/got-read-gitconfig/GNUMakefile
414 #                 gotweb/libexec/got-read-gotconfig/GNUMakefile
415 #                 gotweb/libexec/got-read-object/GNUMakefile
416 #                 gotweb/libexec/got-read-pack/GNUMakefile
417 #                 gotweb/libexec/got-read-tag/GNUMakefile
418 #                 gotweb/libexec/got-read-tree/GNUMakefile