Merge from vendor branch NTPD:
[dragonfly.git] / contrib / lukemftpd / aclocal.m4
1 dnl $Id: aclocal.m4,v 1.1 2000/07/29 13:34:15 lukem Exp $
2 dnl
3
4 dnl
5 dnl AC_MSG_TRY_COMPILE
6 dnl
7 dnl Written by Luke Mewburn <lukem@netbsd.org>
8 dnl
9 dnl Usage:
10 dnl     AC_MSG_TRY_COMPILE(Message, CacheVar, Includes, Code,
11 dnl                         ActionPass [,ActionFail] )
12 dnl
13 dnl effectively does:
14 dnl     AC_CACHE_CHECK(Message, CacheVar,
15 dnl             AC_TRY_COMPILE(Includes, Code, CacheVar = yes, CacheVar = no)
16 dnl             if CacheVar == yes
17 dnl                     AC_MESSAGE_RESULT(yes)
18 dnl                     ActionPass
19 dnl             else
20 dnl                     AC_MESSAGE_RESULT(no)
21 dnl                     ActionFail
22 dnl     )
23 dnl
24 AC_DEFUN(AC_MSG_TRY_COMPILE, [
25         AC_CACHE_CHECK($1, $2, [
26                 AC_TRY_COMPILE([ $3 ], [ $4; ], [ $2=yes ], [ $2=no ])
27         ])
28         if test "x[$]$2" = "xyes"; then
29                 $5
30         else
31                 $6
32                 :
33         fi
34 ])
35
36 dnl
37 dnl AC_MSG_TRY_LINK
38 dnl
39 dnl Usage:
40 dnl     AC_MSG_TRY_LINK(Message, CacheVar, Includes, Code,
41 dnl                         ActionPass [,ActionFail] )
42 dnl
43 dnl as AC_MSG_TRY_COMPILE, but uses AC_TRY_LINK instead of AC_TRY_COMPILE
44 dnl
45 AC_DEFUN(AC_MSG_TRY_LINK, [
46         AC_CACHE_CHECK($1, $2, [
47                 AC_TRY_LINK([ $3 ], [ $4; ], [ $2=yes ], [ $2=no ])
48         ])
49         if test "x[$]$2" = "xyes"; then
50                 $5
51         else
52                 $6
53                 :
54         fi
55 ])
56
57
58 dnl
59 dnl AC_LIBRARY_NET: #Id: net.m4,v 1.5 1997/11/09 21:36:54 jhawk Exp #
60 dnl
61 dnl Written by John Hawkinson <jhawk@mit.edu>. This code is in the Public
62 dnl Domain.
63 dnl
64 dnl This test is for network applications that need socket() and
65 dnl gethostbyname() -ish functions.  Under Solaris, those applications need to
66 dnl link with "-lsocket -lnsl".  Under IRIX, they should *not* link with
67 dnl "-lsocket" because libsocket.a breaks a number of things (for instance:
68 dnl gethostbyname() under IRIX 5.2, and snoop sockets under most versions of
69 dnl IRIX).
70 dnl 
71 dnl Unfortunately, many application developers are not aware of this, and
72 dnl mistakenly write tests that cause -lsocket to be used under IRIX.  It is
73 dnl also easy to write tests that cause -lnsl to be used under operating
74 dnl systems where neither are necessary (or useful), such as SunOS 4.1.4, which
75 dnl uses -lnsl for TLI.
76 dnl 
77 dnl This test exists so that every application developer does not test this in
78 dnl a different, and subtly broken fashion.
79 dnl 
80 dnl It has been argued that this test should be broken up into two seperate
81 dnl tests, one for the resolver libraries, and one for the libraries necessary
82 dnl for using Sockets API. Unfortunately, the two are carefully intertwined and
83 dnl allowing the autoconf user to use them independantly potentially results in
84 dnl unfortunate ordering dependancies -- as such, such component macros would
85 dnl have to carefully use indirection and be aware if the other components were
86 dnl executed. Since other autoconf macros do not go to this trouble, and almost
87 dnl no applications use sockets without the resolver, this complexity has not
88 dnl been implemented.
89 dnl
90 dnl The check for libresolv is in case you are attempting to link statically
91 dnl and happen to have a libresolv.a lying around (and no libnsl.a).
92 dnl
93 AC_DEFUN(AC_LIBRARY_NET, [
94    # Most operating systems have gethostbyname() in the default searched
95    # libraries (i.e. libc):
96    AC_CHECK_FUNC(gethostbyname, ,
97      # Some OSes (eg. Solaris) place it in libnsl:
98      AC_CHECK_LIB(nsl, gethostbyname, , 
99        # Some strange OSes (SINIX) have it in libsocket:
100        AC_CHECK_LIB(socket, gethostbyname, ,
101           # Unfortunately libsocket sometimes depends on libnsl.
102           # AC_CHECK_LIB's API is essentially broken so the following
103           # ugliness is necessary:
104           AC_CHECK_LIB(socket, gethostbyname,
105              LIBS="-lsocket -lnsl $LIBS",
106                AC_CHECK_LIB(resolv, gethostbyname),
107              -lnsl)
108        )
109      )
110    )
111   AC_CHECK_FUNC(socket, , AC_CHECK_LIB(socket, socket, ,
112     AC_CHECK_LIB(socket, socket, LIBS="-lsocket -lnsl $LIBS", , -lnsl)))
113   ])
114
115
116 dnl Checks for SOCKS firewall support.
117 dnl
118 dnl Written by Matthew R. Green <mrg@eterna.com.au>
119 dnl
120 AC_DEFUN(AC_LIBRARY_SOCKS, [
121     AC_MSG_CHECKING(whether to support SOCKS)
122     AC_ARG_WITH(socks,
123     [  --with-socks            Compile with SOCKS firewall traversal support.],
124     [
125         case "$withval" in
126         no)
127             AC_MSG_RESULT(no)
128             ;;
129         yes)
130             AC_MSG_RESULT(yes)
131             AC_CHECK_LIB(socks5, SOCKSconnect, [
132                 socks=5
133                 LIBS="-lsocks5 $LIBS"], [
134               AC_CHECK_LIB(socks, Rconnect, [
135                 socks=4
136                 LIBS="-lsocks $LIBS"], [
137                     AC_MSG_ERROR(Could not find socks library.  You must first install socks.) ] ) ] )
138             ;;
139         esac
140     ],
141         AC_MSG_RESULT(no)
142     )
143
144     if test "x$socks" = "x"; then
145         AC_MSG_CHECKING(whether to support SOCKS5)
146         AC_ARG_WITH(socks5,
147         [  --with-socks5[=PATH]    Compile with SOCKS5 firewall traversal support.],
148         [
149             case "$withval" in
150             no)
151                 AC_MSG_RESULT(no)
152                 ;;
153             *)
154                 AC_MSG_RESULT(yes)
155                 socks=5
156                 if test "x$withval" = "xyes"; then
157                     withval="-lsocks5"
158                 else
159                     if test -d "$withval"; then
160                         if test -d "$withval/include"; then
161                             CFLAGS="$CFLAGS -I$withval/include"
162                         else
163                             CFLAGS="$CFLAGS -I$withval"
164                         fi
165                         if test -d "$withval/lib"; then
166                             withval="-L$withval/lib -lsocks5"
167                         else
168                             withval="-L$withval -lsocks5"
169                         fi
170                     fi
171                 fi
172                 LIBS="$withval $LIBS"
173                 # If Socks was compiled with Kerberos support, we will need
174                 # to link against kerberos libraries.  Temporarily append
175                 # to LIBS.  This is harmless if there is no kerberos support.
176                 TMPLIBS="$LIBS"
177                 LIBS="$LIBS $KERBEROS_LIBS"
178                 AC_TRY_LINK([],
179                     [ SOCKSconnect(); ],
180                     [],
181                     [ AC_MSG_ERROR(Could not find the $withval library.  You must first install socks5.) ])
182                 LIBS="$TMPLIBS"
183                 ;;
184             esac
185         ],
186             AC_MSG_RESULT(no)
187         )
188     fi
189
190     if test "x$socks" = "x"; then
191         AC_MSG_CHECKING(whether to support SOCKS4)
192         AC_ARG_WITH(socks4,
193         [  --with-socks4[=PATH]    Compile with SOCKS4 firewall traversal support.],
194         [
195             case "$withval" in
196             no)
197                 AC_MSG_RESULT(no)
198                 ;;
199             *)
200                 AC_MSG_RESULT(yes)
201                 socks=4
202                 if test "x$withval" = "xyes"; then
203                     withval="-lsocks"
204                 else
205                     if test -d "$withval"; then
206                         withval="-L$withval -lsocks"
207                     fi
208                 fi
209                 LIBS="$withval $LIBS"
210                 AC_TRY_LINK([],
211                     [ Rconnect(); ],
212                     [],
213                     [ AC_MSG_ERROR(Could not find the $withval library.  You must first install socks.) ])
214                 ;;
215             esac
216         ],
217             AC_MSG_RESULT(no)
218         )
219     fi
220
221     if test "x$socks" = "x4"; then
222         AC_DEFINE(SOCKS)
223         AC_DEFINE(SOCKS4)
224         AC_DEFINE(connect, Rconnect)
225         AC_DEFINE(getsockname, Rgetsockname)
226         AC_DEFINE(bind, Rbind)
227         AC_DEFINE(accept, Raccept)
228         AC_DEFINE(listen, Rlisten)
229         AC_DEFINE(select, Rselect)
230     fi
231
232     if test "x$socks" = "x5"; then
233         AC_DEFINE(SOCKS)
234         AC_DEFINE(SOCKS5)
235         AC_DEFINE(connect,SOCKSconnect)
236         AC_DEFINE(getsockname,SOCKSgetsockname)
237         AC_DEFINE(getpeername,SOCKSgetpeername)
238         AC_DEFINE(bind,SOCKSbind)
239         AC_DEFINE(accept,SOCKSaccept)
240         AC_DEFINE(listen,SOCKSlisten)
241         AC_DEFINE(select,SOCKSselect)
242         AC_DEFINE(recvfrom,SOCKSrecvfrom)
243         AC_DEFINE(sendto,SOCKSsendto)
244         AC_DEFINE(recv,SOCKSrecv)
245         AC_DEFINE(send,SOCKSsend)
246         AC_DEFINE(read,SOCKSread)
247         AC_DEFINE(write,SOCKSwrite)
248         AC_DEFINE(rresvport,SOCKSrresvport)
249         AC_DEFINE(shutdown,SOCKSshutdown)
250         AC_DEFINE(listen,SOCKSlisten)
251         AC_DEFINE(close,SOCKSclose)
252         AC_DEFINE(dup,SOCKSdup)
253         AC_DEFINE(dup2,SOCKSdup2)
254         AC_DEFINE(fclose,SOCKSfclose)
255         AC_DEFINE(gethostbyname,SOCKSgethostbyname)
256     fi
257 ])