Skip to content

Commit f524857

Browse files
committed
Separate machdep-config.h for each architecture
1 parent a35d59e commit f524857

5 files changed

Lines changed: 36 additions & 17 deletions

File tree

src/dune

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,31 @@
1616
(target machdep-config.h)
1717
(action (run ./machdepConfigure.exe)))
1818

19+
(rule
20+
(target machdep32-config.h)
21+
(action (run ./machdepConfigure.exe -m 32)))
22+
23+
(rule
24+
(target machdep64-config.h)
25+
(action (run ./machdepConfigure.exe -m 64)))
26+
1927
(rule
2028
(deps machdep-config.h machdep-ml.c)
2129
(target machdep-ml.exe)
22-
(action (run %{read-lines:../bin/real-gcc} -D_GNUCC machdep-ml.c -o %{target})))
30+
(action (run %{read-lines:../bin/real-gcc} -D_GNUCC -include machdep-config.h machdep-ml.c -o %{target})))
2331

2432
(executable
2533
(name machdepArchConfigure)
2634
(modules machdepArchConfigure)
2735
(libraries dune-configurator))
2836

2937
(rule
30-
(deps machdep-config.h machdep-ml.c)
38+
(deps machdep32-config.h machdep-ml.c)
3139
(target machdep32)
3240
(action (with-stdout-to %{target} (run ./machdepArchConfigure.exe --real-gcc %{read-lines:../bin/real-gcc} -m 32))))
3341

3442
(rule
35-
(deps machdep-config.h machdep-ml.c)
43+
(deps machdep64-config.h machdep-ml.c)
3644
(target machdep64)
3745
(action (with-stdout-to %{target} (run ./machdepArchConfigure.exe --real-gcc %{read-lines:../bin/real-gcc} -m 64))))
3846

@@ -44,13 +52,13 @@
4452

4553
; for Cilly.pm
4654
(rule
47-
(deps machdep-config.h machdep-ml.c)
55+
(deps machdep32-config.h machdep-ml.c)
4856
(target gcc32model)
4957
(action (with-stdout-to %{target} (run ./modelConfigure.exe --real-gcc %{read-lines:../bin/real-gcc} -m 32))))
5058

5159
; for Cilly.pm
5260
(rule
53-
(deps machdep-config.h machdep-ml.c)
61+
(deps machdep64-config.h machdep-ml.c)
5462
(target gcc64model)
5563
(action (with-stdout-to %{target} (run ./modelConfigure.exe --real-gcc %{read-lines:../bin/real-gcc} -m 64))))
5664

src/machdep-ml.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@
3535
3636
*/
3737

38-
#include "machdep-config.h"
38+
// Correct config header is now included from command line using -include.
39+
// #include "machdep-config.h"
3940

4041
#include <stdio.h>
4142
#include <string.h>

src/machdepArchConfigure.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ let () =
1010
in
1111
C.main ~name:"model" ~args (fun c ->
1212
let exe = "./machdep" ^ !m ^ "-ml.exe" in
13-
let {C.Process.exit_code; stdout; stderr} = C.Process.run c !real_gcc ["-D_GNUCC"; "-m" ^ !m; "machdep-ml.c"; "-o"; exe] in
13+
let {C.Process.exit_code; stdout; stderr} = C.Process.run c !real_gcc ["-D_GNUCC"; "-include"; "machdep" ^ !m ^ "-config.h"; "-m" ^ !m; "machdep-ml.c"; "-o"; exe] in
1414
if exit_code = 0 then (
1515
let {C.Process.stdout; stderr; exit_code} = C.Process.run c exe [] in
1616
assert (exit_code = 0);

src/machdepConfigure.ml

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
module C = Configurator.V1
22

3+
let c_flags = ref []
4+
35
let has_header_code f =
46
Format.sprintf {|
57
#include <%s>
68
int main() { return 0; } // Just so that dune-configurator linking works
79
|} f
810

911
let has_header c f =
10-
C.c_test c (has_header_code f)
12+
C.c_test c ~c_flags:!c_flags (has_header_code f)
1113

1214
let builtin_va_list_code = {|
1315
int
@@ -59,7 +61,7 @@ int main() { return 0; } // Just so that dune-configurator linking works
5961
exception FoundType of string
6062

6163
let cil_check_integer_type_type c t1 t2 =
62-
if C.c_test c (cil_check_integer_type_type_code t1 t2) then
64+
if C.c_test c ~c_flags:!c_flags (cil_check_integer_type_type_code t1 t2) then
6365
raise (FoundType t2)
6466

6567
let cil_check_integer_type_signs c t1 t2 =
@@ -78,13 +80,21 @@ let cil_check_integer_type c t1 =
7880
t2
7981

8082
let () =
81-
C.main ~name:"machdep" (fun c ->
82-
let have_builtin_va_list = C.c_test c builtin_va_list_code in
83-
let thread_is_keyword = not @@ C.c_test c thread_is_keyword_code in
84-
let underscore_name = C.c_test c underscore_name_code in
85-
let have_float16 = C.c_test c have_float16_code in
86-
87-
C.C_define.gen_header_file c ~fname:"machdep-config.h" [
83+
let fname = ref "machdep-config.h" in
84+
let args = Arg.[
85+
("-m", String (fun s ->
86+
c_flags := ("-m" ^ s) :: !c_flags;
87+
fname := "machdep" ^ s ^ "-config.h";
88+
), "");
89+
]
90+
in
91+
C.main ~name:"machdep" ~args (fun c ->
92+
let have_builtin_va_list = C.c_test c ~c_flags:!c_flags builtin_va_list_code in
93+
let thread_is_keyword = not @@ C.c_test c ~c_flags:!c_flags thread_is_keyword_code in
94+
let underscore_name = C.c_test c ~c_flags:!c_flags underscore_name_code in
95+
let have_float16 = C.c_test c ~c_flags:!c_flags have_float16_code in
96+
97+
C.C_define.gen_header_file c ~fname:!fname [
8898
("HAVE_STDLIB_H", Switch (has_header c "stdlib.h"));
8999
("HAVE_WCHAR_H", Switch (has_header c "wchar.h"));
90100
("HAVE_STDBOOL_H", Switch (has_header c "stdbool.h"));

src/modelConfigure.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ let () =
1010
in
1111
C.main ~name:"model" ~args (fun c ->
1212
let exe = "./machdep-ml" ^ !m ^ ".exe" in
13-
let {C.Process.exit_code; stdout; stderr} = C.Process.run c !real_gcc ["-D_GNUCC"; "-m" ^ !m; "machdep-ml.c"; "-o"; exe] in
13+
let {C.Process.exit_code; stdout; stderr} = C.Process.run c !real_gcc ["-D_GNUCC"; "-include"; "machdep" ^ !m ^ "-config.h"; "-m" ^ !m; "machdep-ml.c"; "-o"; exe] in
1414
if exit_code = 0 then (
1515
let {C.Process.stdout; stderr; exit_code} = C.Process.run c exe ["--env"] in
1616
assert (exit_code = 0);

0 commit comments

Comments
 (0)