-
Notifications
You must be signed in to change notification settings - Fork 15
/
configure
executable file
·210 lines (179 loc) · 5.76 KB
/
configure
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
#! /bin/bash
###########################################################################
## ##
## OCamlCC ##
## ##
## Michel Mauny, Benoit Vaugon ##
## ENSTA ParisTech ##
## ##
## This file is distributed under the terms of the CeCILL license. ##
## See file LICENSE-en. ##
## ##
###########################################################################
function error () {
echo "$@" 1>&2
exit 1
}
function usage () {
echo "$@" 1>&2
error "Usage: $0 [ -prefix <dir> ] [ -bindir <dir> ] [ -includedir <dir> ] [ -mandir <dir> ]"
}
function check_command () {
which "$1" > /dev/null
if [ $? -ne 0 ]; then
error "Error: \"$1\" not installed"
fi
}
function check_absolute_path () {
case "$1" in
/*);;
*) error "Error: \"$1\" is not an absolute path";;
esac
}
function remove_trailing_slash () {
echo "$1" | sed 'sX^\(.*[^/]\)/*$X\1X'
}
###
cd $(dirname "$0")
mkdir -p bin etc dist
###
check_command "ocamlbuild"
check_command "ocamlc"
check_command "mkdir"
check_command "echo"
check_command "grep"
check_command "pwd"
check_command "sed"
check_command "cp"
check_command "rm"
check_command "gcc"
###
OCAML_VERSION=$(ocamlc -version | cut -c1-4)
DEFAULT_RUNTIME_VERSION=''
RUNTIME_VERSIONS=''
for d in runtime/ocamlcc-byterun-?.??; do
V="${d:24:4}"
RUNTIME_VERSIONS="$RUNTIME_VERSIONS $V"
if [ "$OCAML_VERSION" = "$V" ]; then
DEFAULT_RUNTIME_VERSION="$OCAML_VERSION"
fi
done
if [ "$OCAML_VERSION" != "$DEFAULT_RUNTIME_VERSION" ]; then
echo "Error: Incompatible OCaml version: $OCAML_VERSION" 1>&2
echo " Supported versions: $RUNTIME_VERSIONS" 1>&2
exit 1
fi
RUNTIME_VERSION_LIST='['
for v in $RUNTIME_VERSIONS; do
RUNTIME_VERSION_LIST="$RUNTIME_VERSION_LIST \"$v\";"
done
RUNTIME_VERSION_LIST="$RUNTIME_VERSION_LIST ]"
###
OCAMLBUILD=$(which ocamlbuild)
OCAMLLIB=$(ocamlc -where)
GCC=$(which gcc)
ARCH=$(test -x /bin/uname && /bin/uname -m || echo none)
VERSION=$(cat VERSION)
SAVED_PWD=$(pwd)
###
BINDIR=/usr/local/bin
INCLUDEDIR=/usr/local/include
MANDIR=/usr/local/man
while [ $# -ne 0 ]; do
case "$1" in
-bindir)
check_absolute_path "$2"
BINDIR="$(remove_trailing_slash $2)" ;;
-includedir)
check_absolute_path "$2"
INCLUDEDIR="$(remove_trailing_slash $2)" ;;
-mandir)
check_absolute_path "$2"
MANDIR="$(remove_trailing_slash $2)" ;;
-prefix)
check_absolute_path "$2"
PREFIX="$(remove_trailing_slash $2)"
BINDIR="$2"/bin
INCLUDEDIR="$2"/include
MANDIR="$2"/man ;;
*)
usage "Don't know what to do with \"$1\"" ;;
esac
shift
shift
done
CCOMP="$GCC"
###
OCAMLCLEAN_LOCAL_VERSION=$(
echo ocamlclean/ocamlclean-*.tar.bz2 | \
sed 'sX.*ocamlclean/ocamlclean-\(.*\)\.tar\.bz2$X\1X'
)
INSTALLED_OCAMLCLEAN="$(which ocamlclean 2> /dev/null)"
if [ $? -eq 0 ]; then
INSTALLED_OCAMLCLEAN_VERSION=$("$INSTALLED_OCAMLCLEAN" -version)
if [ $INSTALLED_OCAMLCLEAN_VERSION '<' $OCAMLCLEAN_LOCAL_VERSION ]; then
echo -n "Warning: an old OCamlClean version is already installed: "
echo "$INSTALLED_OCAMLCLEAN_VERSION"
echo -n " => configure new embedded OCamlClean version: "
echo "$OCAMLCLEAN_LOCAL_VERSION"
INSTALL_OCAMLCLEAN=true
if [ "$INSTALLED_OCAMLCLEAN" != "$BINDIR/ocamlclean" ]; then
echo -n "Warning: OCamlClean was installed in: "
echo "$INSTALLED_OCAMLCLEAN"
echo -n " The new version will be installed in: "
echo "$BINDIR/ocamlclean"
fi
else
INSTALL_OCAMLCLEAN=false
OCAMLCLEAN="$INSTALLED_OCAMLCLEAN"
OCAMLCLEAN_VERSION="$INSTALLED_OCAMLCLEAN_VERSION"
OCAMLCLEAN_DIRECTORY="-none-"
OCAMLCLEAN_ARCHIVE="-none-"
fi
else
echo -n "Warning: OCamlClean not installed => configure OCamlClean "
echo "$OCAMLCLEAN_LOCAL_VERSION"
INSTALL_OCAMLCLEAN=true
fi
if [ $INSTALL_OCAMLCLEAN = true ]; then
OCAMLCLEAN="$BINDIR/ocamlclean"
OCAMLCLEAN_VERSION="$OCAMLCLEAN_LOCAL_VERSION"
OCAMLCLEAN_DIRECTORY="$SAVED_PWD/ocamlclean/ocamlclean-$OCAMLCLEAN_VERSION"
OCAMLCLEAN_ARCHIVE="$OCAMLCLEAN_DIRECTORY.tar.bz2"
cd "ocamlclean"
tar jxf "$OCAMLCLEAN_ARCHIVE"
cd "$OCAMLCLEAN_DIRECTORY"
./configure -bindir "$BINDIR" -mandir "$MANDIR"
cd "$SAVED_PWD"
fi
###
echo "\
SHELL = bash
INSTALL_OCAMLCLEAN = $INSTALL_OCAMLCLEAN
OCAMLCLEAN = $OCAMLCLEAN
OCAMLCLEAN_VERSION = $OCAMLCLEAN_VERSION
OCAMLCLEAN_DIRECTORY = $OCAMLCLEAN_DIRECTORY
OCAMLCLEAN_ARCHIVE = $OCAMLCLEAN_ARCHIVE
VERSION = $VERSION
RUNTIME_VERSIONS = $RUNTIME_VERSIONS
DEFAULT_RUNTIME_VERSION = $DEFAULT_RUNTIME_VERSION
OCAMLBUILD = $OCAMLBUILD -cflags -w,Ae,-warn-error,A -lflags -w,Ae,-warn-error,A -no-links -classic-display
BINDIR = $BINDIR
INCLUDEDIR = $INCLUDEDIR/ocamlcc
MAN1DIR = $MANDIR/man1
" > etc/Makefile.conf
###
echo "\
(* Generated by configure *)
let version = \"$VERSION\";;
let runtime_versions = $RUNTIME_VERSION_LIST;;
let default_runtime_version = \"$DEFAULT_RUNTIME_VERSION\";;
let include_dir = \"$INCLUDEDIR/ocamlcc\";;
let default_arch = \"gen\";;
let ccomp = \"$CCOMP\";;
let ocamlclean = \"$OCAMLCLEAN\";;
" > etc/config.ml
###
cp "$OCAMLLIB/caml/config.h" "./etc/config.h"
###
echo "** OCamlCC configuration completed successfully **"