Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 356 lines (311 sloc) 12.188 kb
22b433a @fperrin Don't assume that bash is in /bin
fperrin 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
3bf738f @OpaOnWindowsNow [cleanup] documentation: disabling book generation, and old api offli…
OpaOnWindowsNow authored
12 NODOC="true"
973304b @OpaOnWindowsNow [feature] install_release: new -no-man option
OpaOnWindowsNow authored
13 NOMAN="false"
fccc685 Initial open-source release
MLstate authored
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";;
973304b @OpaOnWindowsNow [feature] install_release: new -no-man option
OpaOnWindowsNow authored
58 -no-man)
59 NOMAN="true";;
fccc685 Initial open-source release
MLstate authored
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
1112282 @OpaOnWindowsNow [fix] fedora,install_release: -keep-install-sys should use installed …
OpaOnWindowsNow authored
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
fccc685 Initial open-source release
MLstate authored
183 fi
184 fi
185
186 # mlstate libs and tools (generic)
187 msg Installing mlstate stuff
188
1112282 @OpaOnWindowsNow [fix] fedora,install_release: -keep-install-sys should use installed …
OpaOnWindowsNow authored
189 if [ "$KEEP_INSTALL_SYS" = "false" ] && [ -z "$IS_WINDOWS" ] && [ -z "$IS_MAC" ] && [ "$(ocamlc.opt -where)" != "$INSTALLDIR_LIBOPAOCAML/lib/ocaml" ]; then
fccc685 Initial open-source release
MLstate authored
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
1112282 @OpaOnWindowsNow [fix] fedora,install_release: -keep-install-sys should use installed …
OpaOnWindowsNow authored
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
fccc685 Initial open-source release
MLstate authored
202 else
1112282 @OpaOnWindowsNow [fix] fedora,install_release: -keep-install-sys should use installed …
OpaOnWindowsNow authored
203 OCAMLOPT=ocamlopt.opt
fccc685 Initial open-source release
MLstate authored
204 fi
205 cd $OPAGENERAL
206 SRCDIR=$OPAGENERAL
207 OPABOOK=$OPAGENERAL/doc/book # the tutorial and book
208
a8ccea3 [fix] install_release: -no-dbm
François-Régis Sinot authored
209 ./configure -prefix $INSTALLDIR -ocamlopt $OCAMLOPT -release -no-dbm
fccc685 Initial open-source release
MLstate authored
210
973304b @OpaOnWindowsNow [feature] install_release: new -no-man option
OpaOnWindowsNow authored
211
212 TARGETS="distrib"
213 if [ $NOMAN = "false" ]; then
214 TARGETS="$TARGETS manpages"
215 fi
216
217 make clean $TARGETS install
fccc685 Initial open-source release
MLstate authored
218
219 mkdir -p $INSTALLDIR/share/opa/
220 mkdir -p $INSTALLDIR/share/doc/opa/
221
838b1c9 @OpaOnWindowsNow [fix] install_release.sh: .api generation is still neded
OpaOnWindowsNow authored
222 make packages-api
fccc685 Initial open-source release
MLstate authored
223 # generating the book
d65924b @BourgerieQuentin [fix] install_release: fix install_release script
BourgerieQuentin authored
224 # if [ $NODOC = "false" ]; then
3bf738f @OpaOnWindowsNow [cleanup] documentation: disabling book generation, and old api offli…
OpaOnWindowsNow authored
225 # if ! make book-clean book; then
226 # msg "Error: could not build the doc in $OPABOOK."
227 # msg "You may want to fix and re-run with -keep-install-sys -keep-build"
228 # exit 1
229 # fi
d65924b @BourgerieQuentin [fix] install_release: fix install_release script
BourgerieQuentin authored
230 # fi
fccc685 Initial open-source release
MLstate authored
231 # installing the book
232 if [ $NODOC = "false" ] && [ -z "$IS_WINDOWS" ]; then
233 mkdir -p $INSTALLDIR/share/doc/opa/book
234 cp -r $OPABOOK/* $INSTALLDIR/share/doc/opa/book
235 fi
236
237 $SRCDIR/utils/install.sh --uninstall --dir $INSTALLDIR
238 install -m 0755 -v $SRCDIR/utils/install.sh $INSTALLDIR/share/opa
239 mkdir -p $INSTALLDIR/share/opa/emacs
806bffb @nrs135 [feature] js-like,mode: new mode for js-like syntax
nrs135 authored
240 install -m 0644 -v $SRCDIR/utils/emacs/{opa-mode.el,opa-js-mode.el,site-start.el} $INSTALLDIR/share/opa/emacs
fccc685 Initial open-source release
MLstate authored
241 mkdir -p $INSTALLDIR/share/opa/vim
242 cp -r $SRCDIR/utils/vim/* $INSTALLDIR/share/opa/vim/
243
244 # installing changelog (follows standard conventions)
245 gzip -c -9 CHANGELOG > $INSTALLDIR/share/doc/opa/changelog.gz
246
247 # installing copyright
248 if ! grep -q "Copyright.*\<$(date +%Y)\>" copyright/copyright; then
249 echo "WARNING: copyright doesn't appear to be up-to-date (doesn't mention current year)"
250 fi
251 # Careful: copyright file mentions that it must be along <AGPL> and <other_licenses>
252 # (which _must_ both be included for legal reasons)
253 install -m 0644 -v $SRCDIR/copyright/copyright $INSTALLDIR/share/doc/opa/
254 {
255 echo "OPA includes parts of the following software, with the given licenses:"
256 echo
257 for f in $SRCDIR/copyright/[0-9][0-9]_*; do
258 name=$(basename $f)
259 name=${name#??_}
260 echo
261 echo "----------------------------------------------------------------------"
262 echo "------------------------ License for $name ------------------------"
263 echo
264 cat $f
265 done
266 } > $INSTALLDIR/share/doc/opa/other_licenses
267 chmod 644 $INSTALLDIR/share/doc/opa/other_licenses
268 install -m 0644 -v $SRCDIR/LICENSE $INSTALLDIR/share/doc/opa/AGPL
269
270 # Cleaning up:
271 msg Removing unneeded ocaml executables
272 # ocaml
273 rm -rvf $INSTALLDIR_LIBOPAOCAML/man*
274 # leave only ocamlc.opt, ocamlopt.opt
275 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
276 echo " -- Removing $INSTALLDIR_LIBOPAOCAML/bin/$i"
277 rm -fv $INSTALLDIR_LIBOPAOCAML/bin/$i
278 done
279 rm -rvf $INSTALLDIR_LIBOPAOCAML/etc
280 for i in {findlib,etc,camlp4,labltk,ocamldoc,objinfo_helper,toplevellib.cma,addlabels,camlheader,expunge,extract_crc,scrapelabels}; do
281 echo " -- Removing $INSTALLDIR_LIBOPAOCAML/lib/ocaml/$i"
282 rm -rvf $INSTALLDIR_LIBOPAOCAML/lib/ocaml/$i
283 done
284 rm -rvf $INSTALLDIR/lib/ocaml/mascot
285 rm -fv $INSTALLDIR/bin/mascot.*
286
287 if [ -z "$IS_MAC" ] ; then
288 msg "Removing any source, bytecode, headers or other compilation artefacts"
289 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
290
291 fi
292
293 msg "Cleaning RPATH of binaries and shared libraries"
294 if ! which chrpath &> /dev/null; then
295 msg "WARNING: chrpath not found, you'll have dirty stuff in your libs/binaries"
296 sleep 10
297 else
298 find $INSTALLDIR \( -name '*.so' -or \( -executable ! -type d \) \) -exec chrpath -k -d {} + 2>/dev/null || true
299 fi
300
301 msg Stripping and upx-ing
302 UPX=upx
303 STRIP=strip
304
305 upxf(){
306 if [ -n "$IS_WINDOWS" ];
307 then
308 FILETOMOD="$(cygpath -w $1)"
309 editbin /NOLOGO /STACK:10000000,10000000 "$FILETOMOD" # bigger stacksize because ocamlopt.opt needs it
310 /windows_libs/utils/upx "$FILETOMOD"
311 editbin /NOLOGO /STACK:10000000,10000000 "$FILETOMOD" # in case upx malfunctions
312 elif [ -n "$IS_MAC" ];
313 then
314 echo No upx on mac
315 else
316 upx $1 || true
317 fi
318 }
319
320
321 stripf(){
322 if [ -n "$IS_WINDOWS" ];
323 then
324 echo No strip on windows
325 elif [ -n "$IS_MAC" ];
326 then
327 # not $STRIP there ?
328 strip $1 || true
329 else
330 strip $1 || true
331 fi
332 }
333
334 for i in $INSTALLDIR/bin/* $INSTALLDIR/lib/opa/bin/*; do
335 # Strip BEFORE upx, otherwise the exe is DESTROYED
336 stripf $i
337 # upxf $i -- upx disabled, last version seems to cause problems
338 done
339 # same previous stuff, but on mac this directory does not exists, so we put this extra test to avoid a warning
340 # if this is a directory (and exist)
341 if [ -d $INSTALLDIR_LIBOPAOCAML/bin ]; then
342 for i in $INSTALLDIR_LIBOPAOCAML/bin/*; do
343 # extra protection against an empty 'bin/*'
344 if [ -f $i ]; then
345 # here we will pass up on ocamlopt.opt, so we must be carefull to not break it
346 stripf $i
347 fi
348 done
349 fi
350
351 ## not some on stripf there ?
352 find $INSTALLDIR -name '*.cmxs' -exec $STRIP {} \;
353 find $INSTALLDIR -name '*.so' -exec $STRIP {} \;
354
355 msg "Installation in $INSTALLDIR finished."
Something went wrong with that request. Please try again.