Blob


1 AC_INIT([kamid], [0.2], [kamid@omarpolo.com], [],
2 [https://kamid.omarpolo.com])
3 AC_CONFIG_AUX_DIR(etc)
4 AC_CONFIG_LIBOBJ_DIR(compat)
5 AM_INIT_AUTOMAKE([foreign subdir-objects])
7 KAMID_RELEASE=No
9 AC_DEFINE_UNQUOTED(VERSION, "$VERSION")
10 AC_SUBST(VERSION)
11 AC_SUBST(KAMID_RELEASE)
13 AC_CANONICAL_HOST
15 # When CFLAGS isn't set at this stage and gcc is detected by the macro below,
16 # autoconf will automatically use CFLAGS="-O2 -g". Prevent that by using an
17 # empty default.
18 : ${CFLAGS=""}
20 # Save user CPPFLAGS, CFLAGS and LDFLAGS. We need to change them because
21 # AC_CHECK_HEADER doesn't give us any other way to update the include
22 # paths. But for Makefile.am we want to use AM_CPPFLAGS and friends.
23 SAVED_CFLAGS="$CFLAGS"
24 SAVED_CPPFLAGS="$CPPFLAGS"
25 SAVED_LDFLAGS="$LDFLAGS"
27 # Checks for programs.
28 AC_PROG_CC
29 AC_PROG_CPP
30 AC_PROG_INSTALL
31 AC_PROG_LN_S
32 AC_PROG_MAKE_SET
33 AC_PROG_RANLIB
34 AC_PROG_YACC
35 PKG_PROG_PKG_CONFIG
36 AC_USE_SYSTEM_EXTENSIONS
38 # Some functions can be in libbsd. Thanks to lldpb for the inspiration :)
39 AC_ARG_WITH([libbsd],
40 AS_HELP_STRING([--with-libbsd], [Use libbsd @<:@default=auto@:>@]),
41 [],
42 [with_libbsd=auto])
43 if test x"$with_libbsd" != x"no"; then
44 PKG_CHECK_MODULES([libbsd], [libbsd-overlay libbsd-ctor], [
45 _save_AM_CFLAGS="$AM_CFLAGS"
46 _save_LIBS="$LIBS"
47 AM_CFLAGS="$AM_CFLAGS $libbsd_CFLAGS"
48 LIBS="$LIBS $libbsd_LIBS"
49 ], [
50 if test x"$with_libbsd" = x"yes"; then
51 AC_MSG_FAILURE([*** no libbsd support found])
52 fi
53 with_libbsd=no
54 ])
55 fi
57 AC_REPLACE_FUNCS([
58 asprintf \
59 err \
60 freezero \
61 getdtablecount \
62 getdtablesize \
63 getprogname \
64 memmem \
65 reallocarray \
66 recallocarray \
67 setproctitle \
68 setprogname \
69 strlcat \
70 strlcpy \
71 strsep \
72 strtonum \
73 vis \
74 ])
76 AC_MSG_CHECKING([for sys/queue.h with TAILQ_FOREACH_SAFE and STAILQ_ENTRY])
77 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([
78 #include <sys/queue.h>
79 #include <stddef.h>
80 ], [
81 TAILQ_HEAD(tailhead, entry) head;
82 struct entry {
83 TAILQ_ENTRY(entry) entries;
84 } *np, *nt;
85 TAILQ_INIT(&head);
86 TAILQ_FOREACH_SAFE(np, &head, entries, nt) {
87 /* nop */ ;
88 }
90 STAILQ_HEAD(listhead, qentry) qhead = STAILQ_HEAD_INITIALIZER(qhead);
91 struct qentry {
92 STAILQ_ENTRY(qentry) entries;
93 } foo;
95 return 0;
96 ])], [
97 AC_MSG_RESULT(yes)
98 AC_DEFINE([HAVE_QUEUE_H], 1, [QUEUE_H])
99 ], AC_MSG_RESULT(no))
101 AC_CHECK_HEADERS([sys/tree.h])
103 AC_CHECK_DECL(PR_SET_NAME, AC_DEFINE([HAVE_PR_SET_NAME], 1, [pr_set_name]), [],
104 [[#include <sys/prctl.h>]])
106 AC_CHECK_LIB([crypto], [RAND_add], [], [
107 AC_MSG_ERROR([requires openssl])
108 ])
110 AC_CHECK_LIB(tls, tls_init, [], [
111 AC_MSG_ERROR([requires libtls])
112 ])
114 AS_CASE([$host_os],
115 [*openbsd*], [AC_CHECK_LIB([event], [event_init], [],
116 [AC_MSG_ERROR([requires libevent])])],
117 [PKG_CHECK_MODULES([libevent2], [libevent_core >= 2],
119 AC_DEFINE([HAVE_EVENT2], 1, [1 if using event2])
120 AM_CFLAGS="$libevent2_CFLAGS $AM_CFLAGS"
121 LIBS="$libevent2_LIBS $LIBS"
122 ], [AC_MSG_ERROR([requires libevent])])])
124 AC_CHECK_LIB(util, imsg_init, [], [
125 AC_LIBOBJ(fmt_scaled)
126 AC_LIBOBJ(imsg)
127 AC_LIBOBJ(imsg-buffer)
128 AC_LIBOBJ(ohash)
129 ])
131 # Check for readline
132 AS_CASE([$host_os],
133 [*openbsd*], [
134 AC_DEFINE([HAVE_READLINE], 1, [1 if readline found])
135 READLINE_CFLAGS=''
136 READLINE_LIBS='-lreadline'
137 ], [
138 PKG_CHECK_MODULES([READLINE], [readline], [
139 AC_DEFINE([HAVE_READLINE], 1, [])
140 ], [
141 AC_DEFINE([HAVE_READLINE], 0, [])
142 ])
145 AC_SUBST(READLINE_CFLAGS)
146 AC_SUBST(READLINE_LIBS)
148 # check compiler flags
149 AC_DEFUN([CC_ADD_CHECK_FLAGS], [
150 AC_MSG_CHECKING([if $CC supports $1 flag])
151 old_AM_CFLAGS="$AM_CFLAGS"
152 AM_CFLAGS="$AM_CFLAGS $1"
153 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [])],
154 AC_MSG_RESULT(yes), [
155 AC_MSG_RESULT(no)
156 AM_CFLAGS="$old_AM_CFLAGS"
157 ])
158 ])
159 CC_ADD_CHECK_FLAGS([-Wall])
160 CC_ADD_CHECK_FLAGS([-Wextra])
161 CC_ADD_CHECK_FLAGS([-Wmissing-declarations])
162 CC_ADD_CHECK_FLAGS([-Wmissing-prototypes])
163 CC_ADD_CHECK_FLAGS([-Wstrict-prototypes])
164 CC_ADD_CHECK_FLAGS([-Wwrite-strings])
165 CC_ADD_CHECK_FLAGS([-Wno-unused-parameter])
166 CC_ADD_CHECK_FLAGS([-Wpointer-arith])
167 CC_ADD_CHECK_FLAGS([-Wsign-compare])
168 CC_ADD_CHECK_FLAGS([-Wcast-align])
170 # Save our CFLAGS/CPPFLAGS/LDFLAGS for the Makefile and restore the old user
171 # variables.
172 AC_SUBST(AM_CPPFLAGS)
173 CPPFLAGS="$SAVED_CPPFLAGS"
174 AC_SUBST(AM_CFLAGS)
175 CFLAGS="$SAVED_CFLAGS"
176 AC_SUBST(AM_LDFLAGS)
177 LDFLAGS="$SAVED_LDFLAGS"
179 AC_CONFIG_HEADERS([config.h])
180 AC_CONFIG_FILES([
181 Makefile
182 compat/Makefile
183 contrib/Makefile
184 kamictl/Makefile
185 kamid/Makefile
186 kamiftp/Makefile
187 kamiproxy/Makefile
188 kamirepl/Makefile
189 ninepscript/Makefile
190 regress/Makefile
191 regress/lisp/Makefile
192 regress/ninepscript/Makefile
193 ])
195 AC_OUTPUT