forked from ocaml-obuild/obuild
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbootstrap
More file actions
executable file
·130 lines (110 loc) · 3.74 KB
/
bootstrap
File metadata and controls
executable file
·130 lines (110 loc) · 3.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/bin/sh
libs="unix.cma"
OCAMLC="ocamlc -g -I +unix"
OCAMLVER=$($OCAMLC -version)
echo "$OCAMLVER"
extmodules="compat fugue filepath filesystem"
coremodules="types gconf filetype dag libname pp expr utils modname taskdep helper dagutils process findlibConf scheduler prog dependencies generators hier meta metacache target dist project analyze configure prepare_types ppx_resolver prepare buildprogs build exception"
commandmodules="sdist doc init help install"
mainmodules="path_generated main"
set -e
########################################################################
########################################################################
########################################################################
# build lib (combining base utilities, core library, and command modules)
cd lib/
rm -f ./*.cmi ./*.cmo ./*.o
rm -f base/*.cmi base/*.cmo base/*.o
rm -f core/*.cmi core/*.cmo core/*.o
# Compile base modules as top-level (for bootstrap compatibility)
cd base
for mod in $extmodules
do
echo "COMPILING base/$mod"
[ -f "${mod}.mli" ] && $OCAMLC -c "${mod}.mli"
$OCAMLC -c "${mod}.ml"
done;
cd ..
# Compile core modules (can access base modules directly)
cd core
for mod in $coremodules
do
echo "COMPILING core/$mod"
[ -f "${mod}.mli" ] && $OCAMLC -I .. -I ../base -c "${mod}.mli"
$OCAMLC -I .. -I ../base -c "${mod}.ml"
done;
cd ..
# Compile command modules
for mod in $commandmodules
do
echo "COMPILING command/$mod"
[ -f "${mod}.mli" ] && $OCAMLC -I . -I base -I core -c "${mod}.mli"
$OCAMLC -I . -I base -I core -c "${mod}.ml"
done;
# During bootstrap, copy all modules to root for main.ml compatibility
cd ..
echo "COPYING modules to root for bootstrap"
cp lib/base/*.cmo ./
cp lib/base/*.cmi ./
cp lib/core/*.cmo ./
cp lib/core/*.cmi ./
cp lib/*.cmo ./
cp lib/*.cmi ./
# Create a minimal Lib.cmo for bootstrap (main.ml expects it)
echo "CREATING minimal Lib.cmo for bootstrap"
touch empty.ml
$OCAMLC -c empty.ml
$OCAMLC -pack -o Lib.cmo empty.cmo
rm empty.ml empty.cmo
# then bootstrap the main executable
# main needs the version number
cat <<EOF > src/path_generated.ml
(* autogenerated file by bootstrap. do not modify *)
let project_version = "0.0.0"
EOF
cd src
FILES=""
for mod in $mainmodules
do
echo "COMPILING $mod"
[ -f "${mod}.mli" ] && $OCAMLC -I ../ -c "${mod}.mli"
$OCAMLC -I ../ -c "${mod}.ml"
FILES="${FILES} ${mod}.cmo"
done
echo "LINKING obuild.bootstrap"
# Link with all individual .cmo files for bootstrap
ALLCMO=""
for mod in $extmodules; do ALLCMO="$ALLCMO ${mod}.cmo"; done
for mod in $coremodules; do ALLCMO="$ALLCMO ${mod}.cmo"; done
for mod in $commandmodules; do ALLCMO="$ALLCMO ${mod}.cmo"; done
$OCAMLC -o ../obuild.bootstrap -I ../ $libs $ALLCMO $FILES
cd ..
rm -f lib/*.cmi lib/*.cmo lib/*.o
rm -f lib/base/*.cmi lib/base/*.cmo lib/base/*.o
rm -f lib/core/*.cmi lib/core/*.cmo lib/core/*.o
rm -f src/*.cmi src/*.cmo src/*.o
rm -f ./*.cmi ./*.o ./*a ./*.cmo
rm -f src/path_generated.ml
########################################################################
########################################################################
########################################################################
# rebuild everything with the bootstraped version
export OCAMLRUNPARAM=b
./obuild.bootstrap clean
if [ -x "$(command -v ocamlopt)" ]; then
./obuild.bootstrap configure
time ./obuild.bootstrap build
else
./obuild.bootstrap configure \
--disable-executable-native \
--disable-library-native \
--disable-library-plugin \
--enable-executable-bytecode \
--enable-library-bytecode
time ./obuild.bootstrap build
mv dist/build/obuild/obuild.byte dist/build/obuild/obuild
mv dist/build/obuild-simple/obuild-simple.byte dist/build/obuild-simple/obuild-simple
fi
if [ -x dist/build/obuild/obuild ]; then
rm obuild.bootstrap
fi