Fix boot-pkgs's sed usage to work with Solaris's sed
[ghc-hetmet.git] / boot-pkgs
1 #! /bin/sh
2 set -e
3
4 libraries=
5
6 # We do the sed in 3 steps, as the -snapshot may or may not be there,
7 # and I can't see a way to optionally match it with POSIX BREs
8 tarred=`ls -1 libraries/tarballs | sed -e 's/\.tar\.gz$//' -e 's/-snapshot$//' -e 's/-[0-9.]*$//'`
9
10 for p in $tarred
11 do
12     libraries="$libraries libraries/$p"
13     if [ -d "libraries/$p/_darcs" ]
14     then
15         echo Ignoring libraries/$p as it looks like a darcs checkout
16     else
17         tarball=libraries/tarballs/$p-*.tar.gz
18         stamp="libraries/stamp/$p"
19         if [ ! -d "libraries/$p" ] ||
20            [ ! -f "$stamp" ] ||
21            [ "libraries/stamp/$p" -ot $tarball ]
22         then
23             rm -rf "libraries/$p"
24             mkdir "libraries/$p"
25             (
26                 cd "libraries/$p"
27                 cat ../../$tarball | gzip -d | tar xf -
28                 mv */* .
29             )
30             touch "$stamp"
31         fi
32     fi
33 done
34
35 for f in libraries/*; do
36   pkgs=$f/ghc-packages
37   if test -f $pkgs; then
38     for p in `cat $pkgs`; do
39       libraries="$libraries $f/$p"
40     done
41   else
42     libraries="$libraries $f"
43   fi
44 done
45
46 for f in $libraries; do
47    dir=`basename $f`
48    cabals=`echo $f/*.cabal`
49    if test -f $cabals; then
50        echo "Creating $f/ghc.mk"
51        rm -f $f/ghc.mk
52        pkg=`echo "$cabals" | sed -e 's#.*/##' -e 's#\.cabal$##'`
53        if test -f $f/ghc-stage; then
54            stage=`cat $f/ghc-stage`
55        else
56            stage=1
57        fi
58        top=`echo $f | sed 's#[^/][^/]*#..#g'`
59        echo "${f}_PACKAGE = ${pkg}" >> $f/ghc.mk
60        echo "${f}_dist-install_GROUP = libraries" >> $f/ghc.mk
61        echo "\$(eval \$(call build-package,${f},dist-install,${stage}))" >> $f/ghc.mk
62        rm -f $f/GNUmakefile
63        echo "Creating $f/GNUmakefile"
64        echo "dir = ${f}" >> $f/GNUmakefile
65        echo "TOP = ${top}" >> $f/GNUmakefile
66        echo "include \$(TOP)/mk/sub-makefile.mk" >> $f/GNUmakefile
67    fi
68 done