-
Notifications
You must be signed in to change notification settings - Fork 0
/
configure
executable file
·231 lines (204 loc) · 6.85 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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
#! /bin/bash
###########################################################################
## ##
## OCaPIC ##
## ##
## Benoit Vaugon ##
## ##
## 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 [ OPTIONS... ]
-bindir <dir> Directory where the binaries will be installed
(default: /usr/local/bin)
-libdir <dir> Directory where the OCaml library PIC tools will be installed
(default: /usr/local/lib/ocapic)
-mandir <dir> Directory where the manual pages will be installed
(default: /usr/local/man)
-prefix <dir> Set bindir, libdir and mandir to <dir>/bin, <dir>/lib/ocapic
and <dir>/man respectively
-cc <cmd> C compiler to use for building the system
-pics <regexp> Choose PIC to be managed by OCaPIC"
}
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'
}
###
CAMLLIB="$(ocamlc -where)"
OCAML="$CAMLLIB/../../bin/ocaml"
OCAMLOPT="$CAMLLIB/../../bin/ocamlopt"
OCAMLC="$CAMLLIB/../../bin/ocamlc"
OCAMLDOC="$CAMLLIB/../../bin/ocamldoc"
OCAMLBUILD="$CAMLLIB/../../bin/ocamlbuild"
VERSION="$(cat VERSION)"
SAVED_PWD=$(pwd)
###
CC=gcc
BINDIR=/usr/local/bin
LIBDIR=/usr/local/lib/ocapic
MANDIR=/usr/local/man
OCAMLSTDLIB=$($OCAMLC -where)
PICS_REGEXP='18f4620'
while [ $# -ne 0 ]; do
case "$1" in
-pics)
PICS_REGEXP="$2" ;;
-cc)
CC="$2" ;;
-bindir)
check_absolute_path "$2"
BINDIR="$(remove_trailing_slash "$2")" ;;
-libdir)
check_absolute_path "$2"
LIBDIR="$(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="$PREFIX/bin"
LIBDIR="$PREFIX/lib/ocapic"
MANDIR="$PREFIX/man" ;;
*)
usage "Don't know what to do with \"$1\""
esac
shift
shift
done
###
ALL_PICS=$(echo $(ls src/pics/pic*.reg | sed 'sXsrc/pics/pic\(.*\)\.regX\1X'))
SELECTED_PICS=$(echo $(ls src/pics/pic*.reg | \
sed 'sXsrc/pics/pic\(.*\)\.regX\1X' | \
grep -E -o "^$PICS_REGEXP$"))
PICS_NB=0; for p in $SELECTED_PICS; do PICS_NB=$((PICS_NB+1)); done
if [ $PICS_NB -eq 0 ]; then
error "Error: invalid regexp: '$PICS_REGEXP' \
(no memory map found in src/pics/)"
fi
echo "$PICS_NB selected PIC: $SELECTED_PICS"
###
OCAMLCLEAN_LOCAL_VERSION=$(
echo ocamlclean/ocamlclean-*.tar.bz2 | \
sed 'sX.*ocamlclean/ocamlclean-\(.*\)\.tar\.bz2$X\1X'
)
INSTALLED_OCAMLCLEAN="$CAMLLIB/../../bin/ocamlclean"
if [ -e "$INSTALLED_OCAMLCLEAN" ]; 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 -n "\
INSTALL_OCAMLCLEAN = $INSTALL_OCAMLCLEAN
OCAMLCLEAN = $OCAMLCLEAN
OCAMLCLEAN_VERSION = $OCAMLCLEAN_VERSION
OCAMLCLEAN_DIRECTORY = $OCAMLCLEAN_DIRECTORY
OCAMLCLEAN_ARCHIVE = $OCAMLCLEAN_ARCHIVE
ALL_PICS = $ALL_PICS
SELECTED_PICS = $SELECTED_PICS
BINDIR = $BINDIR
LIBDIR = $LIBDIR
MAN1DIR = $MANDIR/man1
MAN3DIR = $MANDIR/man3
CC = $CC
OCAMLC = $OCAMLC -w @a-4-70 -warn-error A -safe-string -strict-formats -strict-sequence -ccopt -fPIE
OCAMLOPT = $OCAMLOPT -w @a-4-70 -warn-error A -safe-string -strict-formats -strict-sequence
OCAMLDOC = $OCAMLDOC
OCAMLC_UNSAFE = $OCAMLC
OCAMLBUILD = $OCAMLBUILD -cflags -w,@a-4-70,-warn-error,A,-safe-string,-strict-formats,-strict-sequence -lflags -w,@a-4-70,-warn-error,A,-safe-string,-strict-formats,-strict-sequence -no-links -classic-display
OCAMLSTDLIB = $OCAMLSTDLIB
SRC = $SAVED_PWD/src
BIN = $SAVED_PWD/bin
LIB = $SAVED_PWD/lib
ETC = $SAVED_PWD/etc
DIST = $SAVED_PWD/dist
ONE_PIC = $(echo $SELECTED_PICS | grep -o '^[^ ]*')
define compile
@make --no-print-directory -q -C \$1 && \
make --no-print-directory -C \$1 || \
make -C \$1
endef
define clean
@make --no-print-directory -C \$1 clean > /dev/null
endef
define capitalize
\$(shell echo \$1 | cut -c1 | tr [:lower:] [:upper:])\$(shell echo \$1 \
| cut -c2-)
endef
define uncapitalize
\$(shell echo \$1 | cut -c1 | tr [:upper:] [:lower:])\$(shell echo \$1 \
| cut -c2-)
endef
define rmprefix
\$(shell echo \$2 | sed 'sX^\$1\\(.*\\)X\\1X')
endef
" > etc/Makefile.conf
###
(
echo -n "\
let libdir = \"$LIBDIR\"
let ocaml = \"$OCAML\"
let ocamlc = \"$OCAMLC\"
let camllib = \"$CAMLLIB\"
let bc2asm = \"$BINDIR/bc2asm\"
let ocamlclean = \"$OCAMLCLEAN\"
let version = \"$VERSION\"
let supported_pics = [
"
for pic in $SELECTED_PICS; do
echo " \"$pic\";"
done
echo "]"
) > etc/config.ml
###
echo -n "\
OCAPIC = $BINDIR/ocapic
" > etc/TestsMakefile.conf
###
echo "** OCaPIC configuration completed successfully **"