]> sjero.net Git - wget/blob - m4/wget.m4
[svn] Merge of fix for bugs 20341 and 20410.
[wget] / m4 / wget.m4
1 dnl Wget-specific Autoconf macros.
2 dnl Copyright (C) 1996-2005 Free Software Foundation, Inc.
3
4 dnl This program is free software; you can redistribute it and/or modify
5 dnl it under the terms of the GNU General Public License as published by
6 dnl the Free Software Foundation; either version 3 of the License, or
7 dnl (at your option) any later version.
8
9 dnl This program is distributed in the hope that it will be useful,
10 dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
11 dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 dnl GNU General Public License for more details.
13
14 dnl You should have received a copy of the GNU General Public License
15 dnl along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
17 dnl In addition, as a special exception, the Free Software Foundation
18 dnl gives permission to link the code of its release of Wget with the
19 dnl OpenSSL project's "OpenSSL" library (or with modified versions of it
20 dnl that use the same license as the "OpenSSL" library), and distribute
21 dnl the linked executables.  You must obey the GNU General Public License
22 dnl in all respects for all of the code used other than "OpenSSL".  If you
23 dnl modify this file, you may extend this exception to your version of the
24 dnl file, but you are not obligated to do so.  If you do not wish to do
25 dnl so, delete this exception statement from your version.
26
27 dnl
28 dnl Check for `struct utimbuf'.
29 dnl
30
31 AC_DEFUN([WGET_STRUCT_UTIMBUF], [
32   AC_CHECK_TYPES([struct utimbuf], [], [], [
33 #include <stdio.h>
34 #if HAVE_SYS_TYPES_H
35 # include <sys/types.h>
36 #endif
37 #if HAVE_UTIME_H
38 # include <utime.h>
39 #endif
40   ])
41 ])
42
43
44 dnl Check for socklen_t.  The third argument of accept, getsockname,
45 dnl etc. is int * on some systems, but size_t * on others.  POSIX
46 dnl finally standardized on socklen_t, but older systems don't have
47 dnl it.  If socklen_t exists, we use it, else if accept() accepts
48 dnl size_t *, we use that, else we use int.
49
50 AC_DEFUN([WGET_SOCKLEN_T], [
51   AC_MSG_CHECKING(for socklen_t)
52   AC_COMPILE_IFELSE([
53 #include <sys/types.h>
54 #include <sys/socket.h>
55 socklen_t x;
56   ], [AC_MSG_RESULT(socklen_t)], [
57     AC_COMPILE_IFELSE([
58 #include <sys/types.h>
59 #include <sys/socket.h>
60 int accept (int, struct sockaddr *, size_t *);
61     ], [
62       AC_MSG_RESULT(size_t)
63       AC_DEFINE([socklen_t], [size_t],
64                 [Define to int or size_t on systems without socklen_t.])
65     ], [
66       AC_MSG_RESULT(int)
67       AC_DEFINE([socklen_t], [int],
68                 [Define to int or size_t on systems without socklen_t.])
69     ])
70   ])
71 ])
72
73 dnl Check whether fnmatch.h can be included.  This doesn't use
74 dnl AC_FUNC_FNMATCH because Wget is already careful to only use
75 dnl fnmatch on certain OS'es.  However, fnmatch.h is sometimes broken
76 dnl even on those because Apache installs its own fnmatch.h to
77 dnl /usr/local/include (!), which GCC uses before /usr/include.
78
79 AC_DEFUN([WGET_FNMATCH], [
80   AC_MSG_CHECKING([for working fnmatch.h])
81   AC_COMPILE_IFELSE([#include <fnmatch.h>
82                     ], [
83     AC_MSG_RESULT(yes)
84     AC_DEFINE([HAVE_WORKING_FNMATCH_H], 1,
85               [Define if fnmatch.h can be included.])
86   ], [
87     AC_MSG_RESULT(no)
88   ])
89 ])
90
91 dnl Check for nanosleep.  For nanosleep to work on Solaris, we must
92 dnl link with -lrt (recently) or with -lposix4 (older releases).
93
94 AC_DEFUN([WGET_NANOSLEEP], [
95   AC_CHECK_FUNCS(nanosleep, [], [
96     AC_CHECK_LIB(rt, nanosleep, [
97       AC_DEFINE([HAVE_NANOSLEEP], 1,
98                 [Define if you have the nanosleep function.])
99       LIBS="-lrt $LIBS"
100     ], [
101       AC_CHECK_LIB(posix4, nanosleep, [
102         AC_DEFINE([HAVE_NANOSLEEP], 1,
103                   [Define if you have the nanosleep function.])
104         LIBS="-lposix4 $LIBS"
105       ])
106     ])
107   ])
108 ])
109
110 AC_DEFUN([WGET_POSIX_CLOCK], [
111   AC_CHECK_FUNCS(clock_gettime, [], [
112     AC_CHECK_LIB(rt, clock_gettime)
113   ])
114 ])
115
116 dnl Check whether we need to link with -lnsl and -lsocket, as is the
117 dnl case on e.g. Solaris.
118
119 AC_DEFUN([WGET_NSL_SOCKET], [
120   dnl On Solaris, -lnsl is needed to use gethostbyname.  But checking
121   dnl for gethostbyname is not enough because on "NCR MP-RAS 3.0"
122   dnl gethostbyname is in libc, but -lnsl is still needed to use
123   dnl -lsocket, as well as for functions such as inet_ntoa.  We look
124   dnl for such known offenders and if one of them is not found, we
125   dnl check if -lnsl is needed.
126   wget_check_in_nsl=NONE
127   AC_CHECK_FUNCS(gethostbyname, [], [
128     wget_check_in_nsl=gethostbyname
129   ])
130   AC_CHECK_FUNCS(inet_ntoa, [], [
131     wget_check_in_nsl=inet_ntoa
132   ])
133   if test $wget_check_in_nsl != NONE; then
134     AC_CHECK_LIB(nsl, $wget_check_in_nsl)
135   fi
136   AC_CHECK_LIB(socket, socket)
137 ])
138
139
140 dnl ************************************************************
141 dnl START OF IPv6 AUTOCONFIGURATION SUPPORT MACROS
142 dnl ************************************************************
143
144 AC_DEFUN([TYPE_STRUCT_SOCKADDR_IN6],[
145   wget_have_sockaddr_in6=
146   AC_CHECK_TYPES([struct sockaddr_in6],[
147     wget_have_sockaddr_in6=yes
148   ],[
149     wget_have_sockaddr_in6=no
150   ],[
151 #include <sys/types.h>
152 #include <sys/socket.h>
153 #include <netinet/in.h>
154   ])
155
156   if test "X$wget_have_sockaddr_in6" = "Xyes"; then :
157     $1
158   else :
159     $2
160   fi
161 ])
162
163
164 AC_DEFUN([MEMBER_SIN6_SCOPE_ID],[
165   AC_REQUIRE([TYPE_STRUCT_SOCKADDR_IN6])
166   
167   wget_member_sin6_scope_id=
168   if test "X$wget_have_sockaddr_in6" = "Xyes"; then
169     AC_CHECK_MEMBER([struct sockaddr_in6.sin6_scope_id],[
170       wget_member_sin6_scope_id=yes
171     ],[
172       wget_member_sin6_scope_id=no
173     ],[
174 #include <sys/types.h>
175 #include <sys/socket.h>
176 #include <netinet/in.h>
177     ])
178   fi
179
180   if test "X$wget_member_sin6_scope_id" = "Xyes"; then
181     AC_DEFINE([HAVE_SOCKADDR_IN6_SCOPE_ID], 1,
182       [Define if struct sockaddr_in6 has the sin6_scope_id member])
183     $1
184   else :
185     $2
186   fi
187 ])
188
189
190 AC_DEFUN([PROTO_INET6],[
191   AC_CACHE_CHECK([for INET6 protocol support], [wget_cv_proto_inet6],[
192     AC_TRY_CPP([
193 #include <sys/types.h>
194 #include <sys/socket.h>
195
196 #ifndef PF_INET6
197 #error Missing PF_INET6
198 #endif
199 #ifndef AF_INET6
200 #error Mlssing AF_INET6
201 #endif
202     ],[
203       wget_cv_proto_inet6=yes
204     ],[
205       wget_cv_proto_inet6=no
206     ])
207   ])
208
209   if test "X$wget_cv_proto_inet6" = "Xyes"; then :
210     $1
211   else :
212     $2
213   fi
214 ])
215
216
217 AC_DEFUN([WGET_STRUCT_SOCKADDR_STORAGE],[
218   AC_CHECK_TYPES([struct sockaddr_storage],[], [], [
219 #include <sys/types.h>
220 #include <sys/socket.h>
221   ])
222 ])
223
224 dnl ************************************************************
225 dnl END OF IPv6 AUTOCONFIGURATION SUPPORT MACROS
226 dnl ************************************************************
227 \f
228 # This code originates from Ulrich Drepper's AM_WITH_NLS.
229
230 AC_DEFUN([WGET_WITH_NLS],
231   [AC_MSG_CHECKING([whether NLS is requested])
232     dnl Default is enabled NLS
233     AC_ARG_ENABLE(nls,
234       [  --disable-nls           do not use Native Language Support],
235       HAVE_NLS=$enableval, HAVE_NLS=yes)
236     AC_MSG_RESULT($HAVE_NLS)
237
238     dnl If something goes wrong, we may still decide not to use NLS.
239     dnl For this reason, defer AC_SUBST'ing HAVE_NLS until the very
240     dnl last moment.
241
242     if test x"$HAVE_NLS" = xyes; then
243       dnl If LINGUAS is specified, use only those languages.  In fact,
244       dnl compute an intersection of languages in LINGUAS and
245       dnl ALL_LINGUAS, and use that.
246       if test x"$LINGUAS" != x; then
247         new_linguas=
248         for lang1 in $ALL_LINGUAS; do
249           for lang2 in $LINGUAS; do
250             if test "$lang1" = "$lang2"; then
251               new_linguas="$new_linguas $lang1"
252             fi
253           done
254         done
255         ALL_LINGUAS=$new_linguas
256       fi
257       AC_MSG_NOTICE([language catalogs: $ALL_LINGUAS])
258       AM_PATH_PROG_WITH_TEST(MSGFMT, msgfmt,
259         [test -z "`$ac_dir/$ac_word -h 2>&1 | grep 'dv '`"], msgfmt)
260       AM_PATH_PROG_WITH_TEST(XGETTEXT, xgettext,
261           [test -z "`$ac_dir/$ac_word -h 2>&1 | grep '(HELP)'`"], :)
262       AC_SUBST(MSGFMT)
263       AC_PATH_PROG(GMSGFMT, gmsgfmt, $MSGFMT)
264       CATOBJEXT=.gmo
265       INSTOBJEXT=.mo
266       DATADIRNAME=share
267
268       dnl Test whether we really found GNU xgettext.
269       if test "$XGETTEXT" != ":"; then
270         dnl If it is no GNU xgettext we define it as : so that the
271         dnl Makefiles still can work.
272         if $XGETTEXT --omit-header /dev/null 2> /dev/null; then
273           : ;
274         else
275           AC_MSG_RESULT(
276             [found xgettext programs is not GNU xgettext; ignore it])
277           XGETTEXT=":"
278         fi
279       fi
280
281       AC_CHECK_HEADERS(libintl.h)
282
283       dnl Prefer gettext found in -lintl to the one in libc.
284       dnl Otherwise it can happen that we include libintl.h from
285       dnl /usr/local/lib, but fail to specify -lintl, which results in
286       dnl link or run-time failures.  (Symptom: libintl_bindtextdomain
287       dnl not found at link-time.)
288
289       AC_CHECK_LIB(intl, gettext, [
290         dnl gettext is in libintl; announce the fact manually.
291         LIBS="-lintl $LIBS"
292         AC_DEFINE([HAVE_GETTEXT], 1,
293                   [Define if you have the gettext function.])
294       ], [
295         AC_CHECK_FUNCS(gettext, [], [
296           AC_MSG_RESULT([gettext not found; disabling NLS])
297           HAVE_NLS=no
298         ])
299       ])
300
301       for lang in $ALL_LINGUAS; do
302         GMOFILES="$GMOFILES $lang.gmo"
303         POFILES="$POFILES $lang.po"
304       done
305       dnl Construct list of names of catalog files to be constructed.
306       for lang in $ALL_LINGUAS; do
307         CATALOGS="$CATALOGS ${lang}${CATOBJEXT}"
308       done
309
310       dnl Make all variables we use known to autoconf.
311       AC_SUBST(CATALOGS)
312       AC_SUBST(CATOBJEXT)
313       AC_SUBST(DATADIRNAME)
314       AC_SUBST(GMOFILES)
315       AC_SUBST(INSTOBJEXT)
316       AC_SUBST(INTLLIBS)
317       AC_SUBST(POFILES)
318     fi
319     AC_SUBST(HAVE_NLS)
320     dnl Some independently maintained files, such as po/Makefile.in,
321     dnl use `USE_NLS', so support it.
322     USE_NLS=$HAVE_NLS
323     AC_SUBST(USE_NLS)
324     if test "x$HAVE_NLS" = xyes; then
325       AC_DEFINE([HAVE_NLS], 1, [Define this if you want the NLS support.])
326     fi
327   ])
328
329 dnl Generate list of files to be processed by xgettext which will
330 dnl be included in po/Makefile.
331 dnl
332 dnl This is not strictly an Autoconf macro, because it is run from
333 dnl within `config.status' rather than from within configure.  This
334 dnl is why special rules must be applied for it.
335 AC_DEFUN(WGET_PROCESS_PO,
336   [
337    dnl I wonder what the following several lines do...
338    if test "x$srcdir" != "x."; then
339      if test "x`echo $srcdir | sed 's@/.*@@'`" = "x"; then
340        posrcprefix="$srcdir/"
341      else
342        posrcprefix="../$srcdir/"
343      fi
344    else
345      posrcprefix="../"
346    fi
347    rm -f po/POTFILES
348    dnl Use `echo' rather than AC_MSG_RESULT, because this is run from
349    dnl `config.status'.
350    echo "generating po/POTFILES from $srcdir/po/POTFILES.in"
351    sed -e "/^#/d" -e "/^\$/d" -e "s,.*, $posrcprefix& \\\\,"  \
352        -e "\$s/\(.*\) \\\\/\1/" \
353         < $srcdir/po/POTFILES.in > po/POTFILES
354    echo "creating po/Makefile"
355    sed -e "/POTFILES =/r po/POTFILES" po/Makefile.in > po/Makefile
356   ])
357
358 # Search path for a program which passes the given test.
359 # Ulrich Drepper <drepper@cygnus.com>, 1996.
360 #
361 # This file may be copied and used freely without restrictions.  It
362 # can be used in projects which are not available under the GNU Public
363 # License but which still want to provide support for the GNU gettext
364 # functionality.  Please note that the actual code is *not* freely
365 # available.
366
367 # serial 1
368
369 dnl AM_PATH_PROG_WITH_TEST(VARIABLE, PROG-TO-CHECK-FOR,
370 dnl   TEST-PERFORMED-ON-FOUND_PROGRAM [, VALUE-IF-NOT-FOUND [, PATH]])
371 AC_DEFUN(AM_PATH_PROG_WITH_TEST,
372 [# Extract the first word of "$2", so it can be a program name with args.
373 set dummy $2; ac_word=[$]2
374 AC_MSG_CHECKING([for $ac_word])
375 AC_CACHE_VAL(ac_cv_path_$1,
376 [case "[$]$1" in
377   /*)
378   ac_cv_path_$1="[$]$1" # Let the user override the test with a path.
379   ;;
380   *)
381   IFS="${IFS=   }"; ac_save_ifs="$IFS"; IFS="${IFS}:"
382   for ac_dir in ifelse([$5], , $PATH, [$5]); do
383     test -z "$ac_dir" && ac_dir=.
384     if test -f $ac_dir/$ac_word; then
385       if [$3]; then
386         ac_cv_path_$1="$ac_dir/$ac_word"
387         break
388       fi
389     fi
390   done
391   IFS="$ac_save_ifs"
392 dnl If no 4th arg is given, leave the cache variable unset,
393 dnl so AC_PATH_PROGS will keep looking.
394 ifelse([$4], , , [  test -z "[$]ac_cv_path_$1" && ac_cv_path_$1="$4"
395 ])dnl
396   ;;
397 esac])dnl
398 $1="$ac_cv_path_$1"
399 if test -n "[$]$1"; then
400   AC_MSG_RESULT([$]$1)
401 else
402   AC_MSG_RESULT(no)
403 fi
404 AC_SUBST($1)dnl
405 ])
406