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