Skip to content

Commit a2bed03

Browse files
committed
Change the way the tools like the linker, assembler, etc. are specified by including an .ini file parser. The .ini file is generated in the Makefile instead of the Configuration.ml file and parsed on start.
1 parent e5b59af commit a2bed03

File tree

4 files changed

+113
-22
lines changed

4 files changed

+113
-22
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Makefile.config
2323
# ocamlbuild's temp dir
2424
_build/
2525
# Generated files
26-
driver/Configuration.ml
26+
compcert.ini
2727
ia32/ConstpropOp.v
2828
ia32/SelectOp.v
2929
powerpc/ConstpropOp.v

Makefile

+23-21
Original file line numberDiff line numberDiff line change
@@ -157,34 +157,34 @@ extraction/STAMP: $(FILES:.v=.vo) extraction/extraction.v $(ARCH)/extractionMach
157157
$(COQEXEC) extraction/extraction.v
158158
touch extraction/STAMP
159159

160-
ccomp: extraction/STAMP driver/Configuration.ml
160+
ccomp: extraction/STAMP compcert.ini
161161
$(OCAMLBUILD) $(OCB_OPTIONS) Driver.native \
162162
&& rm -f ccomp && $(SLN) _build/driver/Driver.native ccomp
163163

164-
ccomp.prof: extraction/STAMP driver/Configuration.ml
164+
ccomp.prof: extraction/STAMP compcert.ini
165165
$(OCAMLBUILD) $(OCB_OPTIONS) Driver.p.native \
166166
&& rm -f ccomp.prof && $(SLN) _build/driver/Driver.p.native ccomp.prof
167167

168-
ccomp.byte: extraction/STAMP driver/Configuration.ml
168+
ccomp.byte: extraction/STAMP compcert.ini
169169
$(OCAMLBUILD) $(OCB_OPTIONS) Driver.d.byte \
170170
&& rm -f ccomp.byte && $(SLN) _build/driver/Driver.d.byte ccomp.byte
171171

172172
runtime:
173173
$(MAKE) -C runtime
174174

175-
cchecklink: driver/Configuration.ml
175+
cchecklink: compcert.ini
176176
$(OCAMLBUILD) $(OCB_OPTIONS_CHECKLINK) Validator.native \
177177
&& rm -f cchecklink && $(SLN) _build/checklink/Validator.native cchecklink
178178

179-
cchecklink.byte: driver/Configuration.ml
179+
cchecklink.byte: compcert.ini
180180
$(OCAMLBUILD) $(OCB_OPTIONS_CHECKLINK) Validator.d.byte \
181181
&& rm -f cchecklink.byte && $(SLN) _build/checklink/Validator.d.byte cchecklink.byte
182182

183-
clightgen: extraction/STAMP driver/Configuration.ml exportclight/Clightdefs.vo
183+
clightgen: extraction/STAMP compcert.ini exportclight/Clightdefs.vo
184184
$(OCAMLBUILD) $(OCB_OPTIONS_CLIGHTGEN) Clightgen.native \
185185
&& rm -f clightgen && $(SLN) _build/exportclight/Clightgen.native clightgen
186186

187-
clightgen.byte: extraction/STAMP driver/Configuration.ml exportclight/Clightdefs.vo
187+
clightgen.byte: extraction/STAMP compcert.ini exportclight/Clightdefs.vo
188188
$(OCAMLBUILD) $(OCB_OPTIONS_CLIGHTGEN) Clightgen.d.byte \
189189
&& rm -f clightgen.byte && $(SLN) _build/exportclight/Clightgen.d.byte clightgen.byte
190190

@@ -220,20 +220,20 @@ latexdoc:
220220
@tools/ndfun $*.vp > $*.v || { rm -f $*.v; exit 2; }
221221
@chmod -w $*.v
222222

223-
driver/Configuration.ml: Makefile.config VERSION
224-
(echo let stdlib_path = "\"$(LIBDIR)\""; \
225-
echo let prepro = "\"$(CPREPRO)\""; \
226-
echo let asm = "\"$(CASM)\""; \
227-
echo let linker = "\"$(CLINKER)\""; \
228-
echo let arch = "\"$(ARCH)\""; \
229-
echo let model = "\"$(MODEL)\""; \
230-
echo let abi = "\"$(ABI)\""; \
231-
echo let system = "\"$(SYSTEM)\""; \
232-
echo let has_runtime_lib = $(HAS_RUNTIME_LIB); \
233-
echo let asm_supports_cfi = $(ASM_SUPPORTS_CFI); \
223+
compcert.ini: Makefile.config VERSION
224+
(echo stdlib_path=$(LIBDIR); \
225+
echo prepro=$(CPREPRO); \
226+
echo asm=$(CASM); \
227+
echo linker=$(CLINKER); \
228+
echo arch=$(ARCH); \
229+
echo model=$(MODEL); \
230+
echo abi=$(ABI); \
231+
echo system=$(SYSTEM); \
232+
echo has_runtime_lib=$(HAS_RUNTIME_LIB); \
233+
echo asm_supports_cfi=$(ASM_SUPPORTS_CFI); \
234234
version=`cat VERSION`; \
235-
echo let version = "\"$$version\"") \
236-
> driver/Configuration.ml
235+
echo version=$$version) \
236+
> compcert.ini
237237

238238
cparser/Parser.v: cparser/Parser.vy
239239
$(MENHIR) --coq cparser/Parser.vy
@@ -246,6 +246,8 @@ depend: $(FILES) exportclight/Clightdefs.v
246246
install:
247247
install -d $(BINDIR)
248248
install ./ccomp $(BINDIR)
249+
install -d $(SHAREDIR)
250+
install ./compcert.ini $(SHAREDIR)
249251
ifeq ($(CCHECKLINK),true)
250252
install ./cchecklink $(BINDIR)
251253
endif
@@ -259,7 +261,7 @@ clean:
259261
rm -rf _build
260262
rm -rf doc/html doc/*.glob
261263
rm -f doc/coq2html.ml doc/coq2html doc/*.cm? doc/*.o
262-
rm -f driver/Configuration.ml
264+
rm -f compcert.ini
263265
rm -f extraction/STAMP extraction/*.ml extraction/*.mli
264266
rm -f tools/ndfun tools/*.cm? tools/*.o
265267
rm -f $(ARCH)/ConstpropOp.v $(ARCH)/SelectOp.v backend/SelectDiv.v backend/SelectLong.v

configure

+3
Original file line numberDiff line numberDiff line change
@@ -274,11 +274,14 @@ fi
274274

275275
# Generate Makefile.config
276276

277+
sharedir="$(dirname "$bindir")"/share
278+
277279
rm -f Makefile.config
278280
cat > Makefile.config <<EOF
279281
PREFIX=$prefix
280282
BINDIR=$bindir
281283
LIBDIR=$libdir
284+
SHAREDIR=$sharedir
282285
EOF
283286

284287
if test "$target" != "manual"; then

driver/Configuration.ml

+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
(* *********************************************************************)
2+
(* *)
3+
(* The Compcert verified compiler *)
4+
(* *)
5+
(* Bernhard Schommer, AbsInt Angewandte Informatik GmbH *)
6+
(* *)
7+
(* AbsInt Angewandte Informatik GmbH. All rights reserved. This file *)
8+
(* is distributed under the terms of the INRIA Non-Commercial *)
9+
(* License Agreement. *)
10+
(* *)
11+
(* *********************************************************************)
12+
13+
14+
let config_vars: (string, string) Hashtbl.t = Hashtbl.create 10
15+
16+
17+
(* Read in the .ini file, which is either in the same directory or in the directory ../share *)
18+
let _ =
19+
try
20+
let file =
21+
let dir = Sys.getcwd ()
22+
and name = Sys.argv.(0) in
23+
let dirname = if Filename.is_relative name then
24+
Filename.dirname (Filename.concat dir name)
25+
else
26+
Filename.dirname name
27+
in
28+
let share_dir = Filename.concat (Filename.concat dirname Filename.parent_dir_name) "share" in
29+
try
30+
open_in (Filename.concat dirname "compcert.ini")
31+
with Sys_error _ ->
32+
open_in (Filename.concat share_dir "compcert.ini")
33+
in
34+
(try
35+
let ini_line = Str.regexp "\\([^=]+\\)=\\(.+\\)" in
36+
while true do
37+
let line = input_line file in
38+
if Str.string_match ini_line line 0 then
39+
let key = Str.matched_group 1 line
40+
and value = Str.matched_group 2 line in
41+
Hashtbl.add config_vars key value
42+
else
43+
Printf.eprintf "Wrong value %s in .ini file.\n" line
44+
done
45+
with End_of_file -> close_in file)
46+
with Sys_error msg -> Printf.eprintf "Unable to open .ini file\n"
47+
48+
let get_config key =
49+
try
50+
Hashtbl.find config_vars key
51+
with Not_found ->
52+
Printf.eprintf "Configuration option `%s' is not set\n" key; exit 2
53+
54+
let bad_config key v =
55+
Printf.eprintf "Invalid value `%s' for configuation option `%s'\n" v key; exit 2
56+
57+
let stdlib_path = get_config "stdlib_path"
58+
59+
let prepro = get_config "prepro"
60+
let asm = get_config "asm"
61+
let linker = get_config "linker"
62+
let arch =
63+
let v = get_config "arch" in
64+
(match v with
65+
| "powerpc"
66+
| "arm"
67+
| "ia32" -> ()
68+
| _ -> bad_config "arch" v);
69+
v
70+
71+
let model = get_config "model"
72+
let abi = get_config "abi"
73+
let system = get_config "system"
74+
let has_runtime_lib =
75+
match get_config "has_runtime_lib" with
76+
| "true" -> true
77+
| "false" -> false
78+
| v -> bad_config "has_runtime_lib" v
79+
80+
let asm_supports_cfi =
81+
match get_config "asm_supports_cfi" with
82+
| "true" -> true
83+
| "false" -> false
84+
| v -> bad_config "asm_supports_cfi" v
85+
86+
let version = get_config "version"

0 commit comments

Comments
 (0)