7d326c155392dca3a1cc8f9f2049a79462e6e7ed
[obnox/tinyproxy.git] / configure.ac
1 # Process this file with autoconf to produce a configure script.
2 # Portions of this file were adapted from GIMP.
3
4 AC_PREREQ(2.54)
5
6 m4_define([tinyproxy_major_version], [1])
7 m4_define([tinyproxy_minor_version], [9])
8 m4_define([tinyproxy_micro_version], [0])
9 m4_define([tinyproxy_real_version],
10           [tinyproxy_major_version.tinyproxy_minor_version.tinyproxy_micro_version])
11 m4_define([tinyproxy_version], [tinyproxy_real_version])
12
13 # For overriding the version string. Comment out if not needed.
14 # m4_define([tinyproxy_version], [1.9.0])
15
16 m4_define([tinyproxy_unstable],
17           m4_if(m4_eval(tinyproxy_minor_version % 2), [1], [yes], [no]))
18 m4_define([tinyproxy_stable],
19           m4_if(m4_eval(tinyproxy_minor_version % 2), [0], [yes], [no]))
20
21 AC_INIT([Tinyproxy], [tinyproxy_version],
22         [https://www.banu.com/bugzilla/enter_bug.cgi?product=tinyproxy],
23         [tinyproxy])
24
25 AC_CANONICAL_TARGET
26 AM_INIT_AUTOMAKE([foreign dist-bzip2])
27 AM_CONFIG_HEADER(config.h)
28 AC_CONFIG_MACRO_DIR([m4macros])
29
30 m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES([yes])])
31
32 TINYPROXY_MAJOR_VERSION=tinyproxy_major_version
33 TINYPROXY_MINOR_VERSION=tinyproxy_minor_version
34 TINYPROXY_MICRO_VERSION=tinyproxy_micro_version
35 TINYPROXY_REAL_VERSION=tinyproxy_real_version
36 TINYPROXY_VERSION=tinyproxy_version
37 TINYPROXY_UNSTABLE=tinyproxy_unstable
38 AC_SUBST(TINYPROXY_MAJOR_VERSION)
39 AC_SUBST(TINYPROXY_MINOR_VERSION)
40 AC_SUBST(TINYPROXY_MICRO_VERSION)
41 AC_SUBST(TINYPROXY_REAL_VERSION)
42 AC_SUBST(TINYPROXY_VERSION)
43 AC_SUBST(TINYPROXY_UNSTABLE)
44
45 dnl Temporarily defined here until we get tinyproxy-version.h
46 AC_DEFINE(TINYPROXY_VERSION, "tinyproxy_version", [Tinyproxy version number])
47
48 # The symbol TINYPROXY_UNSTABLE is defined above for substitution in
49 # Makefiles and conditionally defined here as a preprocessor symbol
50 # and automake conditional.
51 if test "x$TINYPROXY_UNSTABLE" = "xyes"; then
52   AC_DEFINE(TINYPROXY_UNSTABLE, 1,
53             [Define to 1 if this is an unstable version of Tinyproxy])
54 fi
55 AM_CONDITIONAL(TINYPROXY_UNSTABLE, test "x$TINYPROXY_UNSTABLE" = "xyes")
56
57
58 dnl Check if we're compiling on a weird platform :)
59 AC_USE_SYSTEM_EXTENSIONS
60
61
62 dnl Set the domain name for find the statistics of tinyproxy
63 AH_TEMPLATE([TINYPROXY_STATHOST],
64         [This controls remote proxy stats display.])
65 AC_ARG_WITH(stathost,
66             [AC_HELP_STRING([--with-stathost=HOST], [Default status host])],
67             [AC_DEFINE_UNQUOTED(TINYPROXY_STATHOST, "$withval")
68              TINYPROXY_STATHOST="$withval"],
69             [AC_DEFINE_UNQUOTED(TINYPROXY_STATHOST, "tinyproxy.stats")
70              TINYPROXY_STATHOST="tinyproxy.stats"])
71
72 AC_SUBST(TINYPROXY_STATHOST)
73
74 dnl Add compiler-specific optimization flags
75 TP_ARG_ENABLE(debug,
76               [Enable debugging support code and methods (default is NO)],
77               no)
78
79 dnl Check to see if the XTinyproxy header is to be included
80 AH_TEMPLATE([XTINYPROXY_ENABLE],
81             [Define if you want to have the peer's IP address included in a XTinyproxy header sent to the server.])
82 TP_ARG_ENABLE(xtinyproxy,
83               [Include the X-Tinyproxy header (default is YES)],
84               yes)
85
86 if test x"$xtinyproxy_enabled" = x"yes"; then
87     AC_DEFINE(XTINYPROXY_ENABLE)
88 fi
89
90 dnl Include filtering for domain/URLs
91 AH_TEMPLATE([FILTER_ENABLE],
92             [Defined if you would like filtering code included.])
93 TP_ARG_ENABLE(filter,
94               [Enable filtering of domains/URLS (default is YES)],
95               yes)
96
97 if test x"$filter_enabled" = x"yes"; then
98     ADDITIONAL_OBJECTS="$ADDITIONAL_OBJECTS filter.o"
99     AC_DEFINE(FILTER_ENABLE)
100 fi
101
102 dnl Include support for upstream proxies?
103 AH_TEMPLATE([UPSTREAM_SUPPORT],
104             [Include support for connecting to an upstream proxy.])
105 TP_ARG_ENABLE(upstream,
106               [Enable upstream proxying (default is YES)],
107               yes)
108 if test x"$upstream_enabled" = x"yes"; then
109     AC_DEFINE(UPSTREAM_SUPPORT)
110 fi
111
112 dnl Include support for reverse proxy?
113 AH_TEMPLATE([REVERSE_SUPPORT],
114             [Include support for reverse proxy.])
115 TP_ARG_ENABLE(reverse,
116               [Enable reverse proxying (default is NO)],
117               no)
118 if test x"$reverse_enabled" = x"yes"; then
119     ADDITIONAL_OBJECTS="$ADDITIONAL_OBJECTS reverse-proxy.o"
120     AC_DEFINE(REVERSE_SUPPORT)
121 fi
122
123 dnl Include the transparent proxy support
124 AH_TEMPLATE([TRANSPARENT_PROXY],
125             [Include support for using tinyproxy as a transparent proxy.])
126 TP_ARG_ENABLE(transparent,
127               [Enable transparent proxying code (default is NO)],
128               no)
129 if test x"$transparent_enabled" = x"yes"; then
130    ADDITIONAL_OBJECTS="$ADDITIONAL_OBJECTS transparent-proxy.o"
131    AC_DEFINE(TRANSPARENT_PROXY)
132 fi
133
134 dnl Check for broken regex library
135 TP_ARG_ENABLE(regexcheck,
136               [Check for working regex library (default is YES)],
137               yes)
138
139 # This is required to build test programs below
140 AC_PROG_CC
141
142 dnl
143 dnl Checks for libraries
144 dnl
145 AC_CHECK_LIB(socket, socket, , [AC_CHECK_LIB(socket, htonl)])
146
147 dnl Some systems (OpenServer 5) dislike -lsocket -lnsl, so we try to
148 dnl avoid -lnsl checks, if we already have the functions which are
149 dnl usually in libnsl
150
151 unset ac_cv_func_yp_get_default_domain
152 AC_CHECK_FUNC(yp_get_default_domain,
153               tinyproxy_no_nsl_checks=yes,
154               tinyproxy_no_nsl_checks=no)
155 unset ac_cv_func_yp_get_default_domain
156
157 if test x"$tinyproxy_no_nsl_checks" != x"yes"; then
158     AC_CHECK_LIB(nsl, gethostname, , [AC_CHECK_LIB(nsl, gethostbyaddr)])
159 fi
160
161 AC_CHECK_LIB(resolv, inet_aton)
162
163 dnl
164 dnl Checks for headers
165 dnl
166 AC_HEADER_STDC
167 AC_HEADER_TIME
168 AC_HEADER_SYS_WAIT
169 AC_CHECK_HEADERS([sys/ioctl.h sys/mman.h sys/resource.h \
170                   sys/select.h sys/socket.h sys/time.h sys/uio.h \
171                   sys/un.h arpa/inet.h netinet/in.h \
172                   assert.h ctype.h errno.h fcntl.h grp.h io.h libintl.h \
173                   netdb.h pwd.h regex.h signal.h stdarg.h stddef.h stdio.h \
174                   sysexits.h syslog.h time.h wchar.h wctype.h \
175                   values.h])
176
177 dnl OpenBSD machines don't like having malloc included (even if it's present)
178 dnl as they expect you to use stdlib.h
179 case "$target" in
180     *-openbsd*) ;;
181     *)         AC_CHECK_HEADER(malloc.h);;
182 esac
183
184
185 dnl Checks for types
186 AC_TYPE_SIZE_T
187 AC_TYPE_PID_T
188 AC_UNP_CHECK_TYPE(uint8_t, unsigned char)
189 AC_UNP_CHECK_TYPE(int16_t, short)
190 AC_UNP_CHECK_TYPE(uint16_t, unsigned short)
191 AC_UNP_CHECK_TYPE(int32_t, int)
192 AC_UNP_CHECK_TYPE(uint32_t, unsigned int)
193 AC_UNP_CHECK_TYPE(ssize_t, int)
194 AC_UNP_CHECK_TYPE(socklen_t, unsigned int)
195 AC_UNP_CHECK_TYPE(in_addr_t, uint32_t)
196
197
198 dnl Checks for libary functions
199 AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK
200 AC_FUNC_MALLOC
201 AC_FUNC_REALLOC
202
203 AC_CHECK_FUNCS([gethostname inet_ntoa memchr memset select socket strcasecmp \
204                 strchr strdup strerror strncasecmp strpbrk strstr strtol])
205 AC_CHECK_FUNCS([isascii memcpy setrlimit ftruncate regcomp regexec])
206 AC_CHECK_FUNCS([strlcpy strlcat])
207
208
209 dnl Enable extra warnings
210 DESIRED_FLAGS="-fdiagnostics-show-option -Wall -Wextra -Wno-unused-parameter -Wmissing-prototypes -Wstrict-prototypes -Wmissing-declarations -Wfloat-equal -Wundef -Wformat=2 -Wlogical-op -Wmissing-include-dirs -Wformat-nonliteral -Wold-style-definition -Wpointer-arith -Waggregate-return -Winit-self -Wpacked --std=c89 -ansi -pedantic -Wno-overlength-strings -Wc++-compat -Wno-long-long -Wno-overlength-strings -Wdeclaration-after-statement -Wredundant-decls -Wmissing-noreturn -Wshadow -Wendif-labels -Wcast-qual -Wcast-align -Wwrite-strings -Wp,-D_FORTIFY_SOURCE=2 -fno-common"
211
212 if test -n "${MAINTAINER_MODE_FALSE}"; then
213    DESIRED_FLAGS="-Werror $DESIRED_FLAGS"
214 fi
215
216 for flag in $DESIRED_FLAGS; do
217   AS_COMPILER_FLAG([$flag], [CFLAGS="$CFLAGS $flag"])
218 done
219
220 dnl Disable debugging if it's not specified
221 if test x"$debug_enabled" != x"yes" ; then
222     CFLAGS="-DNDEBUG $CFLAGS"
223 fi
224
225 LDFLAGS="-Wl,-z,defs"
226
227 dnl
228 dnl Make sure we can actually handle the "--with-*" and "--enable-*" stuff.
229 dnl
230
231 dnl Handle the REGEX library
232 if test x"$ac_cv_func_regexec" != x"yes"; then
233     AC_MSG_ERROR([Could not locate the regexec() function])
234 else
235     if test x"$regexcheck_enabled" = x"yes" ; then
236         AC_MSG_CHECKING([whether the system's regex library is broken])
237         AC_CACHE_VAL(tinyproxy_cv_regex_broken,
238                      [AC_TRY_RUN([
239 #if HAVE_SYS_TYPES_H
240 #  include <sys/types.h>
241 #endif
242 #if HAVE_UNISTD_H
243 # include <unistd.h>
244 #endif
245 #if HAVE_REGEX_H
246 # include <regex.h>
247 #endif
248 #if HAVE_STDLIB_H
249 # include <stdlib.h>
250 #endif
251 int main(void)
252 {
253         regex_t blah;
254         if (regcomp(&blah, "foo.*bar", REG_NOSUB) != 0)
255                 exit(1);
256         if (regexec(&blah, "foobar", 0, NULL, 0) != 0)
257                 exit(1);
258         else
259                 exit(0);
260
261         return 0;
262 }
263                      ],
264                      tinyproxy_cv_regex_broken=no,
265                      tinyproxy_cv_regex_broken=yes,
266                      tinyproxy_cv_regex_broken=yes)])
267
268         AC_MSG_RESULT([$tinyproxy_cv_regex_broken])
269
270         if test x"$tinyproxy_cv_regex_broken" = x"yes" ; then
271             AC_MSG_ERROR([Your system's regexec() function is broken.])
272         fi
273     fi
274 fi
275
276 dnl
277 dnl Substitute the variables into the various Makefiles
278 dnl
279 AC_SUBST(CFLAGS)
280 AC_SUBST(LDFLAGS)
281 AC_SUBST(CPPFLAGS)
282 AC_SUBST(LIBS)
283 AC_SUBST(ADDITIONAL_OBJECTS)
284
285 # Check for xml tools
286 AC_PATH_PROG(XMLLINT, xmllint, no)
287 AM_CONDITIONAL(HAVE_XMLLINT, test "x$XMLLINT" != "xno")
288 AC_PATH_PROG(XSLTPROC, xsltproc, no)
289 AM_CONDITIONAL(HAVE_XSLTPROC, test "x$XSLTPROC" != "xno")
290
291 # Check for asciidoc
292 AC_PATH_PROG(A2X, a2x, no)
293 AM_CONDITIONAL(HAVE_A2X, test "x$A2X" != "xno")
294 if test x"$A2X" = x"no"; then
295   AC_MSG_ERROR([Test for asciidoc failed. See the file 'INSTALL' for help.])
296 fi
297
298 AC_CONFIG_FILES([
299 Makefile
300 src/Makefile
301 data/Makefile
302 data/templates/Makefile
303 etc/Makefile
304 docs/Makefile
305 docs/man5/Makefile
306 docs/man5/tinyproxy.conf.txt
307 docs/man8/Makefile
308 docs/man8/tinyproxy.txt
309 m4macros/Makefile
310 tests/Makefile
311 tests/scripts/Makefile
312 ])
313
314 AC_OUTPUT