Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0005823OCamlOCaml backend (code generation)public2012-11-14 10:472014-06-04 21:57
Reporterdaweil 
Assigned To 
PrioritynormalSeverityfeatureReproducibilityalways
StatusacknowledgedResolutionopen 
PlatformOSOS Version
Product Version4.00.1 
Target VersionFixed in Version 
Summary0005823: wish that ocamlopt compile .cpp files as well as c files
DescriptionI tried the following very simple patch that seems to work :

diff -ur ocaml-4.00.1/driver/main.ml ocaml-4.00.1_patched/driver/main.ml
--- ocaml-4.00.1/driver/main.ml Wed May 30 13:29:48 2012
+++ ocaml-4.00.1_patched/driver/main.ml Thu Nov 8 11:27:45 2012
@@ -52,7 +52,7 @@
     ccobjs := name :: !ccobjs
   else if Filename.check_suffix name ext_dll then
     dllibs := name :: !dllibs
- else if Filename.check_suffix name ".c" then begin
+ else if Filename.check_suffix name ".c" or Filename.check_suffix name ".cpp" then begin
     Compile.c_file name;
     ccobjs := (Filename.chop_suffix (Filename.basename name) ".c" ^ ext_obj)
               :: !ccobjs
diff -ur ocaml-4.00.1/driver/optmain.ml ocaml-4.00.1_patched/driver/optmain.ml
--- ocaml-4.00.1/driver/optmain.ml Wed May 30 13:29:48 2012
+++ ocaml-4.00.1_patched/driver/optmain.ml Thu Nov 8 11:34:20 2012
@@ -51,7 +51,7 @@
   else if Filename.check_suffix name ext_obj
        || Filename.check_suffix name ext_lib then
     ccobjs := name :: !ccobjs
- else if Filename.check_suffix name ".c" then begin
+ else if Filename.check_suffix name ".c" or Filename.check_suffix name ".cpp" then begin
     Optcompile.c_file name;
     ccobjs := (Filename.chop_suffix (Filename.basename name) ".c" ^ ext_obj)
               :: !ccobjs


and add the following rule for ocamlbuild:
  rule "C files cpp -> o"
    ~insert:`top
    ~prod:x_o
    ~dep:"%.cpp"
    begin fun env _build ->
      let c = env "%.cpp" in
      let o = env x_o in
      let comp = if Tags.mem "native" (tags_of_pathname c) then !Options.ocamlopt else !Options.ocamlc in
      let cc = Cmd(S[comp; T(tags_of_pathname c++"c"++"compile"); A"-c"; Px c]) in
      if Pathname.dirname o = Pathname.current_dir_name then cc
      else Seq[cc; mv (Pathname.basename o) o]
    end;
Tagspatch
Attached Files

- Relationships

-  Notes
(0009637)
doligez (administrator)
2013-06-28 17:57

Your patch won't work because you failed to change the calls to "chop_suffix". Also, this would change the requirements on configure from "find a C compiler" to "find something that can indifferently compile C and C++". I'm not sure if that is a big deal or not, but it has to be considered.
(0009730)
daweil (reporter)
2013-07-09 14:40

No, that's not a big deal, but just a nice feature if ocaml & ocamlbuild can handle both C and C++ files...
(0009742)
ygrek (reporter)
2013-07-10 07:40

if this is to be implemented, please consider also .cxx and .cc extensions..

- Issue History
Date Modified Username Field Change
2012-11-14 10:47 daweil New Issue
2013-06-28 17:57 doligez Note Added: 0009637
2013-06-28 17:57 doligez Status new => feedback
2013-07-09 14:40 daweil Note Added: 0009730
2013-07-09 14:40 daweil Status feedback => new
2013-07-10 07:40 ygrek Note Added: 0009742
2013-12-16 13:34 doligez Tag Attached: patch
2014-06-04 21:57 doligez Status new => acknowledged


Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker