-
Notifications
You must be signed in to change notification settings - Fork 14
/
EmbErl.sh
executable file
·215 lines (172 loc) · 4.84 KB
/
EmbErl.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
#!/bin/bash
PROJECT=EmbErl
VERSION=R14B01
OTP_SRC=otp_src_$VERSION
OTP_SRC_TAR=${OTP_SRC}.tar.gz
XCOMP_CONF=erl-xcomp-arm-darwin.conf
XCOMP_CONF_PATH=xcomp/$XCOMP_CONF
TARGET_ERL_ROOT=/usr/local/erlang
TAR_NAME="EmbErl_"
#standard configuration values
STRIP_BIN=false
STRIP_BEAM=false
SLIM_COMPILE=false
COMPRESS_COMPILE=false
COMPRESS_APP=true
#standard gcc opt levels [1,2,3,s]
OPT_LEVEL=s
HOST=arm-apple-darwin10
#STRIP_CMD=${HOST}-strip
STRIP_CMD="/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/strip"
#Arguments parsing
while getopts ":scCoH:h" Option
do
case $Option in
s ) #echo "Stripping beam and Slim compiles"
STRIP_BEAM=true
SLIM_COMPILE=true
TAR_NAME=${TAR_NAME}s
;;
S ) #echo "Stipping binaries"
STRIP_BIN=true
;;
c ) #echo "Compress compiling"
COMPRESS_COMPILE=true
TAR_NAME=${TAR_NAME}c
;;
C ) #echo "Compressing Applications"
COMPRESS_APP=true
TAR_NAME=${TAR_NAME}C
;;
o ) #echo "Optimization level $OPTARG"
OPT_LEVEL=$OPTARG
TAR_NAME=${TAR_NAME}o${OPTARG}
;;
H ) #echo "Host $OPTARG"
HOST=$OPTARG
TAR_NAME=${TAR_NAME}H-${OPTARG}
;;
h ) echo \
"./Emberl.sh [options]
Available options:
-s Strip beam files and compile with the slim flag
-c Compile beams using the compress flag
-C Compress applications into zip's
-o <arg> Compile the virtual machine with the <arg> optimization flag
-H <arg> Compile the virtual machine for the host <arg>
-h Display this help message "
exit 0
;;
* ) echo "Unimplemented option chosen." # DEFAULT
;;
esac
done
#Create the erl-xcomp configuration
cat $XCOMP_CONF.in > $XCOMP_CONF
sed -ie "s/@OPT_LEVEL@/${OPT_LEVEL}/" $XCOMP_CONF
sed -ie "s/@HOST@/${HOST}/" $XCOMP_CONF
## FUNCTION DECLARATION SPACE
show()
{
cat <<EOF
*
* $1...
*
EOF
}
# END OF FUNCTION DECLARATION
WD=$(pwd)
#Do not do unnecessary work
if [ -e ${TAR_NAME}.tgz ]
then
show "The build exists.. see $TAR_NAME.tgz"
exit 0
fi
#Download the erlang source if it does not exist.
[ -e $OTP_SRC_TAR ] || (show "Downloading sources" && wget http://erlang.org/download/$OTP_SRC_TAR)
#Unpack
[ -d $OTP_SRC ] || (show "Unpacking $OTP_SRC" && tar xfz $OTP_SRC_TAR)
cp $XCOMP_CONF ${OTP_SRC}/$XCOMP_CONF_PATH
show "Patching some files for arm-apple-darwin gcc compiler and iOS SDK compatibility"
patch -N -p1 < arm-apple-darwin.patch
#Enter the Build directory and do configure
#TODO: remove any SKIP files that were created previously
show "Configuring for cross compilation using $XCOMP_CONF_PATH"
pushd $OTP_SRC
./otp_build configure --xcomp-conf=$XCOMP_CONF_PATH
if [[ "$SLIM_COMPILE" == "true" || "$COMPRESS_COMPILE" == "true" ]]
then
NEW_COMPILE_OPTS=""
if [ "$SLIM_COMPILE" == "true" ]
then
NEW_COMPILE_OPTS="$NEW_COMPILE_OPTS \+slim"
fi
if [ "$COMPRESS_COMPILE" == "true" ]
then
NEW_COMPILE_OPTS="$NEW_COMPILE_OPTS \+compressed"
fi
OTP_MK="make/${HOST}/otp.mk"
show "Patching $OTP_MK to edit erlc options"
sed -ie "s/ \+debug_info/$NEW_COMPILE_OPTS/" $OTP_MK
fi
#Put SKIP files in the apps we don't want.
show "Selecting applications to keep"
KEEPSIES=$(tr '\n' ' ' < ../keep)
for APP in $(ls lib); do
[ -d lib/$APP ] &&
echo "Not listed in keep file" >> lib/$APP/SKIP
done
for KEEP in $KEEPSIES; do
show "Keeping $KEEP"
rm -f lib/$KEEP/SKIP
done
show "Creating bootstrap and building"
./otp_build boot
for KEEP in $KEEPSIES; do
show "Removing prebuilt files in $KEEP"
rm lib/$KEEP/ebin/*.beam
done
show "Creating release"
./otp_build release
echo $(pwd)
pushd release/${HOST}/ 2> /dev/null || (show "Building release failed!" ; exit 1)
show "Running Install script to setup paths and executables"
./Install -cross -minimal $TARGET_ERL_ROOT
rm Install
if [ $STRIP_BEAM == true ]
then
show "Stripping beam files"
erl -eval "beam_lib:strip_release('${WD}/otp_src_${VERSION}/release/${HOST}')" -s init stop
fi
if [ $STRIP_BIN == true ]
then
show "Stripping erts binaries"
$STRIP_CMD erts-*/bin/*
fi
show "Removing source code, documentation, and examples"
for DIR in $(ls | grep erts) lib/*; do
rm -rf ${DIR}/src
rm -rf ${DIR}/include
rm -rf ${DIR}/doc
rm -rf ${DIR}/man
rm -rf ${DIR}/examples
done
rm -rf usr/include
rm -rf misc
if [ $COMPRESS_APP = true ]
then
show "Compressing erlang applications"
pushd lib
for APP in $(ls); do
zip -r ${APP}.zip $APP
mv ${APP}.zip ${APP}.ez
rm -f -r $APP
done
popd
fi
show "Creating tarball"
tar czf ${WD}/${TAR_NAME}.tgz .
popd
popd
## Test the resulted binaries for TARGET compatability
file ./otp_src_R14B01/bin/${HOST}/erlexec