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