Ticket #7136: mkinstaller

File mkinstaller, 4.5 KB (added by carter, 2 years ago)

fixed mkinstaller

Line 
1#!/bin/bash
2
3set -e
4
5die () {
6    echo "Error: $1" >&2
7    exit 1
8}
9
10if ! [ -d installer-scripts ]
11then
12    die "Doesn't look like you are running this script from the right location"
13fi
14
15if [ "$#" -ne 1 ]
16then
17    die "Must be given one argument (the bindist)"
18fi
19
20BINDIST="$1"
21
22GHC_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/'`
23GHC_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/'`
24GHC_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/'`
25GHC_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/'`
26GHC_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/'`
27GHC_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
29if [ "$GHC_ARCHITECTURE" == "$BINDIST" ]
30then
31    die "Bindist filename not in expected format"
32fi
33
34if [ "$(($GHC_VERSION_DIG2 % 2))" -eq 1 ]
35then
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
43else
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
52fi
53
54# The user-visible CFBundleShortVersionString
55SHORT_VERSION_STRING="$FRAMEWORK_VERSION"
56
57# Name of the installer package
58PACKAGE_NAME="GHC-$FRAMEWORK_VERSION.pkg"
59
60# Xcode's installation build product location (this is where the GHC.framework
61# is assembled)
62DSTROOT="/tmp/GHC.dst"
63
64# Tools directory for a system volume install
65TOOLS_SYSTEM="$DSTROOT/Library/Frameworks/GHC.framework/Versions/$FRAMEWORK_VERSION/Tools"
66
67rm -rf "$DSTROOT"
68mkdir -p "$TOOLS_SYSTEM"
69sed "s/@FRAMEWORK_VERSION@/$FRAMEWORK_VERSION/" \
70    < installer-scripts/Uninstaller.in          \
71    > installer-scripts/Uninstaller
72sed "s/@FRAMEWORK_VERSION@/$FRAMEWORK_VERSION/" \
73    < installer-scripts/create-links.in         \
74    > installer-scripts/create-links
75sed "s/@FRAMEWORK_VERSION@/$FRAMEWORK_VERSION/" \
76    < GHC-system.pmdoc/index.xml.in             \
77    > GHC-system.pmdoc/index.xml
78cp installer-scripts/Uninstaller installer-scripts/create-links "$TOOLS_SYSTEM"
79xcodebuild -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
87rm -f GHC-system.pmdoc/*-contents.xml
88
89/Applications/PackageMaker.app/Contents/MacOS/PackageMaker           \
90    -v --doc GHC-system.pmdoc               \
91    -o $PACKAGE_NAME                        \
92    -i org.haskell.ghc."$FRAMEWORK_VERSION"
93
94# Clean up
95xcodebuild -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
101rm -r "$GHC_UNPACKS_INTO"
102rm -r "$DSTROOT"
103rm installer-scripts/Uninstaller installer-scripts/create-links
104rm GHC-system.pmdoc/index.xml
105