[Pkg-ocaml-maint-commits] [SCM] dh-ocaml packaging branch, master, updated. debian/0.5.0-8-g6aae140

Mehdi Dogguy dogguy at pps.jussieu.fr
Tue Jul 21 13:28:29 UTC 2009


The following commit has been merged in the master branch:
commit 6aae1408764fd2104228a13b2393aaddd9929c36
Author: Mehdi Dogguy <dogguy at pps.jussieu.fr>
Date:   Sun Jul 19 17:57:44 2009 +0200

    Make debhelper OCaml-aware (alpha)
    
    * Add dh_ocamldoc to let debhelper generate api reference documentation for
      OCaml libraries (tested on some packages, reviews are very welcome):
      - It uses files named debian/<package>.ocamldoc*: So you can install several
        documentations per package.
      - Flags given to ocamldoc should be written in .ocamldoc files
      - .ocamldoc.in can be used and will be pre-processed by dh_ocamlinit
      - If you the specify « -d <dir> » option of ocamldoc in .ocamldoc, then the
        value will rewritten as « debian/<package>/usr/share/doc/<package>/<dir>
      - If some flags of ocamlfind are present in .ocamldoc files, then we will use
        « ocamlfind ocamldoc » instead of plain « ocamldoc ».
      - All lines starting with « # » (matching /^#/) in .ocamldoc files are
        considered as comments.
    * Add dh_ocamlinit to process debian/*.in files and replace relevant variables
      with their appropriate values (as it's already done in ocamlinit.mk)
    * Add ocaml.pm, which is a debheper module, to be able to run
        dh --with ocaml
      which will perform the following tasks:
      - dh_ocamlinit before configuring the source
      - dh_ocamlinit -d to clean the debian directory from generated files
      - dh_ocamldoc to generate documentation before installing it
      - dh_ocaml will compute automatically OCaml dependencies and fill
        ${ocaml:Depends} in the control file. It's executed after dh_shlibdeps and
        before dh_gencontrol
    
    /!\ This should not be considered stable enough to use it in production packages
        since dh_ocaml is not ready yet!

diff --git a/debhelper/Makefile b/debhelper/Makefile
index f363564..17695aa 100644
--- a/debhelper/Makefile
+++ b/debhelper/Makefile
@@ -1,5 +1,10 @@
-all: dh_ocaml.1
+
+PAGES=dh_ocaml.1 dh_ocamlinit.1 dh_ocamldoc.1
+
+all:
+	for i in $(PAGES); do \
+		pod2man $${i/.1/} > $$i; \
+	done
+
 clean:
-	rm -f dh_ocaml.1
-dh_ocaml.1:
-	pod2man dh_ocaml > $@
+	rm -f $(PAGES)
diff --git a/debhelper/dh_ocamldoc b/debhelper/dh_ocamldoc
new file mode 100755
index 0000000..462894b
--- /dev/null
+++ b/debhelper/dh_ocamldoc
@@ -0,0 +1,155 @@
+#!/usr/bin/perl -w
+
+# Copyright © 2009 Mehdi Dogguy <mehdi at dogguy.org>
+#
+# This is free software, you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 or above
+# as published by the Free Software Foundation.
+#
+# 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, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+# USA
+
+=head1 NAME
+
+dh_ocamldoc - Generates documentation for OCaml libraries
+
+=cut
+
+use strict;
+use Debian::Debhelper::Dh_Lib;
+init();
+
+=head1 SYNOPSIS
+
+B<dh_ocamldoc> [S<I<debhelper options>>]
+
+=head1 DESCRIPTION
+
+dh_ocamldoc looks for debian/*.ocamldoc files where it can find the flags that
+will be given to ocamldoc. You can have several flags per line.
+
+dh_ocamldoc detects automatically if « ocamlfind ocamldoc » should be called
+instead of plain « ocamldoc ». Lines starting with « # » are comments.
+
+=head1 OPTIONS
+
+=over 4
+
+=item B<-X> I<files>
+
+Exclude files from documentation processing.
+
+Clean files generated from present debian/*.in ones and exit.
+
+=back
+
+=cut
+
+my $odoc = "/usr/bin/ocamldoc";
+my $ocaml_lib_dir = "/usr/lib/ocaml/";
+$odoc = "/usr/bin/ocamldoc.opt" if -x "/usr/bin/ocamldoc.opt";
+$ocaml_lib_dir = `ocamlc -where` if -x "/usr/bin/ocamlc";
+chomp $ocaml_lib_dir;
+
+error "$odoc does not exists or is not executable"
+    unless -x $odoc;
+
+sub ocamldoc_destdir_html($$) {
+    my ($package, $html_dir) = @_;
+    return "/usr/share/doc/$package/$html_dir/";
+}
+
+sub generate_docbase($$$$) {
+    my ($package, $tmp_dir, $html_dir, $document_name) = @_;
+    my $dest_dir = ocamldoc_destdir_html($package, $html_dir);
+    my $file = "debian/${package}.doc-base.apiref${document_name}";
+    verbose_print("Generating doc-base file: $file");
+    complex_doit("> $file");
+    open(DOC, ">> $file");
+    print DOC "Document: ${package}-ocamldoc-api-reference${document_name}\n";
+    print DOC "Title: $package OCamldoc API Reference\n";
+    print DOC "Abstract: API reference manual for $package (generated via OCamldoc)\n";
+    print DOC "Section: Programming/OCaml\n";
+    print DOC "\n";
+    print DOC "Format: HTML\n";
+    print DOC "Index: ${dest_dir}index.html\n";
+    print DOC "Files: ${dest_dir}*\n";
+    close(DOC);
+}
+
+sub read_ocamldoc_file($) {
+    my ($file) = @_;
+    open (OCAMLDOC, "< $file");
+    my $use_ocamlfind = 0;
+    my $html_dir = "html/api";
+    my $content = "";
+    while (<OCAMLDOC>) {
+        next if /^\#/;
+        $use_ocamlfind = 1 if / -package | -predicates | -syntax | -ppopt /;
+        if (/-d[\s]+([^\s]+)/) {
+            $html_dir = $1;
+        }
+        chomp;
+        $content .= " " . $_;
+    }
+    close OCAMLDOC;
+    $html_dir = "html/api" if $html_dir =~ "";
+    return ($content, $html_dir, $use_ocamlfind);
+}
+
+sub do_doc_package($@) {
+    my ($package, @ocamldoc_files) = @_;
+    foreach my $fdoc (@ocamldoc_files) {
+        my $ocamldoc = $odoc;
+        my $document_name = $fdoc;
+        $document_name =~ s/debian\/.*\.ocamldoc//g;
+        my ($ocamldoc_flags, $html_dir, $use_ocamlfind) = read_ocamldoc_file($fdoc);
+        if ($dh{EXCLUDE_FIND}) {
+            $ocamldoc_flags .= ' -and ! \( '.$dh{EXCLUDE_FIND}.' \)';
+        }
+        my $dest_dir = ocamldoc_destdir_html($package, $html_dir);
+        my $tmpdir = tmpdir($package);
+        my $search_dir = "$tmpdir$ocaml_lib_dir";
+        $ocamldoc = "ocamlfind ocamldoc" if $use_ocamlfind;
+        complex_doit("mkdir -p $tmpdir$dest_dir");
+        my $doc_files = `find ${search_dir} -type f -name '*.mli' -or -name '*.ml' | xargs echo || true`;
+        if (! ($doc_files =~ "" and $ocamldoc_flags =~ /-I .*/)) {
+            $doc_files =~ s/\n//g;
+            complex_doit("$ocamldoc $ocamldoc_flags -html -stars -m A -d $tmpdir$dest_dir $doc_files");
+            generate_docbase($package, $tmpdir, $html_dir, $document_name);
+        } else {
+            warning("No doc files (*.mli or *.ml), nor included directories. Nothing to do...");
+        }
+    }
+}
+
+foreach my $pkg (@{$dh{DOPACKAGES}}) {
+    my $tmp_dir = tmpdir($pkg);
+    my @files = pkgfile($pkg, "ocamldoc");
+    my @ocamldoc_files = split /\n/,
+    `find debian/ -type f -name "$pkg.ocamldoc*"`;
+    if (@ocamldoc_files) {
+        verbose_print("Generating documentation for $pkg");
+        do_doc_package($pkg, @ocamldoc_files);
+    }
+}
+
+=head1 SEE ALSO
+
+L<debhelper(7)>, L<dh(1)>, L<dh_ocaml(1)>
+
+This program is meant to be used together with debhelper.
+
+=head1 AUTHOR
+
+Mehdi Dogguy <mehdi at dogguy.org>
+
+=cut
+
diff --git a/debhelper/dh_ocamlinit b/debhelper/dh_ocamlinit
new file mode 100755
index 0000000..5d25971
--- /dev/null
+++ b/debhelper/dh_ocamlinit
@@ -0,0 +1,99 @@
+#!/usr/bin/perl -w
+
+# Copyright © 2009 Mehdi Dogguy <mehdi at dogguy.org>
+#
+# This is free software, you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 or above
+# as published by the Free Software Foundation.
+#
+# 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, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+# USA
+
+=head1 NAME
+
+dh_ocamlinit - Substitutes ocaml variables in debian/*.in files with
+their corresponding value.
+
+=cut
+
+use strict;
+use Debian::Debhelper::Dh_Lib;
+init();
+
+=head1 SYNOPSIS
+
+B<dh_ocamlinit> [S<I<debhelper options>>]
+
+=head1 DESCRIPTION
+
+dh_ocamlinit looks for debian/*.in files and replaces all present
+variables (like @OCAML_ABI@, @OCamlStdlibDir@ and @OCamlDllDir@) with
+the corresponding value.
+
+dh_ocamlinit handles additional substitutions by specifying them in the
+OCAMLINIT_SED environement variable.
+
+=head1 OPTIONS
+
+=over 4
+
+=item B<-d>
+
+Clean files generated from present debian/*.in ones and exit.
+
+=back
+
+=cut
+
+my $ocamlc = "/usr/bin/ocamlc";
+my $ocamlopt = "/usr/bin/ocamlopt";
+error "$ocamlc does not exists or is not executable" unless -x $ocamlc;
+
+chomp (my $ocaml_version = `$ocamlc -version`);
+chomp (my $ocaml_lib_dir = `$ocamlc -where`);
+
+my @ocaml_in_files = split /\n/,
+    `find debian/ -type f -name "*.in" -not \\( -name control\.in \\) | sed 's/.in\$//'`;
+
+if (defined($dh{D_FLAG})) {
+    complex_doit("rm -f ocamlinit-stamp @ocaml_in_files");
+    exit;
+}
+
+my $ocamlinit_sed = " -e 's%\@OCamlABI\@%$ocaml_version%g'"
+                  . " -e 's%\@OCamlStdlibDir\@%$ocaml_lib_dir%g'"
+                  . " -e 's%\@OCamlDllDir\@%$ocaml_lib_dir/stublibs%g'";
+
+if (-x $ocamlopt) {
+    $ocamlinit_sed .= " -e 's/^OPT: //' -e '/^BYTE: /d'";
+} else {
+    $ocamlinit_sed .= " -e '/^OPT: /d' -e 's/^BYTE: //'";
+}
+
+$ocamlinit_sed .= " ".$ENV{"OCAMLINIT_SED"} if $ENV{"OCAMLINIT_SED"};
+
+foreach my $file (@ocaml_in_files) {
+    complex_doit("sed $ocamlinit_sed ${file}.in > $file");
+}
+
+complex_doit("touch ocamlinit-stamp");
+
+=head1 SEE ALSO
+
+L<debhelper(7)>, L<dh(1)>, L<dh_ocaml(1)>
+
+This program is meant to be used together with debhelper.
+
+=head1 AUTHOR
+
+Mehdi Dogguy <mehdi at dogguy.org>
+
+=cut
+
diff --git a/debhelper/ocaml.pm b/debhelper/ocaml.pm
new file mode 100644
index 0000000..4bf6962
--- /dev/null
+++ b/debhelper/ocaml.pm
@@ -0,0 +1,11 @@
+#!/usr/bin/perl
+use warnings;
+use strict;
+use Debian::Debhelper::Dh_Lib;
+
+insert_after  ("dh_shlibdeps"     , "dh_ocaml"       );
+insert_before ("dh_auto_configure", "dh_ocamlinit"   );
+insert_before ("dh_auto_clean"    , "dh_ocamlinit -d");
+insert_before ("dh_installdocs"   , "dh_ocamldoc"    );
+
+1;

-- 
dh-ocaml packaging



More information about the Pkg-ocaml-maint-commits mailing list