1#       $NetBSD: configure.ac,v 1.44 2021/08/27 02:29:39 lukem Exp $
2#
3# Process this file with autoconf to produce a configure script.
4
5AC_INIT([tnftp], [20210827], [lukem@NetBSD.org])
6AC_PREREQ([2.69])
7
8AC_COPYRIGHT([
9Copyright (c) 1999-2021 The NetBSD Foundation, Inc.
10All rights reserved.
11])
12AC_REVISION([$Revision: 1.44 $])
13
14AS_SHELL_SANITIZE()
15
16AC_CONFIG_SRCDIR([tnftp.h])
17AC_CONFIG_AUX_DIR([buildaux])
18AC_CONFIG_MACRO_DIR([buildaux])
19AC_CONFIG_HEADERS([tnftp_config.h])
20AC_CONFIG_LIBOBJ_DIR([libnetbsd])
21
22AC_USE_SYSTEM_EXTENSIONS()
23
24AM_INIT_AUTOMAKE([-Wall -Werror foreign nostdinc silent-rules])
25AM_MAINTAINER_MODE()
26
27#
28# Arguments for which features are included.
29#
30AC_ARG_ENABLE([editcomplete],
31              [AS_HELP_STRING([--enable-editcomplete],
32                              [turn on command line editing and completion
33                               (requires system or local libedit)
34                               [default=enabled]])],
35              [opt_editcomplete=$enableval],
36              [opt_editcomplete=yes])
37AC_ARG_ENABLE([ipv6],
38              [AS_HELP_STRING([--enable-ipv6],
39                              [enable IPv6 support (if your OS supports it)
40                               [default=enabled]])],
41              [opt_ipv6=$enableval],
42              [opt_ipv6=yes])
43AC_ARG_ENABLE([ssl],
44              [AS_HELP_STRING([--enable-ssl],
45                              [enable SSL support (requires --with-openssl)
46                               [default=auto]])],
47              [with_ssl=$enableval],
48              [with_ssl=auto])
49AC_ARG_WITH([local-libedit],
50            [AS_HELP_STRING([--with-local-libedit],
51                            [use local libedit instead of system library:
52                             yes; auto (try system, fallback to local); no
53                             [default=auto]])],
54            [],
55            [with_local_libedit=auto])
56AC_ARG_WITH([socks],
57            [AS_HELP_STRING([--with-socks],
58                            [enable support for (Dante) SOCKS5 proxy
59                             [default=auto]])],
60            [],
61            [with_socks=auto])
62
63#
64# Autoheader templates symbols.
65#
66AH_TEMPLATE([HAVE_POLL],
67            [Define if we have poll() and it is not emulated.])
68AH_TEMPLATE([HAVE_PRINTF_QD],
69            [Define if *printf() uses %qd to print 'long long'
70             (otherwise uses %lld).])
71AH_TEMPLATE([HAVE_PRINTF_LONG_LONG],
72            [Define if 'long long' is supported and
73             *printf() supports %lld or %qd to print them.])
74AH_TEMPLATE([HAVE_VA_COPY],
75            [Define to 1 if the 'va_copy' function is supported.])
76AH_TEMPLATE([HAVE___BUILTIN_VA_COPY],
77            [Define to 1 if the '__builtin_va_copy' function is supported.])
78AH_TEMPLATE([NO_EDITCOMPLETE],
79            [Define if disabling command-line editing and completion.])
80AH_TEMPLATE([USE_GLOB_H],
81            [Define if using system <glob.h> instead of local glob.])
82AH_TEMPLATE([USE_INET6],
83            [Define if using IPv6 support.])
84AH_TEMPLATE([USE_SOCKS],
85            [Define if using (Dante) SOCKS5 proxy.])
86AH_TEMPLATE([WITH_SSL],
87            [Define if enabling SSL support.])
88
89#
90# Checks for programs.
91#
92AC_PROG_CC()
93AC_PROG_AWK()
94AM_PROG_AR()
95AC_PROG_LIBTOOL()
96
97#
98# Checks for tool features.
99#
100AS_CASE([$target_os],
101        [darwin*],
102        [# Mac OS X linker needs -search_paths_first so our private libraries
103         # are used before system libraries.
104         #
105         old_LDFLAGS=$LDFLAGS
106         LDFLAGS="$LDFLAGS -Wl,-search_paths_first"
107         AC_MSG_CHECKING([if ld accepts -search_paths_first])
108         AC_LINK_IFELSE([AC_LANG_PROGRAM([], [[int i;]])],
109                        [AC_MSG_RESULT([yes])],
110                        [AC_MSG_RESULT([no])
111                         LDFLAGS=$old_LDFLAGS])],
112        )
113
114#
115# Checks for libraries.
116#
117
118# Check if libedit is required, and which implementation.
119#
120AS_IF([test "$opt_editcomplete" = yes],
121      [AC_MSG_NOTICE([--enable-editcomplete; checking for required features])
122       AC_SEARCH_LIBS([tgetent],
123                      [termcap termlib curses ncurses tinfo],
124                      [],
125                      [AC_MSG_ERROR([no relevant library found containing tgetent])])
126       AS_IF([test "$with_local_libedit" != yes],
127             [AC_CHECK_LIB([edit],
128                           [el_init],
129                           [AC_MSG_NOTICE([using system libedit])
130                            with_local_libedit=no],
131                           [AS_IF([test "$with_local_libedit" = no],
132                                  [AC_MSG_ERROR([--without-local-libedit was given, but system libedit was not found])])
133                            AC_MSG_NOTICE([using local libedit])
134                            with_local_libedit=yes])],
135             [AC_MSG_NOTICE([using local libedit])])],
136      [AC_MSG_NOTICE([--disable-editcomplete; disabling --with-local-libedit])
137       AC_DEFINE([NO_EDITCOMPLETE], [1])
138       with_local_libedit=no])
139
140# Check for ns and socket libraries.
141#
142AC_SEARCH_LIBS([gethostbyname], [nsl])
143AC_SEARCH_LIBS([socket],
144               [socket],
145               [],
146               [AC_CHECK_LIB([socket],
147                             [socket],
148                             [LIBS="-lsocket -lnsl $LIBS"],
149                             [],
150                             [-lnsl])])
151
152# Check for (Dante) SOCKS5.
153#
154AS_IF([test "$with_socks" != no],
155      [AC_MSG_NOTICE([--with-socks=$with_socks; checking for required SOCKS5 features])
156       AC_SEARCH_LIBS([SOCKSinit],
157                      [socksd socks],
158                      [AC_DEFINE([USE_SOCKS], [1])
159                       AC_MSG_NOTICE([enabling SOCKS5 support])
160                       with_socks=yes
161                       AS_IF([test "$opt_ipv6" = yes],
162                             [AC_MSG_WARN(
163                [IPv6 is incompatible with socks, disabling IPv6 support])
164                              opt_ipv6=no])],
165                      [AS_IF([test "$with_socks" != auto],
166                             [AC_MSG_ERROR(
167                [--with-socks was given, but SOCKSinit() was not found])])
168                       AC_MSG_NOTICE([disabling --with-socks])
169                       with_socks=no])])
170
171# Check for OpenSSL.
172#
173AX_CHECK_OPENSSL([have_ssl=yes])
174
175AS_IF([test "$with_ssl" != no],
176      [AC_MSG_NOTICE([--with-ssl=$with_ssl; checking for required OpenSSL features])
177       AS_IF([test "$have_ssl" = yes],
178             [AC_DEFINE([WITH_SSL], [1])
179              AC_MSG_NOTICE([enabling SSL support])
180              with_ssl=yes],
181             [AS_IF([test "$with_ssl" != auto],
182                    [AC_MSG_ERROR([--with-ssl was given, but OpenSSL was not found])])
183              AC_MSG_NOTICE([disabling --with-ssl])
184              with_ssl=no])])
185
186#
187# Checks for header files.
188#
189accheck_includes='
190#include <stdio.h>
191#if defined(HAVE_SYS_TYPES_H)
192# include <sys/types.h>
193#endif
194#if defined(HAVE_SYS_STAT_H)
195# include <sys/stat.h>
196#endif
197#if defined(STDC_HEADERS)
198# include <stdarg.h>
199# include <stdlib.h>
200# include <string.h>
201#endif
202#if defined(TIME_WITH_SYS_TIME)
203# include <sys/time.h>
204# include <time.h>
205#else
206# if defined(HAVE_SYS_TIME_H)
207#  include <sys/time.h>
208# else
209#  include <time.h>
210# endif
211#endif
212#if defined(HAVE_LIBGEN_H)
213# include <libgen.h>
214#endif
215#if defined(HAVE_PWD_H)
216# include <pwd.h>
217#endif
218#if defined(HAVE_UNISTD_H)
219# include <unistd.h>
220#endif
221#if defined(HAVE_POLL_H)
222# include <poll.h>
223#elif defined(HAVE_SYS_POLL_H)
224# include <sys/poll.h>
225#endif
226#if defined(HAVE_SYS_SOCKET_H)
227# include <sys/socket.h>
228#endif
229#if defined(HAVE_NETINET_IN_H)
230# include <netinet/in.h>
231#endif
232#if defined(HAVE_NETINET_IN_SYSTM_H)
233# include <netinet/in_systm.h>
234#endif
235#if defined(HAVE_NETINET_IP_H)
236# include <netinet/ip.h>
237#endif
238#if defined(HAVE_NETINET_TCP_H)
239# include <netinet/tcp.h>
240#endif
241#if defined(HAVE_NETDB_H)
242# include <netdb.h>
243#endif
244#if defined(HAVE_ARPA_INET_H)
245# include <arpa/inet.h>
246#endif
247#if defined(HAVE_DIRENT_H)
248# include <dirent.h>
249#else
250# define dirent direct
251# if defined(HAVE_SYS_NDIR_H)
252#  include <sys/ndir.h>
253# endif
254# if defined(HAVE_SYS_DIR_H)
255#  include <sys/dir.h>
256# endif
257# if defined(HAVE_NDIR_H)
258#  include <ndir.h>
259# endif
260#endif
261' # accheck_includes
262
263AC_CHECK_HEADERS([sys/types.h sys/ioctl.h sys/param.h sys/stat.h \
264                  sys/socket.h sys/syslimits.h sys/time.h sys/uio.h \
265                  sys/wait.h],
266                 [], [], [$accheck_includes])
267AC_HEADER_DIRENT()
268AC_HEADER_RESOLV()
269AC_HEADER_STAT()
270AC_HEADER_STDC()
271AC_HEADER_TIME()
272AC_HEADER_TIOCGWINSZ()
273AC_CHECK_HEADERS([arpa/ftp.h arpa/inet.h arpa/nameser.h err.h \
274                  fcntl.h libgen.h limits.h locale.h malloc.h \
275                  netinet/in.h netinet/in_systm.h netinet/ip.h \
276                  netinet/tcp.h \
277                  paths.h poll.h pwd.h sys/poll.h regex.h \
278                  setjmp.h signal.h stddef.h termcap.h termios.h \
279                  unistd.h utime.h vis.h],
280                  [], [], [$accheck_includes])
281
282#
283# Checks for typedefs, structures, and compiler characteristics.
284#
285AC_CHECK_DECLS([AI_NUMERICHOST, dirname, fclose, getpass, h_errno, pclose,
286                optarg, optind],
287               [], [], [$accheck_includes])
288AC_TYPE_LONG_DOUBLE()
289AC_TYPE_LONG_LONG_INT()
290AC_TYPE_UINT32_T()
291AC_TYPE_OFF_T()
292AC_TYPE_PID_T()
293AC_TYPE_SIZE_T()
294AC_STRUCT_TM()
295AC_CHECK_MEMBERS([struct sockaddr.sa_len, struct sockaddr_in.sin_len,
296                  struct dirent.d_namlen],
297                 [], [], [$accheck_includes])
298AC_CHECK_TYPES([in_port_t, sa_family_t, socklen_t, struct addrinfo],
299               [], [], [$accheck_includes])
300AC_SYS_LARGEFILE()
301
302# If IPv6 is enabled, check for necessary items.
303#
304AS_IF([test "$opt_ipv6" = yes],
305      [AC_MSG_NOTICE([--enable-ipv6; checking for required IPv6 features])
306       AC_CHECK_DECLS([AF_INET6, NS_IN6ADDRSZ], [], [],
307[$accheck_includes
308#if defined(HAVE_ARPA_NAMESER_H)
309#include <arpa/nameser.h>
310#endif
311])
312       AC_CHECK_TYPES([struct sockaddr_in6], [], [opt_ipv6=no],
313                      [$accheck_includes])
314       AS_IF([test "$opt_ipv6" = yes],
315             [AC_MSG_NOTICE([enabling IPv6 support])
316              AC_DEFINE([USE_INET6], [1])],
317             [AC_MSG_NOTICE([disabling IPv6 support])])
318       ])
319
320#
321# Checks for library functions.
322#
323AC_FUNC_CLOSEDIR_VOID()
324AC_FUNC_FORK()
325AC_FUNC_FSEEKO()
326AC_FUNC_STRCOLL()
327AC_REPLACE_FUNCS([dirname err fgetln getaddrinfo getnameinfo \
328                  inet_ntop inet_pton mkstemp setprogname sl_init snprintf \
329                  strdup strerror strlcat strlcpy strptime strsep strunvis \
330                  strvis timegm usleep utimes vasprintf])
331AC_CHECK_FUNCS([getcwd gethostbyaddr gethostbyname gethostbyname2 gethostname \
332                getpass getpassphrase getpgrp gettimeofday isascii \
333                memchr memmove memset realpath regcomp \
334                select setlocale socket strcasecmp strchr strcspn strdup \
335                strerror strncasecmp strpbrk strrchr strstr strtol strtoul \
336                utime])
337AS_IF([test "$ac_cv_func_getpgrp" = yes], [AC_FUNC_GETPGRP])
338AS_IF([test "$ac_cv_func_strptime" = yes], [AC_CHECK_DECLS([strptime])])
339
340# Use system glob if GLOB_BRACE and GLOB_TILDE are available.
341#
342use_local_glob=yes
343AC_CHECK_HEADER([glob.h],
344                [AC_MSG_CHECKING([glob supports required flags])
345                 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
346#include <glob.h>]], [[
347int f = GLOB_BRACE|GLOB_NOCHECK|GLOB_TILDE;
348]])],
349                         [AC_MSG_RESULT([yes])
350			  use_local_glob=no],
351                         [AC_MSG_RESULT([no - using local version])],
352                         [AC_MSG_RESULT([unknown - cross-compiling])])])
353AS_IF([test "$use_local_glob" = yes],
354      [AC_LIBOBJ([glob])],
355      [AC_DEFINE([USE_GLOB_H], [1])])
356
357# We assume that if sprintf() supports %lld or %qd,
358# then all of *printf() does. If not, disable long long
359# support because we don't know how to display it.
360#
361AS_IF([test "$ac_cv_type_long_long_int" = yes],
362      [AC_MSG_CHECKING([*printf() support for %lld])
363       can_printf_longlong=no
364       AC_RUN_IFELSE([AC_LANG_PROGRAM([[
365$accheck_includes
366]], [[
367char buf[100];
368sprintf(buf, "%lld", 4294967300LL);
369exit(0 != strcmp(buf, "4294967300"));
370]])],
371                     [AC_MSG_RESULT([yes])
372                      can_printf_longlong=yes],
373                     [AC_MSG_RESULT([no])],
374                     [AC_MSG_RESULT([unknown - cross-compiling])])
375        AS_IF([test "$can_printf_longlong" != yes],
376              [AC_MSG_CHECKING([*printf() support for %qd])
377               AC_RUN_IFELSE([AC_LANG_PROGRAM([[
378$accheck_includes
379]], [[
380char buf[100];
381sprintf(buf, "%qd", 4294967300LL);
382exit(0 != strcmp(buf, "4294967300"));
383]])],
384                             [AC_MSG_RESULT([yes])
385                              can_printf_longlong=yes
386                              AC_DEFINE([HAVE_PRINTF_QD], [1])],
387                             [AC_MSG_RESULT([no])],
388                             [AC_MSG_RESULT([unknown - cross-compiling])])])
389        AC_MSG_CHECKING([if *printf() can print long long ints])
390        AS_IF([test "$can_printf_longlong" = yes],
391              [AC_MSG_RESULT([yes])
392               AC_DEFINE([HAVE_PRINTF_LONG_LONG], [1])
393               AC_REPLACE_FUNCS([strtoll])],
394              [AC_MSG_RESULT([no])])])
395
396# Handle Darwin 7 having a poll() compatibility function,
397# and don't use it if it's emulated.
398# Be conservative, if we don't find one of poll.h or sys/poll.h,
399# don't attempt to use poll().
400#
401AC_CHECK_TYPES([struct pollfd], [], [], [$accheck_includes])
402AC_CHECK_FUNC([poll],
403              [AC_CHECK_DECL([_POLL_EMUL_H_],
404                             [],
405                             [AC_DEFINE([HAVE_POLL], [1])],
406                             [$accheck_includes])])
407
408AC_MSG_CHECKING([for va_copy])
409AC_RUN_IFELSE([AC_LANG_PROGRAM([[
410$accheck_includes
411]], [[
412va_list ap, ap2;
413va_copy(ap2, ap);
414return 0;
415]])],
416              [AC_MSG_RESULT([yes])
417               AC_DEFINE([HAVE_VA_COPY], [1])],
418              [AC_MSG_RESULT([no])],
419              [AC_MSG_RESULT([unknown - cross-compiling])])
420
421AC_MSG_CHECKING([for __builtin_va_copy])
422AC_RUN_IFELSE([AC_LANG_PROGRAM([[
423$accheck_includes
424]], [[
425va_list ap, ap2;
426__builtin_va_copy(ap2, ap);
427return 0;
428]])],
429              [AC_MSG_RESULT([yes])
430               AC_DEFINE([HAVE___BUILTIN_VA_COPY], [1])],
431              [AC_MSG_RESULT([no])],
432              [AC_MSG_RESULT([unknown - cross-compiling])])
433
434AS_IF([test "$ac_cv_func_strptime" = yes],
435      [AC_MSG_CHECKING([if strptime() needs separators between conversions])
436       AC_RUN_IFELSE([AC_LANG_PROGRAM([[
437$accheck_includes
438]], [[
439struct tm timebuf;
440char * res;
441memset(&timebuf, 0, sizeof(timebuf));
442res = strptime("20011122161900", "%Y%m%d%H%M%S", &timebuf);
443exit(!res);
444]])],
445                     [AC_MSG_RESULT([no])],
446                     [AC_MSG_RESULT([yes - using local version])
447                      AC_LIBOBJ([strptime])],
448                     [AC_MSG_RESULT([unknown - cross-compiling])])])
449
450# Replace sl_init() (et al) if it provides the older API.
451#
452AS_IF([test "$ac_cv_func_sl_init" = yes],
453      [AC_MSG_CHECKING([if sl_add() returns int])
454       AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <stringlist.h>]],
455                                          [[int f = sl_add((StringList *)0,
456                                                           "foo");]])],
457                         [AC_MSG_RESULT([yes])],
458                         [AC_MSG_RESULT([no - using local version])
459                          AC_LIBOBJ([sl_init])],
460                         [AC_MSG_RESULT([unknown - cross-compiling])])])
461
462# Replace getaddrinfo() if missing or AI_NUMERICHOST isn't declared.
463#
464AC_MSG_CHECKING([for working getaddrinfo()])
465AS_IF([test "$ac_cv_have_decl_AI_NUMERICHOST" = yes],
466      [AC_MSG_RESULT([yes])],
467      [AS_IF([test "$ac_cv_func_getaddrinfo" = yes],
468             [AC_LIBOBJ([getaddrinfo])
469              AC_MSG_RESULT([no - using local version])],
470             [AC_MSG_RESULT([using local version])])])
471
472# Check for VIS_WHITE in <vis.h>
473#
474AS_IF([test "$ac_cv_header_vis_h" = yes],
475      [AC_CHECK_DECL([VIS_WHITE], [], [], [
476#include <vis.h>
477])])
478
479AM_CONDITIONAL([WITH_SSL], [test "$with_ssl" = yes])
480AM_CONDITIONAL([OPT_EDITCOMPLETE], [test "$opt_editcomplete" = yes])
481AM_CONDITIONAL([WITH_LOCAL_LIBEDIT], [test "$with_local_libedit" = yes])
482
483#
484# Create the Makefiles.
485#
486AC_CONFIG_FILES([
487        Makefile
488        libedit/Makefile
489        libnetbsd/Makefile
490        src/Makefile
491])
492
493AC_OUTPUT()
494
495# Display feature results.
496#
497AC_MSG_NOTICE([ === Configuration results ===])
498AC_MSG_NOTICE([Package:               $PACKAGE_STRING])
499AC_MSG_NOTICE([Prefix:                $prefix])
500AC_MSG_NOTICE([--enable-editcomplete  $opt_editcomplete])
501AC_MSG_NOTICE([--enable-ipv6          $opt_ipv6])
502AC_MSG_NOTICE([--enable-ssl           $with_ssl])
503AC_MSG_NOTICE([--with-local-libedit   $with_local_libedit])
504AC_MSG_NOTICE([--with-socks           $with_socks])
505AC_MSG_NOTICE([ =============================])
506