#!/bin/sh

cat <<-"(head-end)"
	cabal-version: >= 1.4
	name: bindings-gts
	synopsis:
	  Low level bindings supporting GTS, the GNU Triangulated Surface Library
	description:
	  This package contains bindings to GTS (<http://gts.sourceforge.net>)
	  library using bindings-DSL macros and style. Like GObject,
	  it's not useful by itself, but as a foundation for other
	  libraries making use of its type system.
	  .
	  NOTE: these bindings were not made by the author(s) of GTS
	  so please don't bug them about issues with the bindings! Any
	  errors in these bindings are my responsibility not that of
	  the GTS team.
	  .
	  Changelog:
	  .
	  [0.0.1] Initial version.
	  .
	  [0.0.2] Improved documentation; added some missing functions;
	  fixed a function name; bumped version of base to >=4
	  .
	  [0.0.3] Adding missing GTS enumeration for CSG boolean
	  operations; added some more missing functions; fixed some bad
	  FunPtr references; added some helper methods, added missing
	  GTS_inline.h header to sdist archive
	  .
	  [0.1.1] Bindings reorganized by Maurício Antunes, author
	  of Bindings-DSL. Bindings much improved as a result. This
	  is an incompatible API change but should be the last change
	  to the package organization. Should now cover all of the GTS
	  library. Some features (GSList etc) moved into Bindings-GLib
	  (<http://hackage.haskell.org/package/bindings-glib>)
	  as they should be there.
	  .
	version: 0.1.1
	license: LGPL-3
	license-file: LICENSE
	maintainer: Joel Crisp <joel.a.crisp@googlemail.com>
	author: Joel Crisp
	build-type: Simple
	category: FFI
	library
	  hs-source-dirs:
	    src
	  extensions:
	    ForeignFunctionInterface
	  pkgconfig-depends: gts >= 0.7.6
	  build-depends:
	    base >= 3 && < 5,
	    bindings-DSL >= 1.0.9 && < 1.1,
	    bindings-glib >= 0.1.5 && < 0.2
	  ghc-options: -Wall -fno-warn-unused-imports
(head-end)

printf "  exposed-modules:\n    Bindings.Gts\n"

base="\
	BasicMacrosFunctionsAndDataStructures:gts.sourceforge.net/reference/c4.html \
	GeometricalObjectHierarchy:gts.sourceforge.net/reference/c2933.html \
	GeometricalDataStructures:gts.sourceforge.net/reference/c10592.html \
	SurfaceOperations:gts.sourceforge.net/reference/c12244.html \
	ProgressiveAndHierarchicalSurfaces:gts.sourceforge.net/reference/c15281.html \
	GraphAndOperationsOnGraphs:gts.sourceforge.net/reference/c17131.html"

imports=$(mktemp)

for b in $base ; do
	module=$(printf "%s" $b | cut -d ':' -f 1)
	printf "    Bindings.Gts.%s\n" $module
	dir=src/Bindings/Gts/$module
	doc=$(printf "%s" $b | cut -d ':' -f 2)
	printf -- "-- | <http://%s>\nmodule Bindings.Gts.%s (\n" $doc $module > $dir.hs
	printf " ) where\n" > $imports
	sub=$(ls -1 $dir | grep '.hsc$' | sed 's/\.hsc$//')
	for s in $sub ; do
		printf "    Bindings.Gts.%s.%s\n" $module $s
		printf "  module Bindings.Gts.%s.%s,\n" $module $s >> $dir.hs
		printf "import Bindings.Gts.%s.%s\n" $module $s >> $imports
	done
	cat $imports >> $dir.hs
done

printf "    Bindings.Gts.Types\n"

rm $imports

printf "  c-sources:\n"

for f in $(ls -1 src/*.c) ; do
	printf "    %s\n" $f
done
