Skip to content

Commit 4dbf653

Browse files
gretay-jspoechsel
authored andcommitted
Use OC_CFLAGS, OC_CPPFLAGS, and SHAREDLIB_CFLAGS for foreign libs (#30)
Use the same options as in the upstream Makefiles, based on ocaml/Makefile.config This fixes the missing -ffunction-sections in compilation of C stubs. We should disable dune behavior of taking C compiler options from "ocamlc -config" when we move to dune 2.8.
1 parent 4648a6c commit 4dbf653

File tree

7 files changed

+45
-9
lines changed

7 files changed

+45
-9
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,6 @@ configure_opts
5454
ocaml-stage1-config.status
5555
ocaml-stage2-config.status
5656
ocamlopt_flags.sexp
57+
oc_cflags.sexp
58+
oc_cppflags.sexp
59+
sharedlib_cflags.sexp

Makefile.in

+20-4
Original file line numberDiff line numberDiff line change
@@ -168,11 +168,9 @@ ocaml/otherlibs/dynlink/natdynlinkops2: ocaml-stage1-config.status
168168

169169
# Extract compilation flags from Makefile.config of stage1
170170
# and write them to a file that dune can use in stage1 and stage2.
171-
# CR gyorsh: do we need a separate rule for stage2?
172-
# or can the file be reused?
173-
174171
.PHONY: flags.sexp
175-
flags.sexp: ocamlopt_flags.sexp
172+
flags.sexp: ocamlopt_flags.sexp oc_cflags.sexp oc_cppflags.sexp \
173+
sharedlib_cflags.sexp
176174

177175
ocamlopt_flags.sexp: ocaml-stage1-config.status
178176
cp ocaml-stage1-config.status ocaml/config.status
@@ -184,6 +182,24 @@ ocamlopt_flags.sexp: ocaml-stage1-config.status
184182
/bin/echo -n "(:standard)" > ocamlopt_flags.sexp; \
185183
fi
186184

185+
oc_cflags.sexp: ocaml-stage1-config.status
186+
cp ocaml-stage1-config.status ocaml/config.status
187+
(cd ocaml && ./config.status)
188+
/bin/echo -n "( $$(grep "^OC_CFLAGS=" ocaml/Makefile.config \
189+
| sed 's/^OC_CFLAGS=//') )" > oc_cflags.sexp
190+
191+
oc_cppflags.sexp: ocaml-stage1-config.status
192+
cp ocaml-stage1-config.status ocaml/config.status
193+
(cd ocaml && ./config.status)
194+
/bin/echo -n "( $$(grep "^OC_CPPFLAGS=" ocaml/Makefile.config \
195+
| sed 's/^OC_CPPFLAGS=//') )" > oc_cppflags.sexp
196+
197+
sharedlib_cflags.sexp: ocaml-stage1-config.status
198+
cp ocaml-stage1-config.status ocaml/config.status
199+
(cd ocaml && ./config.status)
200+
/bin/echo -n "( $$(grep "^SHAREDLIB_CFLAGS=" ocaml/Makefile.config \
201+
| sed 's/^SHAREDLIB_CFLAGS=//') )" > sharedlib_cflags.sexp
202+
187203
# Most of the installation tree is correctly set up by dune, but we need to
188204
# copy it to the final destination, and rearrange a few things to match
189205
# upstream.

dune-project

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
(wrapped_executables false)
33
(using experimental_building_ocaml_compiler_with_dune 0.1)
44

5+
;; CR-soon gyorsh: uncomment the following line when we upgrade to dune 2.8
6+
;; (use_standard_c_and_cxx_flags true)
57
(cram enable)
68

79
(package

ocaml/ocamltest/dune

+4-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,10 @@
4747
(-> ocamltest_unix.dummy.ml)))
4848
(modules (:standard \ options main))
4949
(foreign_stubs (language c) (names run_unix run_stubs)
50-
(flags -DCAML_INTERNALS -I%{project_root}/ocaml/runtime)))
50+
(flags ((-DCAML_INTERNALS)
51+
(:include %{project_root}/oc_cflags.sexp)
52+
(:include %{project_root}/oc_cppflags.sexp)))
53+
(include_dirs %{project_root}/ocaml/runtime)))
5154

5255
(rule
5356
(targets empty.ml)

ocaml/otherlibs/str/dune

+5-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@
2323
(ocamlopt_flags (:include %{project_root}/ocamlopt_flags.sexp))
2424
(library_flags (:standard -linkall))
2525
(libraries stdlib)
26-
(foreign_stubs (language c) (names strstubs)))
26+
(foreign_stubs (language c) (names strstubs)
27+
(flags ((:include %{project_root}/oc_cflags.sexp)
28+
(:include %{project_root}/sharedlib_cflags.sexp)
29+
(:include %{project_root}/oc_cppflags.sexp)))
30+
(include_dirs %{project_root}/ocaml/runtime)))
2731

2832
(install
2933
(files

ocaml/otherlibs/systhreads/dune

+7-2
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,18 @@
3030
(language c)
3131
(names st_stubs_byte)
3232
(mode byte)
33-
(flags -DCAML_NAME_SPACE)
33+
(flags ((:include %{project_root}/oc_cflags.sexp)
34+
(:include %{project_root}/sharedlib_cflags.sexp)
35+
(:include %{project_root}/oc_cppflags.sexp)))
3436
(include_dirs %{project_root}/ocaml/runtime))
3537
(foreign_stubs
3638
(language c)
3739
(names st_stubs_native)
3840
(mode native)
39-
(flags -DNATIVE_CODE -DCAML_NAME_SPACE)
41+
(flags ((-DNATIVE_CODE)
42+
(:include %{project_root}/oc_cflags.sexp)
43+
(:include %{project_root}/sharedlib_cflags.sexp)
44+
(:include %{project_root}/oc_cppflags.sexp)))
4045
(include_dirs %{project_root}/ocaml/runtime)))
4146

4247
(rule

ocaml/otherlibs/unix/dune

+4-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@
3535
shutdown signals sleep socket socketaddr socketpair sockopt stat strofaddr
3636
symlink termios time times truncate umask unixsupport unlink utimes wait
3737
write spawn)
38-
(flags -I %{project_root}/ocaml/runtime)
38+
(flags ((:include %{project_root}/oc_cflags.sexp)
39+
(:include %{project_root}/sharedlib_cflags.sexp)
40+
(:include %{project_root}/oc_cppflags.sexp)))
41+
(include_dirs %{project_root}/ocaml/runtime)
3942
))
4043

4144
(install

0 commit comments

Comments
 (0)