Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

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