Merge branch 'master' into lua-scripting
[screen-lua.git] / src / configure.in
blob7e88a6ad08d5a273a22dd83e71e07712fca44c48
1 dnl Process this file with autoconf to produce a configure script.
2 dnl
3 dnl $Id$ FAU
4 dnl
5 dnl Many thanks to David MacKenzie for writing autoconf and
6 dnl providing a sample configure.in file for screen.
7 dnl
8 AC_REVISION($Revision$)dnl
9 AC_INIT(screen.c)
10 AC_CONFIG_HEADER(config.h)
12 dnl
13 dnl Define some useful macros
14 dnl
15 AC_DEFUN([AC_PROGRAM_SOURCE],
16 [AC_REQUIRE([AC_PROG_CPP])AC_PROVIDE([$0])cat > conftest.c <<EOF
17 #include "confdefs.h"
18 [$1]
19 _CUT_HERE_
20 [$2]
21 EOF
22 eval "$ac_cpp conftest.c 2>&5 | sed -e '1,/_CUT_HERE_/d' -e 's/ //g' > conftest.out"
23 . ./conftest.out
24 rm -f conftest*
25 ])dnl
26 dnl
27 define(AC_NOTE,
28 [echo "$1" 1>&AC_FD_MSG
29 ])dnl
31 dnl
32 dnl Extract version from patchlevel.h
33 dnl
34 rev=`sed < ${srcdir}/patchlevel.h -n -e '/#define REV/s/#define REV  *//p'`
35 vers=`sed < ${srcdir}/patchlevel.h -n -e '/#define VERS/s/#define VERS  *//p'`
36 pat=`sed < ${srcdir}/patchlevel.h -n -e '/#define PATCHLEVEL/s/#define PATCHLEVEL  *//p'`
37 VERSION="$rev.$vers.$pat"
38 AC_NOTE(this is screen version $VERSION)
39 AC_SUBST(VERSION)
40 AC_PREFIX_PROGRAM(screen)
41 AC_PREFIX_PROGRAM(gzip)
43 old_CFLAGS="$CFLAGS"
44 AC_PROG_CC
45 AC_PROG_CPP
46 AC_PROG_GCC_TRADITIONAL
47 AC_ISC_POSIX
49 AC_TRY_RUN(main(){exit(0);},,[
50 if test $CC != cc ; then
51 AC_NOTE(Your $CC failed - restarting with CC=cc)
52 AC_NOTE()
53 CC=cc
54 export CC
55 exec $0 $configure_args
59 AC_TRY_RUN(main(){exit(0);},,
60 exec 5>&2
61 eval $ac_link
62 AC_NOTE(CC=$CC; CFLAGS=$CFLAGS; LIBS=$LIBS;)
63 AC_NOTE($ac_compile)
64 AC_MSG_ERROR(Can't run the compiler - sorry))
66 AC_TRY_RUN([
67 main()
69   int __something_strange_();
70   __something_strange_(0);
72 ],AC_MSG_ERROR(Your compiler does not set the exit status - sorry))
74 AC_PROG_AWK
76 AC_PROG_INSTALL
78 if test -f etc/toolcheck; then
79 AC_CHECKING(for buggy tools)
80 sh etc/toolcheck 1>&AC_FD_MSG
85 dnl SOCKDIR
86 AC_MSG_CHECKING(if a system-wide socket dir should be used) 
87 AC_ARG_ENABLE(socket-dir,
88     [  --disable-socket-dir    disable system wide socket-dir and use ~/.screen instead],
89     [
90         AC_MSG_RESULT(no.  ~/.screen will be used instead.)
91     ],
92     [
93         AC_MSG_RESULT(yes)
94         AC_MSG_CHECKING(for the socket dir)
95         SOCKDIR="(eff_uid ? \"/tmp/uscreens\" : \"/tmp/screens\")"
96         AC_ARG_WITH(socket-dir, [  --with-socket-dir=path  where to put the per-user sockets], [ 
97           case "${withval}" in
98             *\"*) SOCKDIR="${withval}" ;;
99             *) SOCKDIR="\"${withval}\"" ;;
100           esac
101         ])
102         AC_MSG_RESULT(${SOCKDIR})
103         AC_DEFINE_UNQUOTED(SOCKDIR, $SOCKDIR)
104     ]
109 dnl    ****  special unix variants  ****
111 if test -n "$ISC"; then
112   AC_DEFINE(ISC) LIBS="$LIBS -linet"
115 dnl AC_CHECKING(for OSF1)
116 dnl if test -f /bin/uname ; then
117 dnl if test `/bin/uname` = OSF1 || test -f /osf_boot; then
118 dnl AC_DEFINE(OSF1)     # this disables MIPS again....
119 dnl fi
120 dnl fi
122 if test -f /sysV68 ; then
123 AC_DEFINE(sysV68)
126 AC_CHECKING(for MIPS)
127 if test -f /lib/libmld.a || test -f /usr/lib/libmld.a || test -f /usr/lib/cmplrs/cc/libmld.a; then
128 oldlibs="$LIBS"
129 test -f /bin/mx || LIBS="$LIBS -lmld" # for nlist. But not on alpha.
130 dnl djm@eng.umd.edu: "... for one thing, it doubles the size of the executable"
131 AC_CHECKING(mld library)
132 AC_TRY_LINK(,,,LIBS="$oldlibs")
135 if test -r /dev/ptc; then
136 AC_DEFINE(MIPS)
137 AC_CHECKING(wait3)
138 AC_TRY_LINK(,[wait3();], ,
139 AC_CHECKING(wait2)
140 AC_TRY_LINK(,[wait2();],
141 dnl John Rouillard (rouilj@sni-usa.com):
142 dnl need -I/usr/include/bsd in RISCOS otherwise sockets are broken, no
143 dnl job control etc.
144 dnl Detect RISCOS if wait2 is present, but not wait3.
145 AC_DEFINE(USE_WAIT2) LIBS="$LIBS -lbsd" ; CC="$CC -I/usr/include/bsd"
151 AC_CHECKING(for Ultrix)
152 AC_EGREP_CPP(yes,
153 [#if defined(ultrix) || defined(__ultrix)
154    yes;
155 #endif
156 ], ULTRIX=1)
158 if test -f /usr/lib/libpyr.a ; then
159 oldlibs="$LIBS"
160 LIBS="$LIBS -lpyr"
161 AC_CHECKING(Pyramid OSX)
162 AC_TRY_LINK(,[open_controlling_pty("")], AC_DEFINE(OSX), LIBS="$oldlibs")
165 dnl ghazi@caip.rutgers.edu (Kaveh R. Ghazi):
166 dnl BBN butterfly is not POSIX, but a MACH BSD system.
167 dnl Do not define POSIX and TERMIO.
168 AC_CHECKING(for butterfly)
169 AC_EGREP_CPP(yes,
170 [#if defined(butterfly)
171   yes;
172 #endif
173 ], butterfly=1)
175 if test -z "$butterfly"; then
176 if test -n "$ULTRIX"; then
177   test -z "$GCC" && CC="$CC -YBSD"
179 AC_CHECKING(for POSIX.1)
180 AC_EGREP_CPP(yes,
181 [#include <sys/types.h>
182 #include <unistd.h>
183 main () {
184 #ifdef _POSIX_VERSION
185   yes;
186 #endif
187 ], AC_NOTE(- you have a POSIX system) AC_DEFINE(POSIX) posix=1)
190 AC_CHECKING(for System V)
191 AC_TRY_COMPILE(
192 [#include <sys/types.h>
193 #include <signal.h>
194 #include <fcntl.h>], [int x = SIGCHLD | FNDELAY;], , AC_DEFINE(SYSV))
196 AC_CHECKING(for sequent/ptx)
197 AC_EGREP_CPP(yes,
198 [#ifdef _SEQUENT_
199   yes;
200 #endif
201 ], LIBS="$LIBS -lsocket -linet";seqptx=1)
203 oldlibs="$LIBS"
204 LIBS="$LIBS -lelf"
205 AC_CHECKING(SVR4)
206 AC_TRY_LINK([#include <utmpx.h>
208 [AC_CHECK_HEADER(dwarf.h, AC_DEFINE(SVR4) AC_DEFINE(BUGGYGETLOGIN),
209 [AC_CHECK_HEADER(elf.h, AC_DEFINE(SVR4) AC_DEFINE(BUGGYGETLOGIN))])]
210 ,LIBS="$oldlibs")
211 AC_CHECK_HEADERS([stropts.h string.h strings.h])
213 AC_CHECKING(for Solaris 2.x)
214 AC_EGREP_CPP(yes,
215 [#if defined(SVR4) && defined(sun)
216   yes
217 #endif
218 ], LIBS="$LIBS -lsocket -lnsl -lkstat")
221 dnl    ****  typedefs ****
223 dnl (currently not used)
225 dnl AC_CHECKING(for pid_t)
226 dnl AC_EGREP_CPP(pid_t,[#include <sys/types.h>
227 dnl ],AC_DEFINE(PID_T_DEFINED))
229 dnl AC_CHECKING(for sig_t)
230 dnl AC_EGREP_CPP(sig_t,[#include <sys/types.h>
231 dnl #include <signal.h>
232 dnl ],AC_DEFINE(SIG_T_DEFINED))
234 dnl AC_CHECKING(for uid_t)
235 dnl AC_EGREP_CPP(uid_t,[#include <sys/types.h>
236 dnl ],AC_DEFINE(UID_T_DEFINED))
240 dnl   ****     Job control     ****
243 AC_CHECKING(BSD job jontrol)
244 AC_TRY_LINK(
245 [#include <sys/types.h>
246 #include <sys/ioctl.h>
247 ], [
248 #ifdef POSIX
249 tcsetpgrp(0, 0);
250 #else
251 int x = TIOCSPGRP;
252 #ifdef SYSV
253 setpgrp();
254 #else
255 int y = TIOCNOTTY;
256 #endif
257 #endif
258 ], AC_NOTE(- you have jobcontrol) AC_DEFINE(BSDJOBS), AC_NOTE(- you don't have jobcontrol))
261 dnl    ****  setresuid(), setreuid(), seteuid()  ****
263 AC_CHECKING(setresuid)
264 AC_TRY_LINK(,[
265 setresuid(0, 0, 0);
266 ], AC_DEFINE(HAVE_SETRESUID))
267 AC_CHECKING(setreuid)
268 AC_TRY_LINK(,[
269 setreuid(0, 0);
270 ], AC_DEFINE(HAVE_SETREUID))
272 dnl seteuid() check:
273 dnl   linux seteuid was broken before V1.1.11
274 dnl   NeXT, AUX, ISC, and ultrix are still broken (no saved uid support)
275 dnl   Solaris seteuid doesn't change the saved uid, bad for
276 dnl     multiuser screen sessions
277 AC_CHECKING(seteuid)
278 AC_TRY_LINK(,[
279 #if defined(linux) || defined(NeXT) || defined(_AUX_SOURCE) || defined(AUX) || defined(ultrix) || (defined(sun) && defined(SVR4)) || defined(ISC) || defined(sony_news)
280 seteuid_is_broken(0);
281 #else
282 seteuid(0);
283 #endif
284 ], AC_DEFINE(HAVE_SETEUID))
287 dnl    ****  select()  ****
290 AC_CHECKING(select)
291 AC_TRY_LINK(,[select(0, 0, 0, 0, 0);],, 
292 LIBS="$LIBS -lnet -lnsl"
293 AC_CHECKING(select with $LIBS)
294 AC_TRY_LINK(,[select(0, 0, 0, 0, 0);],, 
295 AC_MSG_ERROR(!!! no select - no screen))
298 dnl    ****  FIFO tests  ****
301 AC_CHECKING(fifos)
302 AC_TRY_RUN([
303 /* For select - According to POSIX 1003.1-2001 */
304 #include <sys/select.h>
306 /* For select - According to earlier standards */
307 #include <sys/time.h>
308 #include <sys/types.h>
309 #include <unistd.h>
311 #include <sys/stat.h>
312 #include <fcntl.h>
314 #ifndef O_NONBLOCK
315 #define O_NONBLOCK O_NDELAY
316 #endif
317 #ifndef S_IFIFO
318 #define S_IFIFO 0010000
319 #endif
321 char *fin = "/tmp/conftest$$";
323 main()
325   struct stat stb;
326   fd_set f;
328   (void)alarm(5);
329   unlink(fin);
330 #ifdef POSIX
331   if (mkfifo(fin, 0777))
332 #else
333   if (mknod(fin, S_IFIFO|0777, 0))
334 #endif
335     exit(1);
336   if (stat(fin, &stb) || (stb.st_mode & S_IFIFO) != S_IFIFO)
337     exit(1);
338   close(0);
339 #ifdef __386BSD__
340   /*
341    * The next test fails under 386BSD, but screen works using fifos.
342    * Fifos in O_RDWR mode are only used for the BROKEN_PIPE case and for
343    * the select() configuration test.
344    */
345   exit(0);
346 #endif
347   if (open(fin, O_RDONLY | O_NONBLOCK))
348     exit(1);
349   if (fork() == 0)
350     {
351       close(0);
352       if (open(fin, O_WRONLY | O_NONBLOCK))
353         exit(1);
354       close(0);
355       if (open(fin, O_WRONLY | O_NONBLOCK))
356         exit(1);
357       if (write(0, "TEST", 4) == -1)
358         exit(1);
359       exit(0);
360     }
361   FD_SET(0, &f);
362   if (select(1, &f, 0, 0, 0) == -1)
363     exit(1);
364   exit(0);
366 ], AC_NOTE(- your fifos are usable) fifo=1,
367 AC_NOTE(- your fifos are not usable))
368 rm -f /tmp/conftest*
370 if test -n "$fifo"; then
371 AC_CHECKING(for broken fifo implementation)
372 AC_TRY_RUN([
373 /* For select - According to POSIX 1003.1-2001 */
374 #include <sys/select.h>
376 /* For select - According to earlier standards */
377 #include <sys/time.h>
378 #include <sys/types.h>
379 #include <unistd.h>
381 #include <sys/stat.h>
382 #include <fcntl.h>
384 #ifndef O_NONBLOCK
385 #define O_NONBLOCK O_NDELAY
386 #endif
387 #ifndef S_IFIFO
388 #define S_IFIFO 0010000
389 #endif
391 char *fin = "/tmp/conftest$$";
393 main()
395   struct timeval tv;
396   fd_set f;
398 #ifdef POSIX
399   if (mkfifo(fin, 0600))
400 #else
401   if (mknod(fin, S_IFIFO|0600, 0))
402 #endif
403     exit(1);
404   close(0);
405   if (open(fin, O_RDONLY|O_NONBLOCK))
406     exit(1);
407   FD_SET(0, &f);
408   tv.tv_sec = 1;
409   tv.tv_usec = 0;
410   if (select(1, &f, 0, 0, &tv))
411     exit(1);
412   exit(0);
414 ], AC_NOTE(- your implementation is ok), 
415 AC_NOTE(- you have a broken implementation) AC_DEFINE(BROKEN_PIPE) fifobr=1)
416 rm -f /tmp/conftest*
420 dnl    ****  SOCKET tests  ****
421 dnl 
422 dnl     may need        LIBS="$LIBS -lsocket"   here
425 AC_CHECKING(sockets)
426 AC_TRY_RUN([
427 /* For select - According to POSIX 1003.1-2001 */
428 #include <sys/select.h>
430 /* For select - According to earlier standards */
431 #include <sys/time.h>
432 #include <sys/types.h>
433 #include <unistd.h>
435 #include <sys/stat.h>
436 #include <fcntl.h>
437 #include <sys/socket.h>
438 #include <sys/un.h>
440 char *son = "/tmp/conftest$$";
442 main()
444   int s1, s2, l;
445   struct sockaddr_un a;
446   fd_set f;
448   (void)alarm(5);
449   if ((s1 = socket(AF_UNIX, SOCK_STREAM, 0)) == -1)
450     exit(1);
451   a.sun_family = AF_UNIX;
452   strcpy(a.sun_path, son);
453   (void) unlink(son);
454   if (bind(s1, (struct sockaddr *) &a, strlen(son)+2) == -1)
455     exit(1);
456   if (listen(s1, 2))
457     exit(1);
458   if (fork() == 0)
459     {
460       if ((s2 = socket(AF_UNIX, SOCK_STREAM, 0)) == -1)
461         kill(getppid(), 3);
462       (void)connect(s2, (struct sockaddr *)&a, strlen(son) + 2);
463       if (write(s2, "HELLO", 5) == -1)
464         kill(getppid(), 3);
465       exit(0);
466     }
467   l = sizeof(a);
468   close(0);
469   if (accept(s1, &a, &l))
470     exit(1);
471   FD_SET(0, &f);
472   if (select(1, &f, 0, 0, 0) == -1)
473     exit(1);
474   exit(0);
476 ], AC_NOTE(- your sockets are usable) sock=1,
477 AC_NOTE(- your sockets are not usable))
478 rm -f /tmp/conftest*
480 if test -n "$sock"; then
481 AC_CHECKING(socket implementation)
482 AC_TRY_RUN([
483 /* For select - According to POSIX 1003.1-2001 */
484 #include <sys/select.h>
486 /* For select - According to earlier standards */
487 #include <sys/time.h>
488 #include <sys/types.h>
489 #include <unistd.h>
491 #include <sys/stat.h>
492 #include <sys/socket.h>
493 #include <sys/un.h>
495 char *son = "/tmp/conftest$$";
497 main()
499   int s;
500   struct stat stb;
501   struct sockaddr_un a;
502   if ((s = socket(AF_UNIX, SOCK_STREAM, 0)) == -1)
503     exit(0);
504   a.sun_family = AF_UNIX;
505   strcpy(a.sun_path, son);
506   (void) unlink(son);
507   if (bind(s, (struct sockaddr *) &a, strlen(son)+2) == -1)
508     exit(0);
509   if (stat(son, &stb))
510     exit(1);
511   close(s);
512   exit(0);
514 ],AC_NOTE(- you are normal),
515 AC_NOTE(- unix domain sockets are not kept in the filesystem)
516 AC_DEFINE(SOCK_NOT_IN_FS) socknofs=1)
517 rm -f /tmp/conftest*
522 dnl    ****  choose sockets or fifos  ****
524 if test -n "$fifo"; then
525   if test -n "$sock"; then
526     if test -n "$nore"; then
527       AC_NOTE(- hmmm... better take the fifos)
528       AC_DEFINE(NAMEDPIPE)
529     elif test -n "$fifobr"; then
530       AC_NOTE(- as your fifos are broken lets use the sockets.)
531     else
532       AC_NOTE(- both sockets and fifos usable. let's take sockets.)
533     fi
534   else
535     AC_NOTE(- using named pipes, of course)
536     AC_DEFINE(NAMEDPIPE)
537   fi
538 elif test -n "$sock"; then
539   AC_NOTE(- using unix-domain sockets, of course)
540 else
541   AC_MSG_ERROR(you have neither usable sockets nor usable pipes -> no screen)
545 dnl    ****  check the select implementation ****
548 AC_CHECKING(select return value)
549 AC_TRY_RUN([
550 /* For select - According to POSIX 1003.1-2001 */
551 #include <sys/select.h>
553 /* For select - According to earlier standards */
554 #include <sys/time.h>
555 #include <sys/types.h>
556 #include <unistd.h>
558 #include <sys/stat.h>
559 #include <fcntl.h>
561 char *nam = "/tmp/conftest$$";
563 #ifdef NAMEDPIPE
565 #ifndef O_NONBLOCK
566 #define O_NONBLOCK O_NDELAY
567 #endif
568 #ifndef S_IFIFO
569 #define S_IFIFO 0010000
570 #endif
573 main()
575   fd_set f;
577 #ifdef __FreeBSD__
578 /* From Andrew A. Chernov (ache@astral.msk.su):
579  * opening RDWR fifo fails in BSD 4.4, but select return values are
580  * right.
581  */
582   exit(0);
583 #endif
584   (void)alarm(5);
585 #ifdef POSIX
586   if (mkfifo(nam, 0777))
587 #else
588   if (mknod(nam, S_IFIFO|0777, 0))
589 #endif
590     exit(1);
591   close(0);
592   if (open(nam, O_RDWR | O_NONBLOCK))
593     exit(1);
594   if (write(0, "TEST", 4) == -1)
595     exit(1);
597 #else
599 #include <sys/types.h>
600 #include <sys/socket.h>
601 #include <sys/un.h>
603 main()
605   int s1, s2, l;
606   struct sockaddr_un a;
607   fd_set f;
609   (void)alarm(5);
610   if ((s1 = socket(AF_UNIX, SOCK_STREAM, 0)) == -1)
611     exit(1);
612   a.sun_family = AF_UNIX;
613   strcpy(a.sun_path, nam);
614   (void) unlink(nam);
615   if (bind(s1, (struct sockaddr *) &a, strlen(nam)+2) == -1)
616     exit(1);
617   if (listen(s1, 2))
618     exit(1);
619   if (fork() == 0)
620     {
621       if ((s2 = socket(AF_UNIX, SOCK_STREAM, 0)) == -1)
622         kill(getppid(), 3);
623       (void)connect(s2, (struct sockaddr *)&a, strlen(nam) + 2);
624       if (write(s2, "HELLO", 5) == -1)
625         kill(getppid(), 3);
626       exit(0);
627     }
628   l = sizeof(a);
629   close(0);
630   if (accept(s1, (struct sockaddr *)&a, &l))
631     exit(1);
632 #endif
635   FD_SET(0, &f);
636   if (select(1, &f, 0, 0, 0) == -1)
637     exit(1);
638   if (select(1, &f, &f, 0, 0) != 2)
639     exit(1);
640   exit(0);
642 ],AC_NOTE(- select is ok),
643 AC_NOTE(- select can't count) AC_DEFINE(SELECT_BROKEN))
646 dnl    ****  termcap or terminfo  ****
648 AC_CHECKING(for tgetent)
649 AC_TRY_LINK(,tgetent((char *)0, (char *)0);,,
650 olibs="$LIBS"
651 LIBS="-lcurses $olibs"
652 AC_CHECKING(libcurses)
653 AC_TRY_LINK(,[
654 #ifdef __hpux
655 __sorry_hpux_libcurses_is_totally_broken_in_10_10();
656 #else
657 tgetent((char *)0, (char *)0);
658 #endif
660 LIBS="-ltermcap $olibs"
661 AC_CHECKING(libtermcap)
662 AC_TRY_LINK(,tgetent((char *)0, (char *)0);,,
663 LIBS="-ltermlib $olibs"
664 AC_CHECKING(libtermlib)
665 AC_TRY_LINK(,tgetent((char *)0, (char *)0);,,
666 LIBS="-lncursesw $olibs"
667 AC_CHECKING(libncursesw)
668 AC_TRY_LINK(,tgetent((char *)0, (char *)0);,,
669 LIBS="-lncurses $olibs"
670 AC_CHECKING(libncurses)
671 AC_TRY_LINK(,tgetent((char *)0, (char *)0);,,
672 AC_MSG_ERROR(!!! no tgetent - no screen)))))))
674 AC_TRY_RUN([
675 main()
677  exit(strcmp(tgoto("%p1%d", 0, 1), "1") ? 0 : 1);
678 }], AC_NOTE(- you use the termcap database),
679 AC_NOTE(- you use the terminfo database) AC_DEFINE(TERMINFO))
680 AC_CHECKING(ospeed)
681 AC_TRY_LINK(extern short ospeed;,ospeed=5;,,AC_DEFINE(NEED_OSPEED))
684 dnl    ****  PTY specific things  ****
686 AC_CHECKING(for /dev/ptc)
687 if test -r /dev/ptc; then
688 AC_DEFINE(HAVE_DEV_PTC)
691 AC_CHECKING(for SVR4 ptys)
692 sysvr4ptys=
693 if test -c /dev/ptmx ; then
694 AC_TRY_LINK([],[ptsname(0);grantpt(0);unlockpt(0);],[AC_DEFINE(HAVE_SVR4_PTYS)
695 sysvr4ptys=1])
698 AC_CHECK_FUNCS(getpt)
700 dnl check for openpty()
701 if test -z "$sysvr4ptys"; then
702 AC_CHECK_FUNCS(openpty,,
703 [AC_CHECK_LIB(util,openpty, [AC_DEFINE(HAVE_OPENPTY)] [LIBS="$LIBS -lutil"])])
706 AC_CHECKING(for ptyranges)
707 if test -d /dev/ptym ; then
708 pdir='/dev/ptym'
709 else
710 pdir='/dev'
712 dnl SCO uses ptyp%d
713 AC_EGREP_CPP(yes,
714 [#ifdef M_UNIX
715    yes;
716 #endif
717 ], ptys=`echo /dev/ptyp??`, ptys=`echo $pdir/pty??`)
718 dnl if test -c /dev/ptyp19; then
719 dnl ptys=`echo /dev/ptyp??`
720 dnl else
721 dnl ptys=`echo $pdir/pty??`
722 dnl fi
723 if test "$ptys" != "$pdir/pty??" ; then
724 p0=`echo $ptys | tr ' ' '\012' | sed -e 's/^.*\(.\).$/\1/g' | sort -u | tr -d '\012'`
725 p1=`echo $ptys | tr ' ' '\012' | sed -e 's/^.*\(.\)$/\1/g'  | sort -u | tr -d '\012'`
726 AC_DEFINE_UNQUOTED(PTYRANGE0,"$p0")
727 AC_DEFINE_UNQUOTED(PTYRANGE1,"$p1")
730 dnl    ****  pty mode/group handling ****
732 dnl support provided by Luke Mewburn <lm@rmit.edu.au>, 931222
733 AC_ARG_WITH(pty-mode, [  --with-pty-mode=mode    default mode for ptys], [ ptymode="${withval}" ])
734 AC_ARG_WITH(pty-group, [  --with-pty-group=group  default group for ptys], [ ptygrp="${withval}" ])
735 test -n "$ptymode" || ptymode=0620
736 if test -n "$ptygrp" ; then
737 AC_DEFINE_UNQUOTED(PTYMODE, $ptymode)
738 AC_DEFINE_UNQUOTED(PTYGROUP,$ptygrp)
739 else
741 AC_CHECKING(default tty permissions/group)
742 rm -f conftest_grp
743 AC_TRY_RUN([
744 #include <sys/types.h>
745 #include <sys/stat.h>
746 #include <stdio.h>
747 main()
749   struct stat sb;
750   char *x,*ttyname();
751   int om, m;
752   FILE *fp;
754   if (!(x = ttyname(0))) exit(1);
755   if (stat(x, &sb)) exit(1);
756   om = sb.st_mode;
757   if (om & 002) exit(0);
758   m = system("mesg y");
759   if (m == -1 || m == 127) exit(1);
760   if (stat(x, &sb)) exit(1);
761   m = sb.st_mode;
762   if (chmod(x, om)) exit(1);
763   if (m & 002) exit(0);
764   if (sb.st_gid == getgid()) exit(1);
765   if (!(fp=fopen("conftest_grp", "w")))
766     exit(1);
767   fprintf(fp, "%d\n", sb.st_gid);
768   fclose(fp);
769   exit(0);
772     if test -f conftest_grp; then
773         ptygrp=`cat conftest_grp`
774         AC_NOTE([- pty mode: $ptymode, group: $ptygrp])
775         AC_DEFINE_UNQUOTED(PTYMODE, $ptymode)
776         AC_DEFINE_UNQUOTED(PTYGROUP,$ptygrp)
777     else
778         AC_NOTE(- ptys are world accessable)
779     fi
781     WRITEPATH=''
782     XTERMPATH=''
783     AC_PATH_PROG(WRITEPATH, write)
784     AC_PATH_PROG(XTERMPATH, xterm)
785     found=
786     if test -n "$WRITEPATH$XTERMPATH"; then
787       findfollow=
788       lsfollow=
789       found=`find $WRITEPATH $XTERMPATH -follow -print 2>/dev/null`
790       if test -n "$found"; then
791         findfollow=-follow
792         lsfollow=L
793       fi
794       if test -n "$XTERMPATH"; then
795         ptygrpn=`ls -l$lsfollow $XTERMPATH | sed -n -e 1p | $AWK '{print $4}'`
796         if test tty != "$ptygrpn"; then
797           XTERMPATH=
798         fi
799       fi
800     fi
801     if test -n "$WRITEPATH$XTERMPATH"; then
802       found=`find $WRITEPATH $XTERMPATH $findfollow -perm -2000 -print` 
803       if test -n "$found"; then
804         ptygrp=`ls -ln$lsfollow $found | sed -n -e 1p | $AWK '{print $4}'`
805         AC_NOTE([- pty mode: $ptymode, group: $ptygrp])
806         AC_DEFINE_UNQUOTED(PTYMODE, $ptymode)
807         AC_DEFINE_UNQUOTED(PTYGROUP,$ptygrp)
808       else
809         AC_NOTE(- ptys are world accessable)
810       fi
811     else
812       AC_NOTE(- can't determine - assume ptys are world accessable)
813     fi
814   ]
816 rm -f conftest_grp
820 dnl    ****  utmp handling  ****
822 AC_CHECKING(getutent)
823 AC_TRY_LINK([
824 #include <time.h> /* to get time_t on SCO */
825 #include <sys/types.h>
826 #if defined(SVR4) && !defined(DGUX)
827 #include <utmpx.h>
828 #define utmp utmpx
829 #else
830 #include <utmp.h>
831 #endif
832 #ifdef __hpux
833 #define pututline _pututline
834 #endif
836 [int x = DEAD_PROCESS; pututline((struct utmp *)0); getutent();], AC_DEFINE(GETUTENT),
837 olibs="$LIBS"
838 LIBS="$LIBS -lgen"
839 AC_CHECKING(getutent with -lgen)
840 AC_TRY_LINK([
841 #include <time.h>
842 #include <sys/types.h>
843 #if defined(SVR4) && !defined(DGUX)
844 #include <utmpx.h>
845 #define utmp utmpx
846 #else
847 #include <utmp.h>
848 #endif
849 #ifdef __hpux
850 #define pututline _pututline
851 #endif
853 [int x = DEAD_PROCESS; pututline((struct utmp *)0); getutent();], AC_DEFINE(GETUTENT), LIBS="$olibs")
855 AC_CHECKING(ut_host)
856 AC_TRY_COMPILE([
857 #include <time.h>
858 #include <sys/types.h>
859 #if defined(SVR4) && !defined(DGUX)
860 #include <utmpx.h>
861 #define utmp utmpx
862 #else
863 #include <utmp.h>
864 #endif
865 ],[struct utmp u; u.ut_host[0] = 0;], AC_DEFINE(UTHOST))
866 AC_CHECK_HEADER(utempter.h, have_utempter=yes, have_utempter=no)
867 if test "$have_utempter" = yes; then
868   AC_DEFINE(HAVE_UTEMPTER)
869   LIBS="$LIBS -lutempter"
873 dnl    ****  loadav  ****
875 AC_CHECKING(for libutil(s))
876 test -f /usr/lib/libutils.a && LIBS="$LIBS -lutils"
877 test -f /usr/lib/libutil.a && LIBS="$LIBS -lutil"
879 AC_CHECKING(getloadavg)
880 AC_TRY_LINK(,[getloadavg((double *)0, 0);],
881 AC_DEFINE(LOADAV_GETLOADAVG) load=1,
882 if test -f /usr/lib/libkvm.a ; then
883 olibs="$LIBS"
884 LIBS="$LIBS -lkvm"
885 AC_CHECKING(getloadavg with -lkvm)
886 AC_TRY_LINK(,[getloadavg((double *)0, 0);],
887 AC_DEFINE(LOADAV_GETLOADAVG) load=1, LIBS="$olibs")
891 if test -z "$load" ; then
892 AC_EGREP_CPP(yes,
893 [#if defined(NeXT) || defined(apollo) || defined(linux)
894   yes;
895 #endif
896 ], load=1)
898 if test -z "$load" ; then
899 AC_CHECKING(for kernelfile)
900 for core in /unix /vmunix /dynix /hp-ux /xelos /dev/ksyms /kernel/unix /kernel/genunix /unicos /mach /netbsd /386bsd /dgux /bsd /stand/vmunix; do
901   if test -f $core || test -c $core; then
902     break
903   fi
904 done
905 if test ! -f $core && test ! -c $core ; then
906   AC_NOTE(- no kernelfile found)
907 else
908   AC_NOTE(- using kernelfile '$core')
909   if test -r $core ; then
910   AC_DEFINE_UNQUOTED(LOADAV_UNIX,"$core")
911   AC_CHECK_HEADER(nlist.h,
912     [AC_DEFINE(NLIST_STRUCT)
913      AC_CHECKING(n_un in struct nlist)
914      AC_TRY_COMPILE([#include <nlist.h>],
915        [struct nlist n; n.n_un.n_name = 0;],
916         AC_DEFINE(NLIST_NAME_UNION))])
918   AC_CHECKING(for nlist declaration)
919   AC_EGREP_CPP([nlist(( |       )( |    )*.*\(|\()],[
920 #ifdef NLIST_STRUCT
921 # include <nlist.h>
922 #else
923 # include <a.out.h>
924 #endif
925 ],AC_DEFINE(NLIST_DECLARED))
927   AC_CHECKING(for avenrun symbol)
928   nlist64=
929   for av in avenrun _avenrun _Loadavg avenrun _avenrun _Loadavg; do
930   AC_TRY_RUN([
931 #include <sys/types.h>
932 #ifdef NLIST_STRUCT
933 #include <nlist.h>
934 #else
935 #include <a.out.h>
936 #endif
938 $nlist64
940 struct nlist nl[2];
942 main()
944 #if !defined(_AUX_SOURCE) && !defined(AUX)
945 # ifdef NLIST_NAME_UNION
946   nl[0].n_un.n_name = "$av";
947 # else
948   nl[0].n_name = "$av";
949 # endif
950 #else
951   strncpy(nl[0].n_name, "$av", sizeof(nl[0].n_name));
952 #endif
953   nlist(LOADAV_UNIX, nl);
954   if (nl[0].n_value == 0)
955     exit(1);
956   exit(0);
958   ],avensym=$av;break)
959   if test "$av" = _Loadavg; then
960     nlist64='#define nlist nlist64'
961   fi
962   done
963   if test -z "$avensym" ; then
964     AC_NOTE(- no avenrun symbol found)
965   else
966     AC_NOTE(- using avenrun symbol '$avensym')
967     AC_DEFINE_UNQUOTED(LOADAV_AVENRUN,"$avensym")
968     if test -n "$nlist64"; then
969       AC_NOTE(- used nlist64 to find it)
970       AC_DEFINE(LOADAV_USE_NLIST64)
971     fi
972     load=1
973   fi
974   else
975     AC_NOTE(  Can't configure the load average display feature)
976     AC_NOTE(  because $core is not readable by you.)
977     AC_NOTE(  To configure the load average display feature,)
978     AC_NOTE(  re-run configure as root if possible.)
979     AC_NOTE(  If you are not the system administrator then disregard)
980     AC_NOTE(  this warning.  You can still use screen without)
981     AC_NOTE(  the load average display feature.)
982   fi
986 AC_PROGRAM_SOURCE([
987 #include <sys/types.h>
988 #include <sys/param.h>
990 #if !defined(LOADAV_GETLOADAVG) && ((defined(hp300) && !defined(__hpux)) || defined(sun) || (defined(ultrix) && defined(mips)) || defined(_SEQUENT_) || defined(sgi) || (defined(SVR4) && !defined(__hpux)) || defined(sony_news) || (!defined(__osf__) && defined(__alpha)) || defined(_IBMR2) || defined(_AUX_SOURCE) || defined(AUX) || defined(m88k))
991 loadtype=long
992 # if defined(apollo) || defined(_IBMR2) || defined(_AUX_SOURCE) || defined(AUX)
993 loadscale=65536
994 # else
995 #  if defined(FSCALE) && !defined(__osf__)
996 #   undef FSCALE
997 loadscale=FSCALE
998 #  else
999 #   ifdef sgi
1000 loadtype=int
1001 loadscale=1024
1002 #   else
1003 #    if defined(MIPS) || defined(SVR4) || defined(m88k)
1004 loadscale=256
1005 #    else /* not MIPS */
1006 loadscale=1000  /* our default value */
1007 #    endif /* MIPS */
1008 #   endif /* sgi */
1009 #  endif /* not FSCALE */
1010 # endif /* not apollo */
1011 #else
1012 loadtype=double
1013 loadscale=1
1014 #endif
1015 #ifdef alliant
1016 loadnum=4
1017 #else
1018 loadnum=3
1019 #endif
1022 if test -n "$load" ; then AC_DEFINE(LOADAV) fi
1023 if test -n "$loadtype" ; then AC_DEFINE_UNQUOTED(LOADAV_TYPE,$loadtype) fi
1024 if test -n "$loadnum" ; then AC_DEFINE_UNQUOTED(LOADAV_NUM,$loadnum) fi
1025 if test -n "$loadscale" ; then AC_DEFINE_UNQUOTED(LOADAV_SCALE,$loadscale) fi
1028 dnl    ****  signal handling  ****
1030 if test -n "$posix" ; then
1032 dnl POSIX has reliable signals with void return type.
1033 AC_NOTE(assuming posix signal definition)
1034 AC_DEFINE(SIGVOID)
1036 else
1038 AC_CHECKING(return type of signal handlers)
1039 AC_TRY_COMPILE(
1040 [#include <sys/types.h>
1041 #include <signal.h>
1042 #ifdef signal
1043 #undef signal
1044 #endif
1045 extern void (*signal ()) ();], [int i;], AC_DEFINE(SIGVOID))
1046 AC_CHECKING(sigset)
1047 AC_TRY_LINK([
1048 #include <sys/types.h>
1049 #include <signal.h>
1051 #ifdef SIGVOID
1052 sigset(0, (void (*)())0);
1053 #else
1054 sigset(0, (int (*)())0);
1055 #endif
1056 ], AC_DEFINE(USESIGSET))
1057 AC_CHECKING(signal implementation)
1058 AC_TRY_RUN([
1059 #include <sys/types.h>
1060 #include <signal.h>
1062 #ifndef SIGCLD
1063 #define SIGCLD SIGCHLD
1064 #endif
1065 #ifdef USESIGSET
1066 #define signal sigset
1067 #endif
1069 int got;
1071 #ifdef SIGVOID
1072 void
1073 #endif
1074 hand()
1076   got++;
1079 main()
1081   /* on hpux we use sigvec to get bsd signals */
1082 #ifdef __hpux
1083   (void)signal(SIGCLD, hand);
1084   kill(getpid(), SIGCLD);
1085   kill(getpid(), SIGCLD);
1086   if (got < 2)
1087     exit(1);
1088 #endif
1089   exit(0);
1091 ],,AC_DEFINE(SYSVSIGS))
1096 dnl    ****  libraries  ****
1099 AC_CHECKING(for crypt and sec libraries)
1100 test -f /lib/libcrypt_d.a || test -f /usr/lib/libcrypt_d.a && LIBS="$LIBS -lcrypt_d"
1101 oldlibs="$LIBS"
1102 LIBS="$LIBS -lcrypt"
1103 AC_CHECKING(crypt)
1104 AC_TRY_LINK(,,,LIBS="$oldlibs")
1105 test -f /lib/libsec.a || test -f /usr/lib/libsec.a && LIBS="$LIBS -lsec"
1106 test -f /lib/libshadow.a || test -f /usr/lib/libshadow.a && LIBS="$LIBS -lshadow"
1107 oldlibs="$LIBS"
1108 LIBS="$LIBS -lsun"
1109 AC_CHECKING(IRIX sun library)
1110 AC_TRY_LINK(,,,LIBS="$oldlibs")
1112 AC_CHECKING(syslog)
1113 AC_TRY_LINK(,[closelog();], , [oldlibs="$LIBS"
1114 LIBS="$LIBS -lbsd"
1115 AC_CHECKING(syslog in libbsd.a)
1116 AC_TRY_LINK(, [closelog();], AC_NOTE(- found.), [LIBS="$oldlibs"
1117 AC_NOTE(- bad news: syslog missing.) AC_DEFINE(NOSYSLOG)])])
1119 AC_EGREP_CPP(yes,
1120 [#ifdef M_UNIX
1121    yes;
1122 #endif
1123 ], LIBS="$LIBS -lsocket -lcrypt_i")
1126 dnl    ****  misc things  ****
1128 AC_CHECKING(wait union)
1129 AC_TRY_COMPILE([#include <sys/types.h>
1130 #include <sys/wait.h>
1132   union wait x;
1133   int y;
1134 #ifdef WEXITSTATUS
1135   y = WEXITSTATUS(x);
1136 #endif
1137 ],AC_DEFINE(BSDWAIT))
1139 if test -z "$butterfly"; then
1140 AC_CHECKING(for termio or termios)
1141 AC_TRY_CPP([#include <termio.h>], AC_DEFINE(TERMIO),
1142 if test -n "$posix"; then
1143 AC_TRY_CPP([#include <termios.h>], AC_DEFINE(TERMIO))
1148 dnl AC_CHECK_HEADER(shadow.h, AC_DEFINE(SHADOWPW))
1149 AC_CHECKING(getspnam)
1150 AC_TRY_LINK([#include <shadow.h>], [getspnam("x");],AC_DEFINE(SHADOWPW))
1152 AC_CHECKING(getttyent)
1153 AC_TRY_LINK(,[getttyent();], AC_DEFINE(GETTTYENT))
1155 AC_CHECKING(fdwalk)
1156 AC_TRY_LINK([#include <stdlib.h>], [fdwalk(NULL, NULL);],AC_DEFINE(HAVE_FDWALK))
1158 AC_CHECKING(whether memcpy/memmove/bcopy handles overlapping arguments)
1159 AC_TRY_RUN([
1160 main() {
1161   char buf[10];
1162   strcpy(buf, "abcdefghi");
1163   bcopy(buf, buf + 2, 3);
1164   if (strncmp(buf, "ababcf", 6))
1165     exit(1);
1166   strcpy(buf, "abcdefghi");
1167   bcopy(buf + 2, buf, 3);
1168   if (strncmp(buf, "cdedef", 6))
1169     exit(1);
1170   exit(0); /* libc version works properly.  */
1171 }], AC_DEFINE(USEBCOPY))
1173 AC_TRY_RUN([
1174 #define bcopy(s,d,l) memmove(d,s,l)
1175 main() {
1176   char buf[10];
1177   strcpy(buf, "abcdefghi");
1178   bcopy(buf, buf + 2, 3);
1179   if (strncmp(buf, "ababcf", 6))
1180     exit(1);
1181   strcpy(buf, "abcdefghi");
1182   bcopy(buf + 2, buf, 3);
1183   if (strncmp(buf, "cdedef", 6))
1184     exit(1);
1185   exit(0); /* libc version works properly.  */
1186 }], AC_DEFINE(USEMEMMOVE))
1189 AC_TRY_RUN([
1190 #define bcopy(s,d,l) memcpy(d,s,l)
1191 main() {
1192   char buf[10];
1193   strcpy(buf, "abcdefghi");
1194   bcopy(buf, buf + 2, 3);
1195   if (strncmp(buf, "ababcf", 6))
1196     exit(1);
1197   strcpy(buf, "abcdefghi");
1198   bcopy(buf + 2, buf, 3);
1199   if (strncmp(buf, "cdedef", 6))
1200     exit(1);
1201   exit(0); /* libc version works properly.  */
1202 }], AC_DEFINE(USEMEMCPY))
1204 AC_MSG_CHECKING(long file names)
1205 (echo 1 > /tmp/conftest9012345) 2>/dev/null
1206 (echo 2 > /tmp/conftest9012346) 2>/dev/null
1207 val=`cat /tmp/conftest9012345 2>/dev/null`
1208 if test -f /tmp/conftest9012345 && test "$val" = 1; then
1209 AC_MSG_RESULT(yes)
1210 else
1211 AC_MSG_RESULT(no)
1212 AC_DEFINE(NAME_MAX, 14)
1214 rm -f /tmp/conftest*
1216 AC_MSG_CHECKING(for vsprintf)
1217 AC_TRY_LINK(,[vsprintf(0,0,0);], AC_MSG_RESULT(yes);AC_DEFINE(USEVARARGS), AC_MSG_RESULT(no))
1219 AC_HEADER_DIRENT
1221 AC_MSG_CHECKING(for setenv)
1222 if test -z "$ac_setenv_args"; then
1223     AC_TRY_COMPILE(
1224     [#include <stdlib.h>],
1225     [
1226         setenv((char *) 0, (char *) 0, 0);
1227     ], ac_setenv_args=3)
1229 if test -z "$ac_setenv_args"; then
1230     AC_TRY_COMPILE(
1231     [#include <stdlib.h>],
1232     [
1233         setenv((char *) 0, (char *) 0);
1234     ], ac_setenv_args=2)
1236 if test -n "$ac_setenv_args"; then
1237     AC_DEFINE(USESETENV)
1238     if test "$ac_setenv_args" = 3; then
1239         AC_DEFINE(HAVE_SETENV_3)
1240     elif test "$ac_setenv_args" = 2; then
1241         AC_DEFINE(HAVE_SETENV_2)
1242     fi
1243 else
1244     AC_MSG_RESULT(no)
1245     AC_MSG_CHECKING(for putenv)
1246     AC_TRY_LINK(,[putenv((char *)0);unsetenv((char *)0);], AC_MSG_RESULT(yes) ,  AC_MSG_RESULT(no);AC_DEFINE(NEEDPUTENV))
1248 AC_MSG_CHECKING([for nl_langinfo(CODESET)])
1249 AC_TRY_LINK([
1250 #include <langinfo.h>
1251 ],[nl_langinfo(CODESET);], AC_MSG_RESULT(yes);AC_DEFINE(HAVE_NL_LANGINFO), AC_MSG_RESULT(no))
1253 AC_SEARCH_LIBS(gethostname, nsl)
1255 AC_CHECK_FUNCS(rename fchmod fchown strerror lstat _exit utimes vsnprintf getcwd setlocale strftime)
1257 AC_ARG_ENABLE(pam, [  --enable-pam            enable PAM support])
1258 if test "$enable_pam" = "yes"; then
1259     AC_MSG_CHECKING(for PAM support)
1260     oldlibs="$LIBS"
1261     LIBS="$LIBS -lpam"
1262     AC_TRY_LINK([#include <security/pam_appl.h>], [
1263         pam_start(0, 0, 0, 0);
1264         pam_authenticate(0, 0);
1265         pam_end(0,0);
1266     ], AC_MSG_RESULT(yes);AC_DEFINE(USE_PAM),
1267        AC_MSG_RESULT(no);LIBS="$oldlibs")
1270 AC_ARG_ENABLE(use_locale, [  --enable-locale         use localized month/day names])
1271 if test "$enable_use_locale" = "yes"; then
1272   AC_DEFINE(USE_LOCALE)
1274 AC_ARG_ENABLE(telnet, [  --enable-telnet         enable builtin telnet])
1275 if test "$enable_telnet" = "yes"; then
1276   AC_DEFINE(BUILTIN_TELNET)
1278 AC_ARG_ENABLE(colors256, [  --enable-colors256      enable support for 256 colors])
1279 if test "$enable_colors256" = "yes"; then
1280   AC_DEFINE(COLORS256)
1282 AC_ARG_ENABLE(rxvt_osc, [  --enable-rxvt_osc       enable support for rxvt OSC codes])
1283 if test "$enable_rxvt_osc" = "yes"; then
1284   AC_DEFINE(RXVT_OSC)
1288 dnl    ****  the end  ****
1290 if test -z "$old_CFLAGS"; then
1291   if test "x$CFLAGS" = "x-g"; then
1292     CFLAGS="-O"
1293   fi
1295 dnl Ptx bug workaround -- insert -lc after -ltermcap
1296 test -n "$seqptx" && LIBS="-ltermcap -lc -lsocket -linet -lnsl -lsec -lseq"
1298 PKG_CHECK_MODULES(LUA, [lua5.1], , [
1299     AC_MSG_RESULT(no)
1300     AC_MSG_ERROR([
1302 *** You need to have lua5.1 (http://www.lua.org/) installed.
1303 *** If you don't want support for lua scripting, please use the official repository
1304 *** (http://git.savannah.gnu.org/gitweb/?p=screen.git;a=summary).
1305 ])])
1307 AC_SUBST(LUA_CFLAGS)
1308 AC_SUBST(LUA_LIBS)
1310 AC_TRY_RUN(main(){exit(0);},,AC_MSG_ERROR(Can't run the compiler - internal error. Sorry.))
1312 AC_OUTPUT(Makefile doc/Makefile, [[
1313 # a hook for preserving undef directive in config.h
1314 mv config.h conftest
1315 sed -e 's@^\(.*\)defin.\( .*\) .*/\*\(.*KEEP_UNDEF_HERE\)@\1undef\2     /\*\3@' < conftest > config.h
1316 rm -f conftest
1319 echo ""
1320 if test -z "$AWK"; then
1321 echo "!!! Since you have no awk you must copy the files 'comm.h.dist'"
1322 echo "!!! and 'term.h.dist' to 'comm.h' and 'term.h'."
1323 echo "!!! Do _not_ change the user configuration section in config.h!"
1324 echo "Please check the pathnames in the Makefile."
1325 else
1326 echo "Now please check the pathnames in the Makefile and in the user"
1327 echo "configuration section in config.h."
1329 echo "Then type 'make' to make screen. Good luck."
1330 echo ""