configure.ac 20 KB
Newer Older
1
dnl -*- mode: shell-script; sh-indentation: 2; -*-
2
dnl $Id$
3

Niels Möller's avatar
Niels Möller committed
4
dnl Process this file with autoconf to produce a configure script.
Niels Möller's avatar
Niels Möller committed
5
AC_INIT([lsh], [1.4], [bug-lsh@gnu.org]) 
Niels Möller's avatar
Niels Möller committed
6
AC_PREREQ(2.52)
7
AC_CONFIG_SRCDIR([src/lsh_types.h])
8
AM_INIT_AUTOMAKE
9
AM_CONFIG_HEADER([config.h])
Niels Möller's avatar
Niels Möller committed
10

11 12
# AH_TEMPLATE([PACKAGE], [The name of this software distribution])
# AH_TEMPLATE([VERSION], [The version of this software distribution])
Niels Möller's avatar
Niels Möller committed
13

14
# FIXME: Move this to the Makefile, as recommended by the autoconf manual.
15 16

AH_TEMPLATE([PREFIX], [The installation prefix])
17
AC_DEFINE_UNQUOTED(PREFIX, "`echo $prefix | sed "s@^NONE@$ac_default_prefix@"`")
18

19
AH_TEMPLATE([SBINDIR], [sbin directory])
20
# NOTE: The definition below is broken.
21
AC_DEFINE_UNQUOTED(SBINDIR, "`echo $sbindir | sed "s@^NONE@$prefix/sbin@" | sed "s@^NONE@$ac_default_prefix@"`")
22

23 24 25 26 27 28 29 30 31 32 33 34
# We want an absolute path to the source-dir.
case "$srcdir" in
    /*)
    ;;
    *)
	oldsrcdir="$srcdir"
	srcdir="`cd \"$srcdir\";pwd`"
	AC_MSG_WARN([ Converted $oldsrcdir to $srcdir,
If this does not work, please use an absolute path to the configure script. ])
    ;;
esac

35
# src/rsync relies on lsh's definitions of WRITE_UINT32 etc.
36
CPPFLAGS="$CPPFLAGS -I$srcdir/src -DLSH"
37

38 39 40 41
# GNU libc defaults to supplying the ISO C library functions only. 
# initgroups() and strsignal() are extensions; the _GNU_SOURCE define
# enables these extensions.
# Enable it on all systems; no problems have been reported with it so far.
Niels Möller's avatar
Niels Möller committed
42

43 44
# We can't use AH_VERBATIM for this, as we want _GNU_SOURCE to be defined
# when running configure's test programs.
Niels Möller's avatar
Niels Möller committed
45 46
CPPFLAGS="$CPPFLAGS -D_GNU_SOURCE"

47
# Check options
48
AC_ARG_ENABLE(debug_alloc,
49
  AC_HELP_STRING([--enable-debug-alloc], [Enable memory allocation sanity checks]),,
50
  [enable_debug_alloc=no])
51 52 53

AH_TEMPLATE([DEBUG_ALLOC],
	    [Define to enable sanity checking on memory allocation and casting])
54
if test x$enable_debug_alloc = xyes ; then
55 56 57
  AC_DEFINE(DEBUG_ALLOC)
fi

58
AC_ARG_ENABLE(debug_trace,
59
  AC_HELP_STRING([--enable-debug-trace], [Enable tracing support]),,
60
  [enable_debug_trace=no])
61

62
AH_TEMPLATE([DEBUG_TRACE], [Define to enable tracing])
63
if test x$enable_debug_trace = xyes ; then
64 65 66
  AC_DEFINE(DEBUG_TRACE)
fi

Niels Möller's avatar
Niels Möller committed
67
AC_ARG_ENABLE(gcov,
68
  AC_HELP_STRING([--enable-gcov], [Instrument for gcov (requires a modern gcc)]),,
Niels Möller's avatar
Niels Möller committed
69 70
  [enable_gcov=no])

71
AC_ARG_WITH(zlib,
72
  AC_HELP_STRING([--without-zlib], [Don't use zlib compression]),,
73
  [with_zlib=yes])
74

75 76
# Checking this variable is delayed until we have checked if zlib is
# actually available.
77

78
AC_ARG_ENABLE(pty,
79
  AC_HELP_STRING([--without-pty], [Disable pty support]),,
80
  [enable_pty=yes])
81

82
AH_TEMPLATE([WITH_PTY_SUPPORT], [Define to enable pty support])
83
if test x$enable_pty = xyes ; then
84 85 86
  AC_DEFINE(WITH_PTY_SUPPORT)
fi

87
AC_ARG_WITH(sshd1,
88
  AC_HELP_STRING([[--with-sshd1[=PROGRAM]]], [support fallback to SSH1 daemon]),,
89
  [with_sshd1=yes])
90

91 92 93 94 95
# Default sshd1 path
if test x$with_sshd1 = xyes ; then
  with_sshd1=/usr/local/sbin/sshd1
fi

96 97
AH_TEMPLATE([SSHD1], [Location of the SSH1 daemon])
AH_TEMPLATE([WITH_SSH1_FALLBACK], [Define to enable fallback to SSH1])
98 99 100 101
if test x$with_sshd1 != xno ; then
  AC_DEFINE(WITH_SSH1_FALLBACK)
  AC_DEFINE_UNQUOTED(SSHD1,"$with_sshd1")
fi
102

103
AC_ARG_ENABLE(srp,
104
  AC_HELP_STRING([--disable-srp], [Disable the (experimental) support for SRP]),,
105 106
  [enable_srp=yes])

107
AC_ARG_ENABLE(kerberos,
108
  AC_HELP_STRING([--disable-kerberos], [Don't support kerberos]),,
109
  [enable_kerberos=yes])
110

111 112 113 114
AC_ARG_ENABLE(pam,
  AC_HELP_STRING([--disable-pam], [Don't support PAM]),,
  [enable_pam=yes])

115
AH_TEMPLATE([WITH_SRP], [Define if SRP should be supported])
116 117
if test x$enable_srp = xyes ; then
  AC_DEFINE(WITH_SRP)
118
  SRP_PROGRAM=srp-gen
119 120
fi

121 122
AC_SUBST(SRP_PROGRAM)

123
AC_ARG_ENABLE(datafellows_workarounds,
124 125
  AC_HELP_STRING([--disable-datafellows-workarounds],
		 [Disable bug-compatibility with SSH Inc's clients and servers]),,
126
  [enable_datafellows_workarounds=yes])
127

128 129
AH_TEMPLATE([DATAFELLOWS_WORKAROUNDS],
	    [Define to support non-standard packets of ssh2])
130
if test x$enable_datafellows_workarounds = xyes ; then
131
  AC_DEFINE(DATAFELLOWS_WORKAROUNDS)
132 133
fi

134
AC_ARG_ENABLE(tcp_forward,
135
  AC_HELP_STRING([--disable-tcp-forward], [Disable tcp forwarding]),,
136
  [enable_tcp_forward=yes])
137

138
AH_TEMPLATE([WITH_TCP_FORWARD], [Define to enable tcp forwarding])
139
if test x$enable_tcp_forward = xyes ; then
140 141
  AC_DEFINE(WITH_TCP_FORWARD)
fi
142

143
AC_ARG_ENABLE(x11_forward,
144
  AC_HELP_STRING([--disable-x11-forward], [Disable x11 forwarding (proxy only)]),,
145
  [eanble_x11_forward=yes])
146

147
AH_TEMPLATE([WITH_X11_FORWARD], [Define to enable x11 forwarding])
148
if test x$enable_x11_forward = xyes ; then
149 150 151
  AC_DEFINE(WITH_X11_FORWARD)
fi

152
AC_ARG_ENABLE(agent_forward,
153
  AC_HELP_STRING([--disable-agent-forward], [Disable auth-agent forwarding (proxy only)]),,
154 155
  [with_agent_forward=yes])

156 157
AH_TEMPLATE([WITH_AGENT_FORWARD],
	    [Define to enable authentication agent forwarding])
158
if test x$disable_agent_forward = xyes ; then
159 160 161
  AC_DEFINE(WITH_AGENT_FORWARD)
fi

162
AC_ARG_WITH(scheme,
163
  AC_HELP_STRING([[--with-scheme[=PROGRAM]]], [Use a particular scheme implementation]),,
164
  [with_scheme=])
165 166

AC_ARG_WITH(system-argp,
167
  AC_HELP_STRING([--without-system-argp], [Don't use the system's argp]),,
168
  [with_system_argp=yes])
169

170
# IPv6 support
171
AC_ARG_ENABLE(ipv6,
172
  AC_HELP_STRING([--disable-ipv6], [Disable IPv6 support]),,
173 174
  [enable_ipv6=yes])

175
# utmp/wtmp logging 
176
AC_ARG_ENABLE(utmp,
177
  AC_HELP_STRING([--disable-utmp], [Disable utmp and wtmp support]),,
178 179
  [enable_utmp=yes])

180
AH_TEMPLATE([WITH_UTMP], [For utmp support])
181 182 183 184
if test x$enable_utmp = xyes ; then
  AC_DEFINE(WITH_UTMP)
fi

185
AC_ARG_WITH(include-path,
186
  AC_HELP_STRING([--with-include-path], [A colon-separated list of directories to search for include files]),,
187 188 189 190 191 192
  [with_include_path=''])

if test x$with_include_path != x ; then
  CPPFLAGS="$CPPFLAGS -I `echo $with_include_path | sed 's/:/ -I /g'`"
fi

193
AC_ARG_WITH(lib-path,
194
  AC_HELP_STRING([--with-lib-path], [A colon-separated list of directories to search for libraries]),,
195 196 197
  [with_lib_path=''])

if test x$with_lib_path != x ; then
198
  LDFLAGS="-L `echo $with_lib_path | sed 's/:/ -L /g'`"
199 200 201 202 203 204 205 206 207
fi

LSH_RPATH_INIT([`echo $with_lib_path | sed 's/:/ /g'` \
    `echo $exec_prefix | sed "s@^NONE@$prefix/lib@g" | sed "s@^NONE@$ac_default_prefix/lib@g"` \
    /usr/local/lib /sw/local/lib /sw/lib \
    /usr/gnu/lib /opt/gnu/lib /sw/gnu/lib /usr/freeware/lib /usr/pkg/lib])

dnl echo RPATH_CANDIDATE_DIRS = $RPATH_CANDIDATE_DIRS

208
# Checks for programs.
Niels Möller's avatar
Niels Möller committed
209 210
AC_PROG_CC
AC_PROG_MAKE_SET
Niels Möller's avatar
Niels Möller committed
211
AC_PROG_RANLIB
212
AM_PROG_CC_STDC
Niels Möller's avatar
Niels Möller committed
213

214
if test "x$am_cv_prog_cc_stdc" = xno ; then
215
  AC_MSG_ERROR([the C compiler doesn't handle ANSI-C])
216 217
fi

218 219
# Use a particular scheme implementation?
if test x$with_scheme != x ; then
220 221 222 223 224 225 226 227 228
  # If an absolute path is given, don't AC_PATH_PROG but just use it
  if grep "^/" > /dev/null <<EOF
$with_scheme 
EOF  
  then
    SCHEME_PROGRAM="$with_scheme" 
  else
    AC_PATH_PROG(SCHEME_PROGRAM, $with_scheme,, $PATH)
  fi
229
else  
230
  AC_PATH_PROGS(SCHEME_PROGRAM, guile scsh,, $PATH)
231
fi
232 233

if test x$SCHEME_PROGRAM = x ; then
234 235
  AC_MSG_WARN([No scheme implementation found.
This is fine as long as you don't modify the source files.])
236 237 238
  SCHEME_PROGRAM=false
fi

239 240 241
SCHEME_NAME=`basename $SCHEME_PROGRAM`
AC_SUBST(SCHEME_NAME)

242 243 244 245 246 247
# BASH gets set to the bogus value "/bin/sh" if /bin/sh is a bash.
# So unset it in that case.
if test "x$BASH" = x/bin/sh ; then
  unset BASH
fi
    
248 249
AC_PATH_PROG(BASH, bash,, $PATH)
AC_PATH_PROG(GROFF, groff,, $PATH)
250 251
AC_PATH_PROG(M4, m4, m4)

252
# Checks for header files.
Niels Möller's avatar
Niels Möller committed
253
AC_HEADER_STDC
254

255 256 257
# We don't look in gmp2 anymore, as we need gmp-3.1 or better.
AC_CHECK_HEADERS(gmp.h,,
  AC_MSG_ERROR([gmp.h not found]))
258
  
259
AC_CHECK_HEADERS(fcntl.h strings.h sys/time.h unistd.h)
260
AC_CHECK_HEADERS(shadow.h)
261

262 263 264
if test x$with_zlib = xyes; then
  AC_CHECK_HEADERS(zlib.h,, [with_zlib=no])
fi
265
AC_CHECK_HEADERS(poll.h sys/poll.h)
266
AC_CHECK_HEADERS(libutil.h)
267
AC_CHECK_HEADERS(crypt.h)
268 269
AC_CHECK_HEADERS(pty.h)
AC_CHECK_HEADERS(stropts.h)
270
AC_CHECK_HEADERS(syslog.h)
271
AC_CHECK_HEADERS(argp.h)
272

273
AC_CHECK_HEADERS(utmp.h, [have_utmp_h=yes], [have_utmp_h=no])
274
AC_CHECK_HEADERS(utmpx.h, [have_utmpx_h=yes], [have_utmpx_h=no])
275

276 277 278 279
dnl With current autoconfs we can't check for struct ut_tv with
dnl AC_CHECK_MEMBERS, but we can check for sub members. Leave the
dnl ut_tv check for clarity.

280
if test x$have_utmp_h = xyes; then
281 282 283
  AC_CHECK_MEMBERS([struct utmp.ut_host,
		    struct utmp.ut_name,
		    struct utmp.ut_user,
284 285
		    struct utmp.ut_time,
		    struct utmp.ut_tv,
286
		    struct utmp.ut_tv.tv_sec,
287 288 289
		    struct utmp.ut_id,
		    struct utmp.ut_syslen,
		    struct utmp.ut_session,
290 291
		    struct utmp.ut_pid,
		    struct utmp.ut_exit,
292 293 294 295 296
		    struct utmp.ut_addr,
		    struct utmp.ut_addr_v6],,,
[# if HAVE_UTMP_H
#  include <utmp.h>
# endif
297 298
])
fi
299

300 301 302 303 304 305 306
if test x$have_utmpx_h = xyes; then
  AC_CHECK_MEMBERS([struct utmpx.ut_host,
		    struct utmpx.ut_name,
		    struct utmpx.ut_user,
		    struct utmpx.ut_time,
		    struct utmpx.ut_id,
		    struct utmpx.ut_tv,
307
		    struct utmpx.ut_tv.tv_sec,
308 309 310 311 312 313 314
		    struct utmpx.ut_syslen,
		    struct utmpx.ut_session,
		    struct utmpx.ut_pid,
		    struct utmpx.ut_exit,
		    struct utmpx.ut_addr,
		    struct utmpx.ut_addr_v6],,,
[# if HAVE_UTMPX_H
315 316 317
#  include <utmpx.h>
# endif
])
318
fi
319

320

321

322 323 324 325
if test x$enable_kerberos = xyes; then
  AC_CHECK_HEADERS(krb5.h,, [enable_kerberos=no])
fi

326 327 328 329
if test x$enable_pam = xyes; then
  AC_CHECK_HEADERS(security/pam_appl.h,, [enable_pam=no])
fi

330 331
# Some systems (in particular, Unixware) doesn't have socklen_t, but
# uses size_t. Falling back to int will cause some warnings.
332

333 334
# AC_CHECK_TYPE doesn't work, probably because the type in
# question is not defined in sys/types.h.
335

336
AC_TYPE_SOCKLEN_T
337

338 339 340 341 342 343 344
AC_CHECK_LIB(gmp, __gmpz_getlimbn,,
    [AC_MSG_ERROR(
    [GNU MP not found, or not 3.1 or up, see http://www.swox.com/gmp.])])

# AC_SEARCH_LIBGMP(gmp gmp2,
#   [LSH_RPATH_FIX],
#   [AC_MSG_ERROR([GMP is missing. Get gmp-2.0.2 or better from ftp://ftp.gnu.org/pub/gnu/gmp]) ])
345

Niels Möller's avatar
Niels Möller committed
346 347 348 349 350
AC_CHECK_LIB([oop], [oop_sys_new],,
  [AC_MSG_ERROR([liboop is missing. Get liboop from http://www.liboop.org])])

LSH_RPATH_FIX

351 352 353 354
if test x$with_zlib = xyes; then
  AC_CHECK_LIB(z, inflate,, [with_zlib=no])
fi

355 356 357 358
if test x$with_zlib = xyes; then
  LSH_RPATH_FIX
fi

359 360 361 362 363 364 365 366 367 368 369 370 371
# X11 stuff. We only need libXau.
AC_PATH_X

if test -z "$no_x" ; then
    CPPFLAGS="$CPPFLAGS -I$x_includes"
    LDFLAGS="$LDFLAGS -L$x_libraries"
    LSH_RPATH_ADD($x_libraries)
fi

AC_CHECK_HEADERS(X11/Xauth.h)
AC_CHECK_LIB(Xau, XauGetAuthByAddr)
LSH_RPATH_FIX

372 373 374 375
AC_CHECK_LIB(crypt, crypt)
AC_CHECK_LIB(xnet, inet_addr)
AC_CHECK_LIB(nsl, gethostbyname)
AC_CHECK_LIB(socket, setsockopt)
376
# logwtmp is also in libutil
377
AC_CHECK_LIB(util, openpty)
378

379
# This macro is new in autoconf-2.13
380
AC_SEARCH_LIBS(syslog, bsd socket inet, [AC_DEFINE(HAVE_SYSLOG)])
381

382
AH_TEMPLATE([WITH_ZLIB], [Define if zlib should be used])
383
# Should we use zlib?
384 385 386 387
if test x$with_zlib = xyes ; then
  AC_DEFINE(WITH_ZLIB)
fi

388 389 390 391 392 393 394 395 396 397 398 399
# The kerberos libraries are needed only to support the
# krb-check-passwd program, so we put them $KRB_LIBS, not in the
# ordinary $LIBS.

if test x$enable_kerberos = xyes; then
  AC_CHECK_KRB_LIB(roken, strlcpy)
  AC_CHECK_KRB_LIB(resolv, dn_expand)
  AC_CHECK_KRB_LIB(des, des_cbc_encrypt)
  AC_CHECK_KRB_LIB(asn1, der_get_octet_string)
  AC_CHECK_KRB_LIB(krb5, krb5_cc_gen_new,, [enable_kerberos=no])
fi

400
AH_TEMPLATE([WITH_KERBEROS], [For kerberos])
401 402 403 404 405 406 407 408
if test x$enable_kerberos = xyes; then
  AC_DEFINE(WITH_KERBEROS)
  KRB_PROGRAM=lsh-krb-checkpw
fi

AC_SUBST(KRB_LIBS)
AC_SUBST(KRB_PROGRAM)

409 410
AH_TEMPLATE([WITH_PAM], [For PAM])
if test x$enable_pam = xyes; then
411 412 413 414 415 416 417 418
  AC_CHECK_LIB(pam,pam_start,, enable_pam=no )

  if test x$enable_pam = xyes; then
    AC_DEFINE(WITH_PAM)
    PAM_PROGRAM=lsh-pam-checkpw
  else
    AC_MSG_WARN([pam_start not found in libpam, disabling PAM])
  fi
419 420 421 422
fi

AC_SUBST(PAM_PROGRAM)

423
AH_TEMPLATE([WITH_GCOV], [Use gcov])
Niels Möller's avatar
Niels Möller committed
424 425
if test "x$enable_gcov" = "xyes"; then
  CFLAGS="$CFLAGS -ftest-coverage -fprofile-arcs"
426
  AC_DEFINE(WITH_GCOV)
Niels Möller's avatar
Niels Möller committed
427 428
fi

429
# Checks for typedefs, structures, and compiler characteristics.
430
AC_C_CONST
431
AC_C_INLINE
432
AC_TYPE_UID_T
Niels Möller's avatar
Niels Möller committed
433
AC_TYPE_SIZE_T
434 435
AC_HEADER_TIME

436
# Needed by the supplied memcmp.c
Niels Möller's avatar
Niels Möller committed
437 438
AC_C_BIGENDIAN

Niels Möller's avatar
Niels Möller committed
439 440 441
AC_CHECK_SIZEOF(short, 2)
AC_CHECK_SIZEOF(int, 4)
AC_CHECK_SIZEOF(long, 4)
442 443

# FIXME: We should check that a pid_t fits in an int
Niels Möller's avatar
Niels Möller committed
444
	
445
# Checks for library functions.
446

447 448 449
AC_FUNC_ALLOCA
AC_FUNC_MEMCMP
AC_FUNC_VPRINTF
450
AC_CHECK_FUNCS(select socket strerror strsignal strtol)
451
AC_CHECK_FUNCS(getrusage gettimeofday)
452
AC_CHECK_FUNCS(getspnam)
453
AC_CHECK_FUNCS(vsnprintf inet_aton)
454
AC_CHECK_FUNCS(openpty)
455
AC_CHECK_FUNCS(cfmakeraw)
456
AC_CHECK_FUNCS(logwtmp login logout pututline pututxline updwtmp updwtmpx)
457
AC_CHECK_FUNCS(getaddrinfo getnameinfo gai_strerror)
458 459 460
AC_FUNC_GETPGRP
AC_CHECK_FUNCS(syslog)
AC_REPLACE_FUNCS(memxor)
461

462
# FIXME: Is there a better way in autoconf 2.50?
463 464 465 466 467 468 469 470 471
AC_CACHE_CHECK([if netdb.h defines AI_NUMERICHOST],
  lsh_cv_sys_ai_numerichost,
  [AC_EGREP_CPP(yes,
    [#include <netdb.h>
     #ifdef AI_NUMERICHOST
     yes
     #endif
    ], lsh_cv_sys_ai_numerichost=yes,
       lsh_cv_sys_ai_numerichost=no)])
472 473

AH_TEMPLATE([HAVE_AI_NUMERICHOST], [Define if AI_NUMERICHOST exists])
474 475 476 477
if test x$lsh_cv_sys_ai_numerichost = xyes ; then
  AC_DEFINE(HAVE_AI_NUMERICHOST)
fi

478
AC_CHECK_FUNCS(poll,,[AC_LIBOBJ([jpoll])])
Niels Möller's avatar
Niels Möller committed
479

480
# Test if the libc includes a good enough argp.
481
if test x$with_system_argp = xyes ; then
482
  AC_LIB_ARGP(,with_system_argp=no)
483 484
fi

485 486 487
# We don't use LIBOBJS for this, as the LIBOBJS are added to
# liblsh.a, and we can't add an archive to an archive.
LIBARGP=""
488
if test x$with_system_argp = xno ; then
Niels Möller's avatar
Niels Möller committed
489
  # FIXME: Perhaps it's better to use an absolute path?
490
  LIBARGP="argp/libargp.a"
491
fi
492

493 494
AC_SUBST(LIBARGP)

495
# Check for broken shutdown
496 497
AC_CACHE_CHECK(for working shutdown on AF_UNIX sockets,
	       lsh_cv_func_shutdown_works_on_unix_sockets,
498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524
[
AC_TRY_RUN([
#include <stdio.h>

#include <errno.h>

#include <sys/types.h>
#include <sys/socket.h>

#include <signal.h>

#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif

/* Creates a one-way socket connection. Returns 1 on success, 0 on
 * failure. fds[0] is for reading, fds[1] for writing (like for the
 * pipe() system call). */
static int make_pipe(int *fds)
{

#ifndef SHUT_RD
#define SHUT_RD 0
#define SHUT_WR 1
#define SHUT_RDWR 2
#endif

525
  if (socketpair(AF_UNIX, SOCK_STREAM, 0, fds) < 0)
526 527 528 529 530 531 532 533
    {
      fprintf(stderr, "socketpair() failed: %s\n", strerror(errno));
      return 0;
    }
  fprintf(stderr, "Created socket pair. Using fd:s %d <-- %d\n", fds[0], fds[1]);

  if(shutdown(fds[0], SHUT_WR) < 0)
    {
534 535
      fprintf(stderr, "shutdown(%d, SHUT_WR) failed: %s\n",
	      fds[0], strerror(errno));
536 537 538 539
      return 0;
    }
  if (shutdown(fds[1], SHUT_RD) < 0)
    {
540 541
      fprintf(stderr, "shutdown(%d, SHUT_RD) failed: %s\n",
	      fds[1], strerror(errno));
542 543 544 545 546 547 548 549 550 551 552 553 554 555 556
      return 0;
    }

  return 1;
}

int main(int argc, char **argv)
{
  int fds[2];
  
  if (!make_pipe(fds))
    exit(1);

  if (signal(SIGPIPE, SIG_IGN) == SIG_ERR)
    {
557
      fprintf(stderr, "signal failed.\n");
558 559 560 561 562 563 564 565 566
      exit(1);
    }

  if ( (write(fds[1], "foo", 3) < 0)
       && (errno == EPIPE))
    exit(1);

  exit(0);
}
567 568 569
], lsh_cv_func_shutdown_works_on_unix_sockets=yes,
   lsh_cv_func_shutdown_works_on_unix_sockets=no,
   lsh_cv_func_shutdown_works_on_unix_sockets=yes)])
570

571 572
AH_TEMPLATE([SHUTDOWN_WORKS_WITH_UNIX_SOCKETS],
	    [Define to indicate that shutdown seems to work properly])
573
if test x$lsh_cv_func_shutdown_works_on_unix_sockets = xyes ; then
574 575 576
    AC_DEFINE(SHUTDOWN_WORKS_WITH_UNIX_SOCKETS)
fi

577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634
AC_CACHE_CHECK(
  [for working UNIX98 ptys],
  lsh_cv_sys_unix98_ptys,
  AC_TRY_RUN([
  /* Try to obtain a working UNIX98-style pty master and slave */
  /* Based on example code from the GNU C library documentation */
  #include <stdlib.h>	/* EXIT_FAILURE, EXIT_SUCCESS, ptsname */
  #include <unistd.h>	/* close(2) */
  
  #include <sys/types.h>	/* open(2) */
  #include <sys/stat.h>	/* - " -   */
  #ifdef HAVE_FCNTL_H
  #  include <fcntl.h>	/* - " -   */
  #endif
  #ifdef HAVE_STROPTS_H
  #  include <stropts.h>	/* isastream() */
  #endif
  
  int main(int argc, char* argv[]) {
    int master, slave;
    char *name;
  
    master = open("/dev/ptmx", O_RDWR); /* PTY master multiplex */
    if (master < 0) {
  	  exit(EXIT_FAILURE);
    }
  
    if (grantpt(master) < 0 || unlockpt(master) < 0)
      goto close_master;
    name = ptsname(master);
    if (name == NULL)
      goto close_master;
  
    slave = open(name, O_RDWR);
    if (slave == -1)
      goto close_master;
  
  #ifdef HAVE_STROPTS_H
    if (isastream(slave))
      {
  	if (ioctl(slave, I_PUSH, "ptem") < 0
  	    || ioctl(slave, I_PUSH, "ldterm") < 0)
  	  goto close_slave;
      }
  #endif
  
    exit(0);
  
  close_slave:
    close (slave);
  
  close_master:
    close (master);
    exit(1);
  }
  ],
  [lsh_cv_sys_unix98_ptys=yes],
  [lsh_cv_sys_unix98_ptys=no],
635
  # Pessimistic default for cross compilation.
636 637
  [lsh_cv_sys_unix98_ptys=no]))

638 639
AH_TEMPLATE([HAVE_UNIX98_PTYS],
	    [Define if a we have working UNIX98 pty handling])
640 641 642 643
if test x$lsh_cv_sys_unix98_ptys = xyes; then
  AC_DEFINE(HAVE_UNIX98_PTYS)
fi
  
644
# Check for gcc's __attribute__ construction
645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661
AC_CACHE_CHECK(for __attribute__,
	       lsh_cv_c_attribute,
[ AC_TRY_COMPILE([
#include <stdlib.h>
],
[
static void foo(void) __attribute__ ((noreturn));

static void __attribute__ ((noreturn))
foo(void)
{
  exit(1);
}
],
lsh_cv_c_attribute=yes,
lsh_cv_c_attribute=no)])

662
AH_TEMPLATE([HAVE_GCC_ATTRIBUTE], [Define if the compiler understands __attribute__])
663 664
if test "x$lsh_cv_c_attribute" = "xyes"; then
  AC_DEFINE(HAVE_GCC_ATTRIBUTE)
665 666
fi

667
# Check for gcc's __FUNCTION__ variable
668 669 670
AC_CACHE_CHECK(for __FUNCTION__,
	       lsh_cv_c_FUNCTION,
  [ AC_TRY_COMPILE(,
671 672 673 674
      [ #if __GNUC__ == 3
	#  error __FUNCTION__ is broken in gcc-3
	#endif
        void foo(void) { char c = __FUNCTION__[0]; } ],
675 676 677
      lsh_cv_c_FUNCTION=yes,
      lsh_cv_c_FUNCTION=no)])

678 679
AH_TEMPLATE([HAVE_GCC_FUNCTION],
	    [Define if the compiler understands __FUNCTION__])
680 681 682 683
if test "x$lsh_cv_c_FUNCTION" = "xyes"; then
  AC_DEFINE(HAVE_GCC_FUNCTION)
fi

684
AC_MSG_CHECKING(for BSD pty names)
Niels Möller's avatar
Niels Möller committed
685

686 687 688 689 690
AH_TEMPLATE([PTY_BSD_SCHEME_FIRST_CHARS],
	    [Possible first characters in a /dev/ptyXX name])
AH_TEMPLATE([PTY_BSD_SCHEME_SECOND_CHARS],
	    [Possible second characters in a /dev/ptyXX name])

691
# FIXME: What is most portable, tr -d '\n' or tr -d '\012' ?
692 693
AC_DEFINE_UNQUOTED(PTY_BSD_SCHEME_FIRST_CHARS, "`ls /dev/pty* | cut -c 9-9 | uniq | tr -d '\n'`")
AC_DEFINE_UNQUOTED(PTY_BSD_SCHEME_SECOND_CHARS, "`ls /dev/pty* | cut -c 10-10 | sort | uniq | tr -d '\n'`")
694

695
# FIXME: How can we test if the bsd scheme is likely to work?
696
AH_TEMPLATE([PTY_BSD_SCHEME], [Traditional BSD pty handling])
697 698 699
AC_DEFINE(PTY_BSD_SCHEME)
AC_MSG_RESULT([done])

700
# IPv6 support
701 702 703

if test x$enable_ipv6 = xyes ; then
  AC_CACHE_CHECK([if IPv6 is supported],
704 705 706 707 708 709 710 711 712 713 714 715 716 717 718
    lsh_cv_sys_ipv6,
    [AC_TRY_RUN([/* AF_INET6 avalable check */
  #include <sys/types.h>
  #include <sys/socket.h>
  int main(int argc, char **argv)
  {
   if (socket(AF_INET6, SOCK_STREAM, 0) < 0)
     exit(1);
   else
     exit(0);
  }
  ], lsh_cv_sys_ipv6=yes,
     lsh_cv_sys_ipv6=no,
     lsh_cv_sys_ipv6=no)])
  
719 720
  if test x$lsh_cv_sys_ipv6 != xyes ; then
    enable_ipv6=no
721
  elif test x$ac_cv_func_getaddrinfo != xyes ; then
722 723
    AC_MSG_WARN([getaddrinfo not found. Disabling IPv6 support])
    enable_ipv6=no
724
  elif test x$ac_cv_func_gai_strerror != xyes ; then
725 726
    AC_MSG_WARN([gai_strerror not found. Disabling IPv6 support])
    enable_ipv6=no
727
  elif test x$lsh_cv_sys_ai_numerichost != xyes ; then
728 729
    AC_MSG_WARN([AI_NUMERICHOST not defined. Disabling IPv6 support])
    enable_ipv6=no
730 731 732
  fi
fi

733
AH_TEMPLATE([WITH_IPV6], [For Ipv6 support])
734
if test x$enable_ipv6 = xyes ; then
735 736 737
  AC_DEFINE(WITH_IPV6)
fi

738
AC_CONFIG_SUBDIRS(src/argp)
739
AC_CONFIG_SUBDIRS(src/nettle)
740
AC_CONFIG_SUBDIRS(src/sftp)
741

742 743
# Set these flags *last*, or else the test programs won't compile
if test x$GCC = xyes ; then
744
    CFLAGS="$CFLAGS -Wall -W \
Niels Möller's avatar
Niels Möller committed
745 746
 -Wmissing-prototypes -Wmissing-declarations -Wstrict-prototypes \
 -Wpointer-arith -Wbad-function-cast -Wnested-externs"
747

748 749
# Don't enable -Wcast-align as it results in tons of warnings in the
# DES code. And when using stdio.
750 751
# Don't enable -Waggregate-return, as that causes warnings for glibc
# inttypes.h.
752

753
fi
Niels Möller's avatar
Niels Möller committed
754

755
AC_CONFIG_FILES([Makefile doc/Makefile misc/Makefile
756
	  src/Makefile src/scm/Makefile
757
	  src/testsuite/Makefile src/rsync/Makefile
758
	  src/nettle/Makefile
759 760
	  contrib/Makefile contrib/lsh.spec])
AC_OUTPUT