update submodules for GHC.HetMet.GArrow -> Control.GArrow renaming
[ghc-hetmet.git] / distrib / MacOS / mkinstaller
1 #!/bin/bash
2
3 set -e
4
5 die () {
6     echo "Error: $1" >&2
7     exit 1
8 }
9
10 if ! [ -d installer-scripts ]
11 then
12     die "Doesn't look like you are running this script from the right location"
13 fi
14
15 if [ "$#" -ne 1 ]
16 then
17     die "Must be given on argument (the bindist)"
18 fi
19
20 BINDIST="$1"
21
22 GHC_UNPACKS_INTO=`echo "$BINDIST" | sed 's/^\(.*\/\)\{0,1\}\(ghc-\([0-9]\{1,\}\)\.\([0-9]\{1,\}\)\.\([0-9]\{1,\}\)\(\.\([0-9]\{1,\}\)\)\{0,1\}\)-\([a-z0-9_]\{1,\}\)-apple-darwin\.tar\.bz2$/\2/'`
23 GHC_VERSION_DIG1=`echo "$BINDIST" | sed 's/^\(.*\/\)\{0,1\}\(ghc-\([0-9]\{1,\}\)\.\([0-9]\{1,\}\)\.\([0-9]\{1,\}\)\(\.\([0-9]\{1,\}\)\)\{0,1\}\)-\([a-z0-9_]\{1,\}\)-apple-darwin\.tar\.bz2$/\3/'`
24 GHC_VERSION_DIG2=`echo "$BINDIST" | sed 's/^\(.*\/\)\{0,1\}\(ghc-\([0-9]\{1,\}\)\.\([0-9]\{1,\}\)\.\([0-9]\{1,\}\)\(\.\([0-9]\{1,\}\)\)\{0,1\}\)-\([a-z0-9_]\{1,\}\)-apple-darwin\.tar\.bz2$/\4/'`
25 GHC_VERSION_DIG3=`echo "$BINDIST" | sed 's/^\(.*\/\)\{0,1\}\(ghc-\([0-9]\{1,\}\)\.\([0-9]\{1,\}\)\.\([0-9]\{1,\}\)\(\.\([0-9]\{1,\}\)\)\{0,1\}\)-\([a-z0-9_]\{1,\}\)-apple-darwin\.tar\.bz2$/\5/'`
26 GHC_VERSION_DIG4=`echo "$BINDIST" | sed 's/^\(.*\/\)\{0,1\}\(ghc-\([0-9]\{1,\}\)\.\([0-9]\{1,\}\)\.\([0-9]\{1,\}\)\(\.\([0-9]\{1,\}\)\)\{0,1\}\)-\([a-z0-9_]\{1,\}\)-apple-darwin\.tar\.bz2$/\7/'`
27 GHC_ARCHITECTURE=`echo "$BINDIST" | sed 's/^\(.*\/\)\{0,1\}\(ghc-\([0-9]\{1,\}\)\.\([0-9]\{1,\}\)\.\([0-9]\{1,\}\)\(\.\([0-9]\{1,\}\)\)\{0,1\}\)-\([a-z0-9_]\{1,\}\)-apple-darwin\.tar\.bz2$/\8/'`
28
29 if [ "$GHC_ARCHITECTURE" == "$BINDIST" ]
30 then
31     die "Bindist filename not in expected format"
32 fi
33
34 if [ "$(($GHC_VERSION_DIG2 % 2))" -eq 1 ]
35 then
36     if [ "$GHC_VERSION_DIG4" == "" ]
37     then
38         FRAMEWORK_VERSION="$GHC_VERSION_DIG1.$GHC_VERSION_DIG2.$GHC_VERSION_DIG3-$GHC_ARCHITECTURE"
39         CURRENT_PROJECT_VERSION=`printf "%02d%02d00.%08d\n" "$GHC_VERSION_DIG1" "$GHC_VERSION_DIG2" "$GHC_VERSION_DIG3"`
40     else
41         die "Huh? 4 component HEAD version?"
42     fi
43 else
44     if [ "$GHC_VERSION_DIG4" == "" ]
45     then
46         FRAMEWORK_VERSION="$GHC_VERSION_DIG1.$GHC_VERSION_DIG2.$GHC_VERSION_DIG3-$GHC_ARCHITECTURE"
47         CURRENT_PROJECT_VERSION=`printf "%02d%02d%02d\n" "$GHC_VERSION_DIG1" "$GHC_VERSION_DIG2" "$GHC_VERSION_DIG3"`
48     else
49         FRAMEWORK_VERSION="$GHC_VERSION_DIG1.$GHC_VERSION_DIG2.$GHC_VERSION_DIG3.$GHC_VERSION_DIG4-$GHC_ARCHITECTURE"
50         CURRENT_PROJECT_VERSION=`printf "%02d%02d%02d.%08d\n" "$GHC_VERSION_DIG1" "$GHC_VERSION_DIG2" "$GHC_VERSION_DIG3" "$GHC_VERSION_DIG4"`
51     fi
52 fi
53
54 # The user-visible CFBundleShortVersionString
55 SHORT_VERSION_STRING="$FRAMEWORK_VERSION"
56
57 # Name of the installer package
58 PACKAGE_NAME="GHC-$FRAMEWORK_VERSION.pkg"
59
60 # Xcode's installation build product location (this is where the GHC.framework
61 # is assembled)
62 DSTROOT="/tmp/GHC.dst"
63
64 # Tools directory for a system volume install
65 TOOLS_SYSTEM="$DSTROOT/Library/Frameworks/GHC.framework/Versions/$FRAMEWORK_VERSION/Tools"
66
67 rm -rf "$DSTROOT"
68 mkdir -p "$TOOLS_SYSTEM"
69 sed "s/@FRAMEWORK_VERSION@/$FRAMEWORK_VERSION/" \
70     < installer-scripts/Uninstaller.in          \
71     > installer-scripts/Uninstaller
72 sed "s/@FRAMEWORK_VERSION@/$FRAMEWORK_VERSION/" \
73     < installer-scripts/create-links.in         \
74     > installer-scripts/create-links
75 sed "s/@FRAMEWORK_VERSION@/$FRAMEWORK_VERSION/" \
76     < GHC-system.pmdoc/index.xml.in             \
77     > GHC-system.pmdoc/index.xml
78 cp installer-scripts/Uninstaller installer-scripts/create-links "$TOOLS_SYSTEM"
79 xcodebuild -target GHC-systemwide clean build install         \
80            BINDIST="$BINDIST"                                 \
81            GHC_UNPACKS_INTO="$GHC_UNPACKS_INTO"               \
82            CURRENT_PROJECT_VERSION="$CURRENT_PROJECT_VERSION" \
83            SHORT_VERSION_STRING="$SHORT_VERSION_STRING"       \
84            FRAMEWORK_VERSION="$FRAMEWORK_VERSION"             \
85            CURRENT_LIBRARY_VERSION="$FRAMEWORK_VERSION"       \
86            COMMAND_MODE=unix2003
87 rm -f GHC-system.pmdoc/*-contents.xml
88
89 /Developer/usr/bin/packagemaker             \
90     -v --doc GHC-system.pmdoc               \
91     -o $PACKAGE_NAME                        \
92     -i org.haskell.ghc."$FRAMEWORK_VERSION"
93
94 # Clean up
95 xcodebuild -target GHC-systemwide clean                       \
96            CURRENT_PROJECT_VERSION="$CURRENT_PROJECT_VERSION" \
97            SHORT_VERSION_STRING="$SHORT_VERSION_STRING"       \
98            FRAMEWORK_VERSION="$FRAMEWORK_VERSION"             \
99            CURRENT_LIBRARY_VERSION="$FRAMEWORK_VERSION"       \
100            COMMAND_MODE=unix2003
101 rm -r "$GHC_UNPACKS_INTO"
102 rm -r "$DSTROOT"
103 rm installer-scripts/Uninstaller installer-scripts/create-links
104 rm GHC-system.pmdoc/index.xml
105