configure.ac 22.8 KB
Newer Older
Niels Möller's avatar
Niels Möller committed
1
dnl Process this file with autoconf to produce a configure script.
Niels Möller's avatar
Niels Möller committed
2
AC_INIT([lsh], [2x1], [bug-lsh@gnu.org]) 
Niels Möller's avatar
Niels Möller committed
3
AC_PREREQ(2.52)
4
AC_CONFIG_SRCDIR([src/lsh.c])
5 6 7
# Needed to stop autoconf from looking for files in parent directories.
AC_CONFIG_AUX_DIR([.])
	
8
AM_INIT_AUTOMAKE
9
AM_CONFIG_HEADER(config.h)
Niels Möller's avatar
Niels Möller committed
10

11 12 13 14 15 16 17 18 19 20 21 22
# 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

23
# src/rsync relies on lsh's definitions of WRITE_UINT32 etc.
24
# CPPFLAGS="$CPPFLAGS -I$srcdir/src -DLSH"
25

26 27 28 29
# 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
30

31
AC_GNU_SOURCE
Niels Möller's avatar
Niels Möller committed
32

33
# Check options
34
AC_ARG_ENABLE(debug_alloc,
35
  AC_HELP_STRING([--enable-debug-alloc], [Enable memory allocation sanity checks]),,
36
  [enable_debug_alloc=no])
37 38 39

AH_TEMPLATE([DEBUG_ALLOC],
	    [Define to enable sanity checking on memory allocation and casting])
40
if test x$enable_debug_alloc = xyes ; then
41 42 43
  AC_DEFINE(DEBUG_ALLOC)
fi

44
AC_ARG_ENABLE(debug_trace,
45
  AC_HELP_STRING([--enable-debug-trace], [Enable tracing support]),,
46
  [enable_debug_trace=no])
47

48
AH_TEMPLATE([DEBUG_TRACE], [Define to enable tracing])
49
if test x$enable_debug_trace = xyes ; then
50 51 52
  AC_DEFINE(DEBUG_TRACE)
fi

Niels Möller's avatar
Niels Möller committed
53
AC_ARG_ENABLE(gcov,
54
  AC_HELP_STRING([--enable-gcov], [Instrument for gcov (requires a modern gcc)]),,
Niels Möller's avatar
Niels Möller committed
55 56
  [enable_gcov=no])

Niels Möller's avatar
Niels Möller committed
57 58 59 60 61
AC_ARG_ENABLE(profiling,
  AC_HELP_STRING([--enable-profiling], [Instrument for gprof profiling]),,
  [enable_profiling=no])


62
AC_ARG_WITH(zlib,
63
  AC_HELP_STRING([--without-zlib], [Don't use zlib compression]),,
64
  [with_zlib=yes])
65

66 67 68 69 70 71 72 73 74 75
AC_ARG_WITH(tcpwrappers,
  AC_HELP_STRING([--with-tcpwrappers], 
                [Use tcp-wrappers for filtering connections]),
  [if test -z "$withval"; then 
    with_tcpwrappers=yes; 
  else 
    with_tcpwrappers="$withval";
  fi],
  [with_tcpwrappers=no])

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

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

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

88
AC_ARG_ENABLE(srp,
89
  AC_HELP_STRING([--disable-srp], [Disable the (experimental) support for SRP]),,
90 91
  [enable_srp=yes])

92 93 94 95
AC_ARG_ENABLE(gss,
  AC_HELP_STRING([--disable-gss], [Disable the (experimental) support for GSS]),,
  [enable_gss=yes])

96
AC_ARG_ENABLE(kerberos,
97
  AC_HELP_STRING([--disable-kerberos], [Don't support kerberos]),,
98
  [enable_kerberos=yes])
99

100 101 102 103
AC_ARG_ENABLE(pam,
  AC_HELP_STRING([--disable-pam], [Don't support PAM]),,
  [enable_pam=yes])

104
AH_TEMPLATE([WITH_SRP], [Define if SRP should be supported])
105 106
if test x$enable_srp = xyes ; then
  AC_DEFINE(WITH_SRP)
107
  SRP_PROGRAM=srp-gen
108 109
fi

110 111
AC_SUBST(SRP_PROGRAM)

112 113 114 115 116 117 118 119 120 121 122 123
AC_ARG_ENABLE(initgroups_workaround,
  AC_HELP_STRING([--enable-initgroups-workaround],
		 [Use a special initgroups for supporting more groups]),,
  [enable_initgroups_workaround=no])

AH_TEMPLATE([INITGROUPS_WORKAROUND],
	    [Define to enable the initgroups workaround])
if test x$enable_initgroups_workaround = xyes ; then
  AC_DEFINE(INITGROUPS_WORKAROUND)
fi


124
AC_ARG_ENABLE(tcp_forward,
125
  AC_HELP_STRING([--disable-tcp-forward], [Disable tcp forwarding]),,
126
  [enable_tcp_forward=yes])
127

128
AH_TEMPLATE([WITH_TCP_FORWARD], [Define to enable tcp forwarding])
129
if test x$enable_tcp_forward = xyes ; then
130 131
  AC_DEFINE(WITH_TCP_FORWARD)
fi
132

133
AC_ARG_ENABLE(x11_forward,
134
  AC_HELP_STRING([--disable-x11-forward], [Disable x11 forwarding (proxy only)]),,
135
  [enable_x11_forward=yes])
136

137
AH_TEMPLATE([WITH_X11_FORWARD], [Define to enable x11 forwarding])
138
if test x$enable_x11_forward = xyes ; then
139 140 141
  AC_DEFINE(WITH_X11_FORWARD)
fi

142
AC_ARG_ENABLE(agent_forward,
143
  AC_HELP_STRING([--disable-agent-forward], [Disable auth-agent forwarding (proxy only)]),,
144 145
  [with_agent_forward=yes])

146 147
AH_TEMPLATE([WITH_AGENT_FORWARD],
	    [Define to enable authentication agent forwarding])
148
if test x$disable_agent_forward = xyes ; then
149 150 151
  AC_DEFINE(WITH_AGENT_FORWARD)
fi

152
AC_ARG_WITH(scheme,
153
  AC_HELP_STRING([[--with-scheme[=PROGRAM]]], [Use a particular scheme implementation]),,
154
  [with_scheme=])
155 156

AC_ARG_WITH(system-argp,
157
  AC_HELP_STRING([--without-system-argp], [Don't use the system's argp]),,
158
  [with_system_argp=yes])
159

160
# IPv6 support
161
AC_ARG_ENABLE(ipv6,
162
  AC_HELP_STRING([--disable-ipv6], [Disable IPv6 support]),,
163 164
  [enable_ipv6=yes])

165
# utmp/wtmp logging 
166
AC_ARG_ENABLE(utmp,
167
  AC_HELP_STRING([--disable-utmp], [Disable utmp and wtmp support]),,
168 169
  [enable_utmp=yes])

170
AH_TEMPLATE([WITH_UTMP], [For utmp support])
171 172 173 174
if test x$enable_utmp = xyes ; then
  AC_DEFINE(WITH_UTMP)
fi

175
AC_ARG_WITH(include-path,
176
  AC_HELP_STRING([--with-include-path], [A colon-separated list of directories to search for include files]),,
177 178 179
  [with_include_path=''])

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

183
AC_ARG_WITH(lib-path,
184
  AC_HELP_STRING([--with-lib-path], [A colon-separated list of directories to search for libraries]),,
185 186 187
  [with_lib_path=''])

if test x$with_lib_path != x ; then
188
  LDFLAGS="$LDFLAGS -L`echo $with_lib_path | sed 's/:/ -L/g'`"
189 190 191 192 193 194 195 196 197
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

198
# Checks for programs.
Niels Möller's avatar
Niels Möller committed
199 200
AC_PROG_CC
AC_PROG_MAKE_SET
Niels Möller's avatar
Niels Möller committed
201
AC_PROG_RANLIB
202
AM_PROG_CC_STDC
Niels Möller's avatar
Niels Möller committed
203

204
if test "x$am_cv_prog_cc_stdc" = xno ; then
205
  AC_MSG_ERROR([the C compiler doesn't handle ANSI-C])
206 207
fi

208 209
# Use a particular scheme implementation?
if test x$with_scheme != x ; then
210 211 212 213 214 215 216 217 218
  # 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
219
else  
220
  AC_PATH_PROGS(SCHEME_PROGRAM, guile scsh,, $PATH)
221
fi
222

223
if test "x$SCHEME_PROGRAM" = x ; then
224 225
  AC_MSG_WARN([No scheme implementation found.
This is fine as long as you don't modify the source files.])
226 227 228
  SCHEME_PROGRAM=false
fi

229 230 231
SCHEME_NAME=`basename $SCHEME_PROGRAM`
AC_SUBST(SCHEME_NAME)

232 233 234 235 236 237 238 239 240 241
if test "x$GROFF" = x; then
  AC_PATH_PROG(GROFF, groff,, $PATH)
fi
AC_ARG_VAR(GROFF, groff)

if test "x$M4" = x; then
  AC_PATH_PROG(M4, m4, m4)
fi
AC_ARG_VAR(M4, M4 macro processor)

242

243
# Checks for header files.
Niels Möller's avatar
Niels Möller committed
244
AC_HEADER_STDC
245

246 247 248
# 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]))
249
  
250
AC_CHECK_HEADERS(fcntl.h strings.h sys/time.h unistd.h)
251
AC_CHECK_HEADERS(shadow.h)
252

253 254 255
if test x$with_zlib = xyes; then
  AC_CHECK_HEADERS(zlib.h,, [with_zlib=no])
fi
256
AC_CHECK_HEADERS(libutil.h)
257
AC_CHECK_HEADERS(crypt.h)
258 259
AC_CHECK_HEADERS(pty.h)
AC_CHECK_HEADERS(stropts.h)
260
AC_CHECK_HEADERS(syslog.h)
261
AC_CHECK_HEADERS(argp.h)
262
AC_CHECK_HEADERS(sys/resource.h)
Niels Möller's avatar
Niels Möller committed
263
AC_CHECK_HEADERS(sys/filio.h)
264

265
AC_CHECK_HEADERS(utmp.h, [have_utmp_h=yes], [have_utmp_h=no])
266
AC_CHECK_HEADERS(utmpx.h, [have_utmpx_h=yes], [have_utmpx_h=no])
267

268 269 270 271
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.

272
if test x$have_utmp_h = xyes; then
273 274 275
  AC_CHECK_MEMBERS([struct utmp.ut_host,
		    struct utmp.ut_name,
		    struct utmp.ut_user,
276 277
		    struct utmp.ut_time,
		    struct utmp.ut_tv,
278
		    struct utmp.ut_tv.tv_sec,
279 280 281
		    struct utmp.ut_id,
		    struct utmp.ut_syslen,
		    struct utmp.ut_session,
282 283
		    struct utmp.ut_pid,
		    struct utmp.ut_exit,
284
		    struct utmp.ut_exit.e_termination,
285 286
		    struct utmp.ut_exit.__e_termination,
		    struct utmp.ut_exit.ut_termination,
287 288 289 290 291
		    struct utmp.ut_addr,
		    struct utmp.ut_addr_v6],,,
[# if HAVE_UTMP_H
#  include <utmp.h>
# endif
292 293
])
fi
294

295 296 297 298 299 300 301
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,
302
		    struct utmpx.ut_tv.tv_sec,
303 304 305 306
		    struct utmpx.ut_syslen,
		    struct utmpx.ut_session,
		    struct utmpx.ut_pid,
		    struct utmpx.ut_exit,
307
		    struct utmpx.ut_exit.e_termination,
308 309
		    struct utmpx.ut_exit.__e_termination,
		    struct utmpx.ut_exit.ut_termination,
310 311 312
		    struct utmpx.ut_addr,
		    struct utmpx.ut_addr_v6],,,
[# if HAVE_UTMPX_H
313 314 315
#  include <utmpx.h>
# endif
])
316
fi
317

318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346
AH_TEMPLATE([WITH_GSS_K5], [Whether to use gss K5 authorization (Heimdal/MIT)])
if test x$enable_gss != xno; then
  if test x$enable_gss = xk5; then
    AC_CHECK_PROG(KRB5CONFIG, krb5-config, krb5-config, no)
    if test x$KRB5CONFIG != xno; then
      CPPFLAGS="$CPPFLAGS `$KRB5CONFIG --cflags gssapi`"
      LIBS="$LIBS `$KRB5CONFIG --libs gssapi`"
      AC_CHECK_HEADERS([gssapi.h gssapi/gssapi.h gssapi/gssapi_generic.h])
      AC_DEFINE(WITH_GSS_K5)
      AC_CHECK_DECL(GSS_C_NT_HOSTBASED_SERVICE,, [
	AC_DEFINE(GSS_C_NT_HOSTBASED_SERVICE,
		gss_nt_service_name,
		[Work around buggy MIT library])], [
#ifdef HAVE_GSSAPI_H
#include <gssapi.h>
#endif
#ifdef HAVE_GSSAPI_GSSAPI_H
#include <gssapi/gssapi.h>
#endif
#ifdef HAVE_GSSAPI_GSSAPI_GENERIC_H
#include <gssapi/gssapi_generic.h>
#endif
])
    fi
  else
    AC_CHECK_HEADERS(gss.h,, [enable_gss=no])
    AC_CHECK_LIB(gss, gss_check_version,, [enable_gss=no])
  fi
fi
347

348 349 350 351
if test x$enable_kerberos = xyes; then
  AC_CHECK_HEADERS(krb5.h,, [enable_kerberos=no])
fi

352 353 354 355
if test x$enable_pam = xyes; then
  AC_CHECK_HEADERS(security/pam_appl.h,, [enable_pam=no])
fi

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

359 360
# AC_CHECK_TYPE doesn't work, probably because the type in
# question is not defined in sys/types.h.
361

362
LSH_TYPE_SOCKLEN_T
363

364 365
# Checks for libraries

366 367 368 369
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.])])

370 371
LSH_RPATH_FIX

Niels Möller's avatar
Niels Möller committed
372 373 374 375 376
AC_CHECK_LIB([oop], [oop_sys_new],,
  [AC_MSG_ERROR([liboop is missing. Get liboop from http://www.liboop.org])])

LSH_RPATH_FIX

377 378 379 380
if test x$with_zlib = xyes; then
  AC_CHECK_LIB(z, inflate,, [with_zlib=no])
fi

381 382 383 384
if test x$with_zlib = xyes; then
  LSH_RPATH_FIX
fi

385 386 387 388 389
# FIXME: Should we let people use --with-tcpwrappers=/here/they/are?

if test x$with_tcpwrappers = xyes; then
  AC_CHECK_LIB(wrap, request_init,, 
  [
390
      AC_MSG_WARN([Failed to link libwrap, you might try adding -lsocket to LDFLAGS])
391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408
      with_tcpwrappers=no
  ])

  AC_CHECK_HEADER(tcpd.h,, [with_tcpwrappers=no])

  if test x$with_tcpwrappers = xno; then
    AC_MSG_WARN([Failed to find a working tcpwrappers setup, disabling wrappers])
  fi
fi

if test x$with_tcpwrappers = xyes; then
  LSH_RPATH_FIX
  AC_DEFINE(WITH_TCPWRAPPERS,1,[Whatever to use tcpwrappers])
else
  AC_DEFINE(WITH_TCPWRAPPERS,0,[Whatever to use tcpwrappers])
fi


409
# X11 stuff. We only need libXau.
410
# FIXME: Use AC_PATH_XTRA instead? 
411 412 413
AC_PATH_X

if test -z "$no_x" ; then
414
  if test -n "$x_includes" ; then
415
    CPPFLAGS="$CPPFLAGS -I$x_includes"
416
  fi
417
  if test -n "$x_libraries" ; then
418 419
    LDFLAGS="$LDFLAGS -L$x_libraries"
    LSH_RPATH_ADD($x_libraries)
420
  fi
421 422 423 424 425 426
fi

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

Pontus Freyhult's avatar
Pontus Freyhult committed
427 428 429 430 431 432 433 434 435 436 437 438
AC_ARG_VAR(XAUTH_PROGRAM, Program used to handle .Xauthority-files by lshd)

if test -z "$XAUTH_PROGRAM"; then
  AC_PATH_PROG(XAUTH_PROGRAM, xauth,, /usr/X11R6/bin:/usr/openwin/bin:/usr/X/bin:/usr/X11/bin:/usr/bin:/usr/bin/X:/usr/bin/X11)
fi

if test -z "$XAUTH_PROGRAM"; then
  AC_MSG_WARN(Couldn't find xauth, try passing XAUTH_PROGRAM=/path/to/xauth to configure)
else
  AC_DEFINE_UNQUOTED(XAUTH_PROGRAM, "$XAUTH_PROGRAM", Program used by lshd to handle .Xauthority-files)
fi

439 440
# Move these checks for system libraries earlier, before checks for
# gmp, liboop etc
441

442 443 444
# glibc has a nis-library "libnsl", which we don't need. So use
# AC_SEARCH_LIBS rather than AC_CHECK_LIB.
AC_SEARCH_LIBS(gethostbyname, nsl)
445
AC_SEARCH_LIBS(inet_ntop, nsl)
446 447 448 449 450 451
AC_CHECK_LIB(socket, setsockopt)

AC_CHECK_LIB(crypt, crypt)
AC_CHECK_LIB(xnet, inet_addr)
# logwtmp is also in libutil
AC_CHECK_LIB(util, openpty)
452

453
# This macro is new in autoconf-2.13
454
AC_SEARCH_LIBS(syslog, bsd socket inet, [AC_DEFINE(HAVE_SYSLOG)])
455

456
AH_TEMPLATE([WITH_ZLIB], [Define if zlib should be used])
457
# Should we use zlib?
458 459 460 461
if test x$with_zlib = xyes ; then
  AC_DEFINE(WITH_ZLIB)
fi

462 463 464 465 466 467
AH_TEMPLATE([WITH_GSS], [Define if gss should be used])
# Should we use gss?
if test x$enable_gss != xno ; then
  AC_DEFINE(WITH_GSS)
fi

468 469 470 471 472
# 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
473 474 475 476
  LSH_CHECK_KRB_LIB(roken, strlcpy)
  LSH_CHECK_KRB_LIB(resolv, dn_expand)
  LSH_CHECK_KRB_LIB(des, des_cbc_encrypt)
  LSH_CHECK_KRB_LIB(asn1, der_get_octet_string)
477 478 479
  # Check for krb5_cc_gen_new too?
  # krb5_verify_user_lrealm seems to be unique to heimdal
  LSH_CHECK_KRB_LIB(krb5, krb5_verify_user_lrealm,, [enable_kerberos=no])
480 481
fi

482
AH_TEMPLATE([WITH_KERBEROS], [For kerberos])
483 484 485 486 487 488 489 490
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)

491 492
AH_TEMPLATE([WITH_PAM], [For PAM])
if test x$enable_pam = xyes; then
493 494 495 496 497 498 499 500
  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
501 502 503 504
fi

AC_SUBST(PAM_PROGRAM)

505
AH_TEMPLATE([WITH_GCOV], [Use gcov])
Niels Möller's avatar
Niels Möller committed
506 507
if test "x$enable_gcov" = "xyes"; then
  CFLAGS="$CFLAGS -ftest-coverage -fprofile-arcs"
508
  AC_DEFINE(WITH_GCOV)
Niels Möller's avatar
Niels Möller committed
509 510
fi

Niels Möller's avatar
Niels Möller committed
511 512 513 514
if test "x$enable_profiling" = "xyes"; then
  CFLAGS="$CFLAGS -pg"
fi

515
# Checks for typedefs, structures, and compiler characteristics.
516
AC_C_CONST
517
AC_C_INLINE
518
AC_TYPE_UID_T
Niels Möller's avatar
Niels Möller committed
519
AC_TYPE_SIZE_T
520 521
AC_HEADER_TIME

522
# Needed by the supplied memcmp.c
Niels Möller's avatar
Niels Möller committed
523 524
AC_C_BIGENDIAN

525
# FIXME: We should check that a pid_t fits in an int
Niels Möller's avatar
Niels Möller committed
526
	
527
# Checks for library functions.
528

529 530 531
LSH_FUNC_ALLOCA
LSH_FUNC_STRERROR
LSH_FUNC_STRSIGNAL
532 533
AC_FUNC_MEMCMP
AC_FUNC_VPRINTF
534
AC_CHECK_FUNCS(select socket strtol alarm)
535
AC_CHECK_FUNCS(getrusage gettimeofday)
536
AC_CHECK_FUNCS(getspnam)
537
AC_CHECK_FUNCS(vsnprintf inet_aton)
538
AC_CHECK_FUNCS(openpty)
539
AC_CHECK_FUNCS(cfmakeraw)
540
AC_CHECK_FUNCS(logwtmp login logout pututline pututxline updwtmp updwtmpx)
541
AC_CHECK_FUNCS(getaddrinfo getnameinfo gai_strerror)
542
AC_CHECK_FUNCS(setrlimit getdtablesize)
543 544
AC_FUNC_GETPGRP
AC_CHECK_FUNCS(syslog)
545

546 547 548 549 550 551 552 553 554 555
# HP-UX doesn't have seteuid
AC_CHECK_FUNCS(seteuid setresuid)

AH_BOTTOM(
[#if !HAVE_SETEUID
# if HAVE_SETRESUID
#  define seteuid(uid) setresuid(-1, (uid), -1)
# endif
#endif])

556
# FIXME: Is there a better way in autoconf 2.50?
557 558 559 560 561 562 563 564 565
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)])
566 567

AH_TEMPLATE([HAVE_AI_NUMERICHOST], [Define if AI_NUMERICHOST exists])
568 569 570 571
if test x$lsh_cv_sys_ai_numerichost = xyes ; then
  AC_DEFINE(HAVE_AI_NUMERICHOST)
fi

572
# Test if the libc includes a good enough argp.
573
if test x$with_system_argp = xyes ; then
574
  LSH_LIB_ARGP(,with_system_argp=no)
575 576
fi

577 578 579
# 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=""
580
DOTDOT_LIBARGP=""
581
if test x$with_system_argp = xno ; then
Niels Möller's avatar
Niels Möller committed
582
  # FIXME: Perhaps it's better to use an absolute path?
583
  LIBARGP="argp/libargp.a"
584 585
  # Needed for linking in src/testsuite.
  DOTDOT_LIBARGP="../argp/libargp.a"
586
fi
587

588
AC_SUBST(LIBARGP)
589
AC_SUBST(DOTDOT_LIBARGP)
590

591
# Check for broken shutdown
592 593
AC_CACHE_CHECK(for working shutdown on AF_UNIX sockets,
	       lsh_cv_func_shutdown_works_on_unix_sockets,
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
[
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

621
  if (socketpair(AF_UNIX, SOCK_STREAM, 0, fds) < 0)
622 623 624 625 626 627 628 629
    {
      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)
    {
630 631
      fprintf(stderr, "shutdown(%d, SHUT_WR) failed: %s\n",
	      fds[0], strerror(errno));
632 633 634 635
      return 0;
    }
  if (shutdown(fds[1], SHUT_RD) < 0)
    {
636 637
      fprintf(stderr, "shutdown(%d, SHUT_RD) failed: %s\n",
	      fds[1], strerror(errno));
638 639 640 641 642 643 644 645 646 647 648 649 650 651 652
      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)
    {
653
      fprintf(stderr, "signal failed.\n");
654 655 656 657 658 659 660 661 662
      exit(1);
    }

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

  exit(0);
}
663 664 665
], 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)])
666

667 668
AH_TEMPLATE([SHUTDOWN_WORKS_WITH_UNIX_SOCKETS],
	    [Define to indicate that shutdown seems to work properly])
669
if test x$lsh_cv_func_shutdown_works_on_unix_sockets = xyes ; then
670 671 672
    AC_DEFINE(SHUTDOWN_WORKS_WITH_UNIX_SOCKETS)
fi

673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730
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],
731
  # Pessimistic default for cross compilation.
732 733
  [lsh_cv_sys_unix98_ptys=no]))

734 735
AH_TEMPLATE([HAVE_UNIX98_PTYS],
	    [Define if a we have working UNIX98 pty handling])
736 737
if test x$lsh_cv_sys_unix98_ptys = xyes; then
  AC_DEFINE(HAVE_UNIX98_PTYS)
738 739
else
  AC_MSG_WARN([No support for UNIX98 PTYs. PTY support disabled.])
740
fi
741

Niels Möller's avatar
Niels Möller committed
742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794
# Check that FIONREAD exists, works, and uses an argument of type int, not long.  
AC_CACHE_CHECK(
  [for FIONREAD with int argument],
  lsh_cv_sys_ioctl_fionread_int,
[AC_TRY_RUN([
#include <errno.h>
#include <fcntl.h>

#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#if HAVE_SYS_FILIO_H
#include <sys/filio.h>
#endif
int main(int argc, char **argv)
{
#ifdef FIONREAD
  union {
    int i[2];
    long l;
  } val;

  int fds[2];

  if (socketpair(AF_UNIX, SOCK_STREAM, 0, fds) < 0)
    {
      printf("socketpair failed: errno = %d.\n", errno);
      return 1;
    }
    
  val.i[0] = 0xdeadbeaf;
  val.i[1] = 0xdeadbeaf;

  if (ioctl(fds[0], FIONREAD, val.i) < 0)
    {
      printf("ioctl FIONREAD failed: errno = %d.\n", errno);
      return 1;
    }
  if (val.i[0] == 0 && val.i[1] == 0xdeadbeaf)
    return 0;
#endif
  return 1;
}
], lsh_cv_sys_ioctl_fionread_int=yes,
   lsh_cv_sys_ioctl_fionread_int=no,
   lsh_cv_sys_ioctl_fionread_int=no)])

AH_TEMPLATE([HAVE_IOCTL_FIONREAD],
	    [Define if the FIONREAD ioctl works, and uses an argument of type int])
if test x$lsh_cv_sys_ioctl_fionread_int = xyes; then
  AC_DEFINE([HAVE_IOCTL_FIONREAD])
fi

795
LSH_GCC_ATTRIBUTES
796

797
AC_MSG_CHECKING(for BSD pty names)
Niels Möller's avatar
Niels Möller committed
798

799 800 801 802 803
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])

804
# FIXME: What is most portable, tr -d '\n' or tr -d '\012' ?
805 806
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'`")
807

808
# FIXME: How can we test if the bsd scheme is likely to work?
809
AH_TEMPLATE([PTY_BSD_SCHEME], [Traditional BSD pty handling])
810 811 812
AC_DEFINE(PTY_BSD_SCHEME)
AC_MSG_RESULT([done])

813
# IPv6 support
814 815

if test x$enable_ipv6 = xyes ; then
816
  if test x$ac_cv_func_getaddrinfo != xyes ; then
817 818
    AC_MSG_WARN([getaddrinfo not found. Disabling IPv6 support])
    enable_ipv6=no
819
  elif test x$ac_cv_func_gai_strerror != xyes ; then
820 821
    AC_MSG_WARN([gai_strerror not found. Disabling IPv6 support])
    enable_ipv6=no
822
  elif test x$lsh_cv_sys_ai_numerichost != xyes ; then
823 824
    AC_MSG_WARN([AI_NUMERICHOST not defined. Disabling IPv6 support])
    enable_ipv6=no
825 826 827
  fi
fi

828
AH_TEMPLATE([WITH_IPV6], [For Ipv6 support])
829
if test x$enable_ipv6 = xyes ; then
830 831 832
  AC_DEFINE(WITH_IPV6)
fi

833
AC_CONFIG_SUBDIRS(src/argp)
834
AC_CONFIG_SUBDIRS(src/nettle)
835
AC_CONFIG_SUBDIRS(src/spki)
836
AC_CONFIG_SUBDIRS(src/sftp)
837

838 839
# Set these flags *last*, or else the test programs won't compile
if test x$GCC = xyes ; then
840 841 842 843 844 845
  # Using -ggdb3 makes (some versions of) Redhat's gcc-2.96 dump core
  if "$CC" --version | grep '^2\.96$' 1>/dev/null 2>&1; then
    true
  else
    CFLAGS="$CFLAGS -ggdb3"
  fi
846
  # FIXME: It would be better to actually test if this option works and/or is needed.
Niels Möller's avatar
Niels Möller committed
847
  # Or perhaps use -funsigned-char.
848 849 850
  if "$CC" --version | grep 'gcc.* 4\.' 1>/dev/null 2>&1; then
    CFLAGS="$CFLAGS -Wno-pointer-sign"
  fi
851 852 853
  CFLAGS="$CFLAGS -Wall -W \
  -Wmissing-prototypes -Wmissing-declarations -Wstrict-prototypes \
  -Wpointer-arith -Wbad-function-cast -Wnested-externs"
854

855 856
# Don't enable -Wcast-align as it results in tons of warnings in the
# DES code. And when using stdio.
857 858
# Don't enable -Waggregate-return, as that causes warnings for glibc
# inttypes.h.
859

860
fi
Niels Möller's avatar
Niels Möller committed
861

Niels Möller's avatar
Niels Möller committed
862
# Used by contrib/solpkg.sh.in.
863 864 865 866
AC_SUBST(BUILD_ARCH, `uname -p`)
AC_SUBST(BUILD_OSSYS,`uname -s`)
AC_SUBST(BUILD_OSREV,`uname -r`)

867
AC_CONFIG_FILES([Makefile doc/Makefile misc/Makefile
868
	  src/Makefile src/scm/Makefile
869
	  src/testsuite/Makefile src/rsync/Makefile
870
	  contrib/Makefile contrib/lsh.spec contrib/solpkg.sh])
871
AC_OUTPUT