[Git][haskell-team/haskell-devscripts][master] 5 commits: Revert "Use d/tmp as a uniform intermediate location; multiple compilers are...

Felix Lechner (@lechner) gitlab at salsa.debian.org
Sat Apr 16 02:58:06 BST 2022



Felix Lechner pushed to branch master at Debian Haskell Group / haskell-devscripts


Commits:
85edc8c5 by Felix Lechner at 2022-04-13T18:16:48-07:00
Revert "Use d/tmp as a uniform intermediate location; multiple compilers are not supported, anyway."

Did not work for pandoc (or dh_install, rather):

dh_install: warning: Cannot find (any matches for) "debian/tmp-inst-*/usr/share/pandoc/data" (tried in ., debian/tmp)

dh_install: warning: pandoc-data missing files: debian/tmp-inst-*/usr/share/pandoc/data
dh_install: error: missing files, aborting
make: *** [/usr/share/cdbs/1/rules/debhelper.mk:252: binary-install/pandoc-data] Error 25
dpkg-buildpackage: error: debian/rules binary subprocess returned exit status 2
debuild: fatal error at line 1182:
dpkg-buildpackage -rfakeroot -us -uc -ui failed

This reverts commit d6321a34a1a39c35670df9bfb0a0ea3084aeb094.

- - - - -
da43e642 by Felix Lechner at 2022-04-14T09:22:59-07:00
Set the link with debian/tmp the other way around.

Let's see if that works for us.

- - - - -
3a103774 by Felix Lechner at 2022-04-15T14:00:59-07:00
Remove references to obsolete version of self; old-old-stable has 0.13.3 already.

- - - - -
7f3adfe6 by Felix Lechner at 2022-04-15T18:53:11-07:00
Break Debhelper scripts into smaller pieces; use Dh_Lib.

- - - - -
fc0baa59 by Felix Lechner at 2022-04-15T18:56:53-07:00
Install package files via small Debhelper scripts instead of centralized recipe.

- - - - -


23 changed files:

- debian/control
- debian/haskell-devscripts-minimal.lintian-overrides
- debian/manpages
- dh_haskell_blurbs
- + dh_haskell_compiler
- dh_haskell_depends
- + dh_haskell_depends_cabal
- + dh_haskell_depends_haddock
- + dh_haskell_depends_hugs
- + dh_haskell_description
- + dh_haskell_extra_depends_ghc
- + dh_haskell_install_development_libs
- + dh_haskell_install_ghc_registration
- + dh_haskell_install_haddock
- + dh_haskell_install_htmldocs
- + dh_haskell_install_profiling_libs
- dh_haskell_provides
- + dh_haskell_provides_ghc
- + dh_haskell_recommends_documentation_references
- dh_haskell_shlibdeps
- + dh_haskell_suggests
- hlibrary.mk
- lib/Debian/Debhelper/Buildsystem/Haskell/Recipes.pm


Changes:

=====================================
debian/control
=====================================
@@ -32,9 +32,7 @@ Depends: dctrl-tools
   , perl
   , ${misc:Depends}
   , ${perl:Depends}
-Breaks: haskell-devscripts (<= 0.10.2.3)
- , dh-haskell (<= 0.6.5)
-Replaces: haskell-devscripts (<= 0.10.2.3)
+Breaks: dh-haskell (<= 0.6.5)
 Suggests: haskell-devscripts
 Description: Tools to help Debian developers build Haskell packages
  This package provides a collection of scripts to help build Haskell


=====================================
debian/haskell-devscripts-minimal.lintian-overrides
=====================================
@@ -1,3 +1,7 @@
 # these make sense in a devscripts package
 binary-package-depends-on-toolchain-package *debhelper*
 binary-package-depends-on-toolchain-package *cdbs*
+
+# obsolete scripts; last remaining uses documented there
+no-manual-page usr/bin/dh_haskell_provides
+no-manual-page usr/bin/dh_haskell_depends


=====================================
debian/manpages
=====================================
@@ -1,4 +1,16 @@
-manual/dh_haskell_provides.1
-manual/dh_haskell_depends.1
-manual/dh_haskell_shlibdeps.1
 manual/dh_haskell_blurbs.1
+manual/dh_haskell_compiler.1
+manual/dh_haskell_depends_cabal.1
+manual/dh_haskell_depends_haddock.1
+manual/dh_haskell_depends_hugs.1
+manual/dh_haskell_description.1
+manual/dh_haskell_extra_depends_ghc.1
+manual/dh_haskell_install_development_libs.1
+manual/dh_haskell_install_ghc_registration.1
+manual/dh_haskell_install_haddock.1
+manual/dh_haskell_install_htmldocs.1
+manual/dh_haskell_install_profiling_libs.1
+manual/dh_haskell_provides_ghc.1
+manual/dh_haskell_recommends_documentation_references.1
+manual/dh_haskell_shlibdeps.1
+manual/dh_haskell_suggests.1


=====================================
dh_haskell_blurbs
=====================================
@@ -23,139 +23,72 @@ use warnings;
 use utf8;
 
 use Const::Fast;
-use File::Basename;
-use Getopt::Long ();
 use Path::Tiny;
-use Unicode::UTF8 qw(encode_utf8);
 
-use Debian::Debhelper::Buildsystem::Haskell::Recipes qw(
-  run
-  installable_type
-  source_hc
-);
+use Debian::Debhelper::Dh_Lib;
 
 const my $EMPTY => q{};
-const my $SPACE => q{ };
 const my $NEWLINE => qq{\n};
 
-my $program_name = basename($0);
+const my $MAGIC_MARKER => q/${Newline}/;
 
-my @excludes;
+init(
+    options => {
+        'type=s' => \$dh{TYPE},
+    });
 
-my %options = (
-    'exclude|X=s' => \@excludes,
-    'help|h' => \&show_help,
-);
+my $type = $dh{TYPE} // $EMPTY;
 
-Getopt::Long::Configure('gnu_getopt', 'pass_through');
-Getopt::Long::GetOptions(%options)
-  or die encode_utf8("error parsing options\n");
+my $short_blurb;
+my $long_blurb;
 
-my @args_bytes = grep { /^-/ } @ARGV;
-my ($default_compiler, @configs) = grep { !/^-/ } @ARGV;
+if ($type eq 'dev') {
 
-die encode_utf8("$program_name: Need default Haskell compiler")
-  unless length $default_compiler;
-
-die encode_utf8("Installed package description file $_ can not be found")
-  for grep { !-e } @configs;
-
-$ENV{DH_EXCLUDES} = join($SPACE, @excludes);
-
-die encode_utf8('grep-dctrl is missing')
-  unless system('command -v grep-dctrl > /dev/null') == 0;
-
-$ENV{DEB_DEFAULT_COMPILER} = $default_compiler;
-my $compiler = source_hc() || $ENV{DEB_DEFAULT_COMPILER};
-
-my $output = run('dh_listpackages', @args_bytes);
-chomp $output;
-
-my @installables = split($SPACE, $output);
-
-for my $installable (@installables) {
-
-    my $substvars_path = "debian/$installable.substvars";
-
-    my $short_blurb;
-    my $blurb;
+    $short_blurb = $EMPTY;
+    $long_blurb =<< 'QUOTE_END';
+This package provides a library for the Haskell programming language.
+See http://www.haskell.org/ for more information on Haskell.
+QUOTE_END
+}
 
-    my $type = installable_type($installable);
-    if ($type eq 'dev') {
+if ($type eq 'prof') {
 
-        $short_blurb = $EMPTY;
-        $blurb
-          = 'This package provides a library for the Haskell programming language.${Newline}See http://www.haskell.org/ for more information on Haskell.';
+    $short_blurb = '; profiling libraries';
+    $long_blurb = << 'QUOTE_END';
+This package provides a library for the Haskell programming language, compiled
+for profiling.  See http://www.haskell.org/ for more information on Haskell.
+QUOTE_END
+}
 
-    }
+if ($type eq 'doc') {
 
-    if ($type eq 'prof') {
+    $short_blurb = '; documentation';
+    $long_blurb = << 'QUOTE_END';
+This package provides the documentation for a library for the Haskell
+programming language.
+See http://www.haskell.org/ for more information on Haskell.
+QUOTE_END
+}
 
-        $short_blurb = '; profiling libraries';
-        $blurb
-          = 'This package provides a library for the Haskell programming language, compiled${Newline}for profiling.  See http://www.haskell.org/ for more information on Haskell.';
+$short_blurb //= $EMPTY;
+$long_blurb //= $EMPTY;
 
-    }
+chomp $short_blurb;
+chomp $long_blurb;
 
-    if ($type eq 'doc') {
+# replace newlines with magic marker
+$long_blurb =~ s{ \n }{$MAGIC_MARKER}gx;
 
-        $short_blurb = '; documentation';
-        $blurb
-          = 'This package provides the documentation for a library for the Haskell${Newline}programming language.${Newline}See http://www.haskell.org/ for more information on Haskell.';
+for my $installable (@{ $dh{DOPACKAGES} }) {
 
-    }
+    my $substvars_path = "debian/$installable.substvars";
 
     replace_line($substvars_path, 'haskell:ShortBlurb',$short_blurb // $EMPTY);
-    replace_line($substvars_path, 'haskell:Blurb', $blurb // $EMPTY);
-
-    # see Bug#1009162
-    my $description = get_source_field('Description');
-
-    # otherwise try X-Description
-    $description ||= get_source_field('X-Description');
-
-    my ($short_description, $long_description) = split(m{\n}, $description, 2);
-
-    $short_description //= $EMPTY;
-    $long_description //= $EMPTY;
-
-    chomp $long_description;
-
-    # drop initial spaces
-    $long_description =~ s{^ [ ] }{}gmx;
-
-    # prepare for dpkg-gencontrol
-    $long_description =~ s{ \n }{\$\{Newline\}}gx;
-
-    replace_line($substvars_path, 'haskell:ShortDescription',
-        $short_description);
-    replace_line($substvars_path, 'haskell:LongDescription',$long_description);
-
-    my $version= run(qw{dpkg-query --showformat=${Version} --show}, $compiler);
-    chomp $version;
-
-    # drop Debian revision
-    $version =~ s{ - [^-]+ $}{}x;
-
-    replace_line($substvars_path, "haskell:$compiler-version",
-        "$compiler (>= $version), $compiler (<< $version+)");
+    replace_line($substvars_path, 'haskell:Blurb', $long_blurb // $EMPTY);
 }
 
 exit;
 
-sub get_source_field {
-    my ($name) = @_;
-
-    # need regex to avoid the empty string, which would be filtered by run()
-    my $value= run(
-        qw{grep-dctrl --no-field-names},
-        "--show-field=$name",
-        qw{--field=Source --regex .* debian/control}
-    );
-
-    return $value;
-}
-
 sub replace_line {
     my ($path, $field, $value) = @_;
 
@@ -172,53 +105,24 @@ sub replace_line {
     return;
 }
 
-sub show_help {
-    my $message =<<"EOT";
-Usage: $program_name [options] cabal-file ...
-
-Options:
-    -X, --exclude INSTALLABLE    exclude INSTALLABLE from processing
-EOT
-
-    print encode_utf8($message);
-
-    exit;
-}
-
 =head1 NAME
 
-dh_haskell_blurb - standard haskell package description blurbs
+dh_haskell_blurbs - standard haskell package description blurbs
 
 =head1 SYNOPSIS
 
 B<dh_haskell_blurbs> [S<I<debhelper options>>]
-[B<-X>I<package>]
-[B<--exclude=>I<package>]
-[S<I<file>> ...]
+[B<--type=>I<blurb-type>]
 
 =head1 DESCRIPTION
 
-dh_haskell_blurbs is a debhelper program provides substvars for the standard blurbs occurring in Haskell package descriptions.
-
-To use it, move the common parts of the description to the source stanza:
-
- X-Description: Cool library
-  This is a pure Haskell implementation of coolness. It is cooler
-  than implementation via foreign languages, because we can.
-
-And then use the following for every Haskell library package stanza, C<dev>, C<prof> and C<doc>:
-
- Description: ${haskell:ShortDescription}${haskell:ShortBlurb}
-  ${haskell:LongDescription}
-  .
-  ${haskell:Blurb}
+dh_haskell_blurbs is a Debhelper program that provides substvars for standard blurbs in Haskell package descriptions.
+You can use it like this: C<${haskell:Blurb}>
 
+or like that: C<${haskell:Blurb}>
 
 =head1 SEE ALSO
 
-L<dh_haskell_depends(1)>
-L<dh_haskell_shlibdeps(1)>
-L<dh_haskell_provides(1)>
 L<debhelper(7)>
 
 =head1 AUTHOR


=====================================
dh_haskell_compiler
=====================================
@@ -0,0 +1,113 @@
+#!/usr/bin/perl
+
+# Copyright © 2022 Felix Lechner <felix.lechner at lease-up.com>
+#
+# based on a shell script by the same name
+#     Joachim Breitner <nomeata at debian.org>
+#
+# This program 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 3 of the License, or
+# (at your option) any later version.
+#
+# This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
+
+use v5.20;
+use warnings;
+use utf8;
+
+use Const::Fast;
+use Path::Tiny;
+
+use Debian::Debhelper::Buildsystem::Haskell::Recipes qw(
+  run
+  installable_hc
+);
+use Debian::Debhelper::Dh_Lib;
+
+const my $EMPTY => q{};
+const my $NEWLINE => qq{\n};
+
+init();
+
+for my $installable (@{ $dh{DOPACKAGES} }) {
+
+    my $compiler = installable_hc($installable) || $ENV{DEB_DEFAULT_COMPILER};
+
+    unless (length $compiler) {
+
+        warning("No Haskell compiler for installable $installable.");
+        next;
+    }
+
+    my $version= run(qw{dpkg-query --showformat=${Version} --show}, $compiler);
+    chomp $version;
+
+    unless (length $version) {
+
+        warning("No version for Haskell compiler $compiler");
+        next;
+    }
+
+    # strip Debian revision
+    $version =~ s{ - [^-]+ $}{}x;
+
+    my $substvars_path = "debian/$installable.substvars";
+
+    replace_line($substvars_path, "haskell:$compiler-version",
+        "$compiler (>= $version), $compiler (<< $version+)");
+}
+
+exit;
+
+sub replace_line {
+    my ($path, $field, $value) = @_;
+
+    $value //= $EMPTY;
+
+    path($path)->touch;
+
+    my @lines = grep { !m{^ $field = }x } path($path)->lines_utf8;
+
+    push(@lines, "$field=$value" . $NEWLINE);
+
+    path($path)->spew_utf8(@lines);
+
+    return;
+}
+
+=head1 NAME
+
+dh_haskell_compiler - store Haskell compiler info in substvars
+
+=head1 SYNOPSIS
+
+B<dh_haskell_compiler> [S<I<debhelper options>>]
+
+=head1 DESCRIPTION
+
+dh_haskell_compiler is a Debhelper program that stores information about Haskell compilers in substvars.
+
+You can use it like this: C<${haskell:ghc-version}>
+
+=head1 SEE ALSO
+
+L<debhelper(7)>
+
+=head1 AUTHOR
+
+Joachim Breitner <nomeata at debian.org>
+
+=cut
+
+# Local Variables:
+# indent-tabs-mode: nil
+# cperl-indent-level: 4
+# End:
+# vim: syntax=perl sw=4 sts=4 sr et


=====================================
dh_haskell_depends
=====================================
@@ -1,10 +1,7 @@
-#!/usr/bin/perl
+#!/bin/sh
 
 # Copyright © 2022 Felix Lechner <felix.lechner at lease-up.com>
 #
-# based on a shell script by the same name
-#     Arjan Oosting <arjan at debian.org>
-#
 # This program 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 3 of the License, or
@@ -18,478 +15,13 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-use v5.20;
-use warnings;
-use utf8;
-
-use Const::Fast;
-use File::Basename;
-use Getopt::Long ();
-use IPC::Run3;
-use List::SomeUtils qw(any uniq);
-use Path::Tiny;
-use Unicode::UTF8 qw(encode_utf8);
-
-use Debian::Debhelper::Buildsystem::Haskell::Recipes qw(
-  run_quiet
-  run
-  installable_type
-  source_hc
-  find_config_for_ghc
-  ghc_pkg_command
-  load_ghc_database
-  hashed_id_to_virtual_installable
-);
-
-const my $EMPTY => q{};
-const my $SPACE => q{ };
-const my $COMMA => q{,};
-const my $PLUS => q{+};
-
-const my $NEWLINE => qq{\n};
-const my $NULL => qq{\0};
-
-const my $WAIT_STATUS_SHIFT => 8;
-
-my $program_name = basename($0);
-
-my @excludes;
-
-my %options = (
-    'exclude|X=s' => \@excludes,
-    'help|h' => \&show_help,
-);
-
-Getopt::Long::Configure('gnu_getopt', 'pass_through');
-Getopt::Long::GetOptions(%options)
-  or die encode_utf8("error parsing options\n");
-
-my @args_bytes = grep { /^-/ } @ARGV;
-my @ghc_configs = grep { !/^-/ } @ARGV;
-
-die encode_utf8("Installed package description file $_ can not be found")
-  for grep { !-e } @ghc_configs;
-
-$ENV{DH_EXCLUDES} = join($SPACE, @excludes);
-
-die encode_utf8('grep-dctrl is missing')
-  unless system('command -v grep-dctrl > /dev/null') == 0;
-
-my $haskell_compiler = source_hc() || $ENV{DEB_DEFAULT_COMPILER};
-my $haskell_ghc_pkg = ghc_pkg_command();
-
-my @extra_depends
-  = get_extra_depends($haskell_compiler, $haskell_ghc_pkg,
-    $ENV{DEB_GHC_DATABASE});
-
-my $package_list = run('dh_listpackages', @args_bytes);
-chomp $package_list;
-
-my @installables = split($SPACE, $package_list);
-for my $installable (@installables) {
-
-    my $substvars_path = "debian/$installable.substvars";
-
-    replace_line($substvars_path, 'haskell:Extra-Depends',
-        join($COMMA . $SPACE, @extra_depends));
-
-    my $type = installable_type($installable);
-
-    my @depends;
-    my @recommends;
-    my @suggests;
-
-    if (any { $haskell_compiler eq $_ } qw{ghc ghcjs}) {
-
-        if (any { $type eq $_ } qw{dev prof}) {
-
-            @ghc_configs = find_config_for_ghc($installable)
-              unless @ghc_configs;
-
-            die encode_utf8(
-'dh_haskell_depends - no installed package description files found'
-            )unless @ghc_configs;
-
-            my @hashed_ids
-              = cabal_depends($haskell_ghc_pkg, $ENV{DEB_GHC_DATABASE},
-                @ghc_configs);
-
-            my @ghc_depends;
-            for my $hashed_id (@hashed_ids) {
-
-                # look in normal database
-                my $prerequisite
-                  =hashed_id_to_virtual_installable($haskell_compiler,
-                    $hashed_id, $type, $haskell_ghc_pkg, '--global');
-
-      # as a transition measure, check if dpkg knows about this virtual package
-                next
-                  unless system(
-                    "dpkg-query --show $prerequisite > /dev/null 2> /dev/null")
-                  == 0;
-
-                if (!length $prerequisite) {
-
-                    my $installable
-                      = providing_package_for_ghc($haskell_compiler,
-                        $hashed_id, $type);
-
-                    if (!length $installable) {
-
-                        warn encode_utf8(
-"WARNING: No Debian package provides the hashed Hackage id $hashed_id."
-                        );
-                        next;
-                    }
-
-                    my $version
-                      = run(qw{dpkg-query --showformat=${Version} --show},
-                        $installable);
-
-                    if (!length $version) {
-
-                        warn encode_utf8(
-"WARNING: No Debian version available for installable $installable."
-                        );
-                        next;
-                    }
-
-                    my $next_upstream_version = $version;
-                    $next_upstream_version =~ s{ - [^-]* $}{}x;
-                    $next_upstream_version .= $PLUS;
-
-                    $prerequisite
-                      ="$installable (>= $version), $installable (<< $next_upstream_version)";
-                }
-
-                push(@ghc_depends, $prerequisite);
-            }
-
-            if ($type eq 'dev') {
-
-                push(@depends, @ghc_depends);
-
-                my $prof = $installable;
-                $prof =~ s{ - [^-]+ $}{-prof}x;
-
-                my $doc = $installable;
-                $doc =~ s{ - [^-]+ $}{-doc}x;
-
-                push(@suggests, $doc)
-                  if system(qw{grep-dctrl --quiet --field=Package},
-                    $doc, 'debian/control') == 0;
-
-                push(@suggests, $prof)
-                  if system(qw{grep-dctrl --quiet --field=Package},
-                    $prof, 'debian/control') == 0;
-            }
-
-            if ($type eq 'prof') {
-
-                my $dev = $installable;
-                $dev =~ s{ - [^-]+ $}{-dev}x;
-
-                push(@depends, "$dev (=\${binary:Version})");
-                push(@depends, @ghc_depends);
-            }
-        }
-
-        if ($type eq 'doc') {
-
-            my $haddock_version = qx{haddock --interface-version};
-            chomp $haddock_version;
-
-            push(@depends, "haddock-interface-$haddock_version");
-
-            say encode_utf8(
-"Finding all links in the documentation in installable $installable."
-            );
-            my @links =split(
-                m{\n}x,
-                run_quiet(
-                    'find', "debian/$installable",
-                    qw{-name *.html -exec hxwls -r \{\} ;}
-                ));
-
-            my @files;
-            for my $link (@links) {
-
-                # filter out fragment, too
-                next
-                  unless $link =~ m{^ file:// ([^#]*) }x;
-
-                my $file = $1;
-                push(@files, $file);
-            }
-
-            my @absolute = uniq +grep { m{^ / }x } @files;
-
-            # already in UTF-8
-            my $input_bytes = $EMPTY;
-            $input_bytes .= $_ . $NULL for @absolute;
-
-            my $stdout_bytes;
-            my $stderr_bytes;
-
-            my @combined = qw{xargs --null --no-run-if-empty dpkg --search};
-            run3(\@combined, \$input_bytes, \$stdout_bytes, \$stderr_bytes);
-
-            my $exitcode = $?;
-            my $status = ($exitcode >> $WAIT_STATUS_SHIFT);
-
-            # already in UTF-8
-            warn encode_utf8("Non-zero exit code $exitcode.")
-              . $NEWLINE
-              . $stderr_bytes
-              if $exitcode;
-
-            my @lines = split(m{\n}, $stdout_bytes);
-
-            my @prerequisites;
-            for my $line (@lines) {
-
-                my ($origin) = split(m{:}, $line, 2);
-                next
-                  unless length $origin;
-
-                push(@prerequisites, $origin);
-            }
-
-            push(@recommends, @prerequisites);
-
-            my $dev = $installable;
-            $dev =~ s{ - [^-]+ $}{-dev}x;
-
-            push(@recommends, $dev)
-              if system(qw{grep-dctrl --quiet --field=Package},
-                $dev, 'debian/control') == 0;
-        }
-    }
-
-    if ($haskell_compiler eq 'hugs') {
-
-        my $version= run(qw{dpkg-query --showformat=${Version} --show hugs});
-        my $upstream_version = $version;
-        $upstream_version =~ s{ - [^-]* $}{}x;
-
-        push(@depends, "hugs (>= $upstream_version)");
-    }
-
-    local $ENV{LC_ALL} = 'C.UTF-8';
-
-    replace_line($substvars_path, 'haskell:Depends',
-        join($COMMA . $SPACE, (sort +uniq @depends)));
-    replace_line($substvars_path, 'haskell:Recommends',
-        join($COMMA . $SPACE, (sort +uniq @recommends)));
-    replace_line($substvars_path, 'haskell:Suggests',
-        join($COMMA . $SPACE, (sort +uniq @suggests)));
-}
-
-exit;
-
-sub cabal_depends {
-    my ($ghc_pkg, $tmp_db, @configs) = @_;
-
-    # fix sort order
-    local $ENV{LC_ALL} = 'C.UTF-8';
-
-    load_ghc_database($ghc_pkg, $tmp_db, @configs);
-
-    my @prerequisites;
-    for my $config (@configs) {
-
-        my $name = path($config)->basename(qr{ [.]conf $}x);
-        my $depends
-          = run($ghc_pkg, '--package-db', $tmp_db, qw{--simple-output field},
-            $name, 'depends');
-        push(@prerequisites, split($SPACE, $depends // $EMPTY));
-    }
-
-    my @have = sort +uniq @prerequisites;
-    my @exclude_patterns = split($SPACE, $ENV{DH_EXCLUDES} // $EMPTY);
-
-    # not sure this complies with Debhelper expectations
-    # excluded installables matching the patterns with or without version
-    # the versions should probably be dropped by the caller
-    s{ - [0-9] [.0-9a-zA-Z]* $}{}x for @exclude_patterns;
-
-    my @retained;
-    for my $prerequisite (@have) {
-
-        next
-          if any { $prerequisite =~ m{\Q$_\E} } @exclude_patterns;
-
-        push(@retained, $prerequisite);
-    }
-
-    return @retained;
-}
-
-sub providing_package_for_ghc {
-    my ($compiler, $hashed_id, $type) = @_;
-
-    my $extension = $EMPTY;
-    $extension = '_p'
-      if $type eq 'prof';
-
-    my $ghc_version= run(qw{dpkg-query --showformat=${Version} --show ghc});
-
-    my $directory_line= ghc_pkg_field($compiler, $hashed_id, 'library-dirs');
-    my (undef, $directory_list) = split(m{ \s* : \s* }x, $directory_line, 2);
-    my @library_dirs = split(m{ \s* , \s* }x, $directory_list);
-
-    my $library_line = ghc_pkg_field($compiler, $hashed_id, 'hs-libraries');
-    my (undef, $library_list) = split(m{ \s* : \s* }x, $library_line, 2);
-    my @libraries = split(m{ \s* , \s* }x, $library_list);
-
-    # look only at the first one
-    my $library = $libraries[0];
-
-    for my $directory (@library_dirs) {
-
-        my $library_path = "$directory/lib$library$extension.a";
-        next
-          unless -e $library_path;
-
-        my $line = run(qw{dpkg-query --search}, $library_path);
-        my ($installable) = split(m{ \s* : \s* }x, $line, 2);
-
-        return $installable;
-    }
-
-    return ();
-}
-
-sub get_extra_depends {
-    my ($compiler, $ghc_pkg, $tmp_db) = @_;
-
-    local $ENV{LC_ALL} = 'C.UTF-8';
-
-    $ENV{DEB_SETUP_BIN_NAME} //= 'debian/hlibrary.setup';
-
-    my $output = run($ENV{DEB_SETUP_BIN_NAME},
-        'register', "--builddir=dist-$compiler",
-        qw{--gen-pkg-config --verbose=verbose+nowrap});
-
-    my @prerequisites;
-
-    if ($output
-        =~ m{^Creating \s package \s registration \s file: \s+ (\S+) $}mx) {
-
-        my $pkg_config = $1;
-
-        my @hackages = cabal_depends($ghc_pkg, $tmp_db, $pkg_config);
-
-        run(qw{rm -f}, $pkg_config);
-
-        for my $hackage (@hackages) {
-
-            next
-              unless $hackage =~ m{^ ([^-]+) - ([0-9.]+) - [0-9a-f]{32} $}x;
-
-            my $name = $1;
-            my $version = $2;
-
-            my $extra_packages_file
-              = "/usr/lib/haskell-packages/extra-packages/$name-$version";
-
-            push(@prerequisites,
-                split(m{ \s* , \s* }x, path($extra_packages_file)->slurp_utf8))
-              if -e $extra_packages_file;
-        }
-
-    } else {
-        warn encode_utf8(
-"$program_name: Skipping extra depends; cannot find package registration file (probablu not a library."
-        );
-    }
-
-    return @prerequisites;
-}
-
-sub ghc_pkg_field {
-    my ($compiler, $hashed_id, $field) = @_;
-
-    my $output= run("$compiler-pkg", qw{--global field}, $hashed_id, $field);
-
-    # may not process multi-line fields correctly
-    my ($value) = split($NEWLINE, $output, 2);
-
-    return ($value // $EMPTY);
-}
-
-sub replace_line {
-    my ($path, $field, $value) = @_;
-
-    path($path)->touch;
-
-    my @lines = grep { !m{^ $field = }x } path($path)->lines_utf8;
-
-    push(@lines, "$field=$value" . $NEWLINE);
-
-    path($path)->spew_utf8(@lines);
-
-    return;
-}
-
-sub show_help {
-    my $message =<<"EOT";
-Usage: $program_name [options] cabal-file ...
-
-Options:
-    -X, --exclude INSTALLABLE    exclude INSTALLABLE from processing
-EOT
-
-    print encode_utf8($message);
-
-    exit;
-}
-
-=head1 NAME
-
-dh_haskell_depends - calculates Haskell dependencies on Cabalized libraries
-
-=head1 SYNOPSIS
-
-B<dh_haskell_depends> [S<I<debhelper options>>]
-[B<-X>I<package>]
-[B<--exclude=>I<package>]
-[S<I<file>> ...]
-
-=head1 DESCRIPTION
-
-dh_haskell_depends is a debhelper program that helps with calculating dependencies
-for building Haskell libraries.
-
-It automates building libraries for the different supported Haskell systems in
-Debian.
-
-This script writes the debian/$package.substvars file, including in it the
-haskell:Depends, haskell:Recommends, haskell:Suggests and haskell:Extra-Depends
-variable.  So, to use this package, include in the Depends: field in debian/control
-${haskell:Depends}, and do the same for Recommends, Suggests and Extra-Depends.
-
-=head1 BUGS
-
-hugs and ghc are the only supported targets at the moment.  Cabal does
-not yet support nhc98.
-
-=head1 SEE ALSO
-
-L<dh_haskell_provides(1)>
-L<dh_haskell_shlibdeps(1)>
-L<debhelper(7)>
-
-=head1 AUTHOR
-
-John Goerzen <jgoerzen at complete.org>
-
-Based on ideas in dh_python by Josselin Mouette <joss at debian.org>
+# this script exists only for two calls from
+#
+# - https://sources.debian.org/src/gitit/0.13.0.0+dfsg-2/debian/rules/?hl=22#L22
+# - https://sources.debian.org/src/haskell-shake/0.19.1-2/debian/rules/?hl=24#L24
 
-=cut
+export DEB_DEFAULT_COMPILER=ghc
+export DEB_GHC_DATABASE=debian/tmp-db
+export DEB_SETUP_BIN_NAME=debian/hlibrary.setup
 
-# Local Variables:
-# indent-tabs-mode: nil
-# cperl-indent-level: 4
-# End:
-# vim: syntax=perl sw=4 sts=4 sr et
+dh_haskell_extra_depends


=====================================
dh_haskell_depends_cabal
=====================================
@@ -0,0 +1,268 @@
+#!/usr/bin/perl
+
+# Copyright © 2022 Felix Lechner <felix.lechner at lease-up.com>
+#
+# based on a shell script by the same name
+#     Arjan Oosting <arjan at debian.org>
+#
+# This program 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 3 of the License, or
+# (at your option) any later version.
+#
+# This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
+
+use v5.20;
+use warnings;
+use utf8;
+
+use Const::Fast;
+use List::SomeUtils qw(any uniq);
+use Path::Tiny;
+use Unicode::UTF8 qw(encode_utf8);
+
+use Debian::Debhelper::Buildsystem::Haskell::Recipes qw(
+  run
+  installable_type
+  installable_hc
+  hc_pkgdir
+  ghc_pkg_command
+  load_ghc_database
+  hashed_id_to_virtual_installable
+);
+use Debian::Debhelper::Dh_Lib;
+
+const my $EMPTY => q{};
+const my $SPACE => q{ };
+const my $COMMA => q{,};
+const my $PLUS => q{+};
+
+const my $NEWLINE => qq{\n};
+
+init(
+    options => {
+        'config-shipper=s' => \$dh{CONFIG_SHIPPER},
+    });
+
+my $haskell_ghc_pkg = ghc_pkg_command();
+
+for my $installable (@{ $dh{DOPACKAGES} }) {
+
+    my $type = installable_type($installable);
+
+    my $haskell_compiler
+      = installable_hc($installable) || $ENV{DEB_DEFAULT_COMPILER};
+
+    my $pkgdir = hc_pkgdir($haskell_compiler);
+
+    my $config_shipper = $dh{CONFIG_SHIPPER} || $installable;
+    my $confdir = "debian/$config_shipper/$pkgdir";
+
+    my @ghc_configs;
+    @ghc_configs
+      = grep { $_->is_file } path($confdir)->children(qr{ [.]conf $}x)
+      if -e $confdir;
+
+    unless (@ghc_configs) {
+
+        warn encode_utf8('No Haskell package description are being shipped.');
+        next;
+    }
+
+    my @hashed_ids
+      = cabal_depends($haskell_ghc_pkg, $ENV{DEB_GHC_DATABASE}, at ghc_configs);
+
+    my @depends;
+    for my $hashed_id (@hashed_ids) {
+
+        # look in normal database
+        my $prerequisite
+          =hashed_id_to_virtual_installable($haskell_compiler,
+            $hashed_id, $type, $haskell_ghc_pkg, '--global');
+
+        if (length $prerequisite) {
+
+      # as a transition measure, check if dpkg knows about this virtual package
+            next
+              unless system(
+                "dpkg-query --show $prerequisite > /dev/null 2> /dev/null")
+              == 0;
+
+        } else {
+            my $provider
+              = providing_package_for_ghc($haskell_compiler,$hashed_id, $type);
+
+            if (!length $provider) {
+
+                warn encode_utf8(
+"WARNING: No Debian package provides the hashed Hackage id $hashed_id."
+                );
+                next;
+            }
+
+            my $version
+              = run(qw{dpkg-query --showformat=${Version} --show},$provider);
+
+            if (!length $version) {
+
+                warn encode_utf8(
+"WARNING: No Debian version available for prerequisite $provider."
+                );
+                next;
+            }
+
+            my $next_upstream_version = $version;
+            $next_upstream_version =~ s{ - [^-]* $}{}x;
+            $next_upstream_version .= $PLUS;
+
+            $prerequisite
+              ="$provider (>= $version), $provider (<< $next_upstream_version)";
+        }
+
+        push(@depends, $prerequisite);
+    }
+
+    push(@depends, "$config_shipper (=\${binary:Version})")
+      if $installable ne $config_shipper;
+
+    # fix sort order
+    local $ENV{LC_ALL} = 'C.UTF-8';
+
+    my $substvars_path = "debian/$installable.substvars";
+    replace_line($substvars_path, 'haskell:Depends',
+        join($COMMA . $SPACE, (sort +uniq @depends)));
+}
+
+exit;
+
+sub cabal_depends {
+    my ($ghc_pkg, $tmp_db, @configs) = @_;
+
+    load_ghc_database($ghc_pkg, $tmp_db, @configs);
+
+    my @prerequisites;
+    for my $config (@configs) {
+
+        my $name = path($config)->basename(qr{ [.]conf $}x);
+        my $depends
+          = run($ghc_pkg, '--package-db', $tmp_db, qw{--simple-output field},
+            $name, 'depends');
+        push(@prerequisites, split($SPACE, $depends // $EMPTY));
+    }
+
+    my @have = uniq @prerequisites;
+    my @exclude_patterns = split($SPACE, $ENV{DH_EXCLUDES} // $EMPTY);
+
+    # not sure this complies with Debhelper expectations
+    # excluded installables matching the patterns with or without version
+    # the versions should probably be dropped by the caller
+    s{ - [0-9] [.0-9a-zA-Z]* $}{}x for @exclude_patterns;
+
+    my @retained;
+    for my $prerequisite (@have) {
+
+        next
+          if any { $prerequisite =~ m{\Q$_\E} } @exclude_patterns;
+
+        push(@retained, $prerequisite);
+    }
+
+    return @retained;
+}
+
+sub providing_package_for_ghc {
+    my ($compiler, $hashed_id, $type) = @_;
+
+    my $extension = $EMPTY;
+    $extension = '_p'
+      if $type eq 'prof';
+
+    my $ghc_version= run(qw{dpkg-query --showformat=${Version} --show ghc});
+
+    my $directory_line= ghc_pkg_field($compiler, $hashed_id, 'library-dirs');
+    my (undef, $directory_list) = split(m{ \s* : \s* }x, $directory_line, 2);
+    my @library_dirs = split(m{ \s* , \s* }x, $directory_list);
+
+    my $library_line = ghc_pkg_field($compiler, $hashed_id, 'hs-libraries');
+    my (undef, $library_list) = split(m{ \s* : \s* }x, $library_line, 2);
+    my @libraries = split(m{ \s* , \s* }x, $library_list);
+
+    # look only at the first one
+    my $library = $libraries[0];
+
+    for my $directory (@library_dirs) {
+
+        my $library_path = "$directory/lib$library$extension.a";
+        next
+          unless -e $library_path;
+
+        my $line = run(qw{dpkg-query --search}, $library_path);
+        my ($installable) = split(m{ \s* : \s* }x, $line, 2);
+
+        return $installable;
+    }
+
+    return ();
+}
+
+sub ghc_pkg_field {
+    my ($compiler, $hashed_id, $field) = @_;
+
+    my $output= run("$compiler-pkg", qw{--global field}, $hashed_id, $field);
+
+    # may not process multi-line fields correctly
+    my ($value) = split($NEWLINE, $output, 2);
+
+    return ($value // $EMPTY);
+}
+
+sub replace_line {
+    my ($path, $field, $value) = @_;
+
+    path($path)->touch;
+
+    my @lines = grep { !m{^ $field = }x } path($path)->lines_utf8;
+
+    push(@lines, "$field=$value" . $NEWLINE);
+
+    path($path)->spew_utf8(@lines);
+
+    return;
+}
+
+=head1 NAME
+
+dh_haskell_depends_cabal - calculates Haskell dependencies on Cabalized libraries
+
+=head1 SYNOPSIS
+
+B<dh_haskell_depends_cabal> [S<I<debhelper options>>]
+
+=head1 DESCRIPTION
+
+dh_haskell_depends_cabal is a debhelper program that helps with calculating dependencies
+for building Haskell libraries.
+
+=head1 SEE ALSO
+
+L<debhelper(7)>
+
+=head1 AUTHOR
+
+John Goerzen <jgoerzen at complete.org>
+
+Based on ideas in dh_python by Josselin Mouette <joss at debian.org>
+
+=cut
+
+# Local Variables:
+# indent-tabs-mode: nil
+# cperl-indent-level: 4
+# End:
+# vim: syntax=perl sw=4 sts=4 sr et


=====================================
dh_haskell_depends_haddock
=====================================
@@ -0,0 +1,106 @@
+#!/usr/bin/perl
+
+# Copyright © 2022 Felix Lechner <felix.lechner at lease-up.com>
+#
+# based on a shell script by the same name
+#     Arjan Oosting <arjan at debian.org>
+#
+# This program 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 3 of the License, or
+# (at your option) any later version.
+#
+# This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
+
+use v5.20;
+use warnings;
+use utf8;
+
+use Const::Fast;
+use List::SomeUtils qw(uniq);
+use Path::Tiny;
+
+use Debian::Debhelper::Buildsystem::Haskell::Recipes qw(
+  run
+  installable_hc
+  hc_haddock
+);
+use Debian::Debhelper::Dh_Lib;
+
+const my $SPACE => q{ };
+const my $COMMA => q{,};
+
+const my $NEWLINE => qq{\n};
+
+init();
+
+for my $installable (@{ $dh{DOPACKAGES} }) {
+
+    my $compiler = installable_hc($installable);
+    my $haddock_command = hc_haddock($compiler);
+
+    my $version = run($haddock_command, '--interface-version');
+    chomp $version;
+
+    my @depends = ("haddock-interface-$version");
+
+    # fix sort order
+    local $ENV{LC_ALL} = 'C.UTF-8';
+
+    my $substvars_path = "debian/$installable.substvars";
+    replace_line($substvars_path, 'haskell:Depends',
+        join($COMMA . $SPACE, (sort +uniq @depends)));
+}
+
+exit;
+
+sub replace_line {
+    my ($path, $field, $value) = @_;
+
+    path($path)->touch;
+
+    my @lines = grep { !m{^ $field = }x } path($path)->lines_utf8;
+
+    push(@lines, "$field=$value" . $NEWLINE);
+
+    path($path)->spew_utf8(@lines);
+
+    return;
+}
+
+=head1 NAME
+
+dh_haskell_depends_haddock - calculates Haskell dependencies on Cabalized libraries
+
+=head1 SYNOPSIS
+
+B<dh_haskell_depends_haddock> [S<I<debhelper options>>]
+
+=head1 DESCRIPTION
+
+dh_haskell_depends_haddock is a debhelper program that helps with calculating dependencies
+for building Haskell libraries.
+
+=head1 SEE ALSO
+
+L<debhelper(7)>
+
+=head1 AUTHOR
+
+John Goerzen <jgoerzen at complete.org>
+
+Based on ideas in dh_python by Josselin Mouette <joss at debian.org>
+
+=cut
+
+# Local Variables:
+# indent-tabs-mode: nil
+# cperl-indent-level: 4
+# End:
+# vim: syntax=perl sw=4 sts=4 sr et


=====================================
dh_haskell_depends_hugs
=====================================
@@ -0,0 +1,110 @@
+#!/usr/bin/perl
+
+# Copyright © 2022 Felix Lechner <felix.lechner at lease-up.com>
+#
+# based on a shell script by the same name
+#     Arjan Oosting <arjan at debian.org>
+#
+# This program 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 3 of the License, or
+# (at your option) any later version.
+#
+# This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
+
+use v5.20;
+use warnings;
+use utf8;
+
+use Const::Fast;
+use List::SomeUtils qw(uniq);
+use Path::Tiny;
+
+use Debian::Debhelper::Buildsystem::Haskell::Recipes qw(run);
+use Debian::Debhelper::Dh_Lib;
+
+const my $EMPTY => q{};
+const my $SPACE => q{ };
+const my $COMMA => q{,};
+const my $NEWLINE => qq{\n};
+
+init();
+
+my $version = run(qw{dpkg-query --showformat=${Version} --show hugs});
+my $upstream_version = $version;
+
+# strip Debian revision
+$upstream_version =~ s{ - [^-]* $}{}x;
+
+my @depends = ("hugs (>= $upstream_version)");
+
+for my $installable (@{ $dh{DOPACKAGES} }) {
+
+    my $substvars_path = "debian/$installable.substvars";
+
+    # fix sort order
+    local $ENV{LC_ALL} = 'C.UTF-8';
+
+    replace_line($substvars_path, 'haskell:Depends',
+        join($COMMA . $SPACE, (sort +uniq @depends)));
+}
+
+exit;
+
+sub replace_line {
+    my ($path, $field, $value) = @_;
+
+    $value //= $EMPTY;
+
+    path($path)->touch;
+
+    my @lines = grep { !m{^ $field = }x } path($path)->lines_utf8;
+
+    push(@lines, "$field=$value" . $NEWLINE);
+
+    path($path)->spew_utf8(@lines);
+
+    return;
+}
+
+=head1 NAME
+
+dh_haskell_depends_hugs - store Haskell compiler info in substvars
+
+=head1 SYNOPSIS
+
+B<dh_haskell_depends_hugs> [S<I<debhelper options>>]
+
+=head1 DESCRIPTION
+
+dh_haskell_depends_hugs is a Debhelper program that Debian prerequisites for Haskell programs and libraries.
+
+You can use it like this: C<${haskell:Depends}>
+
+This script writes the debian/$package.substvars file, including in it the
+haskell:Depends variable.  So, to use this package, include in the Depends:
+field in debian/control ${haskell:Depends}.
+
+=head1 SEE ALSO
+
+L<debhelper(7)>
+
+=head1 AUTHOR
+
+John Goerzen <jgoerzen at complete.org>
+
+Based on ideas in dh_python by Josselin Mouette <joss at debian.org>
+
+=cut
+
+# Local Variables:
+# indent-tabs-mode: nil
+# cperl-indent-level: 4
+# End:
+# vim: syntax=perl sw=4 sts=4 sr et


=====================================
dh_haskell_description
=====================================
@@ -0,0 +1,128 @@
+#!/usr/bin/perl
+
+# Copyright © 2022 Felix Lechner <felix.lechner at lease-up.com>
+#
+# based on a shell script by the same name
+#     Joachim Breitner <nomeata at debian.org>
+#
+# This program 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 3 of the License, or
+# (at your option) any later version.
+#
+# This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
+
+use v5.20;
+use warnings;
+use utf8;
+
+use Const::Fast;
+use Path::Tiny;
+
+use Debian::Debhelper::Buildsystem::Haskell::Recipes qw(run);
+use Debian::Debhelper::Dh_Lib;
+
+const my $EMPTY => q{};
+const my $NEWLINE => qq{\n};
+
+init();
+
+# see Bug#1009162
+my $description = get_source_field('Description');
+
+# otherwise try X-Description
+$description ||= get_source_field('X-Description');
+
+my ($short_description, $long_description) = split(m{\n}, $description, 2);
+
+$short_description //= $EMPTY;
+$long_description //= $EMPTY;
+
+# drop initial spaces
+$long_description =~ s{^ [ ] }{}gmx;
+
+# prepare for dpkg-gencontrol
+$long_description =~ s{ \n }{\$\{Newline\}}gx;
+
+for my $installable (@{ $dh{DOPACKAGES} }) {
+
+    my $substvars_path = "debian/$installable.substvars";
+
+    replace_line($substvars_path, 'haskell:ShortDescription',
+        $short_description);
+    replace_line($substvars_path, 'haskell:LongDescription',$long_description);
+}
+
+exit;
+
+sub get_source_field {
+    my ($name) = @_;
+
+    die encode_utf8('grep-dctrl is missing')
+      unless system('command -v grep-dctrl > /dev/null') == 0;
+
+    # need regex to avoid the empty string, which would be filtered by run()
+    my $value= run(
+        qw{grep-dctrl --no-field-names},
+        "--show-field=$name",
+        qw{--field=Source --regex .* debian/control}
+    );
+
+    chomp $value;
+
+    return $value;
+}
+
+sub replace_line {
+    my ($path, $field, $value) = @_;
+
+    $value //= $EMPTY;
+
+    path($path)->touch;
+
+    my @lines = grep { !m{^ $field = }x } path($path)->lines_utf8;
+
+    push(@lines, "$field=$value" . $NEWLINE);
+
+    path($path)->spew_utf8(@lines);
+
+    return;
+}
+
+=head1 NAME
+
+dh_haskell_description - store Haskell package descriptions info in substvars
+
+=head1 SYNOPSIS
+
+B<dh_haskell_description> [S<I<debhelper options>>]
+
+=head1 DESCRIPTION
+
+dh_haskell_description is a Debhelper program that stores package descriptions in substvars.
+
+You can use it like this: C<${haskell:ShortDescription}>
+
+or like that: C<${haskell:LongDescription}>
+
+=head1 SEE ALSO
+
+L<debhelper(7)>
+
+=head1 AUTHOR
+
+Joachim Breitner <nomeata at debian.org>
+
+=cut
+
+# Local Variables:
+# indent-tabs-mode: nil
+# cperl-indent-level: 4
+# End:
+# vim: syntax=perl sw=4 sts=4 sr et


=====================================
dh_haskell_extra_depends_ghc
=====================================
@@ -0,0 +1,152 @@
+#!/usr/bin/perl
+
+# Copyright © 2022 Felix Lechner <felix.lechner at lease-up.com>
+#
+# based on a shell script by the same name
+#     Arjan Oosting <arjan at debian.org>
+#
+# This program 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 3 of the License, or
+# (at your option) any later version.
+#
+# This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
+
+use v5.20;
+use warnings;
+use utf8;
+
+use Const::Fast;
+use List::SomeUtils qw(uniq);
+use Path::Tiny;
+use Unicode::UTF8 qw(encode_utf8);
+
+use Debian::Debhelper::Buildsystem::Haskell::Recipes qw(
+  run
+  installable_hc
+  ghc_pkg_command
+  load_ghc_database
+  own_cabal_prerequisites
+);
+use Debian::Debhelper::Dh_Lib;
+
+const my $EMPTY => q{};
+const my $SPACE => q{ };
+const my $COMMA => q{,};
+
+const my $NEWLINE => qq{\n};
+
+init();
+
+# this installs the extra-packages file
+if (length $ENV{DEB_GHC_EXTRA_PACKAGES}) {
+
+    die encode_utf8('Need CABAL_PACKAGE for DEB_GHC_EXTRA_PACKAGES')
+      unless length $ENV{CABAL_PACKAGE};
+
+    die encode_utf8('Need CABAL_VERSION for DEB_GHC_EXTRA_PACKAGES')
+      unless length $ENV{CABAL_VERSION};
+
+    for my $installable (@{ $dh{DOPACKAGES} }) {
+
+        my $EP_DIR
+          = "debian/$installable/usr/lib/haskell-packages/extra-packages";
+        run(qw{mkdir --parents}, $EP_DIR);
+
+        path("$EP_DIR/$ENV{CABAL_PACKAGE}-$ENV{CABAL_VERSION}")
+          ->spew_utf8($ENV{DEB_GHC_EXTRA_PACKAGES});
+    }
+}
+
+# and that consumes it
+for my $installable (@{ $dh{DOPACKAGES} }) {
+
+    my $compiler = installable_hc($installable) || $ENV{DEB_DEFAULT_COMPILER};
+
+    my @extra_depends;
+
+    my @hashed_ids= own_cabal_prerequisites($compiler, $ENV{DEB_GHC_DATABASE});
+    for my $hashed_id (@hashed_ids) {
+
+        next
+          unless $hashed_id =~ m{^ ([^-]+) - ([0-9.]+) - [0-9a-f]{32} $}x;
+
+        my $name = $1;
+        my $version = $2;
+
+        my $extra_packages_file
+          = "/usr/lib/haskell-packages/extra-packages/$name-$version";
+
+        push(@extra_depends,
+            split(m{ \s* , \s* }x, path($extra_packages_file)->slurp_utf8))
+          if -e $extra_packages_file;
+    }
+
+    my $substvars_path = "debian/$installable.substvars";
+
+    # fix sort order
+    local $ENV{LC_ALL} = 'C.UTF-8';
+
+    replace_line($substvars_path, 'haskell:Extra-Depends',
+        join($COMMA . $SPACE, (sort +uniq @extra_depends)));
+}
+
+exit;
+
+sub replace_line {
+    my ($path, $field, $value) = @_;
+
+    $value //= $EMPTY;
+
+    path($path)->touch;
+
+    my @lines = grep { !m{^ $field = }x } path($path)->lines_utf8;
+
+    push(@lines, "$field=$value" . $NEWLINE);
+
+    path($path)->spew_utf8(@lines);
+
+    return;
+}
+
+=head1 NAME
+
+dh_haskell_extra_depends_ghc - store Haskell compiler info in substvars
+
+=head1 SYNOPSIS
+
+B<dh_haskell_extra_depends_ghc> [S<I<debhelper options>>]
+
+=head1 DESCRIPTION
+
+dh_haskell_extra_depends_ghc is a Debhelper program that Debian prerequisites for Haskell programs and libraries.
+
+You can use it like this: C<${haskell:Depends}>
+
+This script writes the debian/$package.substvars file, including in it the
+haskell:Depends variable.  So, to use this package, include in the Depends:
+field in debian/control ${haskell:Depends}.
+
+=head1 SEE ALSO
+
+L<debhelper(7)>
+
+=head1 AUTHOR
+
+John Goerzen <jgoerzen at complete.org>
+
+Based on ideas in dh_python by Josselin Mouette <joss at debian.org>
+
+=cut
+
+# Local Variables:
+# indent-tabs-mode: nil
+# cperl-indent-level: 4
+# End:
+# vim: syntax=perl sw=4 sts=4 sr et


=====================================
dh_haskell_install_development_libs
=====================================
@@ -0,0 +1,101 @@
+#!/usr/bin/perl
+
+# Copyright © 2022 Felix Lechner <felix.lechner at lease-up.com>
+#
+# based on a shell script library by John Goerzen
+#
+# This program 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 3 of the License, or
+# (at your option) any later version.
+#
+# This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
+
+use v5.20;
+use warnings;
+use utf8;
+
+use Const::Fast;
+use Cwd;
+
+use Debian::Debhelper::Buildsystem::Haskell::Recipes qw(
+  run
+  installable_hc
+  hc_libdir
+);
+use Debian::Debhelper::Dh_Lib;
+
+const my $DOT => q{.};
+const my $SEMICOLON => q{;};
+
+init(
+    options => {
+        'source-dir=s' => \$dh{SOURCE_DIR},
+    });
+
+for my $installable (@{ $dh{DOPACKAGES} }) {
+
+    my $compiler = installable_hc($installable) || $ENV{DEB_DEFAULT_COMPILER};
+    my $libdir = hc_libdir($compiler);
+
+    my $source = $dh{SOURCE_DIR} || $DOT;
+
+    next
+      unless -e "$source/$libdir";
+
+    my $savedir = Cwd::getcwd;
+    chdir($source)
+      or die encode_utf8("Cannot change folder to $source");
+
+    run(
+        'find',
+        "./$libdir",
+        qw{ ( ! -name *_p.a ! -name *.p_hi ! -type d ) },
+        qw{-exec install -D --mode=644},
+        '{}',
+        "$savedir/debian/$installable/{}",
+        $SEMICOLON
+    );
+
+    chdir($savedir)
+      or warn encode_utf8("Cannot change folder to $savedir");
+}
+
+exit;
+
+=head1 NAME
+
+dh_haskell_install_development_libs - Haskell install helper
+
+=head1 SYNOPSIS
+
+B<dh_haskell_install_development_libs> [S<I<debhelper options>>]
+
+=head1 DESCRIPTION
+
+dh_haskell_install_development_libs is a Debhelper program that helps with installing files
+when building Haskell libraries.
+
+=head1 SEE ALSO
+
+L<debhelper(7)>
+
+=head1 AUTHOR
+
+John Goerzen <jgoerzen at complete.org>
+
+Based on ideas in dh_python by Josselin Mouette <joss at debian.org>
+
+=cut
+
+# Local Variables:
+# indent-tabs-mode: nil
+# cperl-indent-level: 4
+# End:
+# vim: syntax=perl sw=4 sts=4 sr et


=====================================
dh_haskell_install_ghc_registration
=====================================
@@ -0,0 +1,94 @@
+#!/usr/bin/perl
+
+# Copyright © 2022 Felix Lechner <felix.lechner at lease-up.com>
+#
+# based on a shell script library by John Goerzen
+#
+# This program 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 3 of the License, or
+# (at your option) any later version.
+#
+# This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
+
+use v5.20;
+use warnings;
+use utf8;
+
+use Debian::Debhelper::Buildsystem::Haskell::Recipes qw(
+  run
+  installable_hc
+  hc_pkgdir
+);
+use Debian::Debhelper::Dh_Lib;
+
+init();
+
+die encode_utf8('No Setup.hs executable named.')
+  unless length $ENV{DEB_SETUP_BIN_NAME};
+
+for my $installable (@{ $dh{DOPACKAGES} }) {
+
+    my $compiler = installable_hc($installable) || $ENV{DEB_DEFAULT_COMPILER};
+    my $pkgdir = hc_pkgdir($compiler);
+
+    my $output = run($ENV{DEB_SETUP_BIN_NAME},
+        'register', "--builddir=dist-$compiler",
+        qw{--gen-pkg-config --verbose=verbose+nowrap});
+
+    if ($output
+        =~ m{^Creating \s package \s registration \s file: \s+ (\S+) $}mx) {
+
+        my $pkg_config = $1;
+
+        run(qw{sed -i}, 's/^exposed: True$/exposed: False/',$pkg_config)
+          if length $ENV{HASKELL_HIDE_PACKAGES};
+
+        run(qw{install -D --mode=644},
+            $pkg_config, "debian/$installable/$pkgdir/$pkg_config");
+        run(qw{rm -f}, $pkg_config);
+
+    } else {
+
+        die encode_utf8('Cannot get package registration file.');
+    }
+}
+
+exit;
+
+=head1 NAME
+
+dh_haskell_install_ghc_registration - Haskell install helper
+
+=head1 SYNOPSIS
+
+B<dh_haskell_install_ghc_registration> [S<I<debhelper options>>]
+
+=head1 DESCRIPTION
+
+dh_haskell_install_ghc_registration is a Debhelper program that helps with installing files
+when building Haskell libraries.
+
+=head1 SEE ALSO
+
+L<debhelper(7)>
+
+=head1 AUTHOR
+
+John Goerzen <jgoerzen at complete.org>
+
+Based on ideas in dh_python by Josselin Mouette <joss at debian.org>
+
+=cut
+
+# Local Variables:
+# indent-tabs-mode: nil
+# cperl-indent-level: 4
+# End:
+# vim: syntax=perl sw=4 sts=4 sr et


=====================================
dh_haskell_install_haddock
=====================================
@@ -0,0 +1,99 @@
+#!/usr/bin/perl
+
+# Copyright © 2022 Felix Lechner <felix.lechner at lease-up.com>
+#
+# based on a shell script library by John Goerzen
+#
+# This program 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 3 of the License, or
+# (at your option) any later version.
+#
+# This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
+
+use v5.20;
+use warnings;
+use utf8;
+
+use Const::Fast;
+use Path::Tiny;
+
+use Debian::Debhelper::Buildsystem::Haskell::Recipes qw(
+  run
+  installable_hc
+  hc_docdir
+);
+use Debian::Debhelper::Dh_Lib;
+
+const my $DOT => q{.};
+
+init(
+    options => {
+        'source-dir=s' => \$dh{SOURCE_DIR},
+    });
+
+die encode_utf8('Need CABAL_PACKAGE to install HTML documentation.')
+  unless length $ENV{CABAL_PACKAGE};
+
+die encode_utf8('Need CABAL_VERSION to install HTML documentation.')
+  unless length $ENV{CABAL_VERSION};
+
+for my $installable (@{ $dh{DOPACKAGES} }) {
+
+    my $compiler = installable_hc($installable) || $ENV{DEB_DEFAULT_COMPILER};
+
+    my $docdir
+      = hc_docdir($compiler, $ENV{CABAL_PACKAGE}, $ENV{CABAL_VERSION});
+
+    my $source = $dh{SOURCE_DIR} || $DOT;
+    my $tmp_docdir = "$source/$docdir";
+
+    next
+      unless -e $tmp_docdir;
+
+    my $installable_docdir = "debian/$installable/$docdir";
+
+    run(qw{mkdir --parents}, $installable_docdir);
+
+    run(qw{cp --recursive}, $_->stringify, $installable_docdir)
+      for path($tmp_docdir)->children(qr{ [.]haddock $}x);
+}
+
+exit;
+
+=head1 NAME
+
+dh_haskell_install_haddock - Haskell install helper
+
+=head1 SYNOPSIS
+
+B<dh_haskell_install_haddock> [S<I<debhelper options>>]
+
+=head1 DESCRIPTION
+
+dh_haskell_install_haddock is a Debhelper program that helps with installing files
+when building Haskell libraries.
+
+=head1 SEE ALSO
+
+L<debhelper(7)>
+
+=head1 AUTHOR
+
+John Goerzen <jgoerzen at complete.org>
+
+Based on ideas in dh_python by Josselin Mouette <joss at debian.org>
+
+=cut
+
+# Local Variables:
+# indent-tabs-mode: nil
+# cperl-indent-level: 4
+# End:
+# vim: syntax=perl sw=4 sts=4 sr et


=====================================
dh_haskell_install_htmldocs
=====================================
@@ -0,0 +1,120 @@
+#!/usr/bin/perl
+
+# Copyright © 2022 Felix Lechner <felix.lechner at lease-up.com>
+#
+# based on a shell script library by John Goerzen
+#
+# This program 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 3 of the License, or
+# (at your option) any later version.
+#
+# This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
+
+use v5.20;
+use warnings;
+use utf8;
+
+use Const::Fast;
+use Cwd;
+
+use Debian::Debhelper::Buildsystem::Haskell::Recipes qw(
+  run
+  installable_hc
+  hc_htmldir
+);
+use Debian::Debhelper::Dh_Lib;
+
+const my $DOT => q{.};
+const my $SEMICOLON => q{;};
+
+init(
+    options => {
+        'source-dir=s' => \$dh{SOURCE_DIR},
+    });
+
+die encode_utf8('Need CABAL_PACKAGE to install HTML documentation.')
+  unless length $ENV{CABAL_PACKAGE};
+
+for my $installable (@{ $dh{DOPACKAGES} }) {
+
+    my $compiler = installable_hc($installable) || $ENV{DEB_DEFAULT_COMPILER};
+    my $htmldir = hc_htmldir($compiler, $ENV{CABAL_PACKAGE});
+
+    my $source = $dh{SOURCE_DIR} || $DOT;
+
+    next
+      unless -e "$source/$htmldir";
+
+    my $savedir = Cwd::getcwd;
+    chdir($source)
+      or die encode_utf8("Cannot change folder to $source");
+
+    run(
+        'find',"./$htmldir",
+        qw{ ! -name *.haddock ! -type d},
+        qw{-exec install -D --mode=644},
+        '{}',"$savedir/debian/$installable/{}",$SEMICOLON
+    );
+
+    chdir($savedir)
+      or warn encode_utf8("Cannot change folder to $savedir");
+
+    if ($ENV{DEB_ENABLE_HOOGLE} eq 'yes') {
+
+        # We cannot just invoke dh_link here because that acts on
+        # either libghc-*-dev or all the binary packages, neither of
+        # which is desirable (see dh_link (1)).  So we just create a
+        # (policy-compliant) symlink ourselves
+
+        my $target= "debian/$installable/$htmldir/$ENV{CABAL_PACKAGE}.txt";
+        if (-e $target) {
+
+            my $hoogle = "usr/lib/$compiler-doc/hoogle/";
+            my $name = "debian/$installable/$hoogle$installable.txt";
+
+            run(qw{mkdir --parents}, dirname($name));
+            run(qw{ln --symbolic --relative --no-target-directory},
+                $target, $name);
+        }
+    }
+}
+
+exit;
+
+=head1 NAME
+
+dh_haskell_install_htmldocs - Haskell install helper
+
+=head1 SYNOPSIS
+
+B<dh_haskell_install_htmldocs> [S<I<debhelper options>>]
+
+=head1 DESCRIPTION
+
+dh_haskell_install_htmldocs is a Debhelper program that helps with installing files
+when building Haskell libraries.
+
+=head1 SEE ALSO
+
+L<debhelper(7)>
+
+=head1 AUTHOR
+
+John Goerzen <jgoerzen at complete.org>
+
+Based on ideas in dh_python by Josselin Mouette <joss at debian.org>
+
+=cut
+
+# Local Variables:
+# indent-tabs-mode: nil
+# cperl-indent-level: 4
+# End:
+# vim: syntax=perl sw=4 sts=4 sr et


=====================================
dh_haskell_install_profiling_libs
=====================================
@@ -0,0 +1,101 @@
+#!/usr/bin/perl
+
+# Copyright © 2022 Felix Lechner <felix.lechner at lease-up.com>
+#
+# based on a shell script library by John Goerzen
+#
+# This program 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 3 of the License, or
+# (at your option) any later version.
+#
+# This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
+
+use v5.20;
+use warnings;
+use utf8;
+
+use Const::Fast;
+use Cwd;
+
+use Debian::Debhelper::Buildsystem::Haskell::Recipes qw(
+  run
+  installable_hc
+  hc_libdir
+);
+use Debian::Debhelper::Dh_Lib;
+
+const my $DOT => q{.};
+const my $SEMICOLON => q{;};
+
+init(
+    options => {
+        'source-dir=s' => \$dh{SOURCE_DIR},
+    });
+
+for my $installable (@{ $dh{DOPACKAGES} }) {
+
+    my $compiler = installable_hc($installable) || $ENV{DEB_DEFAULT_COMPILER};
+    my $libdir = hc_libdir($compiler);
+
+    my $source = $dh{SOURCE_DIR} || $DOT;
+
+    next
+      unless -e "$source/$libdir";
+
+    my $savedir = Cwd::getcwd;
+    chdir($source)
+      or die encode_utf8("Cannot change folder to $source");
+
+    run(
+        'find',
+        "./$libdir",
+        qw{ ( -name *_p.a -o -name *.p_hi ) },
+        qw{-exec install -D --mode=644},
+        '{}',
+        "$savedir/debian/$installable/{}",
+        $SEMICOLON
+    );
+
+    chdir($savedir)
+      or warn encode_utf8("Cannot change folder to $savedir");
+}
+
+exit;
+
+=head1 NAME
+
+dh_haskell_install_profiling_libs - Haskell install helper
+
+=head1 SYNOPSIS
+
+B<dh_haskell_install_profiling_libs> [S<I<debhelper options>>]
+
+=head1 DESCRIPTION
+
+dh_haskell_install_profiling_libs is a Debhelper program that helps with installing files
+when building Haskell libraries.
+
+=head1 SEE ALSO
+
+L<debhelper(7)>
+
+=head1 AUTHOR
+
+John Goerzen <jgoerzen at complete.org>
+
+Based on ideas in dh_python by Josselin Mouette <joss at debian.org>
+
+=cut
+
+# Local Variables:
+# indent-tabs-mode: nil
+# cperl-indent-level: 4
+# End:
+# vim: syntax=perl sw=4 sts=4 sr et


=====================================
dh_haskell_provides
=====================================
@@ -1,11 +1,7 @@
-#!/usr/bin/perl
+#!/bin/sh
 
 # Copyright © 2022 Felix Lechner <felix.lechner at lease-up.com>
 #
-# based on a shell script by the same name
-#     by Arjan Oosting <arjan at debian.org>
-#     and Joachim Breitner <nomeata at debian.org>
-#
 # This program 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 3 of the License, or
@@ -19,177 +15,9 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-use v5.20;
-use warnings;
-use utf8;
-
-use Const::Fast;
-use File::Basename;
-use Getopt::Long ();
-use List::SomeUtils qw(none);
-use Path::Tiny;
-use Unicode::UTF8 qw(encode_utf8);
-
-use Debian::Debhelper::Buildsystem::Haskell::Recipes qw(
-  run
-  installable_type
-  installable_hc
-  find_config_for_ghc
-  ghc_pkg_command
-  load_ghc_database
-  hashed_id_to_virtual_installable
-);
-
-const my $SPACE => q{ };
-const my $COMMA => q{,};
-const my $NEWLINE => qq{\n};
-
-my $program_name = basename($0);
-
-# for a call from ghc's d/rules
-$ENV{DEB_DEFAULT_COMPILER} ||= 'ghc';
-$ENV{DEB_GHC_DATABASE} ||= 'debian/tmp-db';
-
-my @excludes;
-
-my %options = (
-    'exclude|X=s' => \@excludes,
-    'help|h' => \&show_help,
-);
-
-Getopt::Long::Configure('gnu_getopt', 'pass_through');
-Getopt::Long::GetOptions(%options)
-  or die encode_utf8("error parsing options\n");
-
-my @args_bytes = grep { /^-/ } @ARGV;
-my @configs = grep { !/^-/ } @ARGV;
-
-die encode_utf8("Installed package description file $_ can not be found")
-  for grep { !-e } @configs;
-
-$ENV{DH_EXCLUDES} = join($SPACE, @excludes);
-
-my $output = run('dh_listpackages', @args_bytes);
-chomp $output;
-
-my @installables = split($SPACE, $output);
-for my $installable (@installables) {
-
-    my $type = installable_type($installable);
-
-    @configs = find_config_for_ghc($installable)
-      unless @configs;
-
-    warn encode_utf8(
-        "$program_name: No installed package description files found")
-      unless @configs;
-
-    my $compiler = installable_hc($installable) || $ENV{DEB_DEFAULT_COMPILER};
-
-    my $ghc_pkg = ghc_pkg_command();
-    load_ghc_database($ghc_pkg, $ENV{DEB_GHC_DATABASE}, @configs);
-
-    my @hashed_ids;
-    for my $config (@configs) {
-
-        my $name = path($config)->basename(qr{ [.]conf $}x);
-        push(
-            @hashed_ids,
-            run(
-                $ghc_pkg, '--package-db', $ENV{DEB_GHC_DATABASE},
-                qw{--simple-output field},
-                $name, 'id'
-            ));
-    }
-
-    my @provides;
-    push(
-        @provides,
-        hashed_id_to_virtual_installable(
-            $compiler, $_, $type,
-            $ghc_pkg, '--package-db', $ENV{DEB_GHC_DATABASE}))for @hashed_ids;
-
-    my $substvars_path = "debian/$installable.substvars";
-    replace_line($substvars_path, 'haskell:Provides',
-        join($COMMA . $SPACE, @provides));
-
-    if ($type eq 'dev') {
-
-        replace_line($substvars_path, "haskell:$compiler-package",
-            join($SPACE, @hashed_ids));
-    }
-}
-
-exit;
-
-sub replace_line {
-    my ($path, $field, $value) = @_;
-
-    path($path)->touch;
-
-    my @lines = grep { !m{^ $field = }x } path($path)->lines_utf8;
-
-    push(@lines, "$field=$value" . $NEWLINE);
-
-    path($path)->spew_utf8(@lines);
-
-    return;
-}
-
-sub show_help {
-    my $message =<<"EOT";
-Usage: $program_name [options] cabal-file ...
-
-Options:
-    -X, --exclude INSTALLABLE    exclude INSTALLABLE from processing
-EOT
-
-    print encode_utf8($message);
-
-    exit;
-}
-
-=head1 NAME
-
-dh_haskell_provides - calculates Haskell virtual package names on Cabalized libraries
-
-=head1 SYNOPSIS
-
-B<dh_haskell_provides> [S<I<debhelper options>>]
-[B<-X>I<package>]
-[B<--exclude=>I<package>]
-[S<I<file>> ...]
-
-=head1 DESCRIPTION
-
-dh_haskell_provides is a debhelper program that calculates the correct virtual
-package to provide, so that dependencies can guarantee ABI stability.
-
-For a package with an idea of package-version-longhashstring, it generates a
-virtual package of the form libghc-package-dev-version-longh for the -dev
-package and libghc-package-prof-version-longh for the prof package
-respectively.
-
-This script writes the debian/$package.substvars file, including in it the
-haskell:Provides.  So, to use this package, include in the Provides: field in
-debian/control ${haskell:Provides}.
-
-=head1 SEE ALSO
-
-L<dh_haskell_depends(1)>
-L<dh_haskell_shlibdeps(1)>
-L<debhelper(7)>
-
-=head1 AUTHOR
-
-Joachim Breitner <nomeata at debian.org>
-
-Based on ideas in dh_ocaml.
+# this script exists only for a call from ghc's d/rules
 
-=cut
+export DEB_DEFAULT_COMPILER=ghc
+export DEB_GHC_DATABASE=debian/tmp-db
 
-# Local Variables:
-# indent-tabs-mode: nil
-# cperl-indent-level: 4
-# End:
-# vim: syntax=perl sw=4 sts=4 sr et
+dh_haskell_provides_ghc --config-shipper=ghc


=====================================
dh_haskell_provides_ghc
=====================================
@@ -0,0 +1,162 @@
+#!/usr/bin/perl
+
+# Copyright © 2022 Felix Lechner <felix.lechner at lease-up.com>
+#
+# based on a shell script by the same name
+#     by Arjan Oosting <arjan at debian.org>
+#     and Joachim Breitner <nomeata at debian.org>
+#
+# This program 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 3 of the License, or
+# (at your option) any later version.
+#
+# This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
+
+use v5.20;
+use warnings;
+use utf8;
+
+use Const::Fast;
+use List::SomeUtils qw(none uniq);
+use Path::Tiny;
+use Unicode::UTF8 qw(encode_utf8);
+
+use Debian::Debhelper::Buildsystem::Haskell::Recipes qw(
+  run
+  installable_type
+  installable_hc
+  hc_pkgdir
+  ghc_pkg_command
+  load_ghc_database
+  hashed_id_to_virtual_installable
+);
+use Debian::Debhelper::Dh_Lib;
+
+const my $SPACE => q{ };
+const my $COMMA => q{,};
+const my $NEWLINE => qq{\n};
+
+init(
+    options => {
+        'config-shipper=s' => \$dh{CONFIG_SHIPPER},
+    });
+
+for my $installable (@{ $dh{DOPACKAGES} }) {
+
+    my $compiler = installable_hc($installable) || $ENV{DEB_DEFAULT_COMPILER};
+    my $pkgdir = hc_pkgdir($compiler);
+
+    my $config_shipper = $dh{CONFIG_SHIPPER} || $installable;
+    my $confdir = "debian/$config_shipper/$pkgdir";
+
+    my @configs;
+    @configs = grep { $_->is_file } path($confdir)->children(qr{ [.]conf $}x)
+      if -e $confdir;
+
+    unless (@configs) {
+
+        warn encode_utf8('No Haskell package description are being shipped.');
+        next;
+    }
+
+    my $ghc_pkg = ghc_pkg_command();
+    load_ghc_database($ghc_pkg, $ENV{DEB_GHC_DATABASE}, @configs);
+
+    my @hashed_ids;
+    for my $config (@configs) {
+
+        my $name = path($config)->basename(qr{ [.]conf $}x);
+        push(
+            @hashed_ids,
+            run(
+                $ghc_pkg, '--package-db', $ENV{DEB_GHC_DATABASE},
+                qw{--simple-output field},
+                $name, 'id'
+            ));
+    }
+
+    my $substvars_path = "debian/$installable.substvars";
+
+    replace_line($substvars_path, "haskell:$compiler-package",
+        join($SPACE, @hashed_ids));
+
+    my $type = installable_type($installable);
+    my @provides = map {
+        hashed_id_to_virtual_installable($compiler, $_, $type,
+            $ghc_pkg, '--package-db', $ENV{DEB_GHC_DATABASE})
+    } @hashed_ids;
+
+    # fix sort order
+    local $ENV{LC_ALL} = 'C.UTF-8';
+
+    replace_line($substvars_path, 'haskell:Provides',
+        join($COMMA . $SPACE, (sort +uniq @provides)));
+}
+
+exit;
+
+sub replace_line {
+    my ($path, $field, $value) = @_;
+
+    path($path)->touch;
+
+    my @lines = grep { !m{^ $field = }x } path($path)->lines_utf8;
+
+    push(@lines, "$field=$value" . $NEWLINE);
+
+    path($path)->spew_utf8(@lines);
+
+    return;
+}
+
+=head1 NAME
+
+dh_haskell_provides_ghc - calculates Haskell virtual package names on Cabalized libraries
+
+=head1 SYNOPSIS
+
+B<dh_haskell_provides_ghc> [S<I<debhelper options>>]
+[B<-X>I<package>]
+[B<--exclude=>I<package>]
+[S<I<file>> ...]
+
+=head1 DESCRIPTION
+
+dh_haskell_provides_ghc is a debhelper program that calculates the correct virtual
+package to provide, so that dependencies can guarantee ABI stability.
+
+For a package with an idea of package-version-longhashstring, it generates a
+virtual package of the form libghc-package-dev-version-longh for the -dev
+package and libghc-package-prof-version-longh for the prof package
+respectively.
+
+This script writes the debian/$package.substvars file, including in it the
+haskell:Provides.  So, to use this package, include in the Provides: field in
+debian/control ${haskell:Provides}.
+
+=head1 SEE ALSO
+
+L<dh_haskell_depends(1)>
+L<dh_haskell_shlibdeps(1)>
+L<debhelper(7)>
+
+=head1 AUTHOR
+
+Joachim Breitner <nomeata at debian.org>
+
+Based on ideas in dh_ocaml.
+
+=cut
+
+# Local Variables:
+# indent-tabs-mode: nil
+# cperl-indent-level: 4
+# End:
+# vim: syntax=perl sw=4 sts=4 sr et


=====================================
dh_haskell_recommends_documentation_references
=====================================
@@ -0,0 +1,161 @@
+#!/usr/bin/perl
+
+# Copyright © 2022 Felix Lechner <felix.lechner at lease-up.com>
+#
+# based on a shell script by the same name
+#     Arjan Oosting <arjan at debian.org>
+#
+# This program 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 3 of the License, or
+# (at your option) any later version.
+#
+# This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
+
+use v5.20;
+use warnings;
+use utf8;
+
+use Const::Fast;
+use List::SomeUtils qw(uniq);
+use IPC::Run3;
+use Path::Tiny;
+use Unicode::UTF8 qw(encode_utf8);
+
+use Debian::Debhelper::Buildsystem::Haskell::Recipes qw(run_quiet);
+use Debian::Debhelper::Dh_Lib;
+
+const my $EMPTY => q{};
+const my $SPACE => q{ };
+const my $COMMA => q{,};
+
+const my $NEWLINE => qq{\n};
+const my $NULL => qq{\0};
+
+const my $WAIT_STATUS_SHIFT => 8;
+
+init();
+
+die encode_utf8('grep-dctrl is missing')
+  unless system('command -v grep-dctrl > /dev/null') == 0;
+
+for my $installable (@{ $dh{DOPACKAGES} }) {
+
+    say encode_utf8(
+        "Finding all links in the documentation in installable $installable.");
+    my @links =split(
+        m{\n}x,
+        run_quiet(
+            'find', "debian/$installable",
+            qw{-name *.html -exec hxwls -r \{\} ;}
+        ));
+
+    my @files;
+    for my $link (@links) {
+
+        # filter out fragment, too
+        next
+          unless $link =~ m{^ file:// ([^#]*) }x;
+
+        my $file = $1;
+        push(@files, $file);
+    }
+
+    my @absolute = uniq +grep { m{^ / }x } @files;
+
+    # already in UTF-8
+    my $input_bytes = $EMPTY;
+    $input_bytes .= $_ . $NULL for @absolute;
+
+    my $stdout_bytes;
+    my $stderr_bytes;
+
+    my @combined = qw{xargs --null --no-run-if-empty dpkg --search};
+    run3(\@combined, \$input_bytes, \$stdout_bytes, \$stderr_bytes);
+
+    my $exitcode = $?;
+    my $status = ($exitcode >> $WAIT_STATUS_SHIFT);
+
+    # already in UTF-8
+    warn encode_utf8("Non-zero exit code $exitcode."). $NEWLINE. $stderr_bytes
+      if $exitcode;
+
+    my @lines = split(m{\n}, $stdout_bytes);
+
+    my @recommends;
+    for my $line (@lines) {
+
+        my ($origin) = split(m{:}, $line, 2);
+        next
+          unless length $origin;
+
+        push(@recommends, $origin);
+    }
+
+    my $dev = $installable;
+    $dev =~ s{ - [^-]+ $}{-dev}x;
+
+    push(@recommends, $dev)
+      if system(qw{grep-dctrl --quiet --field=Package},$dev, 'debian/control')
+      == 0;
+
+    # fix sort order
+    local $ENV{LC_ALL} = 'C.UTF-8';
+
+    my $substvars_path = "debian/$installable.substvars";
+    replace_line($substvars_path, 'haskell:Recommends',
+        join($COMMA . $SPACE, (sort +uniq @recommends)));
+}
+
+exit;
+
+sub replace_line {
+    my ($path, $field, $value) = @_;
+
+    path($path)->touch;
+
+    my @lines = grep { !m{^ $field = }x } path($path)->lines_utf8;
+
+    push(@lines, "$field=$value" . $NEWLINE);
+
+    path($path)->spew_utf8(@lines);
+
+    return;
+}
+
+=head1 NAME
+
+dh_haskell_recommends_documentation_references - calculates Haskell dependencies on Cabalized libraries
+
+=head1 SYNOPSIS
+
+B<dh_haskell_recommends_documentation_references> [S<I<debhelper options>>]
+
+=head1 DESCRIPTION
+
+dh_haskell_recommends_documentation_references is a debhelper program that helps with calculating dependencies
+for building Haskell libraries.
+
+=head1 SEE ALSO
+
+L<debhelper(7)>
+
+=head1 AUTHOR
+
+John Goerzen <jgoerzen at complete.org>
+
+Based on ideas in dh_python by Josselin Mouette <joss at debian.org>
+
+=cut
+
+# Local Variables:
+# indent-tabs-mode: nil
+# cperl-indent-level: 4
+# End:
+# vim: syntax=perl sw=4 sts=4 sr et


=====================================
dh_haskell_shlibdeps
=====================================
@@ -26,138 +26,90 @@ use warnings;
 use utf8;
 
 use Const::Fast;
-use File::Basename;
-use Getopt::Long ();
 use Path::Tiny;
 use Unicode::UTF8 qw(encode_utf8 decode_utf8);
 
 use Debian::Debhelper::Buildsystem::Haskell::Recipes qw(
   run
-  installable_type
-  find_config_for_ghc
+  installable_hc
+  hc_pkgdir
   ghc_pkg_command
   load_ghc_database
 );
+use Debian::Debhelper::Dh_Lib;
 
 const my $SPACE => q{ };
 const my $NEWLINE => qq{\n};
 
-my $program_name = basename($0);
+init();
 
-my @excludes;
-
-my %options = (
-    'exclude|X=s' => \@excludes,
-    'help|h' => \&show_help,
-);
-
-Getopt::Long::Configure('gnu_getopt', 'pass_through');
-Getopt::Long::GetOptions(%options)
-  or die encode_utf8("error parsing options\n");
-
-my @args_bytes = grep { /^-/ } @ARGV;
-my @configs = grep { !/^-/ } @ARGV;
-
-die encode_utf8("Installed package description file $_ can not be found")
-  for grep { !-e } @configs;
+my $ghc_pkg = ghc_pkg_command();
 
-$ENV{DH_EXCLUDES} = join($SPACE, @excludes);
+for my $installable (@{ $dh{DOPACKAGES} }) {
 
-my $output = run('dh_listpackages', @args_bytes);
-chomp $output;
+    my $compiler = installable_hc($installable) || $ENV{DEB_DEFAULT_COMPILER};
+    my $pkgdir = hc_pkgdir($compiler);
 
-my @installables = split($SPACE, $output);
-for my $installable (@installables) {
+    my $confdir = "debian/$installable/$pkgdir";
 
-    my $type = installable_type($installable);
-    next
-      unless $type eq 'dev';
+    my @configs;
+    @configs = grep { $_->is_file } path($confdir)->children(qr{ [.]conf $}x)
+      if -e $confdir;
 
-    @configs = find_config_for_ghc($installable)
-      unless @configs;
-}
+    load_ghc_database($ghc_pkg, $ENV{DEB_GHC_DATABASE}, @configs);
 
-warn encode_utf8("$program_name: No installed package description files found")
-  unless @configs;
+    my @gcc_args;
 
-my $T_DIR = 'debian/dh_haskell_shlibdeps';
-path($T_DIR)->mkpath;
+    my @hashed_ids = map { path($_)->basename(qr{ [.]conf $}x) } @configs;
+    for my $hashed_id (@hashed_ids) {
 
-my @hackages = map { path($_)->basename(qr{ [.]conf $}x) } @configs;
+        my $libdir_string = decode_utf8(
+            run(
+                $ghc_pkg, '--package-db',
+                $ENV{DEB_GHC_DATABASE}, qw{--simple-output field},
+                $hashed_id, 'library-dirs'
+            ));
+        my @lib_dirs = split($SPACE, $libdir_string);
+        push(@gcc_args, (map { "-L$_" } @lib_dirs));
 
-my $ghc_pkg = ghc_pkg_command();
-load_ghc_database($ghc_pkg, $ENV{DEB_GHC_DATABASE}, @configs);
-
-my @gcc_args;
-for my $hackage (@hackages) {
-
-    my $libdir_string = decode_utf8(
-        run(
-            $ghc_pkg, '--package-db',
-            $ENV{DEB_GHC_DATABASE}, qw{--simple-output field},
-            $hackage, 'library-dirs'
-        ));
-    my @lib_dirs = split($SPACE, $libdir_string);
-    push(@gcc_args, (map { "-L$_" } @lib_dirs));
-
-    my $library_string = decode_utf8(
-        run(
-            $ghc_pkg, '--package-db',
-            $ENV{DEB_GHC_DATABASE}, qw{--simple-output field},
-            $hackage, 'extra-libraries'
-        ));
-    my @libraries = split($SPACE, $library_string);
-    push(@gcc_args, (map { "-l$_" } @libraries));
-}
+        my $library_string = decode_utf8(
+            run(
+                $ghc_pkg, '--package-db',
+                $ENV{DEB_GHC_DATABASE}, qw{--simple-output field},
+                $hashed_id, 'extra-libraries'
+            ));
+        my @libraries = split($SPACE, $library_string);
+        push(@gcc_args, (map { "-l$_" } @libraries));
+    }
 
-my $source_path = "$T_DIR/probe.c";
-my $probe_path = "$T_DIR/probe";
+    my $T_DIR = 'debian/dh_haskell_shlibdeps';
+    path($T_DIR)->mkpath;
 
-path($source_path)->spew_utf8('int main (void) {}');
+    my $source_path = "$T_DIR/probe.c";
+    my $probe_path = "$T_DIR/probe";
 
-my @gcc_args_bytes = map { encode_utf8($_) } @gcc_args;
-run('gcc', @gcc_args_bytes, $source_path, '-o', $probe_path);
+    path($source_path)->spew_utf8('int main (void) {}');
 
-for my $installable (@installables) {
-
-    my $type = installable_type($installable);
-    next
-      unless $type eq 'dev';
+    my @gcc_args_bytes = map { encode_utf8($_) } @gcc_args;
+    run('gcc', @gcc_args_bytes, $source_path, '-o', $probe_path);
 
     my $substvars_path = "debian/$installable.substvars";
 
     run(qw{dpkg-shlibdeps --warnings=1}, "-T$substvars_path", $probe_path);
-}
 
-path($T_DIR)->remove_tree;
+    path($T_DIR)->remove_tree;
+}
 
 exit;
 
-sub show_help {
-    my $message =<<"EOT";
-Usage: $program_name [options] cabal-file ...
-
-Options:
-    -X, --exclude INSTALLABLE    exclude INSTALLABLE from processing
-EOT
-
-    print encode_utf8($message);
-
-    exit;
-}
-
 =head1 NAME
 
-dh_haskell_shlibdeps - calculates Haskell external dependencies on Cabalized
-libraries
+dh_haskell_shlibdeps - calculates external dependencies for Haskell libraries
 
 =encoding utf8
 =head1 SYNOPSIS
 
 B<dh_haskell_depends> [S<I<debhelper options>>]
-[B<-X>I<package>]
-[B<--exclude=>I<package>]
-[S<I<file>> ...]
 
 =head1 DESCRIPTION
 
@@ -178,8 +130,6 @@ not yet support nhc98.
 
 =head1 SEE ALSO
 
-L<dh_haskell_depends(1)>
-L<dh_haskell_provides(1)>
 L<debhelper(7)>
 
 =head1 AUTHOR


=====================================
dh_haskell_suggests
=====================================
@@ -0,0 +1,105 @@
+#!/usr/bin/perl
+
+# Copyright © 2022 Felix Lechner <felix.lechner at lease-up.com>
+#
+# based on a shell script by the same name
+#     Arjan Oosting <arjan at debian.org>
+#
+# This program 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 3 of the License, or
+# (at your option) any later version.
+#
+# This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
+
+use v5.20;
+use warnings;
+use utf8;
+
+use Const::Fast;
+use List::SomeUtils qw(uniq);
+use Path::Tiny;
+
+use Debian::Debhelper::Dh_Lib;
+
+const my $SPACE => q{ };
+const my $COMMA => q{,};
+
+const my $NEWLINE => qq{\n};
+
+init();
+
+for my $installable (@{ $dh{DOPACKAGES} }) {
+
+    my @suggests;
+
+    for my $suffix (qw{prof doc}) {
+
+        my $candidate = $installable;
+        $candidate =~ s{ - [^-]+ $}{-$suffix}x;
+
+        push(@suggests, $candidate)
+          if system(qw{grep-dctrl --quiet --field=Package},
+            $candidate, 'debian/control')== 0;
+    }
+
+    # fix sort order
+    local $ENV{LC_ALL} = 'C.UTF-8';
+
+    my $substvars_path = "debian/$installable.substvars";
+    replace_line($substvars_path, 'haskell:Suggests',
+        join($COMMA . $SPACE, (sort +uniq @suggests)));
+}
+
+exit;
+
+sub replace_line {
+    my ($path, $field, $value) = @_;
+
+    path($path)->touch;
+
+    my @lines = grep { !m{^ $field = }x } path($path)->lines_utf8;
+
+    push(@lines, "$field=$value" . $NEWLINE);
+
+    path($path)->spew_utf8(@lines);
+
+    return;
+}
+
+=head1 NAME
+
+dh_haskell_suggests - calculates Haskell dependencies on Cabalized libraries
+
+=head1 SYNOPSIS
+
+B<dh_haskell_suggests> [S<I<debhelper options>>]
+
+=head1 DESCRIPTION
+
+dh_haskell_suggests is a debhelper program that helps with calculating dependencies
+for building Haskell libraries.
+
+=head1 SEE ALSO
+
+L<debhelper(7)>
+
+=head1 AUTHOR
+
+John Goerzen <jgoerzen at complete.org>
+
+Based on ideas in dh_python by Josselin Mouette <joss at debian.org>
+
+=cut
+
+# Local Variables:
+# indent-tabs-mode: nil
+# cperl-indent-level: 4
+# End:
+# vim: syntax=perl sw=4 sts=4 sr et


=====================================
hlibrary.mk
=====================================
@@ -138,9 +138,11 @@ clean::
 	perl -d:Confess -MDebian::Debhelper::Buildsystem::Haskell::Recipes=/.*/ \
 		-E 'clean_recipe'
 	rm -f build-ghc-stamp build-hugs-stamp
-	rm -f debian/tmp-inst-ghc debian/tmp-inst-ghcjs
-	rm -rf debian/tmp
+	rm -f debian/tmp
+	rm -rf debian/tmp-inst-ghc debian/tmp-inst-ghcjs
 	rm -rf $(DEB_GHC_DATABASE)
+	rm -f $(MAKEFILE)
+
 
 $(DEB_SETUP_BIN_NAME):
 	perl -d:Confess -MDebian::Debhelper::Buildsystem::Haskell::Recipes=/.*/ \
@@ -153,9 +155,10 @@ build-ghc-stamp: $(DEB_SETUP_BIN_NAME)
 
 build/%-dev build/%-prof build/%-doc:: build-ghc-stamp
 
-debian/tmp: $(DEB_SETUP_BIN_NAME) build-ghc-stamp
+debian/tmp-inst-%: $(DEB_SETUP_BIN_NAME) build-ghc-stamp
 	perl -d:Confess -MDebian::Debhelper::Buildsystem::Haskell::Recipes=/.*/ \
 		-E 'install_recipe($$ARGV[0])' "$@"
+	ln --symbolic --force "$@" debian/tmp
 
 dist-hugs: $(DEB_SETUP_BIN_NAME)
 	$(DEB_SETUP_BIN_NAME) configure --hugs --prefix=/usr -v2 \
@@ -164,16 +167,60 @@ dist-hugs: $(DEB_SETUP_BIN_NAME)
 build/libhugs-$(CABAL_PACKAGE):: dist-hugs
 	$(DEB_SETUP_BIN_NAME) build --builddir=dist-hugs
 
-install/libghc-$(CABAL_PACKAGE)-dev install/libghc-$(CABAL_PACKAGE)-prof install/libghc-$(CABAL_PACKAGE)-doc:: debian/tmp
-	ln --symbolic --force debian/tmp debian/tmp-inst-ghc
-
-install/libghcjs-$(CABAL_PACKAGE)-dev install/libghcjs-$(CABAL_PACKAGE)-prof install/libghcjs-$(CABAL_PACKAGE)-doc:: debian/tmp
-	ln --symbolic --force debian/tmp debian/tmp-inst-ghcjs
+install/libghc-$(CABAL_PACKAGE)-dev:: debian/tmp-inst-ghc
+	dh_haskell_install_ghc_registration --package=$(notdir $@)
+	dh_haskell_install_development_libs --package=$(notdir $@) --source-dir="$<"
+	dh_haskell_provides_ghc --package=$(notdir $@)
+	dh_haskell_depends_cabal --package=$(notdir $@)
+	dh_haskell_extra_depends_ghc --package=$(notdir $@)
+	dh_haskell_shlibdeps --package=$(notdir $@)
+	dh_haskell_blurbs --package=$(notdir $@) --type=dev
+
+install/libghc-$(CABAL_PACKAGE)-prof:: debian/tmp-inst-ghc
+	dh_haskell_install_profiling_libs --package=$(notdir $@) --source-dir="$<"
+	dh_haskell_provides_ghc --package=$(notdir $@) --config-shipper="libghc-$(CABAL_PACKAGE)-dev"
+	dh_haskell_depends_cabal --package=$(notdir $@) --config-shipper="libghc-$(CABAL_PACKAGE)-dev"
+	dh_haskell_blurbs --package=$(notdir $@) --type=prof
+
+install/libghc-$(CABAL_PACKAGE)-doc:: debian/tmp-inst-ghc
+	dh_haskell_install_htmldocs --package=$(notdir $@) --source-dir="$<"
+	dh_haskell_install_haddock --package=$(notdir $@) --source-dir="$<"
+	dh_haskell_depends_haddock --package=$(notdir $@)
+	dh_haskell_recommends_documentation_references --package=$(notdir $@)
+	dh_haskell_suggests --package=$(notdir $@)
+	dh_haskell_blurbs --package=$(notdir $@) --type=doc
+
+install/libghcjs-$(CABAL_PACKAGE)-dev:: debian/tmp-inst-ghcjs
+	dh_haskell_install_ghc_registration --package=$(notdir $@)
+	dh_haskell_install_development_libs --package=$(notdir $@) --source-dir="$<"
+	dh_haskell_provides_ghc --package=$(notdir $@)
+	dh_haskell_depends_cabal --package=$(notdir $@)
+	dh_haskell_extra_depends_ghc --package=$(notdir $@)
+	dh_haskell_shlibdeps --package=$(notdir $@)
+	dh_haskell_blurbs --package=$(notdir $@) --type=dev
+
+install/libghcjs-$(CABAL_PACKAGE)-prof:: debian/tmp-inst-ghcjs
+	dh_haskell_install_profiling_libs --package=$(notdir $@) --source-dir="$<"
+	dh_haskell_provides_ghc --package=$(notdir $@) --config-shipper="libghcjs-$(CABAL_PACKAGE)-dev"
+	dh_haskell_depends_cabal --package=$(notdir $@) --config-shipper="libghc-$(CABAL_PACKAGE)-dev"
+	dh_haskell_blurbs --package=$(notdir $@) --type=prof
+
+install/libghcjs-$(CABAL_PACKAGE)-doc:: debian/tmp-inst-ghcjs
+	dh_haskell_install_htmldocs --package=$(notdir $@) --source-dir="$<"
+	dh_haskell_install_haddock --package=$(notdir $@) --source-dir="$<"
+	dh_haskell_depends_haddock --package=$(notdir $@)
+	dh_haskell_recommends_documentation_references --package=$(notdir $@)
+	dh_haskell_suggests --package=$(notdir $@)
+	dh_haskell_blurbs --package=$(notdir $@) --type=doc
 
 install/libhugs-$(CABAL_PACKAGE):: $(DEB_SETUP_BIN_NAME) dist-hugs
-	$(DEB_SETUP_BIN_NAME) copy --destdir=debian/libhugs-$(CABAL_PACKAGE) --builddir=dist-hugs
+	$(DEB_SETUP_BIN_NAME) copy --builddir=dist-hugs --destdir=debian/libhugs-$(CABAL_PACKAGE)
 	rm -rf debian/libhugs-$(CABAL_PACKAGE)/usr/share/doc/*
-	dh_haskell_depends -p$(notdir $@)
+	dh_haskell_depends_hugs --package=$(notdir $@)
+
+$(patsubst %,install/%,$(DEB_PACKAGES)) :: install/%:
+	dh_haskell_description --package=$(cdbs_curpkg)
+	dh_haskell_compiler --package=$(cdbs_curpkg)
 
 
 # Support for installing executables


=====================================
lib/Debian/Debhelper/Buildsystem/Haskell/Recipes.pm
=====================================
@@ -33,11 +33,16 @@ BEGIN {
       installable_hc
       installable_type
       source_hc
+      hc_libdir
+      hc_pkgdir
+      hc_haddock
+      hc_docdir
+      hc_htmldir
       hashed_dependency
       ghc_pkg_command
       load_ghc_database
+      own_cabal_prerequisites
       hashed_id_to_virtual_installable
-      find_config_for_ghc
       clean_recipe
       make_setup_recipe
       configure_recipe
@@ -50,9 +55,7 @@ BEGIN {
 
 use Carp qw(croak);
 use Const::Fast;
-use Cwd;
 use Date::Parse qw(str2time);
-use File::Basename;
 use IPC::Run3;
 use List::SomeUtils qw(uniq any first_value);
 use Path::Tiny;
@@ -60,7 +63,6 @@ use Unicode::UTF8 qw(encode_utf8 decode_utf8);
 
 const my $EMPTY => q{};
 const my $SPACE => q{ };
-const my $SEMICOLON => q{;};
 const my $NEWLINE => qq{\n};
 
 const my $WAIT_STATUS_SHIFT => 8;
@@ -211,6 +213,9 @@ sub source_hc {
 sub hc_libdir {
     my ($compiler) = @_;
 
+    croak encode_utf8('No Haskell compiler.')
+      unless length $compiler;
+
     return 'usr/lib/haskell-packages/ghc/lib'
       if $compiler eq 'ghc';
 
@@ -227,6 +232,9 @@ sub hc_libdir {
 sub hc_pkgdir {
     my ($compiler) = @_;
 
+    croak encode_utf8('No Haskell compiler.')
+      unless length $compiler;
+
     return 'var/lib/ghc/package.conf.d'
       if $compiler eq 'ghc';
 
@@ -252,6 +260,9 @@ sub hc_pkgdir {
 sub hc_prefix {
     my ($compiler) = @_;
 
+    croak encode_utf8('No Haskell compiler.')
+      unless length $compiler;
+
     return 'usr'
       if $compiler eq 'ghc';
 
@@ -268,6 +279,9 @@ sub hc_prefix {
 sub hc_haddock {
     my ($compiler) = @_;
 
+    croak encode_utf8('No Haskell compiler.')
+      unless length $compiler;
+
     return 'haddock'
       if $compiler eq 'ghc';
 
@@ -284,6 +298,9 @@ sub hc_haddock {
 sub hc_docdir {
     my ($compiler, $hackage_name, $hackage_version) = @_;
 
+    croak encode_utf8('No Haskell compiler.')
+      unless length $compiler;
+
     return "usr/lib/$compiler-doc/haddock/$hackage_name-$hackage_version/";
 }
 
@@ -294,6 +311,9 @@ sub hc_docdir {
 sub hc_htmldir {
     my ($compiler, $hackage_name) = @_;
 
+    croak encode_utf8('No Haskell compiler.')
+      unless length $compiler;
+
     return "usr/share/doc/lib$compiler-$hackage_name-doc/html/";
 }
 
@@ -330,6 +350,45 @@ sub ghc_pkg_command {
     return 'ghc-pkg';
 }
 
+=item own_cabal_prerequisites
+
+=cut
+
+sub own_cabal_prerequisites {
+    my ($compiler, $tmp_db) = @_;
+
+    croak encode_utf8('No Setup.hs executable named.')
+      unless length $ENV{DEB_SETUP_BIN_NAME};
+
+    my $output = run($ENV{DEB_SETUP_BIN_NAME},
+        'register', "--builddir=dist-$compiler",
+        qw{--gen-pkg-config --verbose=verbose+nowrap});
+
+    my @hashed_ids;
+    if ($output
+        =~ m{^Creating \s package \s registration \s file: \s+ (\S+) $}mx) {
+
+        my $pkg_config = $1;
+
+        my $ghc_pkg = ghc_pkg_command();
+        load_ghc_database($ghc_pkg, $tmp_db, $pkg_config);
+
+        my $name = path($pkg_config)->basename(qr{ [.]conf $}x);
+        my $depends
+          = run($ghc_pkg, '--package-db', $tmp_db, qw{--simple-output field},
+            $name, 'depends');
+
+        push(@hashed_ids, split($SPACE, $depends // $EMPTY));
+
+        run(qw{rm -f}, $pkg_config);
+
+    } else {
+        warn encode_utf8('Cannot find package registration file.');
+    }
+
+    return @hashed_ids;
+}
+
 =item load_ghc_database
 
 =cut
@@ -364,6 +423,9 @@ sub load_ghc_database {
 sub hashed_id_to_virtual_installable {
     my ($compiler, $hashed_id, $type, @command) = @_;
 
+    croak encode_utf8('No Haskell compiler.')
+      unless length $compiler;
+
     my $name;
     my $version;
     my $long_abi;
@@ -394,31 +456,6 @@ sub hashed_id_to_virtual_installable {
     return $virtual;
 }
 
-=item find_config_for_ghc
-
-=cut
-
-sub find_config_for_ghc {
-    my ($installable) = @_;
-
-    my $compiler = installable_hc($installable) || $ENV{DEB_DEFAULT_COMPILER};
-    my $pkgdir = hc_pkgdir($compiler);
-
-    if ($installable =~ s{ - prof $}{}x) {
-
-        $installable .= '-dev'
-          unless $installable eq 'ghc';
-    }
-
-    my $confdir = "debian/$installable/$pkgdir";
-
-    my @configs;
-    @configs = grep { $_->is_file } path($confdir)->children(qr{ [.]conf $}x)
-      if -e $confdir;
-
-    return @configs;
-}
-
 =item clean_recipe
 
 =cut
@@ -426,16 +463,16 @@ sub find_config_for_ghc {
 sub clean_recipe {
     my () = @_;
 
+    croak encode_utf8('No Setup.hs executable named.')
+      unless length $ENV{DEB_SETUP_BIN_NAME};
+
     run($ENV{DEB_SETUP_BIN_NAME}, qw{clean})
       if -x $ENV{DEB_SETUP_BIN_NAME};
 
-    run(
-        qw{rm -rf dist dist-ghc dist-ghcjs dist-hugs},
-        $ENV{DEB_SETUP_BIN_NAME},
-        qw{Setup.hi Setup.ho Setup.o},
-        glob('.*config*'));
-
-    run(qw{rm -f}, $ENV{MAKEFILE});
+    run(qw{rm -rf dist dist-ghc dist-ghcjs dist-hugs});
+    run(qw{rm -f}, $ENV{DEB_SETUP_BIN_NAME});
+    run(qw{rm -f Setup.hi Setup.ho Setup.o});
+    run(qw{rm -f}, glob('.*config*'));
 
     return;
 }
@@ -447,6 +484,9 @@ sub clean_recipe {
 sub make_setup_recipe {
     my () = @_;
 
+    croak encode_utf8('No Setup.hs executable named.')
+      unless length $ENV{DEB_SETUP_BIN_NAME};
+
     my $shipped_setup = first_value { -e } qw{Setup.lhs Setup.hs};
 
     if (length $shipped_setup) {
@@ -501,6 +541,9 @@ sub make_setup_recipe {
 sub configure_recipe {
     my () = @_;
 
+    croak encode_utf8('No Setup.hs executable named.')
+      unless length $ENV{DEB_SETUP_BIN_NAME};
+
     # deleted when out of scope
     my $time_reference = Path::Tiny->tempfile;
     $time_reference->touch(str2time('1975-01-01', 'UTC'));
@@ -515,6 +558,8 @@ sub configure_recipe {
     );
 
     my $compiler = source_hc() || $ENV{DEB_DEFAULT_COMPILER};
+    die encode_utf8('No Haskell compiler.')
+      unless length $compiler;
 
     my $package_list = run('dh_listpackages');
     chomp $package_list;
@@ -576,7 +621,13 @@ sub configure_recipe {
 sub build_recipe {
     my () = @_;
 
+    croak encode_utf8('No Setup.hs executable named.')
+      unless length $ENV{DEB_SETUP_BIN_NAME};
+
     my $compiler = source_hc() || $ENV{DEB_DEFAULT_COMPILER};
+    die encode_utf8('No Haskell compiler.')
+      unless length $compiler;
+
     my $output
       = run($ENV{DEB_SETUP_BIN_NAME},'build', "--builddir=dist-$compiler");
 
@@ -590,6 +641,9 @@ sub build_recipe {
 sub check_recipe {
     my () = @_;
 
+    croak encode_utf8('No Setup.hs executable named.')
+      unless length $ENV{DEB_SETUP_BIN_NAME};
+
     if ($ENV{DEB_ENABLE_TESTS} ne 'yes') {
 
         say encode_utf8(
@@ -607,6 +661,9 @@ sub check_recipe {
     }
 
     my $compiler = source_hc() || $ENV{DEB_DEFAULT_COMPILER};
+    die encode_utf8('No Haskell compiler.')
+      unless length $compiler;
+
     my $output = run($ENV{DEB_SETUP_BIN_NAME},
         'test', "--builddir=dist-$compiler", '--show-details=direct');
 
@@ -620,7 +677,13 @@ sub check_recipe {
 sub haddock_recipe {
     my () = @_;
 
+    croak encode_utf8('No Setup.hs executable named.')
+      unless length $ENV{DEB_SETUP_BIN_NAME};
+
     my $compiler = source_hc() || $ENV{DEB_DEFAULT_COMPILER};
+    die encode_utf8('No Haskell compiler.')
+      unless length $compiler;
+
     my $haddock = hc_haddock($compiler);
 
     return
@@ -645,164 +708,16 @@ sub haddock_recipe {
 sub install_recipe {
     my ($destination) = @_;
 
-    # fix sort order
-    local $ENV{LC_ALL} = 'C.UTF-8';
+    croak encode_utf8('No Setup.hs executable named.')
+      unless length $ENV{DEB_SETUP_BIN_NAME};
 
     my $compiler = source_hc() || $ENV{DEB_DEFAULT_COMPILER};
+    die encode_utf8('No Haskell compiler.')
+      unless length $compiler;
 
     run($ENV{DEB_SETUP_BIN_NAME},
         'copy', "--builddir=dist-$compiler", "--destdir=$destination");
 
-    my $package_list = run('dh_listpackages');
-    chomp $package_list;
-
-    my @installables = split($SPACE, $package_list);
-    for my $installable (@installables) {
-
-        my $type = installable_type($installable);
-
-        if ($type eq 'dev') {
-
-            my $savedir = Cwd::getcwd;
-            chdir($destination)
-              or warn encode_utf8("Cannot change folder to $destination");
-
-            my $libdir = hc_libdir($compiler);
-
-            run(qw{mkdir --parents}, $libdir);
-            run(
-                'find',
-                "./$libdir",
-                qw{ ( ! -name *_p.a ! -name *.p_hi ! -type d ) },
-                qw{-exec install -D --mode=644},
-                '{}',
-                "$savedir/debian/$installable/{}",
-                $SEMICOLON
-            );
-
-            chdir($savedir)
-              or warn encode_utf8("Cannot change folder to $savedir");
-
-            my $output = run($ENV{DEB_SETUP_BIN_NAME},
-                'register', "--builddir=dist-$compiler",
-                qw{--gen-pkg-config --verbose=verbose+nowrap});
-
-            if ($output
-                =~ m{^Creating \s package \s registration \s file: \s+ (\S+) $}mx
-            ) {
-
-                my $pkg_config = $1;
-
-                run(qw{sed -i}, 's/^exposed: True$/exposed: False/',
-                    $pkg_config)
-                  if length $ENV{HASKELL_HIDE_PACKAGES};
-
-                my $pkgdir = hc_pkgdir($compiler);
-                run(qw{install -D --mode=644},
-                    $pkg_config, "debian/$installable/$pkgdir/$pkg_config");
-                run(qw{rm -f}, $pkg_config);
-
-                if (length $ENV{DEB_GHC_EXTRA_PACKAGES}) {
-
-                    my $EP_DIR
-                      = "debian/$installable/usr/lib/haskell-packages/extra-packages";
-                    run(qw{mkdir --parents}, $EP_DIR);
-
-                    path("$EP_DIR/$ENV{CABAL_PACKAGE}-$ENV{CABAL_VERSION}")
-                      ->spew_utf8($ENV{DEB_GHC_EXTRA_PACKAGES});
-
-                } else {
-                    warn encode_utf8(
-'Skipping extra depends; cannot get package registration file (probably not a library).'
-                    );
-                }
-            }
-        }
-
-        if ($type eq 'prof') {
-
-            my $savedir = Cwd::getcwd;
-            chdir($destination)
-              or warn encode_utf8("Cannot change folder to $destination");
-
-            my $libdir = hc_libdir($compiler);
-
-            run(qw{mkdir --parents}, $libdir);
-            run(
-                'find',
-                "./$libdir",
-                qw{ ( -name *_p.a -o -name *.p_hi ) },
-                qw{-exec install -D --mode=644},
-                '{}',
-                "$savedir/debian/$installable/{}",
-                $SEMICOLON
-            );
-
-            chdir($savedir)
-              or warn encode_utf8("Cannot change folder to $savedir");
-        }
-
-        if ($type eq 'doc') {
-
-            my $savedir = Cwd::getcwd;
-            chdir($destination)
-              or warn encode_utf8("Cannot change folder to $destination");
-
-            my $htmldir = hc_htmldir($compiler, $ENV{CABAL_PACKAGE});
-
-            run(qw{mkdir --parents}, $htmldir);
-            run(
-                'find',
-                "./$htmldir",
-                qw{ ! -name *.haddock ! -type d},
-                qw{-exec install -D --mode=644},
-                '{}',
-                "$savedir/debian/$installable/{}",
-                $SEMICOLON
-            );
-
-            chdir($savedir)
-              or warn encode_utf8("Cannot change folder to $savedir");
-
-            my $docdir
-              = hc_docdir($compiler, $ENV{CABAL_PACKAGE}, $ENV{CABAL_VERSION});
-
-            my $tmp_inst_docdir = "$destination/$docdir";
-            my $installable_docdir = "debian/$installable/$docdir";
-
-            run(qw{mkdir --parents}, $installable_docdir);
-
-            run(qw{cp --recursive}, $_->stringify, $installable_docdir)
-              for path($tmp_inst_docdir)->children(qr{ [.]haddock $}x);
-
-            if ($ENV{DEB_ENABLE_HOOGLE} eq 'yes') {
-
-                # We cannot just invoke dh_link here because that acts on
-                # either libghc-*-dev or all the binary packages, neither of
-                # which is desirable (see dh_link (1)).  So we just create a
-                # (policy-compliant) symlink ourselves
-
-                my $target
-                  = "debian/$installable/$htmldir/$ENV{CABAL_PACKAGE}.txt";
-                if (-e $target) {
-
-                    my $hoogle = "usr/lib/$compiler-doc/hoogle/";
-                    my $name = "debian/$installable/$hoogle$installable.txt";
-
-                    run(qw{mkdir --parents}, dirname($name));
-                    run(qw{ln --symbolic --relative --no-target-directory},
-                        $target, $name);
-                }
-            }
-        }
-    }
-
-    run('dh_haskell_provides');
-    run('dh_haskell_depends');
-    run('dh_haskell_shlibdeps');
-
-    run('dh_haskell_blurbs', $compiler);
-
     return;
 }
 



View it on GitLab: https://salsa.debian.org/haskell-team/haskell-devscripts/-/compare/957878e1cb73719c2bb4afb88fe60b0d835013ca...fc0baa59df7875995e34e4ff23886e73eb8274bd

-- 
View it on GitLab: https://salsa.debian.org/haskell-team/haskell-devscripts/-/compare/957878e1cb73719c2bb4afb88fe60b0d835013ca...fc0baa59df7875995e34e4ff23886e73eb8274bd
You're receiving this email because of your account on salsa.debian.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/pkg-haskell-commits/attachments/20220416/c32becff/attachment-0001.htm>


More information about the Pkg-haskell-commits mailing list