-
Notifications
You must be signed in to change notification settings - Fork 125
/
gen_myocamlbuild.sh
executable file
·135 lines (120 loc) · 4.02 KB
/
gen_myocamlbuild.sh
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
131
132
133
134
135
#!/bin/bash -ue
# This script reads files config.{sh,ml}, build_rules*.ml, build_libs, build_tools and uses them
# to build an ocamlbuild plugin in <build_dir>/myocamlbuild
#
# You can then run your compilations with:
# $ <build_dir>/myocamlbuild -no-plugin -j 6 <targets>
CONFIG_SH=config.sh
if [ ! -e $CONFIG_SH ]; then
if [ -e $(dirname "$0")/config.sh ]; then
CONFIG_SH=$(dirname "$0")/config.sh
else
echo "Error: config.sh not found. Please run ./configure"
exit 1
fi
fi
. $CONFIG_SH
. platform_helper.sh
: ${BLDDIR:="$PWD"/build}
CONFIG_ML=config.ml
if [ ! -e $CONFIG_ML ]; then
echo $BLDDIR/config.ml >&2
if [ -e $BLDDIR/config.ml ]; then
CONFIG_ML=$BLDDIR/config.ml
else
echo "Error: config.ml not found. Please run ./configure"
exit 1
fi
fi
if [ $CONFIG_ML -ot ${CONFIG_ML}i ]; then
echo "[1m[31mWarning[0m: ${CONFIG_ML}i is newer than $CONFIG_ML, you should probably re-run ./configure" >&2
fi
BUILD_DIR="_build"
BUILD_RULES="build_rules.ml"
BUILD_LIBS="build_libs"
BUILD_TOOLS="build_tools"
while [ $# -gt 0 ]; do
case $1 in
-private)
BUILD_RULES="build_rules*.ml"
BUILD_LIBS="build_libs*"
BUILD_TOOLS="build_tools*"
;;
-build-dir)
if [ $# -lt 2 ]; then echo "Error: option $1 requires an argument"; exit 1; fi
shift
BUILD_DIR="$1"
;;
-bytecode)
BYTECODE=1
;;
*)
echo "Error: unknown option $1"
exit 1
esac
shift
done
MYOCAMLBUILD=$BUILD_DIR/myocamlbuild.ml
mkdir -p $BUILD_DIR
# Generate the myocamlbuild.ml
{
SED_FILTER='s/#.*$//'
if [ "${BYTECODE:-}" ]; then
SED_FILTER=$SED_FILTER'; s/\.native\>/.byte/g'
fi
if [ "$IS_WINDOWS" ]; then
SED_FILTER=$SED_FILTER'; s/\.o\>/\.obj/g'
fi
echo "(* ****************************************************************************** *)"
echo "(* File generated by bld: DO NOT EDIT. *)"
echo "(* See build_libs*, build_tools* and build_rules*.ml instead. *)"
echo "(* ****************************************************************************** *)"
echo
echo "#1 \"$CONFIG_ML\""
cat $CONFIG_ML
echo "#1 \"$BLDDIR/myocamlbuild_prefix.ml\""
cat $BLDDIR/myocamlbuild_prefix.ml
for i in $BUILD_TOOLS; do
if [ -e "$i" ]; then
echo "#1 \"$i\""
sed "$SED_FILTER" $i |
awk '/^external/ { print "set_tool ~internal:false \""$2"\" \""$3"\";" }
/^internal/ { print "set_tool ~internal:true \""$2"\" \""$3"\";" }'
fi
done
for i in $BUILD_LIBS; do
if [ -e "$i" ]; then
echo "#1 \"$i\""
awk 'BEGIN { split (ENVIRON["DISABLED_LIBS"],a); for (i in a) disabled[a[i]] = 1 }
/^external/ { print "mlstate_lib ~dir:\"lib/opa/static\" \""$2"\";" }
/^internal/ && ! ($2 in disabled) \
{ print "internal_lib", $3 ? "~dir:\""$3"\"" : "", "\""$2"\";" }' $i
fi
done
for i in $BUILD_RULES; do
if [ -e "$i" ]; then
echo "#1 \"$i\""
cat $i
echo ";"
fi
done
echo "#1 \"$BLDDIR/myocamlbuild_suffix.ml\""
cat $BLDDIR/myocamlbuild_suffix.ml
} > $MYOCAMLBUILD
# Compile the myocamlbuild
OCAMLBUILD_LIB=$($OCAMLBUILD -where)
cp $CONFIG_ML ${CONFIG_ML}i $BUILD_DIR
if [ "${BYTECODE:-}" ]; then
cd $BUILD_DIR
OCAMLC=${OCAMLOPT/ocamlopt/ocamlc}
$OCAMLC -c config.mli
$OCAMLC -c config.ml
$OCAMLC -w y -I "$OCAMLBUILD_LIB" unix.cma ocamlbuildlib.cma config.ml myocamlbuild.ml "$OCAMLBUILD_LIB"/ocamlbuild.cmo -o myocamlbuild
else
rm -f _build/config.*
cp $CONFIG_ML ${CONFIG_ML}i $BUILD_DIR
cd $BUILD_DIR
$OCAMLOPT -c config.mli
$OCAMLOPT -c config.ml
$OCAMLOPT -w y -I "$OCAMLBUILD_LIB" unix.cmxa ocamlbuildlib.cmxa config.cmx myocamlbuild.ml "$OCAMLBUILD_LIB"/ocamlbuild.cmx -o myocamlbuild
fi