Permalink
Newer
Older
100755 358 lines (313 sloc) 12 KB
1
#!/usr/bin/env bash
2
3
set -e
4
set -u
5
6
. ./platform_helper.sh
7
8
# these must be absolute
9
PREFIX=/usr
10
INSTALLDIR=$PWD/release_install_root
11
14
15
# the version string will be MAJORNAME+BUILDnnnn with nnnn the build number
16
# (MAJORNAME if BUILD is empty)
17
18
msg () {
19
case "$1" in
20
-n) shift; echo -n "$*";;
21
*) echo "$*";;
22
esac
23
}
24
25
MYDIR=$PWD
26
27
OPAGENERAL=$MYDIR
28
29
CLEAN=true
30
KEEP_INSTALL_SYS="false"
31
32
help() {
33
echo "Installs a stripped stand-alone (including ocaml) version of OPA in the system."
34
echo "The installed system can then be used for building packages."
35
echo "Options"
36
echo " -prefix <dir> Build for install in <dir>. Warning, you may need to recompile"
37
echo " ocaml if you change this (default $PREFIX)"
38
echo " -dir <dir> Install to <dir> (default $INSTALLDIR)"
39
echo " -srcdir <dir> Your opageneral directory (default current dir)"
40
echo " -keep-install-sys Don't rebuild ocaml and libs, assume it has already been done"
41
echo " -keep-build Don't cleanup your _build. Only use if you're sure it was"
42
echo " made with the right version of ocaml (the one this script"
43
echo " builds)"
44
echo " -fetch-git [branch|tag] Instead of setting a source directory, you can select this"
45
echo " option to freshly clone the sources at branch/tag"
46
echo " (default remotes/origin/master)"
47
echo " -license <prefix> Use given license (files <prefix>_EN, <prefix>_FR)"
48
echo
49
echo "GUIDELINES: Run from a proper opageneral or with the fetch-git option."
50
echo "In the former case, you'll need an opa-doc repo along your opageneral."
51
echo "you could have a syntax error in ocaml-doc, when building, so you can remplace the makefile by empty rule, because it not needed"
52
}
53
54
while [ $# -gt 0 ]; do
55
case $1 in
56
-no-doc)
57
NODOC="true";;
58
-no-man)
59
NOMAN="true";;
60
-force-doc)
61
NODOC="false";;
62
-fetch-git)
63
BRANCH=remotes/origin/master
64
if echo $2 | grep -q "^[^-]"; then shift; BRANCH=$1; fi
65
cd $MYDIR
66
mkdir -p git-masters
67
for d in opa-doc reftester; do
68
if [ ! -d "$MYDIR/git-masters/$d" ]; then
69
cd "$MYDIR/git-masters"; git clone -n git@ovh4:$d.git;
70
fi
71
cd "$MYDIR/git-masters/$d"; git fetch; git checkout $BRANCH
72
done
73
OPAGENERAL="$MYDIR/git-masters/opageneral"
74
cd $OPAGENERAL && ./init.sh --link >/dev/null
75
CMDLINE="$CMDLINE -srcdir $MYDIR/git-masters/opageneral"
76
cd $MYDIR;;
77
-keep-build)
78
CLEAN="false";;
79
-keep-install-sys)
80
KEEP_INSTALL_SYS="true";;
81
-prefix)
82
if [ $# -lt 2 ]; then echo "Error: option $1 requires an argument"; exit 1; fi
83
shift
84
PREFIX="$1";;
85
-dir)
86
if [ $# -lt 2 ]; then echo "Error: option $1 requires an argument"; exit 1; fi
87
shift
88
INSTALLDIR="$1";;
89
-srcdir)
90
if [ $# -lt 2 ]; then echo "Error: option $1 requires an argument"; exit 1; fi
91
shift
92
OPAGENERAL="$1";;
93
-help|--help|-h)
94
help
95
exit 0;;
96
*)
97
echo "Unknown option $1."
98
help
99
exit 1;;
100
esac
101
shift
102
done
103
104
if [ ${INSTALLDIR:0:1} != "/" ] || [ ${PREFIX:0:1} != "/" ]; then
105
msg "Error: your prefix or install directory is not absolute"
106
exit 1
107
fi
108
109
if [ "" != "$(diff $0 $OPAGENERAL/$(basename $0))" ]; then
110
echo "WARNING: current version of $(basename $0) different from the one in the repo you're making the distribution from."
111
fi
112
113
if [ "$CLEAN" = "true" ] && [ -e _build ]; then
114
msg "Cleaning up your _build..."
115
rm -rf _build
116
fi
117
118
if [ "$KEEP_INSTALL_SYS" = "false" ] ; then
119
# Start fresh
120
if ! [ $(ls $INSTALLDIR 2>/dev/null |wc -l) -eq 0 ]; then # checks if dir empty
121
msg -n "Warning, install directory $INSTALLDIR exists. Cleanup ? (no will abort) [Yn] "
122
read yesno
123
case "$yesno" in
124
n|no|non) msg Not installing to a dirty directory; exit 1;;
125
bypass) msg "You seem to know what you're doing...";;
126
*) msg Cleaning $INSTALLDIR;
127
if [ -z $INSTALLDIR ]; then
128
msg 'Bailing out!' ;exit 1 ;
129
else
130
rm -rf $INSTALLDIR/* ;
131
fi
132
esac
133
fi
134
fi
135
136
MLSTATEVARS=$(set | grep -a '^MLSTATE\|^DBGEN\|^OPA' | grep -v "^MLSTATELIBS=\|^OPAGENERAL=\|^OPA_SOURCE_DIR=\|^OPAPRIVATE=" || true )
137
138
if [ -n "$MLSTATEVARS" ]; then
139
msg "Warning: mlstate env vars detected. Please make sure the following won't"
140
msg "have any consequence on the build."
141
echo $MLSTATEVARS
142
msg -n "Continue ? [Yn] "
143
read yesno
144
case "$yesno" in
145
n|no|non) msg Aborting; exit 1;;
146
esac
147
fi
148
149
mkdir -p $INSTALLDIR
150
151
INSTALLDIR_LIBOPAOCAML=$INSTALLDIR/lib/opa/ocaml
152
if [ -n "$IS_MAC" ] ; then
153
INSTALLDIR_LIBOPAOCAML=$INSTALLDIR
154
fi
155
156
157
# Install (our) ocaml
158
if [ -n "$IS_WINDOWS" ]; then
159
msg Local copy of ocaml HACK TEMPORAIRE for debug
160
WINOCAML=/cygdrive/c/ocamlms
161
mkdir -p $INSTALLDIR/lib/ocaml
162
mkdir -p $INSTALLDIR/bin
163
mkdir -p $INSTALLDIR/bin/ocaml
164
cp -ur $WINOCAML/lib/* $INSTALLDIR/lib/ocaml/
165
cp -ur $WINOCAML/bin/* $INSTALLDIR/bin/
166
else
167
msg Installing ocaml and other dependencies
168
if [ "$KEEP_INSTALL_SYS" = "false" ] ; then
169
rm -rf $OPAGENERAL/ocaml/build
170
. platform_helper.sh
171
if [ -n "$IS_MAC" ] ; then
172
$OPAGENERAL/dependencies/installation_helper.sh --prefix $INSTALLDIR
173
else
174
$OPAGENERAL/dependencies/installation_helper.sh --prefix $PREFIX/lib/opa/ocaml --installdir $INSTALLDIR_LIBOPAOCAML
175
fi
176
if [ -n "$IS_MAC" ] ; then
177
export OCAMLLIB=$INSTALLDIR/lib/ocaml
178
export PATH=$INSTALLDIR/bin:$PATH
179
else
180
export OCAMLLIB=$INSTALLDIR_LIBOPAOCAML/lib/ocaml
181
export PATH=$INSTALLDIR_LIBOPAOCAML/bin:$PATH
182
fi
183
fi
184
fi
185
186
# mlstate libs and tools (generic)
187
msg Installing mlstate stuff
188
189
if [ "$KEEP_INSTALL_SYS" = "false" ] && [ -z "$IS_WINDOWS" ] && [ -z "$IS_MAC" ] && [ "$(ocamlc.opt -where)" != "$INSTALLDIR_LIBOPAOCAML/lib/ocaml" ]; then
190
msg "Error: fresh installed ocaml not found (ocamlc -where returned $(ocamlc.opt -where) instead of $INSTALLDIR_LIBOPAOCAML/lib/ocaml"
191
exit 1
192
fi
193
194
export MLSTATELIBS=$INSTALLDIR
195
# in order to build opa with the ocaml freshly built
196
if [ "$KEEP_INSTALL_SYS" = "false" ] ; then
197
if [ -n "$IS_MAC" ] ; then
198
export OCAMLOPT=$INSTALLDIR/bin/ocamlopt.opt
199
else
200
export OCAMLOPT=$INSTALLDIR_LIBOPAOCAML/bin/ocamlopt.opt
201
fi
202
else
204
fi
205
cd $OPAGENERAL
206
SRCDIR=$OPAGENERAL
207
OPABOOK=$OPAGENERAL/doc/book # the tutorial and book
208
OPADOCGEN=$OPAGENERAL/_build/opadoc/doc # the generated API doc
209
210
./configure -prefix $INSTALLDIR -ocamlopt $OCAMLOPT -release -no-dbm
211
212
213
TARGETS="distrib"
214
if [ $NOMAN = "false" ]; then
215
TARGETS="$TARGETS manpages"
216
fi
217
218
make clean $TARGETS install
219
220
mkdir -p $INSTALLDIR/share/opa/
221
mkdir -p $INSTALLDIR/share/doc/opa/
222
224
# generating the book
225
# if [ $NODOC = "false" ]; then
226
# make opadoc/doc install-doc
227
# if ! make book-clean book; then
228
# msg "Error: could not build the doc in $OPABOOK."
229
# msg "You may want to fix and re-run with -keep-install-sys -keep-build"
230
# exit 1
231
# fi
233
# installing the book
234
if [ $NODOC = "false" ] && [ -z "$IS_WINDOWS" ]; then
235
mkdir -p $INSTALLDIR/share/doc/opa/book
236
cp -r $OPABOOK/* $INSTALLDIR/share/doc/opa/book
237
fi
238
239
$SRCDIR/utils/install.sh --uninstall --dir $INSTALLDIR
240
install -m 0755 -v $SRCDIR/utils/install.sh $INSTALLDIR/share/opa
241
mkdir -p $INSTALLDIR/share/opa/emacs
242
install -m 0644 -v $SRCDIR/utils/emacs/{opa-mode.el,opa-js-mode.el,site-start.el} $INSTALLDIR/share/opa/emacs
243
mkdir -p $INSTALLDIR/share/opa/vim
244
cp -r $SRCDIR/utils/vim/* $INSTALLDIR/share/opa/vim/
245
246
# installing changelog (follows standard conventions)
247
gzip -c -9 CHANGELOG > $INSTALLDIR/share/doc/opa/changelog.gz
248
249
# installing copyright
250
if ! grep -q "Copyright.*\<$(date +%Y)\>" copyright/copyright; then
251
echo "WARNING: copyright doesn't appear to be up-to-date (doesn't mention current year)"
252
fi
253
# Careful: copyright file mentions that it must be along <AGPL> and <other_licenses>
254
# (which _must_ both be included for legal reasons)
255
install -m 0644 -v $SRCDIR/copyright/copyright $INSTALLDIR/share/doc/opa/
256
{
257
echo "OPA includes parts of the following software, with the given licenses:"
258
echo
259
for f in $SRCDIR/copyright/[0-9][0-9]_*; do
260
name=$(basename $f)
261
name=${name#??_}
262
echo
263
echo "----------------------------------------------------------------------"
264
echo "------------------------ License for $name ------------------------"
265
echo
266
cat $f
267
done
268
} > $INSTALLDIR/share/doc/opa/other_licenses
269
chmod 644 $INSTALLDIR/share/doc/opa/other_licenses
270
install -m 0644 -v $SRCDIR/LICENSE $INSTALLDIR/share/doc/opa/AGPL
271
272
# Cleaning up:
273
msg Removing unneeded ocaml executables
274
# ocaml
275
rm -rvf $INSTALLDIR_LIBOPAOCAML/man*
276
# leave only ocamlc.opt, ocamlopt.opt
277
for i in {camlp4*,mkcamlp4,ocamlbuild.byte,ocamlcp,ocamldoc,ocamlmklib*,ocamlprof,ocaml,ocamlbuild.native,ocamldebug,ocamldoc.opt,ocamlmktop,ocamlrun,ocamlbrowser,ocamlc,ocamldep,ocamllex,ocamlopt,ocamlyacc,labltk,ocamlbuild,ocamldep.opt,ocamllex.opt,ocamlc.opt,ocamlobjinfo,ocamlfind,findlib,safe_camlp4,camlidl} ; do
278
echo " -- Removing $INSTALLDIR_LIBOPAOCAML/bin/$i"
279
rm -fv $INSTALLDIR_LIBOPAOCAML/bin/$i
280
done
281
rm -rvf $INSTALLDIR_LIBOPAOCAML/etc
282
for i in {findlib,etc,camlp4,labltk,ocamldoc,objinfo_helper,toplevellib.cma,addlabels,camlheader,expunge,extract_crc,scrapelabels}; do
283
echo " -- Removing $INSTALLDIR_LIBOPAOCAML/lib/ocaml/$i"
284
rm -rvf $INSTALLDIR_LIBOPAOCAML/lib/ocaml/$i
285
done
286
rm -rvf $INSTALLDIR/lib/ocaml/mascot
287
rm -fv $INSTALLDIR/bin/mascot.*
288
289
if [ -z "$IS_MAC" ] ; then
290
msg "Removing any source, bytecode, headers or other compilation artefacts"
291
find $INSTALLDIR \( -name '*.ml' -or -name '*.mli' -or -name '*.cma' -or -name '*.cmo' -or -name '*.p.a' -or -name '*.p.cm*' -or -name '*.h' -or -name 'HEAD' -or -name 'META' -or \( -type d -empty \) \) | grep -v $INSTALLDIR/share/doc/opa/book | while read line ; do if [ -f $line ] ; then rm $line ; fi ; if [ -d $line ] ; then rmdir $line ; fi ; done
292
293
fi
294
295
msg "Cleaning RPATH of binaries and shared libraries"
296
if ! which chrpath &> /dev/null; then
297
msg "WARNING: chrpath not found, you'll have dirty stuff in your libs/binaries"
298
sleep 10
299
else
300
find $INSTALLDIR \( -name '*.so' -or \( -executable ! -type d \) \) -exec chrpath -k -d {} + 2>/dev/null || true
301
fi
302
303
msg Stripping and upx-ing
304
UPX=upx
305
STRIP=strip
306
307
upxf(){
308
if [ -n "$IS_WINDOWS" ];
309
then
310
FILETOMOD="$(cygpath -w $1)"
311
editbin /NOLOGO /STACK:10000000,10000000 "$FILETOMOD" # bigger stacksize because ocamlopt.opt needs it
312
/windows_libs/utils/upx "$FILETOMOD"
313
editbin /NOLOGO /STACK:10000000,10000000 "$FILETOMOD" # in case upx malfunctions
314
elif [ -n "$IS_MAC" ];
315
then
316
echo No upx on mac
317
else
318
upx $1 || true
319
fi
320
}
321
322
323
stripf(){
324
if [ -n "$IS_WINDOWS" ];
325
then
326
echo No strip on windows
327
elif [ -n "$IS_MAC" ];
328
then
329
# not $STRIP there ?
330
strip $1 || true
331
else
332
strip $1 || true
333
fi
334
}
335
336
for i in $INSTALLDIR/bin/* $INSTALLDIR/lib/opa/bin/*; do
337
# Strip BEFORE upx, otherwise the exe is DESTROYED
338
stripf $i
339
# upxf $i -- upx disabled, last version seems to cause problems
340
done
341
# same previous stuff, but on mac this directory does not exists, so we put this extra test to avoid a warning
342
# if this is a directory (and exist)
343
if [ -d $INSTALLDIR_LIBOPAOCAML/bin ]; then
344
for i in $INSTALLDIR_LIBOPAOCAML/bin/*; do
345
# extra protection against an empty 'bin/*'
346
if [ -f $i ]; then
347
# here we will pass up on ocamlopt.opt, so we must be carefull to not break it
348
stripf $i
349
fi
350
done
351
fi
352
353
## not some on stripf there ?
354
find $INSTALLDIR -name '*.cmxs' -exec $STRIP {} \;
355
find $INSTALLDIR -name '*.so' -exec $STRIP {} \;
356
357
msg "Installation in $INSTALLDIR finished."