Move PTY_NAME_SPRINTF, PTY_TTY_NAME_SPRINTF from src/s to configure
[bpt/emacs.git] / configure.ac
index eb29a26..191d2ae 100644 (file)
@@ -2722,11 +2722,14 @@ getpwent endpwent getgrent endgrent \
 touchlock \
 cfmakeraw cfsetspeed copysign __executable_start)
 
+dnl FIXME Fragile: something else may test for getwd as a dependency.
+dnl Change to defining BROKEN_xxx ?
 dnl getwd appears to be buggy on SVR4.2, so we don't use it.
 if test $opsys != unixware; then
   AC_CHECK_FUNCS(getwd)
 fi
 
+dnl FIXME Fragile: see above.
 ## Eric Backus <ericb@lsid.hp.com> says, HP-UX 9.x on HP 700 machines
 ## has a broken `rint' in some library versions including math library
 ## version number A.09.05.
@@ -3171,6 +3174,47 @@ case $opsys in
     AC_DEFINE(BROKEN_SIGAIO, 1, [Define if SIGAIO should not be used.])
     AC_DEFINE(BROKEN_SIGPOLL,1, [Define if SIGPOLL should not be used.])
     AC_DEFINE(BROKEN_SIGPTY, 1, [Define if SIGPTY should not be used.])
+
+    dnl On AIX Emacs uses the gmalloc.c malloc implementation.  But given
+    dnl the way this system works, libc functions that return malloced
+    dnl memory use the libc malloc implementation. Calling xfree or
+    dnl xrealloc on the results of such functions results in a crash.
+    dnl
+    dnl One solution for this could be to define SYSTEM_MALLOC in configure,
+    dnl but that does not currently work on this system.
+    dnl
+    dnl It is possible to completely override the malloc implementation on
+    dnl AIX, but that involves putting the malloc functions in a shared
+    dnl library and setting the MALLOCTYPE environment variable to point to
+    dnl that shared library.
+    dnl
+    dnl Emacs currently calls xrealloc on the results of get_current_dir name,
+    dnl to avoid a crash just use the Emacs implementation for that function.
+    dnl
+    dnl FIXME We could change the AC_CHECK_FUNCS call near the start
+    dnl of this file, so that we do not check for get_current_dir_name
+    dnl on AIX.  But that might be fragile if something else ends
+    dnl up testing for get_current_dir_name as a dependency.
+    AC_DEFINE(BROKEN_GET_CURRENT_DIR_NAME, 1, [Define if
+      get_current_dir_name should not be used.])
+    ;;
+
+  freebsd)
+    dnl Circumvent a bug in FreeBSD.  In the following sequence of
+    dnl writes/reads on a PTY, read(2) returns bogus data:
+    dnl
+    dnl write(2)  1022 bytes
+    dnl write(2)   954 bytes, get EAGAIN
+    dnl read(2)   1024 bytes in process_read_output
+    dnl read(2)     11 bytes in process_read_output
+    dnl
+    dnl That is, read(2) returns more bytes than have ever been written
+    dnl successfully.  The 1033 bytes read are the 1022 bytes written
+    dnl successfully after processing (for example with CRs added if the
+    dnl terminal is set up that way which it is here).  The same bytes will
+    dnl be seen again in a later read(2), without the CRs.
+    AC_DEFINE(BROKEN_PTY_READ_AFTER_EAGAIN, 1, [Define on FreeBSD to
+      work around an issue when reading from a PTY.])
     ;;
 
   dnl Define the following so emacs symbols will not conflict with those
@@ -3247,6 +3291,121 @@ case $opsys in
 esac
 
 
+dnl Used in process.c, this must be a loop, even if it only runs once.
+dnl (Except on SGI; see below.  Take that, clarity and consistency!)
+AH_TEMPLATE(PTY_ITERATION, [How to iterate over PTYs.])
+dnl Only used if !PTY_ITERATION.  Iterate from FIRST_PTY_LETTER to z,
+dnl trying suffixes 0-16.
+AH_TEMPLATE(FIRST_PTY_LETTER, [Letter to use in finding device name of
+  first PTY, if PTYs are supported.])
+AH_TEMPLATE(PTY_OPEN, [How to open a PTY, if non-standard.])
+AH_TEMPLATE(PTY_NAME_SPRINTF, [How to get the device name of the control
+  end of a PTY, if non-standard.])
+AH_TEMPLATE(PTY_TTY_NAME_SPRINTF, [How to get device name of the tty
+  end of a PTY, if non-standard.])
+
+case $opsys in
+  aix4-2 )
+    AC_DEFINE(PTY_ITERATION, [int c; for (c = 0; !c ; c++)] )
+    dnl You allocate a pty by opening /dev/ptc to get the master side.
+    dnl To get the name of the slave side, you just ttyname() the master side.
+    AC_DEFINE(PTY_NAME_SPRINTF, [strcpy (pty_name, "/dev/ptc");] )
+    AC_DEFINE(PTY_TTY_NAME_SPRINTF, [strcpy (pty_name, ttyname (fd));] )
+    ;;
+
+  cygwin )
+    AC_DEFINE(PTY_ITERATION, [int i; for (i = 0; i < 1; i++)] )
+    dnl multi-line AC_DEFINEs are hard. :(
+    AC_DEFINE(PTY_OPEN, [ do { int dummy; SIGMASKTYPE mask; mask = sigblock (sigmask (SIGCHLD)); if (-1 == openpty (&fd, &dummy, pty_name, 0, 0)) fd = -1; sigsetmask (mask); if (fd >= 0) emacs_close (dummy); } while (0)] )
+    AC_DEFINE(PTY_NAME_SPRINTF, [] )
+    AC_DEFINE(PTY_TTY_NAME_SPRINTF, [] )
+    ;;
+
+  darwin )
+    AC_DEFINE(PTY_ITERATION, [int i; for (i = 0; i < 1; i++)] )
+    dnl Not used, because PTY_ITERATION is defined.
+    AC_DEFINE(FIRST_PTY_LETTER, ['p'])
+    dnl Note that openpty may fork via grantpt on Mac OS X 10.4/Darwin 8.
+    dnl But we don't have to block SIGCHLD because it is blocked in the
+    dnl implementation of grantpt.
+    AC_DEFINE(PTY_OPEN, [ do { int slave; if (openpty (&fd, &slave, pty_name, NULL, NULL) == -1) fd = -1; else emacs_close (slave); } while (0)] )
+    AC_DEFINE(PTY_NAME_SPRINTF, [] )
+    AC_DEFINE(PTY_TTY_NAME_SPRINTF, [] )
+    ;;
+
+  gnu | freebsd | netbsd | openbsd )
+    AC_DEFINE(FIRST_PTY_LETTER, ['p'])
+    ;;
+
+  gnu-linux | gnu-kfreebsd )
+    dnl if HAVE_GRANTPT
+    if test "x$ac_cv_func_grantpt" = xyes; then
+      AC_DEFINE(PTY_ITERATION, [int i; for (i = 0; i < 1; i++)] )
+      dnl Note that grantpt and unlockpt may fork.  We must block SIGCHLD
+      dnl to prevent sigchld_handler from intercepting the child's death.
+      AC_DEFINE(PTY_TTY_NAME_SPRINTF, [{ char *ptyname; sigblock (sigmask (SIGCHLD)); if (grantpt (fd) == -1 || unlockpt (fd) == -1 || !(ptyname = ptsname(fd))) { sigunblock (sigmask (SIGCHLD)); close (fd); return -1; } snprintf (pty_name, sizeof pty_name, "%s", ptyname); sigunblock (sigmask (SIGCHLD)); }] )
+      dnl if HAVE_GETPT
+      if test "x$ac_cv_func_getpt" = xyes; then
+        AC_DEFINE(PTY_OPEN, [fd = getpt ()])
+        AC_DEFINE(PTY_NAME_SPRINTF, [] )
+      else
+        AC_DEFINE(PTY_NAME_SPRINTF, [strcpy (pty_name, "/dev/ptmx");] )
+      fi
+    else
+      AC_DEFINE(FIRST_PTY_LETTER, ['p'])
+    fi
+    ;;
+
+  hpux*)
+    AC_DEFINE(FIRST_PTY_LETTER, ['p'])
+    AC_DEFINE(PTY_NAME_SPRINTF, [sprintf (pty_name, "/dev/ptym/pty%c%x", c, i);] )
+    AC_DEFINE(PTY_TTY_NAME_SPRINTF, [sprintf (pty_name, "/dev/pty/tty%c%x", c, i);] )
+    ;;
+
+  irix6-5 )
+    dnl It looks like this cannot be right, because it is not a loop.
+    dnl However, process.c actually does this:
+    dnl # ifndef __sgi
+    dnl   continue;
+    dnl # else
+    dnl   return -1;
+    dnl # endif
+    dnl which presumably makes it OK, since irix == sgi (?).
+    dnl FIXME it seems like this special treatment is unnecessary?
+    dnl Why can't irix use a single-trip loop like eg cygwin?
+    AC_DEFINE(PTY_ITERATION, [])
+    dnl Not used, because PTY_ITERATION is defined.
+    AC_DEFINE(FIRST_PTY_LETTER, ['q'])
+    AC_DEFINE(PTY_OPEN, [ { struct sigaction ocstat, cstat; struct stat stb; char * name; sigemptyset(&cstat.sa_mask); cstat.sa_handler = SIG_DFL; cstat.sa_flags = 0; sigaction(SIGCLD, &cstat, &ocstat); name = _getpty (&fd, O_RDWR | O_NDELAY, 0600, 0); sigaction(SIGCLD, &ocstat, (struct sigaction *)0); if (name == 0) return -1; if (fd < 0) return -1; if (fstat (fd, &stb) < 0) return -1; strcpy (pty_name, name); }] )
+    dnl No need to get the pty name at all. 
+    AC_DEFINE(PTY_NAME_SPRINTF, [] )
+    dnl No need to use sprintf to get the tty name--we get that from _getpty.
+    AC_DEFINE(PTY_TTY_NAME_SPRINTF, [] )
+    ;;
+
+  sol2* )
+    dnl This change means that we don't loop through allocate_pty too
+    dnl many times in the (rare) event of a failure.
+    AC_DEFINE(FIRST_PTY_LETTER, ['z'])
+    AC_DEFINE(PTY_NAME_SPRINTF, [strcpy (pty_name, "/dev/ptmx");] )
+    dnl Uses sigblock/sigunblock rather than sighold/sigrelse,
+    dnl which appear to be BSD4.1 specific.  It may also be appropriate
+    dnl for SVR4.x (x<2) but I'm not sure.   fnf@cygnus.com
+    dnl On SysVr4, grantpt(3) forks a subprocess, so keep sigchld_handler()
+    dnl from intercepting that death.  If any child but grantpt's should die
+    dnl within, it should be caught after sigrelse(2).
+    AC_DEFINE(PTY_TTY_NAME_SPRINTF, [{ char *ptsname (int), *ptyname; sigblock (sigmask (SIGCLD)); if (grantpt (fd) == -1) { emacs_close (fd); return -1; } sigunblock (sigmask (SIGCLD)); if (unlockpt (fd) == -1) { emacs_close (fd); return -1; } if (!(ptyname = ptsname (fd))) { emacs_close (fd); return -1; } snprintf (pty_name, sizeof pty_name, "%s", ptyname); }] )
+    ;;
+
+  dnl Comments are as per sol2*.
+  unixware )
+    AC_DEFINE(FIRST_PTY_LETTER, ['z'])
+    AC_DEFINE(PTY_NAME_SPRINTF, [strcpy (pty_name, "/dev/ptmx");] )
+    AC_DEFINE(PTY_TTY_NAME_SPRINTF, [{ char *ptsname (int), *ptyname; sigblock(sigmask(SIGCLD)); if (grantpt(fd) == -1) fatal("could not grant slave pty"); sigunblock(sigmask(SIGCLD)); if (unlockpt(fd) == -1) fatal("could not unlock slave pty"); if (!(ptyname = ptsname(fd))) fatal ("could not enable slave pty"); snprintf (pty_name, sizeof pty_name, "%s", ptyname); }] )
+    ;;
+esac
+
+
 AH_TEMPLATE(SIGNALS_VIA_CHARACTERS, [Make process_send_signal work by
 "typing" a signal character on the pty.])
 
@@ -3365,33 +3524,77 @@ case $opsys in
     ;;
 esac
 
+
+AH_TEMPLATE(TAB3, [Undocumented.])
+
 case $opsys in
-   gnu) opsysfile="s/bsd-common.h" ;;
-
-   gnu-kfreebsd) opsysfile="s/gnu-linux.h" ;;
-
-   hpux11)
-     dnl See comments in sysdep.c:sys_signal.
-     dnl SA_RESTART resets the timeout of `select' on hpux11.
-     dnl Defining BROKEN_SA_RESTART is not the same as undef'ing SA_RESTART.
-     AC_DEFINE(BROKEN_SA_RESTART, 1, [Define if SA_RESTART should only
-       be used in batch mode.])
-     dnl It works to open the pty's tty in the parent (Emacs), then
-     dnl close and reopen it in the child.
-     AC_DEFINE(USG_SUBTTY_WORKS, 1, [Define for USG systems where it
-       works to open a pty's tty in the parent process, then close and
-       reopen it in the child.])
-
-     opsysfile="s/hpux10-20.h"
-   ;;
+  darwin) AC_DEFINE(TAB3, OXTABS) ;;
 
-   openbsd) opsysfile="s/netbsd.h" ;;
+  gnu | freebsd | netbsd | openbsd )
+    AC_DEFINE(TABDLY, OXTABS, [Undocumented.] )
+    AC_DEFINE(TAB3, OXTABS)
+    ;;
 
-   sol2-10)
-     AC_DEFINE(_STRUCTURED_PROC, 1, [Needed for system_process_attributes
-       on Solaris.])
-     opsysfile="s/sol2-6.h"
-   ;;
+  hpux*)
+    AC_DEFINE(RUN_TIME_REMAP, 1, [Define if emacs.c needs to call
+      run_time_remap; for HPUX.])
+    ;;
+esac
+
+
+dnl Used in xfaces.c.
+case $opsys in
+  hpux* | sol2* )
+    AC_DEFINE(XOS_NEEDS_TIME_H, 1, [Compensate for a bug in Xos.h on
+      some systems, where it requires time.h.])
+    ;;
+esac
+
+
+case $opsys in
+  dnl Emacs supplies its own malloc, but glib (part of Gtk+) calls
+  dnl memalign and on Cygwin, that becomes the Cygwin-supplied memalign.
+  dnl As malloc is not the Cygwin malloc, the Cygwin memalign always
+  dnl returns ENOSYS.  A workaround is to set G_SLICE=always-malloc. */
+  cygwin)
+    AC_DEFINE(G_SLICE_ALWAYS_MALLOC, 1, [Define to set the
+      G_SLICE environment variable to "always-malloc" at startup, if
+      using GTK.])
+    ;;
+
+  gnu) opsysfile="s/bsd-common.h" ;;
+
+  gnu-kfreebsd) opsysfile="s/gnu-linux.h" ;;
+
+  hpux11)
+    dnl See comments in sysdep.c:sys_signal.
+    dnl SA_RESTART resets the timeout of `select' on hpux11.
+    dnl Defining BROKEN_SA_RESTART is not the same as undef'ing SA_RESTART.
+    AC_DEFINE(BROKEN_SA_RESTART, 1, [Define if SA_RESTART should only
+      be used in batch mode.])
+    dnl It works to open the pty's tty in the parent (Emacs), then
+    dnl close and reopen it in the child.
+    AC_DEFINE(USG_SUBTTY_WORKS, 1, [Define for USG systems where it
+      works to open a pty's tty in the parent process, then close and
+      reopen it in the child.])
+
+    opsysfile="s/hpux10-20.h"
+    ;;
+
+  irix6-5)
+    AC_DEFINE(PREFER_VSUSP, 1, [Define if process_send_signal should
+      use VSUSP instead of VSWTCH.])
+    AC_DEFINE(SETPGRP_RELEASES_CTTY, 1, [Define if process.c:child_setup
+      should not call setpgrp.])
+    ;;
+
+  openbsd) opsysfile="s/netbsd.h" ;;
+
+  sol2-10)
+    AC_DEFINE(_STRUCTURED_PROC, 1, [Needed for system_process_attributes
+      on Solaris.])
+    opsysfile="s/sol2-6.h"
+    ;;
 esac
 
 # Set up the CFLAGS for real compilation, so we can substitute it.