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