FYI.  dh_haskell is a tool for creating debian packages from cabal
packages.  Jeremy is working on adding support for building separate
profiling libraries.

peace,

  isaac


--- Begin Message ---
Hello John,

Attached is a first crack at adding support to dh_haskell for -prof
packages. I am looking for some feedback on what you might want
changed for a final cut. As I mentioned before, I do not know perl or
the debhelper libraries, so there may be much better ways to do some
stuff. I need to clean up some superious white space and add some
better comments, but the basic method is pretty-well in place.

Overview of Usage
-----------------

Basically, you just add a -prof paragraph that looks like the existing
-dev paragraph. Everything else happens automatically.

Here are example -dev and corresponding -prof paragraphs:

===>

Package: libghc6-fps-dev
Section: libdevel
Architecture: any
Depends: ${haskell:Depends}
Description: A Haskell library that provides fast, packed strings
 This library provides the Data.ByteString library: byte arrays
 manipulable as strings, providing very time and space efficient string
 and IO operations.
 .
 For very large data requirements, or constraints on heap size,
 Data.ByteString.Lazy is provided, a lazy list of bytestring chunks.
 Efficient processing of multi-gigabyte data can be achieved this way.
 .
 This package contains the libraries compiled for GHC 6.

Package: libghc6-fps-prof
Section: libdevel
Architecture: any
Depends: ${haskell:Depends}
Description: A Haskell library that provides fast, packed strings
 This library provides the Data.ByteString library: byte arrays
 manipulable as strings, providing very time and space efficient string
 and IO operations.
 .
 For very large data requirements, or constraints on heap size,
 Data.ByteString.Lazy is provided, a lazy list of bytestring chunks.
 Efficient processing of multi-gigabyte data can be achieved this way.
 .
 This package contains the libraries compiled for GHC 6 with profiling 
 enable.

<===

Development Issues
------------------

Here are the basic issues I encountered,

(1) cabal does not support building the -dev packages and -prof
    packages seperately.

Instead it builds them both at once and lumps them in the same
directory. I think that this should ultimately be fixed in cabal, but
for now, dh_haskell needs to work with the current behaviour.

My current hack is:
 (1) skip over -prof paragraphs debian/control
 (2) when looking at a -dev, check for a matching -prof
 (3) if there is a matching -prof, enable profiling when building the
     -dev packages
 (4) use find/tar to move the profiling libraries out of -dev and into
     -prof

One side-effect is that if you have a -prof with out a matching -dev,
it will be silently ignored.

(2) Dependencies for -prof .debs

Should the -prof .debs depend of the corresponding -dev .debs? I think
ghc might let you install just the profiling libraries -- but then you
would probably have to build with profiling enabled.

I currently make the -prof package equals depend on the -dev package.

TODO: /usr/lib/haskell-utils/*_vars 
-----------------------------------

Unless you object, I am going to modify dh_haskell_prep to generate
the ghc6 dependencies based on /usr/lib/haskell-utils/*_vars as Ian
Lynagh suggests.

j.

diff -rN -u old-haskell-devscripts/dh_haskell_build 
new-haskell-devscripts/dh_haskell_build
--- old-haskell-devscripts/dh_haskell_build     2006-07-10 15:46:04.000000000 
-0700
+++ new-haskell-devscripts/dh_haskell_build     2006-07-10 15:46:04.000000000 
-0700
@@ -95,7 +95,7 @@
 
 sub is_handled_package {
     my $pkgname = shift;
-    if ($pkgname =~ m/^lib(ghc5|ghc6|nhc98|hugs)-.+-dev$/) {
+    if ($pkgname =~ m/^lib(ghc5|ghc6|nhc98|hugs)-.+-(dev|prof)$/) {
         return 1;
     } elsif ($pkgname =~ m/libhugs-.+$/) {
         return 1;
diff -rN -u old-haskell-devscripts/dh_haskell_buildinst 
new-haskell-devscripts/dh_haskell_buildinst
--- old-haskell-devscripts/dh_haskell_buildinst 2006-07-10 15:46:04.000000000 
-0700
+++ new-haskell-devscripts/dh_haskell_buildinst 2006-07-10 15:46:04.000000000 
-0700
@@ -161,6 +161,25 @@
     return getcabalbasepath($pkgtype) . "/lib/" . getcabalnameversion();
 }
 
+sub profiling_name {
+    my $package = shift;
+    my @pn = ($package =~ m/^lib(ghc5|ghc6|nhc98|hugs)-(.+)-dev$/);
+    return "lib$pn[0]-$pn[1]-prof";
+}
+
+sub is_profiling_enabled {
+    my $package = shift;
+    my $packages = shift;
+    my $profname = profiling_name($package);
+
+    foreach my $p (@{$packages}) {
+       if ($p =~ m/^$profname$/) {
+           return 1;
+       }
+    }
+    return 0;
+}
+
 sub safesystem {
     my $program = shift;
     print "Running: $program\n";
@@ -177,6 +196,21 @@
 die unless -e $setup;
 safesystem("ghc6 -package Cabal $setup -o setup");
 
+# Cabal currently has no way to build the -dev and -prof libraries
+# seperately. So the handling of -prof is a bit awkward. The below
+# loop handles each paragraph debian/control individually. To handle
+# -prof we:
+#
+# 1) skip over -prof paragraphs
+# 2) if we encounter a -dev paragraph we check if there is a 
+#    corresponding -prof package
+# 3) if so, we run configure with --enable-library-profiling
+# 4) build and install the libraries
+# 5) use find/tar to move the profiling libraries into
+#    -prof deb
+#
+# One side-effect is that you can not build a -prof unless you also
+# build a -dev. But you probably should not do that anyway?
 foreach my $package (@{$dh{DOPACKAGES}}) {
     my $tmp = tmpdir($package);
     if (is_handled_package($package)) {
@@ -196,7 +230,11 @@
             print "Running: ./setup build\n";
             system("./setup build");
         } else {
-            safesystem("./setup configure --prefix=" . 
getcabalbasepath($pkgtype)
+           my $profiling_option = "";
+           if (is_profiling_enabled($package,$dh{DOPACKAGES})) {
+               $profiling_option = " --enable-library-profiling ";
+           }
+            safesystem("./setup configure " . $profiling_option . " --prefix=" 
. getcabalbasepath($pkgtype)
                        . " --with-compiler=/usr/bin/$pkgtype");
             safesystem("./setup build");
         }
@@ -207,6 +245,17 @@
             safesystem("mkdir -p $tmp/usr/share/doc/$package");
             safesystem("mkdir -p $tmp" . getcabalbasepath($pkgtype));
             safesystem("./setup copy --copy-prefix=$tmp" . 
getcabalbasepath($pkgtype));
+           if (is_profiling_enabled($package, $dh{DOPACKAGES})) {
+               # Have to move all the profiling libraries into a
+               # seperate package. This seems a bit hackish though.
+               my $proftmp=tmpdir(profiling_name($package));
+               safesystem("mkdir -p $proftmp");
+               # NOTE: you might think you can using the -C option to
+               # tar instead using 'cd', but the --null disables -C
+               safesystem("find $tmp \\( -name \"*_p.a\" -o -name \"*.p_hi\" 
-o -name \"*.p_o\" \\) -printf \"%P\\0\" | " .
+                          "(cd $tmp ; tar -c --null --preserve --remove-files 
-T - ) | " .
+                          "tar -C $proftmp -x");
+           }
             safesystem("cp .installed-pkg-config $tmp" . 
getcabalpkglibpath($pkgtype) . "/installed-pkg-config");
         }
     }
diff -rN -u old-haskell-devscripts/dh_haskell_prep 
new-haskell-devscripts/dh_haskell_prep
--- old-haskell-devscripts/dh_haskell_prep      2006-07-10 15:46:04.000000000 
-0700
+++ new-haskell-devscripts/dh_haskell_prep      2006-07-10 15:46:04.000000000 
-0700
@@ -104,12 +104,27 @@
     }
 }
 
+sub is_handled_profiling {
+    my $pkgname = shift;
+    if ($pkgname =~ m/^lib(ghc5|ghc6|nhc98|hugs)-.+-prof$/) {
+        return 1;
+    } else {
+        return 0;
+    }
+}
+
+sub dev_name {
+    my $package = shift;
+    my @pn = ($package =~ m/^lib(ghc5|ghc6|nhc98|hugs)-(.+)-prof$/);
+    return "lib$pn[0]-$pn[1]-dev";
+}
+
 sub type_of_package {
     my $pkgname = shift;
     if ($pkgname =~ m/^libhugs-.+$/) {
         return "hugs";
     } else {
-        my @pn = ($pkgname =~ m/^lib(ghc5|ghc6|nhc98|hugs)-.+-dev$/);
+        my @pn = ($pkgname =~ m/^lib(ghc5|ghc6|nhc98|hugs)-.+-(dev|prof)$/);
         return $pn[0];
     }
 }
@@ -173,7 +188,9 @@
 foreach my $package (@{$dh{DOPACKAGES}}) {
        my $tmp = tmpdir($package);
 
+
         if (is_handled_package($package)) {
+           # substitute ${haskell:Depends}
             my $pkgtype = type_of_package($package);
             delsubstvar($package, "haskell:Depends");
             addsubstvar($package, "haskell:Depends", 
@@ -182,7 +199,8 @@
                 addsubstvar($package, "haskell:Depends",
                             $pkgtype, "<< " . 
upstream_version(version_of_type($pkgtype)) . "-999");
             }
-            
+
+           # add postinst/prerm scripts
             if ($pkgtype eq "ghc5" || $pkgtype eq "ghc6") {
                 # Build scripts
                 my $ghcver = "ghc-" . 
upstream_version(version_of_type($pkgtype));
@@ -198,6 +216,20 @@
             }
         }
 
+        if (is_handled_profiling($package)) {
+           # substitute ${haskell:Depends} for profiling package
+           my $pkgtype = type_of_package($package);
+           delsubstvar($package, "haskell:Depends");
+           addsubstvar($package, "haskell:Depends", 
+                       $pkgtype, ">= " . 
upstream_version(version_of_type($pkgtype)));
+           addsubstvar($package, "haskell:Depends",
+                       $pkgtype, "<< " . 
upstream_version(version_of_type($pkgtype)) . "-999");
+           # Call isnative becuase it sets $dh{VERSION}
+           # as a side effect.
+           isnative($package);
+           addsubstvar($package, "haskell:Depends",
+                       dev_name($package), "= " . $dh{VERSION});
+       }
 }
 
 =head1 BUGS

_______________________________________________
debian-haskell mailing list
debian-haskell@lists.urchin.earth.li
http://urchin.earth.li/mailman/listinfo/debian-haskell

--- End Message ---
_______________________________________________
cabal-devel mailing list
cabal-devel@haskell.org
http://www.haskell.org//mailman/listinfo/cabal-devel

Reply via email to