From ea95a0509ecde0208d26cea272bd8fc5136dd4be Mon Sep 17 00:00:00 2001
From: Eelco Dolstra <eelco.dolstra@logicblox.com>
Date: Sat, 12 Nov 2005 17:05:51 +0000
Subject: [PATCH] * Start the switch to the new X libraries.  It's still
 conditional:   set `useOldXLibs' to `false' in all-packages-generic.nix to
 use   them. * Added Xaw3d. * Added Xaw3d support to Emacs.

svn path=/nixpkgs/trunk/; revision=4263
---
 .../editors/emacs/{patchfile => crt.patch}    |  0
 pkgs/applications/editors/emacs/default.nix   | 27 +++++++---
 pkgs/development/libraries/Xaw3d/builder.sh   | 22 ++++++++
 pkgs/development/libraries/Xaw3d/config.patch | 51 +++++++++++++++++++
 pkgs/development/libraries/Xaw3d/default.nix  | 12 +++++
 .../libraries/xlibs-wrapper/builder.sh        |  8 +++
 .../libraries/xlibs-wrapper/default.nix       | 10 ++++
 pkgs/servers/x11/xorg/default.nix             | 12 +++--
 pkgs/servers/x11/xorg/xmkmf.sh                | 11 ++++
 pkgs/system/all-packages-generic.nix          | 36 ++++++++++---
 10 files changed, 172 insertions(+), 17 deletions(-)
 rename pkgs/applications/editors/emacs/{patchfile => crt.patch} (100%)
 create mode 100644 pkgs/development/libraries/Xaw3d/builder.sh
 create mode 100644 pkgs/development/libraries/Xaw3d/config.patch
 create mode 100644 pkgs/development/libraries/Xaw3d/default.nix
 create mode 100644 pkgs/development/libraries/xlibs-wrapper/builder.sh
 create mode 100644 pkgs/development/libraries/xlibs-wrapper/default.nix
 create mode 100644 pkgs/servers/x11/xorg/xmkmf.sh

diff --git a/pkgs/applications/editors/emacs/patchfile b/pkgs/applications/editors/emacs/crt.patch
similarity index 100%
rename from pkgs/applications/editors/emacs/patchfile
rename to pkgs/applications/editors/emacs/crt.patch
diff --git a/pkgs/applications/editors/emacs/default.nix b/pkgs/applications/editors/emacs/default.nix
index 07253ec9d5bf..63f8b1ecb00e 100644
--- a/pkgs/applications/editors/emacs/default.nix
+++ b/pkgs/applications/editors/emacs/default.nix
@@ -1,14 +1,25 @@
-{stdenv, fetchurl, xlibs}:
+{ xawSupport ? true
+, xpmSupport ? true
+, xaw3dSupport ? false
+, stdenv, fetchurl, x11, libXaw ? null, libXpm ? null, Xaw3d ? null
+}:
+
+assert xawSupport -> libXaw != null;
+assert xpmSupport -> libXpm != null;
+assert xaw3dSupport -> Xaw3d != null;
 
 stdenv.mkDerivation {
-  name = "emacs-21.3";
+  name = "emacs-21.4a-Z";
   builder = ./builder.sh;
   src = fetchurl {
-    url = http://nix.cs.uu.nl/dist/tarballs/emacs-21.3.tar.gz;
-    md5 = "a0bab457cbf5b4f8eb99d1d0a3ada420";
+    url = http://ftp.gnu.org/pub/gnu/emacs/emacs-21.4a.tar.gz;
+    md5 = "8f9d97cbd126121bd5d97e5e31168a87";
   };
-  patches = [./patchfile];
-  inherit (xlibs) libXaw libX11;
-
-  buildInputs = [xlibs.libXaw xlibs.libX11];
+  patches = [./crt.patch];
+  buildInputs = [
+    x11
+    (if xawSupport then libXaw else null)
+    (if xpmSupport then libXpm else null)
+    (if xaw3dSupport then Xaw3d else null)
+  ];
 }
diff --git a/pkgs/development/libraries/Xaw3d/builder.sh b/pkgs/development/libraries/Xaw3d/builder.sh
new file mode 100644
index 000000000000..d64102b4f664
--- /dev/null
+++ b/pkgs/development/libraries/Xaw3d/builder.sh
@@ -0,0 +1,22 @@
+source $stdenv/setup
+
+configurePhase=configurePhase
+configurePhase() {
+    cd lib/Xaw3d
+    (mkdir X11 && cd X11 && ln -fs .. Xaw3d)
+    xmkmf
+}
+
+buildPhase=buildPhase
+buildPhase() {
+    make depend $makeFlags
+    make $makeFlags
+}
+
+installPhase() {
+    make install SHLIBDIR=$out/lib USRLIBDIR=$out/lib INCDIR=$out/include
+}
+
+makeFlags="CDEBUGFLAGS=" # !!! awful hack
+
+genericBuild
\ No newline at end of file
diff --git a/pkgs/development/libraries/Xaw3d/config.patch b/pkgs/development/libraries/Xaw3d/config.patch
new file mode 100644
index 000000000000..4062f313368f
--- /dev/null
+++ b/pkgs/development/libraries/Xaw3d/config.patch
@@ -0,0 +1,51 @@
+diff -rc xc-orig/lib/Xaw3d/Imakefile xc/lib/Xaw3d/Imakefile
+*** xc-orig/lib/Xaw3d/Imakefile	2003-03-08 15:55:18.000000000 +0100
+--- xc/lib/Xaw3d/Imakefile	2005-11-11 20:12:24.000000000 +0100
+***************
+*** 9,15 ****
+  XCOMM For grayed stipple shadows, define GRAY_BLKWHT_STIPPLES:
+  #define GRAY_BLKWHT_STIPPLES
+  XCOMM For scrollbars with arrows, define ARROW_SCROLLBARS:
+! #undef ARROW_SCROLLBARS
+  
+  #define DoNormalLib NormalLibXaw
+  #define DoSharedLib SharedLibXaw
+--- 9,15 ----
+  XCOMM For grayed stipple shadows, define GRAY_BLKWHT_STIPPLES:
+  #define GRAY_BLKWHT_STIPPLES
+  XCOMM For scrollbars with arrows, define ARROW_SCROLLBARS:
+! #define ARROW_SCROLLBARS
+  
+  #define DoNormalLib NormalLibXaw
+  #define DoSharedLib SharedLibXaw
+***************
+*** 22,28 ****
+  #define IncSubSubdir Xaw3d
+  
+  XCOMM When building outside an X11 source tree:
+! XCOMM EXTRA_INCLUDES = -I.
+  
+  #ifdef SharedXawReqs
+  REQUIREDLIBS = SharedXawReqs
+--- 22,28 ----
+  #define IncSubSubdir Xaw3d
+  
+  XCOMM When building outside an X11 source tree:
+! EXTRA_INCLUDES = -I.
+  
+  #ifdef SharedXawReqs
+  REQUIREDLIBS = SharedXawReqs
+diff -rc xc-orig/lib/Xaw3d/laylex.l xc/lib/Xaw3d/laylex.l
+*** xc-orig/lib/Xaw3d/laylex.l	1996-10-15 16:41:26.000000000 +0200
+--- xc/lib/Xaw3d/laylex.l	2005-11-11 20:03:50.000000000 +0100
+***************
+*** 26,31 ****
+--- 26,33 ----
+  #ifdef __STDC__
+  static int count ();
+  #endif
++ 
++ static int LayYY_prev_more_offset = 0;
+  %}
+  %%
+  vertical		return VERTICAL;
diff --git a/pkgs/development/libraries/Xaw3d/default.nix b/pkgs/development/libraries/Xaw3d/default.nix
new file mode 100644
index 000000000000..dd5e5ccc5c3d
--- /dev/null
+++ b/pkgs/development/libraries/Xaw3d/default.nix
@@ -0,0 +1,12 @@
+{stdenv, fetchurl, x11, xmkmf, makedepend, libXmu, libXpm, libXp, bison, flex}:
+
+stdenv.mkDerivation {
+  name = "Xaw3d-1.5E";
+  builder = ./builder.sh;
+  src = fetchurl {
+    url = http://freshmeat.net/redir/xaw3d/11835/url_tgz/Xaw3d-1.5E.tar.gz;
+    md5 = "29ecfdcd6bcf47f62ecfd672d31269a1";
+  };
+  patches = [./config.patch];
+  buildInputs = [x11 xmkmf makedepend libXmu libXpm libXp bison flex];
+}
diff --git a/pkgs/development/libraries/xlibs-wrapper/builder.sh b/pkgs/development/libraries/xlibs-wrapper/builder.sh
new file mode 100644
index 000000000000..7e40acf9198e
--- /dev/null
+++ b/pkgs/development/libraries/xlibs-wrapper/builder.sh
@@ -0,0 +1,8 @@
+source $stdenv/setup
+dontBuild=1
+dontMakeInstall=1
+nop() {
+    sourceRoot=.
+}
+unpackPhase=nop
+genericBuild
diff --git a/pkgs/development/libraries/xlibs-wrapper/default.nix b/pkgs/development/libraries/xlibs-wrapper/default.nix
new file mode 100644
index 000000000000..2593eef158c9
--- /dev/null
+++ b/pkgs/development/libraries/xlibs-wrapper/default.nix
@@ -0,0 +1,10 @@
+{stdenv, packages}:
+
+stdenv.mkDerivation {
+  name = "xlibs-wrapper";
+  builder = ./builder.sh;
+  propagatedBuildInputs = packages;
+} // {
+  # For compatability with XFree86.
+  buildClientLibs = true;
+}
diff --git a/pkgs/servers/x11/xorg/default.nix b/pkgs/servers/x11/xorg/default.nix
index 8840ebba0f34..8456c4b20f5e 100644
--- a/pkgs/servers/x11/xorg/default.nix
+++ b/pkgs/servers/x11/xorg/default.nix
@@ -1040,7 +1040,8 @@ rec {
       url = http://nix.cs.uu.nl/dist/tarballs/xorg/libXft-2.1.8.tar.bz2;
       md5 = "18e7a98444ece30ea5b51a24269f8c7c";
     };
-    buildInputs = [pkgconfig libXrender freetype fontconfig ];
+    buildInputs = [pkgconfig libXrender libX11 ];
+    propagatedBuildInputs = [freetype fontconfig ];
   };
     
   xsm = stdenv.mkDerivation {
@@ -1786,11 +1787,14 @@ rec {
     
   xmkmf = stdenv.mkDerivation {
     name = "xmkmf-0.99.1";
+    builder = ./xmkmf.sh;
     src = fetchurl {
       url = http://nix.cs.uu.nl/dist/tarballs/xorg/xmkmf-0.99.1.tar.bz2;
       md5 = "75013b6eeed99fd7b4e7913144a9de22";
     };
     buildInputs = [pkgconfig ];
+    propagatedBuildInputs = [imake];
+    inherit xorgcffiles;
   };
     
   xorgcffiles = stdenv.mkDerivation {
@@ -1988,7 +1992,7 @@ rec {
       url = http://nix.cs.uu.nl/dist/tarballs/xorg/xclock-0.99.1.tar.bz2;
       md5 = "ec54b47ee229318cef76a3c86da9ef94";
     };
-    buildInputs = [pkgconfig libX11 libXrender libXft libxkbfile ];
+    buildInputs = [pkgconfig libX11 libXrender libXft libxkbfile libXaw ];
   };
     
   xf86videoati = stdenv.mkDerivation {
@@ -2340,6 +2344,7 @@ rec {
       md5 = "a3b65703a80cc0582757c595c0875612";
     };
     buildInputs = [pkgconfig libSM libX11 xproto kbproto ];
+    # !!! prop libSM
   };
     
   editres = stdenv.mkDerivation {
@@ -2438,7 +2443,8 @@ rec {
       url = http://nix.cs.uu.nl/dist/tarballs/xorg/libXaw-0.99.1.tar.bz2;
       md5 = "731f8a6407765466d1170d609137a922";
     };
-    buildInputs = [pkgconfig xproto libX11 libXext libXt libXmu libXpm libXp ];
+    buildInputs = [pkgconfig xproto libX11 libXext libXt libXpm libXp ];
+    propagatedBuildInputs = [libXmu];
   };
     
   x11perf = stdenv.mkDerivation {
diff --git a/pkgs/servers/x11/xorg/xmkmf.sh b/pkgs/servers/x11/xorg/xmkmf.sh
new file mode 100644
index 000000000000..1891f61dabed
--- /dev/null
+++ b/pkgs/servers/x11/xorg/xmkmf.sh
@@ -0,0 +1,11 @@
+source $stdenv/setup
+
+postInstall=postInstall
+postInstall() {
+    ensureDir $out/lib/X11/config
+    ln -s $xorgcffiles/lib/X11/config/* $out/lib/X11/config
+    touch $out/lib/X11/config/host.def # !!! hack
+    touch $out/lib/X11/config/date.def # !!! hack
+}
+
+genericBuild
diff --git a/pkgs/system/all-packages-generic.nix b/pkgs/system/all-packages-generic.nix
index 6eeb4c99d0d4..514fd20d3705 100644
--- a/pkgs/system/all-packages-generic.nix
+++ b/pkgs/system/all-packages-generic.nix
@@ -14,8 +14,18 @@ rec {
 
   ### Symbolic names.
 
-  x11 = xlibs.xlibs; # !!! should be `x11ClientLibs' or some such
+  useOldXLibs = true;
 
+  # `xlibs' is the set of X library components.  This used to be the
+  # old modular X libraries project (called `xlibs') but now it's just
+  # the set of packages in the modular X.org tree (which also includes
+  # non-library components like the server, drivers, fonts, etc.).
+  xlibs = if useOldXLibs then xlibsOld else xorg;
+
+  # `xlibs.xlibs' is a wrapper packages that combines libX11 and a bunch
+  # of other basic X client libraries.
+  x11 = if useOldXLibs then xlibsOld.xlibs else xlibsWrapper;
+  
 
   ### BUILD SUPPORT
 
@@ -979,13 +989,25 @@ rec {
     inherit fetchurl stdenv freetype expat;
   };
 
-  xlibs = (import ../development/libraries/xlibs) {
+  xlibsOld = (import ../development/libraries/xlibs) {
     inherit fetchurl stdenv pkgconfig freetype fontconfig;
   };
 
-#  Xaw3d = import ../development/libraries/Xaw3d {
-#    inherit fetchurl stdenv;
-#  };
+  xlibsWrapper = import ../development/libraries/xlibs-wrapper {
+    inherit stdenv;
+    packages = [
+      freetype fontconfig xlibs.xproto xlibs.libX11 xlibs.libXt
+      xlibs.libXft xlibs.libXext xlibs.libSM xlibs.libICE
+      xlibs.xextproto
+    ];
+  };
+
+  Xaw3d = import ../development/libraries/Xaw3d {
+    inherit fetchurl stdenv x11 bison;
+    flex = flexnew;
+    # !!! makedepend is impure
+    inherit (xlibs) xmkmf makedepend libXmu libXpm libXp;
+  };
 
   libdrm = import ../development/libraries/libdrm {
     inherit fetchurl stdenv;
@@ -1727,7 +1749,9 @@ rec {
   };
 
   emacs = (import ../applications/editors/emacs) {
-    inherit fetchurl stdenv xlibs;
+    inherit fetchurl stdenv x11 Xaw3d;
+    inherit (xlibs) libXaw libXpm;
+    xaw3dSupport = false;
   };
 
   nxml = (import ../applications/editors/emacs/modes/nxml) {