[Haskell-beginners] Combining GHC library and Platform documentation

Mister Globules globules at gmail.com
Wed Jul 20 08:36:46 CEST 2011


Magnus Therning <magnus <at> therning.org> writes:

> 
> On Tue, Jul 19, 2011 at 05:51:31AM +0000, Mister Globules wrote:
> > [...]
> > Is there a simple way to create one index.html file with links to all the
> > documentation?
> > 
> > As a bonus, is it possible to do the same thing with libraries that I
> > install with cabal?
> > 
> > - Globules
> > [...]
> 
> Hopefully you have a script installed, as part of ghc itself, called
> gen_contents_index.  It's what we in Arch use to update the index.html
> file when installing/removing Haskell packages.  I'm not sure it
> already supports privately installed packages, but hopefully it won't
> be too difficult to modify.
> 
> /M
> 

Thanks Magnus, I found the script.  Based on its behaviour in the no-args
case (I didn't look too closely at --inplace) I wrote a similar script that
allows me to specify multiple directories on the command-line.  So, I can
specify the GHC, platform and my personal libraries.

In case anyone finds it useful I've appended it below.  (Hopefully, it will
make it through relatively unscathed.)

- Globules


The following script is in the public domain.

#!/bin/sh -eu
#
# Generate HTML contents and an index for Haskell libraries.
# 
# WARNING: May not handle whitespace, etc. in paths.
# 
# Run this command from the directory in which you want index.html created. The
# package directory arguments can be relative or absolute paths.
#
# Usage:
#
#   mkhaskellhtml pkg_dir ...
#
# Example - GHC and platform docs:
#
#   cd /local/pkg/ghc-7.0.3/share/doc/ghc/html/libraries
#   mkhaskellhtml . /local/pkg/haskell-platform-2011.2.0.1/share/doc
#
# Example - GHC, platform and user package docs:
#
#   cd /local/pkg/ghc-7.0.3/share/doc/ghc/html/libraries
#   mkhaskellhtml . /local/pkg/haskell-platform-2011.2.0.1/share/doc
~/.cabal/share/doc
#

# The default GHC home directory, if the GHC_HOME variable is not set.
GHC_DFL=/local/pkg/ghc-7.0.3

# Exclude the GHC API.  If you want the GHC API use cat instead.
filter_ghc_api () {
    grep -v 'ghc\.haddock$'
#    cat
}

PATH=${GHC_HOME:-$GHC_DFL}/bin:/bin:/usr/bin

if [ $# -lt 1 ]; then
    echo Too few arguments. 1>&2
    echo Usage: $(basename $0) pkg_dir ... 1>&2
    exit 1
fi

ris=$(find "$@" -type f -name \*.haddock |
    filter_ghc_api |
    while read hdk ; do
	echo --read-interface=${hdk%/*.haddock},$hdk
    done)

[ -z "$ris" ] && { echo 'No packages found!'; exit 0; }

haddock \
    --gen-index \
    --gen-contents \
    -o . \
    -t "Haskell Hierarchical Libraries" \
    -p prologue.txt \
    $ris





More information about the Beginners mailing list