Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

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