Reputation: 3936
I am working through the LLVM ocaml tutorial, and using the following command line to compile:
ocamlbuild -cflags -g,-I,+llvm-3.4 -lflags -I,+llvm-3.4 toy.byte
Is there any way to move those extra cflags and lflags into the _tags or myocamlbuild.ml files so that I don't need to type them/can store them in source control/make reproducible builds?
Here is the _tags file:
<{lexer,parser}.ml>: use_camlp4, pp(camlp4of)
<*.{byte,native}>: g++, use_llvm, use_llvm_analysis
<*.{byte,native}>: use_llvm_executionengine, use_llvm_target
<*.{byte,native}>: use_llvm_scalar_opts, use_bindings
And here is the myocamlbuild.ml file:
open Ocamlbuild_plugin;;
ocaml_lib ~extern:true "llvm";;
ocaml_lib ~extern:true "llvm_analysis";;
ocaml_lib ~extern:true "llvm_executionengine";;
ocaml_lib ~extern:true "llvm_target";;
ocaml_lib ~extern:true "llvm_scalar_opts";;
flag ["link"; "ocaml"; "g++"] (S[A"-cc"; A"g++ -rdynamic"]);;
dep ["link"; "ocaml"; "use_bindings"] ["bindings.o"];;
Upvotes: 1
Views: 535
Reputation: 47934
I do something like...
let mlflags = []
and cflags = []
and clibs = []
let rec arg_weave p = function
| x::xs -> (A p) :: (A x) :: arg_weave p xs
| [] -> []
and arg x = A x
...
let () = dispatch begin function
| After_rules ->
flag ["ocaml"; "compile"] (S (List.map arg mlflags));
flag ["c"; "compile"] (S (arg_weave "-ccopt" cflags));
flag ["c"; "link"] (S (arg_weave "-cclib" clibs));
...
end
The other option is to tag additional options. For example, in the ocaml_specific.ml file they have one set-up for debug and all the combinations of flag options for where the option is relevant.
flag ["ocaml"; "debug"; "compile"; "byte"] (A "-g");;
flag ["ocaml"; "debug"; "link"; "byte"; "program"] (A "-g");;
flag ["ocaml"; "debug"; "pack"; "byte"] (A "-g");;
flag ["ocaml"; "debug"; "compile"; "native"] (A "-g");;
flag ["ocaml"; "debug"; "link"; "native"; "program"] (A "-g");;
flag ["ocaml"; "debug"; "pack"; "native"] (A "-g");;
then, in the _tags
file, you can have true : debug
to turn it on for all files, or true
can be replaced by a pattern for limiting the option. So if an option doesn't exist already, you can create your own and you'll see that it's similar to the fully myocamlbuild.ml solution, but additional flags for each tag instead of including them all at once.
Upvotes: 2
Reputation: 6697
-g
is replaced by true: debug
in _tags
.
-I
options ideally should be replaced by the corresponding ocamlfind package, e.g. calling ocamlbuild -use-ocamlfind
and specifying true: package(llvm,llvm_analysis)
in _tags
and/or whatever other packages are called (and remove ocaml_lib
calls in myocamlbuild.ml
).
On the side note, just create a Makefile
with whatever ocamlbuild
invocation is needed and run make
to build.
Upvotes: 1