Subject: GNU emacs 21.2 ported (alpha) to Cygwin
From: Joe Buehler <[email-masked]>
To: [email-masked]
Date: Fri, 02 Aug 2002 14:39:21 -0400
Newsgroups: gmane.os.cygwin

Attached is a script that will compile and install GNU emacs 21.2
under Cygwin, into /usr/local/gnu-emacs.  I used the 2.95 gcc compiler
for this.

Put the script and emacs-21.2.tar.gz into the same directory,
run the script and wait for it to finish.  You need "rebase"
in your PATH (see below).

Consider it alpha -- neither telnet nor gnus work for me, so there
are probably socket-related problems.  Emacs -nw doesn't work,
but that looks to be something simple related to terminfo/termcap.

X11 mode seems to work fine for editing, and the shell seems to work OK.

One of the things I had to do was rebase the DLLs that emacs uses.
This was required because emacs wants its heap and data below
address 0x10000000 and automatic dll relocation violates this.  Once
this gets fixed in some of the Cygwin packages, that part of the
script can go away.

I'll submit the patches to FSF for inclusion in future releases of
GNU emacs if no one sends me any improvements in the next few days.

Joe Buehler
#!/bin/bash
#
# script to build and install GNU emacs under Cygwin
#
# NOTE: The Windows "rebase" utility must be findable in PATH.
#

VERSION=21.2
DESTDIR=/usr/local/gnu-emacs

# where to put rebased dlls (until Cygwin fixes this)
REBASEDIR="$DESTDIR"/rebased-dlls

# This is for use by emacs.exe once it is built.
export PATH="$REBASEDIR:$PATH"

#
# Automatic rebasing of dlls used by emacs.exe causes problems because
# emacs wants the heap in the range 0x00000000 - 0x0fffffff because of
# the way that it represents pointers internally.
#
# So we make copies of the dlls that collide and rebase them for emacs
# to use.  Once the official copies of these libraries are fixed, this
# hack can go away.
#
rebase_dlls_used_by_emacs()
{
	if [ ! -d "$DESTDIR" ]; then
	    mkdir -p "$DESTDIR" &&
	    chmod 755 "$DESTDIR"
	fi &&
	rm -fr "$REBASEDIR" &&
	mkdir -p "$REBASEDIR" &&
	chmod 755 "$REBASEDIR" &&
	while read DLL BASE NEWBASE; do
		echo "*** rebasing $DLL"
		cp -p "$DLL" "$REBASEDIR" &&
		(
			cd "$REBASEDIR" &&
			rebase -b $NEWBASE $(basename "$DLL")
		)
	done <<-\!
		/usr/X11R6/bin/libICE.dll   10001000 0x60700000
		/usr/X11R6/bin/libSM.dll    00331000 0x60800000
		/usr/X11R6/bin/libX11.dll   00911000 0x60900000
		/usr/X11R6/bin/libXext.dll  009f1000 0x60a00000
		/usr/X11R6/bin/libXpm.dll   00a11000 0x60b00000
		/usr/bin/cygjpeg6b.dll      00a31000 0x60c00000
		/usr/bin/cygpng12.dll       00a61000 0x60d00000
		/usr/bin/cygz.dll           00a91000 0x60e00000
		/usr/bin/cygtiff3.dll       00ab1000 0x60f00000
	!
}

#
# patches to GNU emacs source required for Cygwin build
#
patch_emacs_source_for_cygwin()
{
patch -p0 -N <<-\!
diff -u -r -N -x '*~*' configure configure
--- configure	2002-03-15 07:46:09.000000000 -0500
+++ configure	2002-08-01 14:10:03.000000000 -0400
@@ -1628,6 +1628,7 @@
   i[3456]86-*-* )
     machine=intel386
     case "${canonical}" in
+      *-cygwin )                opsys=cygwin ;;
       *-lynxos* )               opsys=lynxos ;;
       *-isc1.* | *-isc2.[01]* )	opsys=386-ix ;;
       *-isc2.2* )		opsys=isc2-2 ;;
diff -u -r -N -x '*~*' lib-src/Makefile.in lib-src/Makefile.in
--- lib-src/Makefile.in	2001-10-18 20:31:27.000000000 -0400
+++ lib-src/Makefile.in	2002-08-02 12:22:31.000000000 -0400
@@ -297,7 +297,7 @@
 	@echo "Installing utilities for users to run."
 	for file in ${INSTALLABLES} ; do \
 	  $(INSTALL_PROGRAM) $(INSTALL_STRIP) $${file} ${bindir}/$${file} ; \
-	  chmod a+rx ${bindir}/$${file}; \
+	  chmod a+rx ${bindir}/$${file}.exe; \
 	done
 	for file in ${INSTALLABLE_SCRIPTS} ; do \
 	  $(INSTALL_PROGRAM) ${srcdir}/$${file} ${bindir}/$${file} ; \
diff -u -r -N -x '*~*' src/Makefile.in src/Makefile.in
--- src/Makefile.in	2001-12-17 09:09:32.000000000 -0500
+++ src/Makefile.in	2002-08-02 11:59:25.000000000 -0400
@@ -836,7 +836,7 @@
 emacs: temacs ${etc}DOC ${lisp}
 #ifdef CANNOT_DUMP
 	rm -f emacs
-	ln temacs emacs
+	ln temacs.exe emacs
 #else
 #ifdef HAVE_SHM
 	LC_ALL=C ./temacs -nl -batch -l loadup dump
@@ -1231,7 +1231,7 @@
 
 bootstrap-emacs: bootstrap-temacs bootstrap-doc
 #ifdef CANNOT_DUMP
-	ln temacs bootstrap-emacs
+	ln temacs.exe bootstrap-emacs
 #else
 #ifdef HAVE_SHM
 	./temacs -nl -batch -l loadup bootstrap
diff -u -r -N -x '*~*' src/fileio.c src/fileio.c
--- src/fileio.c	2002-03-13 14:52:18.000000000 -0500
+++ src/fileio.c	2002-08-01 15:34:10.000000000 -0400
@@ -23,7 +23,7 @@
 
 #include <config.h>
 
-#if defined (USG5) || defined (BSD_SYSTEM) || defined (LINUX)
+#if defined (USG5) || defined (BSD_SYSTEM) || defined (LINUX) || defined (CYGWIN)
 #include <fcntl.h>
 #endif
 
diff -u -r -N -x '*~*' src/keyboard.c src/keyboard.c
--- src/keyboard.c	2002-01-28 11:33:19.000000000 -0500
+++ src/keyboard.c	2002-08-01 15:24:01.000000000 -0400
@@ -6140,6 +6140,9 @@
       int n_to_read;
 
       /* Determine how many characters we should *try* to read.  */
+#ifdef CYGWIN
+      return 0;
+#else
 #ifdef WINDOWSNT
       return 0;
 #else /* not WINDOWSNT */
@@ -6173,6 +6176,7 @@
 #endif
 #endif /* not MSDOS */
 #endif /* not WINDOWSNT */
+#endif /* not CYGWIN */
 
       /* Now read; for one reason or another, this will not block.
 	 NREAD is set to the number of chars read.  */
diff -u -r -N -x '*~*' src/mem-limits.h src/mem-limits.h
--- src/mem-limits.h	2000-03-08 13:49:46.000000000 -0500
+++ src/mem-limits.h	2002-08-01 16:54:47.000000000 -0400
@@ -45,6 +45,10 @@
 #define BSD4_2
 #endif
 
+#ifdef CYGWIN
+#define BSD4_2
+#endif
+
 #ifndef BSD4_2
 #ifndef USG
 #ifndef MSDOS
diff -u -r -N -x '*~*' src/s/cygwin.h src/s/cygwin.h
--- src/s/cygwin.h	1969-12-31 19:00:00.000000000 -0500
+++ src/s/cygwin.h	2002-08-02 11:01:43.000000000 -0400
@@ -0,0 +1,203 @@
+/* Template for system description header files.
+   This file describes the parameters that system description files
+   should define or not.
+   Copyright (C) 1985, 1986, 1992, 1999 Free Software Foundation, Inc.
+
+This file is part of GNU Emacs.
+
+GNU Emacs is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Emacs is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Emacs; see the file COPYING.  If not, write to
+the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
+
+
+/*
+ *	Define symbols to identify the version of Unix this is.
+ *	Define all the symbols that apply correctly.
+ */
+
+/* #define UNIPLUS */
+/* #define USG5 */
+/* #define USG */
+/* #define HPUX */
+/* #define UMAX */
+/* #define BSD4_1 */
+/* #define BSD4_2 */
+/* #define BSD4_3 */
+/* #define BSD_SYSTEM */
+/* #define VMS */
+
+/* SYSTEM_TYPE should indicate the kind of system you are using.
+ It sets the Lisp variable system-type.  */
+
+#define SYSTEM_TYPE "cygwin"
+
+/* NOMULTIPLEJOBS should be defined if your system's shell
+ does not have "job control" (the ability to stop a program,
+ run some other program, then continue the first one).  */
+
+/* #define NOMULTIPLEJOBS */
+
+/* Emacs can read input using SIGIO and buffering characters itself,
+   or using CBREAK mode and making C-g cause SIGINT.
+   The choice is controlled by the variable interrupt_input.
+
+   Define INTERRUPT_INPUT to make interrupt_input = 1 the default (use SIGIO)
+
+   Emacs uses the presence or absence of the SIGIO and BROKEN_SIGIO macros
+   to indicate whether or not signal-driven I/O is possible.  It uses
+   INTERRUPT_INPUT to decide whether to use it by default.
+
+   SIGIO can be used only on systems that implement it (4.2 and 4.3).
+   CBREAK mode has two disadvantages
+     1) At least in 4.2, it is impossible to handle the Meta key properly.
+        I hear that in system V this problem does not exist.
+     2) Control-G causes output to be discarded.
+        I do not know whether this can be fixed in system V.
+
+   Another method of doing input is planned but not implemented.
+   It would have Emacs fork off a separate process
+   to read the input and send it to the true Emacs process
+   through a pipe. */
+
+#define INTERRUPT_INPUT
+
+/* Letter to use in finding device name of first pty,
+  if system supports pty's.  'a' means it is /dev/ptya0  */
+
+/* #define FIRST_PTY_LETTER 'a' */
+
+/*
+ *	Define HAVE_TERMIOS if the system provides POSIX-style
+ *	functions and macros for terminal control.
+ *
+ *	Define HAVE_TERMIO if the system provides sysV-style ioctls
+ *	for terminal control.
+ *
+ *	Do not define both.  HAVE_TERMIOS is preferred, if it is
+ *	supported on your system.
+ */
+
+#define HAVE_TERMIOS
+/* #define HAVE_TERMIO */
+
+/*
+ *	Define HAVE_PTYS if the system supports pty devices.
+ */
+
+#undef HAVE_PTYS
+
+/*
+ *	Define NONSYSTEM_DIR_LIBRARY to make Emacs emulate
+ *      The 4.2 opendir, etc., library functions.
+ */
+
+/* #define NONSYSTEM_DIR_LIBRARY */
+
+/* Define this symbol if your system has the functions bcopy, etc. */
+
+/* #define BSTRING */
+
+/* subprocesses should be defined if you want to
+   have code for asynchronous subprocesses
+   (as used in M-x compile and M-x shell).
+   This is generally OS dependent, and not supported
+   under most USG systems. */
+
+#define subprocesses
+
+/* If your system uses COFF (Common Object File Format) then define the
+   preprocessor symbol "COFF". */
+
+/* #define COFF */
+
+/* define MAIL_USE_FLOCK if the mailer uses flock
+   to interlock access to /usr/spool/mail/$USER.
+   The alternative is that a lock file named
+   /usr/spool/mail/$USER.lock.  */
+
+/* #define MAIL_USE_FLOCK */
+
+/* Define CLASH_DETECTION if you want lock files to be written
+   so that Emacs can tell instantly when you try to modify
+   a file that someone else has modified in his Emacs.  */
+
+#define CLASH_DETECTION
+
+/* Define this if your operating system declares signal handlers to
+   have a type other than the usual.  `The usual' is `void' for ANSI C
+   systems (i.e. when the __STDC__ macro is defined), and `int' for
+   pre-ANSI systems.  If you're using GCC on an older system, __STDC__
+   will be defined, but the system's include files will still say that
+   signal returns int or whatever; in situations like that, define
+   this to be what the system's include files want.  */
+/* #define SIGTYPE int */
+
+/* If the character used to separate elements of the executable path
+   is not ':', #define this to be the appropriate character constant.  */
+/* #define SEPCHAR ':' */
+
+/* Define this if the system can use mmap for buffer text allocation.  */
+/* #define USE_MMAP_FOR_BUFFERS 1 */
+
+/* ============================================================ */
+
+/* Here, add any special hacks needed
+   to make Emacs work on this system.  For example,
+   you might define certain system call names that don't
+   exist on your system, or that do different things on
+   your system and must be used only through an encapsulation
+   (Which you should place, by convention, in sysdep.c).  */
+
+/* Some compilers tend to put everything declared static
+   into the initialized data area, which becomes pure after dumping Emacs.
+   On these systems, you must #define static as nothing to foil this.
+   Note that emacs carefully avoids static vars inside functions.  */
+
+/* #define static */
+
+/* If the system's imake configuration file defines `NeedWidePrototypes'
+   as `NO', we must define NARROWPROTO manually.  Such a define is
+   generated in the Makefile generated by `xmkmf'.  If we don't 
+   define NARROWPROTO, we will see the wrong function prototypes
+   for X functions taking float or double parameters.  */
+
+/*  #define NARROWPROTO 1 */
+
+/* ============================================================ */
+
+/* After adding support for a new system, modify the large case
+   statement in the `configure' script to recognize reasonable
+   configuration names, and add a description of the system to
+   `etc/MACHINES'.
+
+   If you've just fixed a problem in an existing configuration file,
+   you should also check `etc/MACHINES' to make sure its descriptions
+   of known problems in that configuration should be updated.  */
+
+#define PENDING_OUTPUT_COUNT(FILE) ((FILE)->_p - (FILE)->_bf._base)
+#define GETPGRP_NO_ARG 1
+#define SYSV_SYSTEM_DIR 1
+#define CYGWIN 1
+
+#define CANNOT_DUMP 1
+#define POSIX_SIGNALS 1
+#define SYSTEM_MALLOC 1
+#define LINKER $(CC)
+
+/*
+#define DATA_SEG_BITS 0x10000000
+#define PURE_SEG_BITS 0x00000000
+#define HAVE_SHM 1
+#define XPNTR(a) (XUINT (a) | (XUINT (a) > DATA_SEG_BITS ? DATA_SEG_BITS : PURE_SEG_BITS))
+*/
!
}

#
# compile and install GNU emacs
#
build_and_install_emacs()
{
	rm -fr emacs-"$VERSION" &&
	tar -xf emacs-"$VERSION".tar.gz --gzip &&

	(
	    cd emacs-"$VERSION" &&
	    patch_emacs_source_for_cygwin
	) &&

	rm -fr emacs-"$VERSION"-build &&
	mkdir emacs-"$VERSION"-build &&
	(
		cd emacs-"$VERSION"-build &&
		CFLAGS=-g ../emacs-"$VERSION"/configure --prefix="$DESTDIR" &&
		make &&
		make install
	) &&

	rm -fr emacs-"$VERSION"-build &&
	rm -fr emacs-"$VERSION" &&

	mv "$DESTDIR"/bin/emacs "$DESTDIR"/bin/emacs-orig &&

	cat <<-! >"$DESTDIR"/bin/emacs &&
		#!/bin/bash
		export PATH="$REBASEDIR:\$PATH"
		exec "$DESTDIR"/bin/emacs-"$VERSION" "\$@"
	!
	chmod 755 "$DESTDIR"/bin/emacs
}

if [ ! -f emacs-"$VERSION".tar.gz ]; then
    echo "$0: The file emacs-$VERSION.tar.gz is not in the current directory." >&2
    exit 1
fi &&

rebase_dlls_used_by_emacs &&
build_and_install_emacs &&
true

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/