#93: Add a config directive to let Privoxy explicitly request either IPv4 (or IPv6...
[privoxy.git] / configure.in
1 dnl Process this file with autoconf to produce a configure script.
2 dnl 
3 dnl $Id: configure.in,v 1.158 2011/06/23 14:01:01 fabiankeil Exp $
4 dnl 
5 dnl Written by and Copyright (C) 2001-2010 the
6 dnl Privoxy team. http://www.privoxy.org/
7 dnl
8 dnl Based on the Internet Junkbuster originally written
9 dnl by and Copyright (C) 1997 Anonymous Coders and 
10 dnl Junkbusters Corporation.  http://www.junkbusters.com
11 dnl
12 dnl This program is free software; you can redistribute it 
13 dnl and/or modify it under the terms of the GNU General
14 dnl Public License as published by the Free Software
15 dnl Foundation; either version 2 of the License, or (at
16 dnl your option) any later version.
17 dnl 
18 dnl This program is distributed in the hope that it will
19 dnl be useful, but WITHOUT ANY WARRANTY; without even the
20 dnl implied warranty of MERCHANTABILITY or FITNESS FOR A
21 dnl PARTICULAR PURPOSE.  See the GNU General Public
22 dnl License for more details.
23 dnl 
24 dnl The GNU General Public License should be included with
25 dnl this file.  If not, you can view it at
26 dnl http://www.gnu.org/copyleft/gpl.html
27 dnl or write to the Free Software Foundation, Inc., 59
28 dnl Temple Place - Suite 330, Boston, MA  02111-1307, USA.
29 dnl 
30
31 dnl =================================================================
32 dnl AutoConf Initialization
33 dnl =================================================================
34
35 AC_REVISION($Revision: 1.158 $)
36 AC_INIT(jcc.c)
37
38 if test ! -f config.h.in; then
39    echo "You need to run autoheader first. "
40    echo -n "Shall I do this for you now? (y/n) "
41    read answer
42    if test "$answer" != "y"; then
43       exit 1
44    else
45       autoheader
46   fi
47 fi  
48
49 AC_CONFIG_HEADER([config.h])
50 AC_CANONICAL_HOST
51
52 dodk=auto
53 DKPREFIX=none
54 AC_ARG_WITH(docbook, dnl
55   --with-docbook=[[yes|no|directory]]   
56                            Enable docbook documentation creation 
57                            (default = yes, for gnu and linux),[dnl
58 case "$with_docbook" in
59 yes) dodk=yes;;
60 no) dodk=no;;
61 *) 
62         dodk=yes
63         DKPREFIX=$withval
64         ;;
65 esac
66 ])
67 DB2HTML=false
68 AC_ARG_WITH(db2html, dnl
69   --with-db2html=<path/executable>
70                           Set the location of the docbook to html converter
71                           (default = search),[dnl
72 DB2HTML=$withval
73 ])
74
75 dnl =================================================================
76 dnl Application version number
77 dnl =================================================================
78
79 VERSION_MAJOR=3
80 VERSION_MINOR=0
81 VERSION_POINT=18
82 CODE_STATUS="UNRELEASED"
83
84 dnl CODE_STATUS can be "alpha", "beta", or "stable", and will be
85 dnl used for CGI output. Set version to 0.0.0 and status to "UNRELEASED"
86 dnl whenever CVS in a stable branch differs from the last release.
87
88 dnl =================================================================
89 dnl Substitute the version numbers
90 dnl =================================================================
91
92 AC_SUBST(VERSION_MAJOR)
93 AC_SUBST(VERSION_MINOR)
94 AC_SUBST(VERSION_POINT)
95 AC_SUBST(CODE_STATUS)
96
97 dnl
98 AC_DEFINE_UNQUOTED(VERSION_MAJOR,${VERSION_MAJOR})
99 AC_DEFINE_UNQUOTED(VERSION_MINOR,${VERSION_MINOR})
100 AC_DEFINE_UNQUOTED(VERSION_POINT,${VERSION_POINT})
101 AC_DEFINE_UNQUOTED(VERSION,"${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_POINT}")
102 AC_DEFINE_UNQUOTED(CODE_STATUS,"${CODE_STATUS}")
103
104 dnl =================================================================
105 dnl Checks for programs needed to build.
106 dnl =================================================================
107
108 dnl Keep AC_PROG_CC from setting its own defaults:
109 if test "X$CFLAGS" = "X"; then
110    CFLAGS=" "
111 fi
112
113 AC_PROG_CC
114 AC_PROG_CPP
115 AC_PROG_INSTALL
116 AC_PROG_LN_S
117 AC_PROG_MAKE_SET
118 AC_PROG_AWK
119
120 AC_CHECK_PROG(GDB,gdb,yes,no)
121 AC_PATH_PROG(BGROUPS,groups,no,$PATH:/bin:/usr/bin:/usr/local/bin)
122 AC_PATH_PROG(ID,id,no,$PATH:/bin:/usr/bin:/usr/local/bin)
123 AC_SUBST(ID)
124 AC_SUBST(BGROUPS)
125
126 dnl =================================================================
127 dnl debug, gcc and gdb support 
128 dnl =================================================================
129
130 AC_ARG_WITH(debug,
131         [  --with-debug            Enable debug mode],
132         [
133                 if test "x$withval" != "xno" ; then
134                     if test $ac_cv_prog_cc_g = yes; then
135                       if test "$GCC" = yes; then
136                         if test "$GDB"; then
137                           CFLAGS="$CFLAGS -ggdb"
138                         else
139                           CFLAGS="$CFLAGS -g"
140                         fi
141                         CFLAGS="$CFLAGS -Wshadow  -Wconversion"
142                       else
143                         CFLAGS="$CFLAGS -g"
144                       fi
145                    fi
146                 fi
147         ],
148         [
149             if test "X$CFLAGS" = "X "; then # if CFLAGS were unset (see above)
150               if test "$GCC" = yes; then
151                 CFLAGS="-O2"
152               fi
153             fi
154         ]
155 )
156
157 dnl =================================================================
158 dnl Check for user and group validity
159 dnl =================================================================
160
161
162 if test "$EMXOS2" = yes; then
163   echo "Skipping user and group validity stuff.";
164
165 else
166
167   $ID privoxy >/dev/null 2>/dev/null
168   if test $? -ne 0 ; then
169    AC_MSG_WARN(There is no user 'privoxy' on this system)
170   fi
171   AC_MSG_CHECKING([for user])
172   AC_ARG_WITH(user,
173         [  --with-user=privoxy          Set user under which privoxy will run],
174         [
175                 if test "x$withval" != "xyes"; then
176                   if test $ID = no ; then
177                     AC_MSG_ERROR(There is no 'id' program on this system)
178                   else
179                     AC_MSG_RESULT($with_user)
180                     $ID $with_user 2>/dev/null >/dev/null
181                     if test $? -eq 0 ; then
182                       USER=$with_user;
183                     else
184                       AC_MSG_ERROR(There is no user '$with_user' on this system)
185                     fi
186                   fi
187                   else
188                    AC_MSG_ERROR(We need a user if you give me this parameter)
189                 fi
190         ],
191         [
192           if test $ID = no ; then
193             AC_MSG_ERROR(There is no 'id' programm on this system)
194           else
195             AC_MSG_RESULT(none specified)
196             USER=$with_user
197           fi
198         ]
199   )
200   AC_SUBST(USER)
201
202   AC_MSG_CHECKING([for group])
203   AC_ARG_WITH(group,
204         [  --with-group=privoxy         Set group for privoxy],
205         [ 
206                 if test "x$withval" != "xyes"; then
207                   if test $BGROUPS = no ; then
208                     AC_MSG_ERROR(There is no 'groups' program on this system)
209                   else
210                     AC_MSG_RESULT($with_group)
211                     $BGROUPS $USER >/dev/null
212                     if test $? -eq 0 ; then
213                     # FIXME: this fails if valid group, but not first group
214                     # listed.
215                       if test "$with_group" != "`$BGROUPS $USER | sed 's/.*: //' 2>/dev/null |$AWK '{print $1}'`" ; then
216                         AC_MSG_ERROR(The given value '$withval' does not match group entry)
217                       else
218                         GROUP=$with_group;
219                       fi
220                     else
221                       AC_MSG_ERROR(There is no group entry for user '$USER')
222                     fi
223                   fi
224                 else
225                    AC_MSG_ERROR(We need a group if you give me this parameter)
226                 fi
227         ],
228         [
229           if test $BGROUPS = no ; then
230             AC_MSG_ERROR(There is no 'groups' programm on this system)
231           else
232             AC_MSG_RESULT(none specified)
233             GROUP=$with_group;
234           fi
235         ]
236   )
237   AC_SUBST(GROUP)
238
239 fi
240
241 dnl =================================================================
242 dnl additional gcc flags
243 dnl =================================================================
244 dnl 
245 if test "$GCC"; then
246   if test "$host" != "powerpc-unknown-amigaos"; then
247     CFLAGS="-pipe $CFLAGS"
248   fi
249 fi
250
251
252 dnl =================================================================
253 dnl Build type
254 dnl =================================================================
255 dnl
256 dnl Must do this first.
257 dnl
258 dnl Reason: This sets CFLAGS in order to switch the Cygwin compiler
259 dnl into Cygwin or MinGW32 modes.  Depending on the mode selected,
260 dnl the compiler will use completely different sets of library
261 dnl and include files.
262 dnl 
263 dnl =================================================================
264
265 AC_MINGW32
266 AC_CYGWIN
267
268 if test "$MINGW32" = "yes"; then
269   target_type=mingw
270 else
271   if test "$CYGWIN" = "yes"; then
272     target_type=cygwin
273   else
274     target_type=unix
275   fi
276 fi
277
278 if test $dodk = auto; then
279         dodk=no
280         if test $target_type = unix; then
281                 case "$host_os" in
282                 linux* | gnu*)
283                         dodk=yes
284                 ;;
285                 esac
286         fi
287 fi
288
289 dnl Decide what to do based on target_type
290 dnl Note: PTHREAD_LIB is always set, even if pthread is disabled.
291 dnl This is because we don't know yet whether pthread is enabled.
292
293 AC_ARG_ENABLE(mingw32,
294 [  --enable-mingw32                Use mingw32 for a Windows GUI],
295 [if test $enableval = yes; then
296   target_type=mingw
297 fi])
298
299 if test $target_type = mingw; then
300   WIN_ONLY=
301   CFLAGS="$CFLAGS -DWINVER=0x501"
302   SPECIAL_CFLAGS="-mwindows -mno-cygwin"
303   PTHREAD_LIB=-lpthreadGC
304   echo "Using mingw32 (Win32 GUI)"
305 else
306   WIN_ONLY=#
307   if test $target_type = cygwin; then
308     SPECIAL_CFLAGS="-mno-win32"
309     PTHREAD_LIB=
310     echo "Using Cygnus (Win32 command line)"
311   else
312     SPECIAL_CFLAGS=
313     PTHREAD_LIB=-lpthread
314   fi
315 fi
316 AC_SUBST(WIN_ONLY)
317
318 dnl Checking which text html browser we have available
319 if test $dodk != no; then
320         AC_CHECK_PROGS(WDUMP,w3m lynx links,false)
321         if test "$WDUMP" = false; then
322                 AC_MSG_WARN(You need some kind of text browser to build documentation \(w3m, lynx and links are supported\))
323         fi
324         if test $DB2HTML = false; then
325                 dnl We need to clean the variable, otherwise AC_CHECK_PROGS
326                 dnl will fail   
327                 DB2HTML=""
328                 AC_CHECK_PROGS(DB2HTML,db2html docbook2html,false)
329         fi
330 fi
331 AC_SUBST(WDUMP)
332 AC_SUBST(DB2HTML)
333
334 dnl If we use rpm, we need to check where %_topdir is
335 AC_CHECK_PROGS(RPMBIN,rpm,false)
336 if test $RPMBIN != false; then
337                 RPM_BASE=`rpm --eval "%{_topdir}"`
338                 if test "$RPM_BASE" = ""; then
339                         RPM_BASE=/usr/src/redhat
340                 fi
341 fi
342 AC_SUBST(RPM_BASE)
343
344 dnl Check for jade, so we can build the documentation
345 AC_CHECK_PROGS(JADEBIN,jade openjade,false)
346 AC_SUBST(JADEBIN)
347
348 dnl Check for man2html for docs.
349 AC_CHECK_PROGS(MAN2HTML,man2html,false)
350 AC_SUBST(MAN2HTML)
351
352 dnl Set doc status flag for conditional content inclusions
353 DOC_STATUS=p-not-stable
354 if  test $CODE_STATUS = stable; then
355      DOC_STATUS="p-stable"
356 fi
357 AC_SUBST(DOC_STATUS)
358
359 dnl Checking for the docbook.dsl stylesheet file
360 dnl It is still not portable (directory slash)
361 JADECAT=""
362 if test $dodk = yes; then
363   if test $DKPREFIX = none; then
364     for i in /usr/share/sgml/docbook/dsssl-stylesheets \
365              /usr/share/sgml/docbkdsl /usr/share/sgml/docbook-dsssl \
366              /usr/local/share/sgml/docbook/dsssl/modular \
367              /usr/share/sgml/docbook/stylesheet/dsssl/modular/ \
368              ; do
369 dnl  echo -n does not fly with /bin/sh.
370 dnl      echo -n "checking for $i/html/docbook.dsl..."
371       AC_MSG_CHECKING([for $i])
372       if test -f $i/html/docbook.dsl; then
373         echo "yes"
374         DKPREFIX=$i
375         break
376       else
377         echo "no"
378       fi
379     done
380 # where are the catalogs?
381     for i in /usr/share/sgml/CATALOG.docbk30 \
382              /usr/share/sgml/CATALOG.docbk31 \
383              /usr/share/sgml/CATALOG.docbk31 \
384              /usr/local/share/sgml/docbook/3.0/docbook.cat \
385              /usr/local/share/sgml/docbook/3.1/docbook.cat \
386              /usr/share/sgml/docbook/dtd/3.1/docbook.cat \
387              ; do
388 dnl     echo -n "checking for $i..."
389       AC_MSG_CHECKING([for $i])
390       if test -f $i; then
391         echo "yes"
392         JADECAT="$JADECAT -c $i"
393       else
394         echo "no"
395       fi
396     done
397   fi
398 fi
399 AC_SUBST(JADECAT)
400 AC_SUBST(DKPREFIX)
401
402 AC_ARG_ENABLE(large-file-support,
403 [  --enable-large-file-support     Define _LARGE_FILES and friends.
404                                   Required by some systems to support files larger then 2GB.],
405 [if test $enableval = yes; then
406     CFLAGS="$CFLAGS -D_FILE_OFFSET_BITS=64 -D_LARGE_FILES -D_LARGEFILE_SOURCE=1"
407 fi])
408
409 dnl Save old CFLAGS so we can restore them later, then add SPECIAL_CFLAGS
410 old_CFLAGS_nospecial=$CFLAGS
411 CFLAGS="$CFLAGS $SPECIAL_CFLAGS"
412
413 # Hack to force AutoConf to use the CFLAGS we just set
414 dnl Warning: This may break with a future version of Autoconf
415 dnl          Tested with autoconf 2.13
416 ac_cpp='$CPP $CPPFLAGS $SPECIAL_CFLAGS'
417 ac_compile='${CC-cc} -c $CFLAGS $CPPFLAGS conftest.$ac_ext 1>&5'
418 ac_link='${CC-cc} -o conftest${ac_exeext} $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS 1>&5'
419
420
421 dnl =================================================================
422 dnl Thread support
423 dnl =================================================================
424
425 AC_CHECK_HEADER(pthread.h, [have_pthread=yes], [have_pthread=no])
426
427 AC_ARG_ENABLE(pthread,
428 [  --disable-pthread               Don't use POSIX threads (pthreads)],
429 [if test $enableval = no; then
430   # Disable pthreads
431   if test $have_pthread = yes; then
432      AC_MSG_WARN([pthreads seem to be available but you are using --disable-pthread.]) 
433      AC_MSG_WARN([This is almost always a mistake and can render Privoxy unacceptable slow.])
434   fi
435   have_pthread=no
436 fi])
437
438 if test $have_pthread = yes; then
439   PTHREAD_ONLY=
440   AC_DEFINE(FEATURE_PTHREAD)
441   echo Using POSIX threads
442   if test "$GCC" = "yes"; then
443     # Set a GCC specific switch:
444     if test "$target_type" = "unix"; then
445       ac_jgf_save_CFLAGS=$CFLAGS
446       CFLAGS="$CFLAGS -pthread"
447       AC_TRY_LINK([#include <pthread.h>],
448         [void *p = pthread_create;],
449         [
450           # This compiler switch makes GCC on Linux thread-safe
451           # However, it's not supported on most other OS.
452           PTHREAD_LIB=
453           SPECIAL_CFLAGS="-pthread"
454         ])
455       CFLAGS=$ac_jgf_save_CFLAGS
456     fi
457   fi
458 else
459   PTHREAD_ONLY=#
460   echo Using native threads
461 fi
462
463 AC_SUBST(PTHREAD_ONLY)
464
465 dnl =================================================================
466 dnl Support for thread-safe versions of gethostbyaddr, gethostbyname,
467 dnl gmtime and localtime
468 dnl =================================================================
469
470 dnl Next line needed to find the gethost*_r functions on Solaris
471 AC_CHECK_LIB(nsl, gethostbyname)
472
473 AC_CHECK_FUNC(gethostbyaddr_r, [
474   AC_MSG_CHECKING([signature of gethostbyaddr_r])
475   AC_TRY_COMPILE([
476 #   include <netdb.h>
477   ], [
478     struct hostent *h, *hp;
479     char *a, *b;
480     int l, bl, t, e;
481     (void) gethostbyaddr_r(a, l, t, h, b, bl, &hp, &e)
482   ], [
483     AC_DEFINE(HAVE_GETHOSTBYADDR_R_8_ARGS)
484     AC_MSG_RESULT([8 args])
485   ], [
486     AC_TRY_COMPILE([
487 #     include <netdb.h>
488     ], [
489       struct hostent *h;
490       char *a, *b;
491       int l, bl, t, e;
492       (void) gethostbyaddr_r(a, l, t, h, b, bl, &e)
493     ], [
494       AC_DEFINE(HAVE_GETHOSTBYADDR_R_7_ARGS)
495       AC_MSG_RESULT([7 args])
496     ], [
497       AC_TRY_COMPILE([
498 #       include <netdb.h>
499       ], [
500         struct hostent_data *d;
501         struct hostent *h;
502         char a,
503         int l, t;
504         (void) gethostbyaddr_r(a, l, t, h, d)
505       ], [
506         AC_DEFINE(HAVE_GETHOSTBYADDR_R_5_ARGS)
507         AC_MSG_RESULT([5 args])
508       ], [
509         AC_MSG_RESULT(unrecognised)
510       ])
511     ])
512   ])
513 ], [
514   AC_MSG_RESULT(no)
515 ])
516
517 AC_CHECK_FUNC(gethostbyname_r, [
518   AC_MSG_CHECKING([signature of gethostbyname_r])
519   AC_TRY_COMPILE([
520 #   include <netdb.h>
521   ], [
522     struct hostent *h, *r;
523     char *n, *b;
524     int bl, e;
525     (void) gethostbyname_r(n, h, b, bl, &r, &e)
526   ], [
527     AC_DEFINE(HAVE_GETHOSTBYNAME_R_6_ARGS)
528     AC_MSG_RESULT([6 args])
529   ], [
530     AC_TRY_COMPILE([
531 #     include <netdb.h>
532     ], [
533       struct hostent *h;
534       char *n, *b;
535       int bl, e;
536       (void) gethostbyname_r(n, h, b, bl, &e)
537     ], [
538       AC_DEFINE(HAVE_GETHOSTBYNAME_R_5_ARGS)
539       AC_MSG_RESULT([5 args])
540     ], [
541       AC_TRY_COMPILE([
542 #       include <netdb.h>
543       ], [
544         struct hostent_data *d;
545         struct hostent *h;
546         char *n,
547         (void) gethostbyname_r(n, h, d)
548       ], [
549         AC_DEFINE(HAVE_GETHOSTBYNAME_R_3_ARGS)
550         AC_MSG_RESULT([3 args])
551       ], [
552         AC_MSG_RESULT(unrecognised)
553       ])
554     ])
555   ])
556 ], [
557   AC_MSG_RESULT(no)
558 ])
559
560 AC_CHECK_FUNC(gmtime_r, [
561   AC_MSG_CHECKING([signature of gmtime_r])
562   AC_TRY_COMPILE([
563 #   include <time.h>
564   ], [
565     struct time *t;
566     struct tm *tm;
567     (void) gmtime_r(t, tm)
568   ], [
569     AC_MSG_RESULT(ok)
570     AC_DEFINE(HAVE_GMTIME_R)
571   ], [
572     AC_MSG_RESULT(unrecognised)
573   ])
574 ], [
575   AC_MSG_RESULT(no)
576 ])
577
578 AC_CHECK_FUNC(localtime_r, [
579   AC_MSG_CHECKING([signature of localtime_r])
580   AC_TRY_COMPILE([
581 #   include <time.h>
582   ], [
583     struct time *t;
584     struct tm *tm;
585     (void) localtime_r(t, tm)
586   ], [
587     AC_MSG_RESULT(ok)
588     AC_DEFINE(HAVE_LOCALTIME_R)
589   ], [
590     AC_MSG_RESULT(unrecognised)
591   ])
592 ], [
593   AC_MSG_RESULT(no)
594 ])
595
596 dnl =================================================================
597 dnl Solaris specific
598 dnl FIXME: Not tested on Solaris yet...
599 dnl ISFIXED: Have tested it on Solaris, but there are other ways to
600 dnl     make these checks generic, e.g.:
601 dnl AC_CHECK_FUNC(getsockopt, , AC_CHECK_LIB(socket, getsockopt))
602 dnl     (Moritz Barsnick <moritz@barsnick.net>)
603 dnl =================================================================
604
605
606 SOCKET_LIB=
607
608 case "$host" in
609 *-solaris*) SOCKET_LIB="-lsocket -lnsl"
610             AC_DEFINE(__EXTENSIONS__)
611             if test "$GCC" = "yes"; then
612               # Set a GCC specific switch:
613               # This compiler switch makes Solaris thread-safe
614               PTHREAD_LIB=
615               SPECIAL_CFLAGS="-pthreads"
616             else
617               # What do we do without GCC? Guess this:
618               SPECIAL_CFLAGS="-D_REENTRANT"
619             fi
620 ;;
621 esac
622
623 AC_SUBST(SOCKET_LIB)
624
625 dnl =================================================================
626 dnl Solaris problem, and others perhaps (socklen_t is undefined)
627 dnl =================================================================
628
629 AC_MSG_CHECKING([for socklen_t])
630 AC_EGREP_HEADER(socklen_t, sys/socket.h, AC_MSG_RESULT([yes]),
631         AC_MSG_RESULT([no])
632         AC_DEFINE(socklen_t,int,
633                 [ Define to 'int' if <sys/socket.h> doesn't have it. ]))
634
635
636 dnl =================================================================
637 dnl OS/2 specific
638 dnl =================================================================
639
640 case "$host" in
641 *-os2-emx*) SOCKET_LIB=-lsocket
642 ;;
643 esac
644
645 AC_SUBST(SOCKET_LIB)
646
647 dnl =================================================================
648 dnl Mac OSX specific
649 dnl =================================================================
650     
651 case "$host" in
652 *-apple-darwin*) SPECIAL_CFLAGS="-Dunix"
653 ;;  
654 esac
655
656 dnl =================================================================
657 dnl OpenBSD specific
658 dnl =================================================================
659
660 case "$host" in
661 *-openbsd*) SPECIAL_CFLAGS="$SPECIAL_CFLAGS -Dunix"
662 ;;
663 esac
664
665 dnl =================================================================
666 dnl AmigaOS specific
667 dnl =================================================================
668
669 AMIGAOS_ONLY=#
670
671 case "$host" in
672 *-amigaos) AMIGAOS_ONLY=
673 ;;
674 esac
675
676 AC_SUBST(AMIGAOS_ONLY)
677
678 dnl =================================================================
679 dnl Check for standard compiler stuff
680 dnl =================================================================
681
682 AC_EXEEXT
683 AC_OBJEXT
684 AC_HEADER_STDC
685 AC_HEADER_DIRENT
686 AC_C_CONST
687 AC_TYPE_SIZE_T
688 AC_TYPE_PID_T
689 AC_HEADER_TIME
690 AC_STRUCT_TM
691 AC_CHECK_SIZEOF(int, 4)
692 AC_CHECK_SIZEOF(char *, 4)
693 AC_CHECK_SIZEOF(long, 4)
694 AC_CHECK_SIZEOF(long long, 8)
695 AC_CHECK_SIZEOF(size_t, 4)
696
697 dnl Checks for header files.
698 dnl AC_HEADER_SYS_WAIT
699 dnl AC_CHECK_HEADERS(fcntl.h limits.h malloc.h sys/time.h unistd.h)
700 AC_CHECK_HEADERS([OS.h arpa/inet.h errno.h fcntl.h limits.h locale.h netdb.h netinet/in.h stddef.h stdlib.h string.h sys/ioctl.h sys/socket.h sys/time.h sys/timeb.h sys/wait.h unistd.h])
701
702 dnl Checks for library functions.
703 dnl bcopy is for PCRE
704 AC_CHECK_FUNCS([bcopy])
705 AC_PROG_GCC_TRADITIONAL
706 AC_TYPE_SIGNAL
707 AC_CHECK_FUNCS([access atexit getcwd gethostbyaddr gethostbyaddr_r gethostbyname gethostbyname_r gettimeofday inet_ntoa localtime_r memchr memmove memset poll putenv random regcomp select setlocale snprintf socket strchr strdup strerror strftime strlcat strlcpy strptime strstr strtoul timegm tzset])
708
709 dnl Checks for RFC 2553 resolver and socket functions
710 AC_ARG_ENABLE(ipv6-support,
711 [  --disable-ipv6-support          Disable IPv6 support and other RFC-2554-related improvements],
712 [if test $enableval = yes; then
713   enable_ipv6_support=yes
714 fi], enable_ipv6_support=yes)
715
716 if test $enable_ipv6_support != yes; then
717   AC_MSG_WARN([Skipping checks for IPv6 support and other RFC-2554-related improvements.
718     Due to lock contention, this may result in slower DNS resolution for IPv4 setups, too.])
719 elif test $target_type = mingw; then
720   AC_CHECK_LIB(ws2_32, main)
721
722   AC_MSG_CHECKING(getaddrinfo in ws2_32)
723   AC_TRY_LINK(
724     [
725       #include<windows.h>
726       #include<ws2tcpip.h>
727     ],
728     [getaddrinfo(0,0,0,0)],
729     have_ws2_32_getaddrinfo=yes
730   )
731   AC_MSG_RESULT($have_ws2_32_getaddrinfo)
732
733   AC_MSG_CHECKING(getnameinfo in ws2_32)
734   AC_TRY_LINK(
735     [
736       #include<windows.h>
737       #include<ws2tcpip.h>
738     ],
739     [getnameinfo(0,0,0,0,0,0,0)],
740     have_ws2_32_getnameinfo=yes
741   )
742   AC_MSG_RESULT($have_ws2_32_getnameinfo)
743
744   if test $have_ws2_32_getaddrinfo ; then
745     if test $have_ws2_32_getnameinfo ; then
746       AC_DEFINE([HAVE_RFC2553], [1],
747         [Define if RFC 2553 resolver functions like getaddrinfo(3) and
748          getnameinfo(3) present])
749     fi
750   fi
751 else
752   AC_CHECK_FUNC([getaddrinfo],
753      [AC_CHECK_FUNC([getnameinfo],
754         [AC_DEFINE([HAVE_RFC2553], [1],
755            [Define if RFC 2553 resolver functions like getaddrinfo(3) and
756             getnameinfo(3) present])
757         ])
758   ])
759 fi
760
761 dnl =================================================================
762 dnl Checks for libraries.
763 dnl =================================================================
764 dnl Note: Some systems may have the library but not the system header
765 dnl       file, so we must check for both.
766 dnl       Also check for correct version
767 AC_CHECK_LIB(pcre, pcre_compile, [
768    AC_CHECK_HEADER(pcre.h, [
769       AC_EGREP_HEADER(pcre_fullinfo, pcre.h, [have_pcre=yes], [AC_MSG_WARN([[pcre old version installed]]); have_pcre=no])
770    ], [
771       AC_CHECK_HEADER(pcre/pcre.h, [
772          AC_EGREP_HEADER(pcre_fullinfo, pcre/pcre.h, [have_pcre=yes]; [AC_DEFINE(PCRE_H_IN_SUBDIR)], [AC_MSG_WARN([[pcre old version installed]]); have_pcre=no])
773       ], [have_pcre=no])
774    ])
775 ], [have_pcre=no])
776  
777 AC_CHECK_LIB(pcreposix, regcomp, [
778    AC_CHECK_HEADER(pcreposix.h, [
779       AC_EGREP_HEADER(pcreposix_regerror, pcreposix.h, [AC_MSG_WARN([[pcreposix old version installed]]); have_pcreposix=no], [have_pcreposix=yes])
780    ], [
781       AC_CHECK_HEADER(pcre/pcreposix.h, [
782          AC_EGREP_HEADER(pcreposix_regerror, pcre/pcreposix.h, [AC_MSG_WARN([[pcreposix old version installed]]); have_pcreposix=no], [have_pcreposix=yes]; [AC_DEFINE(PCREPOSIX_H_IN_SUBDIR)])
783       ], [have_pcreposix=no])
784    ])
785 ], [have_pcreposix=no], -lpcre) 
786
787 dnl ================================================================
788 dnl libpcrs is temporarily disabled.
789 dnl
790 dnl Privoxy's own pcrs version fixes some problems that
791 dnl are present in libpcrs 0.3, the last pcrs release we
792 dnl know of, and as libpcrs seems to be currently unmaintained
793 dnl we can't send these fixes upstream.
794 dnl ================================================================
795 dnl
796 dnl AC_CHECK_LIB(pcrs, pcrs_compile, [AC_CHECK_HEADER(pcrs.h, [have_pcrs=yes], [have_pcrs=no])], [have_pcrs=no], -lpcre)
797
798 dnl =================================================================
799 dnl Always defined
800 dnl =================================================================
801
802 AC_DEFINE(__MT__)
803
804 dnl =================================================================
805 dnl Features
806 dnl =================================================================
807
808 AC_ARG_ENABLE(toggle,
809 [  --disable-toggle                Don't support temporary disable],
810 [if test $enableval = yes; then
811   AC_DEFINE(FEATURE_TOGGLE)
812 fi],AC_DEFINE(FEATURE_TOGGLE))
813
814 AC_ARG_ENABLE(force,
815 [  --disable-force                 Don't allow single-page disable],
816 [if test $enableval = yes; then
817   AC_DEFINE(FEATURE_FORCE_LOAD)
818 fi],AC_DEFINE(FEATURE_FORCE_LOAD))
819
820 AC_ARG_ENABLE(fast-redirects,
821 [  --disable-fast-redirects        Don't support fast redirects],
822 [if test $enableval = yes; then
823   AC_DEFINE(FEATURE_FAST_REDIRECTS)
824 fi], AC_DEFINE(FEATURE_FAST_REDIRECTS))
825
826 AC_ARG_ENABLE(stats,
827 [  --disable-stats                 Don't keep statistics],
828 [if test $enableval = yes; then
829   AC_DEFINE(FEATURE_STATISTICS)
830 fi],AC_DEFINE(FEATURE_STATISTICS))
831
832 AC_ARG_ENABLE(ie-images,
833 [  --enable-ie-images              Enable a quick but not always reliable auto-detect whether requests from
834                                   MS Internet Explorer are for an image or not.],
835 [if test $enableval = yes; then
836   AC_DEFINE(FEATURE_IMAGE_DETECT_MSIE)
837 fi],)
838
839 AC_ARG_ENABLE(image-blocking,
840 [  --disable-image-blocking        Don't try to figure out whether a request is 
841                                   for an image or HTML - assume HTML.],
842 [if test $enableval = yes; then
843   AC_DEFINE(FEATURE_IMAGE_BLOCKING)
844 fi],
845 AC_DEFINE(FEATURE_IMAGE_BLOCKING))
846
847 AC_ARG_ENABLE(acl-support,
848 [  --disable-acl-support            Prevents the use of ACLs to control access to
849                                   Privoxy by IP address.],
850 [if test $enableval = yes; then
851   AC_DEFINE(FEATURE_ACL)
852 fi],
853 AC_DEFINE(FEATURE_ACL))
854
855 AC_ARG_ENABLE(trust-files,
856 [  --disable-trust-files           Prevents the use of trust files.],
857 [if test $enableval = yes; then
858   AC_DEFINE(FEATURE_TRUST)
859 fi],
860 AC_DEFINE(FEATURE_TRUST))
861
862 AC_ARG_ENABLE(editor,
863 [  --disable-editor                Prevents the use of the web-based actions file
864                                   editor and web-based temporary disable setting.],
865 [if test $enableval = yes; then
866   AC_DEFINE(FEATURE_CGI_EDIT_ACTIONS)
867 fi],
868 AC_DEFINE(FEATURE_CGI_EDIT_ACTIONS))
869
870 AC_ARG_ENABLE(no-gifs,
871 [  --enable-no-gifs                Use politically correct PNG format instead of GIF
872                                   for built-in images. May not work with all browsers.],
873 [if test $enableval = yes; then
874   AC_DEFINE(FEATURE_NO_GIFS)
875 fi])
876
877 AC_ARG_ENABLE(graceful-termination,
878 [  --enable-graceful-termination   Allow to shutdown Privoxy through the webinterface.],
879 [if test $enableval = yes; then
880   AC_DEFINE(FEATURE_GRACEFUL_TERMINATION)
881 fi])
882
883 AC_ARG_ENABLE(extended-host-patterns,
884 [  --enable-extended-host-patterns Enable and require PCRE syntax in host patterns. This feature hasn't
885                                   been announced yet and it's not clear if it's a good idea. It's expected
886                                   to work, but undocumented. You should only enable it if you know what
887                                   PCRE is and are sure that you need it for your host patterns. You can
888                                   use tools/url-pattern-translator.pl to convert existing action files to
889                                   use PCRE host patterns. Please don't enable this option when creating
890                                   packages for others that may not be expecting it.],
891 [if test $enableval = yes; then
892   AC_DEFINE(FEATURE_EXTENDED_HOST_PATTERNS)
893 fi])
894
895 AC_ARG_ENABLE(accept-filter,
896 [  --enable-accept-filter          Try to use accf_http(9) if supported.],
897 [if test $enableval = yes; then
898   AC_DEFINE(FEATURE_ACCEPT_FILTER)
899 fi])
900
901 dnl pcre/pcrs is needed for CGI anyway, so
902 dnl the choice is only between static and
903 dnl dynamic:
904
905 AC_ARG_ENABLE(dynamic-pcre,
906 [  --disable-dynamic-pcre          Use the built-in, static pcre, even if libpcre is available],
907 [ if test $enableval = "no"; then have_pcre=no; fi ])
908
909 dnl =================================================
910 dnl libpcrs is temporarily disabled,
911 dnl see comment above for the reason.
912 dnl =================================================
913 dnl AC_ARG_ENABLE(dynamic-pcrs,
914 dnl [  --disable-dynamic-pcrs          Use the built-in, static pcrs, even if libpcrs is available],
915 dnl [ if test $enableval = "no"; then have_pcrs=no; fi ])
916
917
918 dnl ====================================================
919 dnl This check is incomplete. For mingw32 zlib is found
920 dnl by configure, but not necessarily by the compiler.
921 dnl ====================================================
922 AC_ARG_ENABLE(zlib,
923 [  --disable-zlib                  Don't use zlib to decompress data before filtering.],
924 [enableval2=$enableval],
925 [enableval2=yes])
926 if test $enableval2 = yes; then
927   AC_CHECK_LIB(z, zlibVersion, [have_zlib="yes"], [have_zlib="no"])
928   if test $have_zlib = "yes"; then
929     LIBS="$LIBS -lz"
930     AC_DEFINE(FEATURE_ZLIB,1,[Define to 1 to use zlib to decompress data before filtering.])
931   else
932    AC_MSG_WARN([No zlib found.
933    Privoxy will not be able to filter compressed content.
934    This may become a fatal error in the future.])
935   fi  
936 fi
937
938 AC_ARG_ENABLE(compression,
939 [  --enable-compression            Allow Privoxy to compress buffered content if the client supports it. Requires zlib support.],
940 [enableval2=$enableval],
941 [enableval2=no])
942 if test $enableval2 = yes; then
943   if test $have_zlib = "yes"; then
944     echo Enabling compression support.
945     AC_DEFINE(FEATURE_COMPRESSION,1,[Define to 1 to use compression through the zlib library.])
946   else
947    AC_MSG_WARN([No zlib found. Privoxy will not be able to (re-)compressed buffered content.])
948   fi
949 fi
950
951
952 # If we have libpcre and either we also have pcreposix or
953 # we don't need pcreposix, then link pcre dynamically; else
954 # build it and link statically
955 #
956 if test $have_pcre = "yes"; then
957   echo "using libpcre"
958   pcre_dyn=yes
959   STATIC_PCRE_ONLY=#
960   LIBS="$LIBS -lpcre -lpcreposix"
961 else
962   AC_MSG_WARN([You are using the static PCRE code which is out of date and scheduled for removal, for details see:
963     http://sourceforge.net/mailarchive/forum.php?thread_name=20080511195555.2dc6cfdc%40fabiankeil.de&forum_name=ijbswa-developers])
964   pcre_dyn=no
965   AC_DEFINE(STATIC_PCRE)
966   STATIC_PCRE_ONLY=
967 fi
968
969 AC_DEFINE(FEATURE_CONNECTION_KEEP_ALIVE)
970
971 if test $have_pthread = "yes" -o $target_type = "mingw"; then
972   echo Enabling connection-sharing support.
973   AC_DEFINE(FEATURE_CONNECTION_SHARING)
974 fi
975
976 dnl =================================================
977 dnl libpcrs is temporarily disabled,
978 dnl see comment above for the reason.
979 dnl =================================================
980 dnl # If we have libpcrs and pcre is linked dynamically
981 dnl # then also link pcrs dynamically, else build and link
982 dnl # pcrs statically
983 dnl
984 dnl if test $have_pcrs = "yes" -a $pcre_dyn = "yes"; then
985 dnl  echo "using libpcrs"
986 dnl  STATIC_PCRS_ONLY=#
987 dnl  LIBS="$LIBS -lpcrs"
988 dnl else
989 dnl  echo "using built-in static pcrs"
990   AC_DEFINE(STATIC_PCRS)
991   STATIC_PCRS_ONLY=
992 dnl fi
993
994 AC_SUBST(STATIC_PCRE_ONLY)
995 AC_SUBST(STATIC_PCRS_ONLY)
996
997 dnl =================================================================
998 dnl Final cleanup and output
999 dnl =================================================================
1000
1001 dnl Remove the SPECIAL_CFLAGS stuff from CFLAGS, and add it separately
1002 dnl in the Makefile
1003 CFLAGS=$old_CFLAGS_nospecial
1004 AC_SUBST(SPECIAL_CFLAGS)
1005
1006 AC_SUBST(PTHREAD_LIB)
1007
1008 AC_OUTPUT(GNUmakefile doc/source/ldp.dsl)