Skip to content

HTTPS clone URL

Subversion checkout URL

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