Commit 3d577242 authored by Maximilien Colange's avatar Maximilien Colange

Better handling of C/C++ files through a custom ocamlbuild plugin.

parent 36d7d2a2
......@@ -10,16 +10,18 @@ OCAMLBUILD=ocamlbuild -use-ocamlfind -classic-display -build-dir $(BUILDDIR) @OC
CXX_FLAGS=-xc++ -std=c++11 -fPIC -O3 -g -DNDEBUG @TIAMO_MACROS@ -I$(UTAP_INCLUDEDIR) -I@abs_top_srcdir@/src
OCAML_CXX_FLAGS=$(foreach i,$(CXX_FLAGS),-ccopt $i)
CXX_FLAGS=-std=c++11 -O3 -DNDEBUG @TIAMO_MACROS@ -I$(UTAP_INCLUDEDIR) -I@abs_top_srcdir@/src
XML_LINK_FLAGS=$(foreach i,$(XML_LIBS),-cclib $i)
$(OCAMLBUILD) -cflags "-cc g++ $(OCAML_CXX_FLAGS)" timedAutomatonBuilder.o
$(OCAMLBUILD) -cflags "-g -noassert -I $(INCLUDEDIR)" -lflags "$(INCLUDEDIR)/udbml.cmxa src/timedAutomatonBuilder.o $(UTAP_LIB) $(XML_LINK_FLAGS) -cclib -L$(INCLUDEDIR)" src/main.native
all-local: tiamo
tiamo: src/main.native
cp `readlink -f $(BUILDDIR)/src/main.native` tiamo
CXX_FLAGS="$(CXX_FLAGS)" $(OCAMLBUILD) -cflags "-noassert -I $(INCLUDEDIR)" -lflags "$(INCLUDEDIR)/udbml.cmxa $(UTAP_LIB) $(XML_LINK_FLAGS) -cclib -L$(INCLUDEDIR)" $@
ocamlbuild -clean
$(OCAMLBUILD) -clean
rm -f tiamo
open Ocamlbuild_plugin (* open the main API module *)
open Command
(* TODO find a cleaner way to retrieve these informations from the environment
* maybe the CXX_FLAGS should be given as arguments to the 'c++' tag,
* thus allowing per-file CXX flags.
let cxx = "g++"
* Default CXX flags:
* -xc++ to be sure to compile .c files as c++
* -fPIC to ensure position-independent code
let cxx_flags = ["-xc++"; "-fPIC"; Sys.getenv "CXX_FLAGS"]
(* a helper function *)
(* prefix every c++ flags with -ccopt *)
let ocaml_cxx_flags = fun flags ->
let camlflags = List.flatten ( (fun opt -> ["-ccopt"; opt]) (cxx_flags @ flags)) in
S [A "-cc"; A cxx; atomize camlflags]
(* TODO add C options when seeing tags:
* noassert -> add '-DNDEBUG'
* This kind of tags (debug, noassert, optimization levels...) should be set
* by the configure script through the file.
let _ =
dispatch begin function
| After_rules ->
(* TODO declare the internal utap library here *)
(* set proper compilation flags for c++ *)
flag ["c++"] (ocaml_cxx_flags []);
flag ["c++";"debug"] (ocaml_cxx_flags ["-g"]);
(* explicit link dependency for C-based object files *)
pdep ["link"] "linkdep" (fun param -> [param])
| _ -> ()
<*>: bin_annot
<*.cm{o,x}> or <main.native>: debug, custom
<main.native>: package(dynlink)
<*.c> or <*.cm{o,x}> or <main.native>: debug, custom
<main.native>: use_dynlink, linkdep(src/timedAutomatonBuilder.o)
<>: pp(camlp4o pa_macro.cmo @TIAMO_MACROS@)
<timedAutomatonBuilder.c>: c++
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment