-
Notifications
You must be signed in to change notification settings - Fork 73
/
build.sh
executable file
·131 lines (106 loc) · 3.49 KB
/
build.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/bin/bash
export SOURCEDIR="`pwd`"
export PATCHDIR="$SOURCEDIR/Patches"
export BUILDDIR="$SOURCEDIR/build"
export LOGPATH="$BUILDDIR"
export INSTALLDIR="$BUILDDIR/homebrew"
export DEPLOYDIR="$BUILDDIR/MacGPG2"
export BUILDENV_DMG=""
export BUILDENV_MOUNT_DIR="$SOURCEDIR/build-env"
export BUILD_PPC=0
export NO_BUILDROOT_EXISTS=$(test -d $INSTALLDIR -a -w $INSTALLDIR; echo $?)
# Include the build-env file.
test -f ".build-env" && source ".build-env"
# Include the local build-env file which is not in git.
test -f ".build-env.local" && source ".build-env.local"
# Include status messages functions.
. status.sh
ACTION=$1
function tryToMountBuildEnvironment {
status "Try to mount the MacGPG2 build environment for ppc support"
if [ -f "$BUILDENV_DMG" ]; then
STATUS=$(mountBuildEnvironment "$BUILDENV_DMG")
if [ "$STATUS" == "0" ]; then
BUILD_PPC=1
stat=$(printf "%s%s%s" $(white) "enabled" $(reset))
status "PPC support $stat."
else
BUILD_PPC=0
stat=$(printf "%s%s%s" $(white) "disabled" $(reset))
status "PPC support $stat."
fi
else
BUILD_PPC=0
stat=$(printf "%s%s%s" $(white) "disabled" $(reset))
status "PPC support $stat."
fi
}
function mountBuildEnvironment {
hdiutil attach -mountpoint "$BUILDENV_MOUNT_DIR" -noverify -quiet "$1"
echo $?
}
function tryToUnmountBuildEnvironment {
status "Unomunt the MacGPG2 build environment"
hdiutil detach -force -quiet "$BUILDENV_MOUNT_DIR"
}
function clean {
if [ -d "$BUILDDIR" ]; then
rm -rf "$BUILDDIR";
fi
}
if [ "$ACTION" == "clean" ]; then
title "Cleaning MacGPG2 build"
clean
title "Finished"
exit 0
fi
title "Building MacGPG2"
tryToMountBuildEnvironment
if [ "$NO_BUILDROOT_EXISTS" == "1" ]; then
status "Bootstrapping Homebrew"
# Download homebrew and install it in BUILDDIR
mkdir -p "$INSTALLDIR"
curl -s -L https://github.com/mxcl/homebrew/tarball/master 2> /dev/null | tar xz --strip 1 -C "$INSTALLDIR"
pushd "$INSTALLDIR" > /dev/null
./bin/brew update 1>/dev/null 2>/dev/null
# Patch brew to add the install name patch and the build options
# patch.
status "Applying GPGTools homebrew patches"
for file in "$PATCHDIR"/homebrew/*.patch; do
patch --force -p1 < $file > /dev/null
done
popd > /dev/null
fi
# Update brew to the latest version.
pushd "$INSTALLDIR" > /dev/null
# Copy the MacGPG2 Formulas to homebrew
cp -R "$SOURCEDIR"/Formula/* ./Library/Formula/
# Link the jail dir which contains all compilers.
if [ ! -h ./build-env ]; then
ln -s "${BUILDENV_MOUNT_DIR}" ./build-env
fi
BUILD_PPC_ARG=""
if [ "$BUILD_PPC" == "1" ]; then
# Set the Build Environment for Homebrew to use.
export HOMEBREW_GPGTOOLS_BUILD_ENV="${INSTALLDIR}/build-env"
BUILD_PPC_ARG="--with-ppc"
fi
# Build MacGPG2
echo "./bin/brew install --universal $BUILD_PPC_ARG --use-llvm --quieter MacGPG2"
./bin/brew install --universal $BUILD_PPC_ARG --use-llvm --quieter MacGPG2
EXIT="$?"
popd > /dev/null
if [ "$BUILD_PPC" == "1" ]; then
tryToUnmountBuildEnvironment
fi
if [ "$EXIT" != "0" ]; then
error "Build failed!"
exit 1
fi
/usr/bin/python packer.py --prune "$INSTALLDIR" "$DEPLOYDIR"
if [ "$?" != "0" ]; then
error "Preparing files for the installer failed."
exit 1
fi
success "Build succeeded!"
exit 0