Skip to content

Commit

Permalink
Adapt to ocamlbuildcpp changes
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeDralliam committed Aug 29, 2013
1 parent b78aaf8 commit a4cb421
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 47 deletions.
31 changes: 31 additions & 0 deletions _tags
@@ -0,0 +1,31 @@
<OcsfmlSystem> or <OcsfmlWindow> : include

<Ocsfml*/libocsfml*.{a,lib}> : release
<Ocsfml*/*.cm{x,}a> : release, ocamlmklib
<Ocsfml*/ocsfml_*_stub/*.cpp> : release

<OcsfmlSystem/ocsfml_system_stub/*.cpp> : include_sfml_system
<OcsfmlSystem/libocsfmlsystem.{a,lib}> : use_libsfml_system
<OcsfmlSystem/*.cm{x,}a> : use_libsfml_system, use_libocsfmlsystem


<OcsfmlWindow/ocsfml_window_stub/*.cpp> : include_sfml_window
<OcsfmlWindow/libocsfmlwindow.{a,lib}> : use_libsfml_window
<OcsfmlWindow/*.cm{x,}a> : use_libsfml_window, use_libocsfmlwindow


<OcsfmlGraphics/ocsfml_graphics_stub/*.cpp> : include_sfml_graphics
<OcsfmlGraphics/libocsfmlgraphics.{a,lib}> : use_libsfml_graphics
<OcsfmlGraphics/*.cm{x,}a> : use_libsfml_graphics, use_libocsfmlgraphics


<OcsfmlAudio/ocsfml_audio_stub/*.cpp> : include_sfml_audio
<OcsfmlAudio/libocsfmlaudio.{a,lib}> : use_libsfml_audio
<OcsfmlAudio/*.cm{x,}a> : use_libsfml_audio, use_libocsfmlaudio

<OcsfmlNetwork/ocsfml_network_stub/*.cpp> : include_sfml_network
<OcsfmlNetwork/libocsfmlnetwork.{a,lib}> : use_libsfml_network
<OcsfmlNetwork/*.cm{x,}a> : use_libsfml_network, use_libocsfmlnetwork


<ocsfml.docdir/index.html> : colorize_code, custom_intro
77 changes: 30 additions & 47 deletions myocamlbuild.ml
Expand Up @@ -2,23 +2,7 @@ open Ocamlbuild_plugin
open Pathname

let link_to_static_sfml_libraries = false ;;
let compiler = List.hd (CppCompiler.available ()) ;;

let link_one to_c lib =
let open CppCompiler.Library in
match lib with
| Library filename -> (
match soname filename with
| Some name -> A ("-l" ^ name)
| None ->
if to_c then A filename
else S []
)
| Framework (path, name) -> S [A ("-F" ^ path) ; A "-framework" ; A name]

let link to_c libs =
S (List.map (link_one to_c) libs)

let compiler = List.hd (CppCompiler.available ()) ;;

let add_sfml_flags static =
let open FindSfml in
Expand All @@ -29,25 +13,23 @@ let add_sfml_flags static =
List.map (fun cp -> Sfml.LibraryMap.find cp lib)
in

let add_flags compilation_mode lib =
let open SfmlConfiguration in
flag [ "ocamlmklib" ; "c" ; compilation_mode ; "use_libsfml_system" ] & link true (libs_of_components lib [System]) ;
flag [ "ocamlmklib" ; "c" ; compilation_mode ; "use_libsfml_window" ] & link true (libs_of_components lib [System ; Window]);
flag [ "ocamlmklib" ; "c" ; compilation_mode ; "use_libsfml_graphics" ] & link true (libs_of_components lib [System ; Window ; Graphics]) ;
flag [ "ocamlmklib" ; "c" ; compilation_mode ; "use_libsfml_audio" ] & link true (libs_of_components lib [System ; Audio ]) ;
flag [ "ocamlmklib" ; "c" ; compilation_mode ; "use_libsfml_network" ] & link true (libs_of_components lib [System ; Network ]) ;
if static then flag ["c++"; "compile"] (A "-DSFML_STATIC") ;

flag [ "ocamlmklib" ; "ocaml" ; compilation_mode ; "use_libsfml_system" ] & link false (libs_of_components lib [System]) ;
flag [ "ocamlmklib" ; "ocaml" ; compilation_mode ; "use_libsfml_window" ] & link false (libs_of_components lib [System ; Window]) ;
flag [ "ocamlmklib" ; "ocaml" ; compilation_mode ; "use_libsfml_graphics" ] & link false (libs_of_components lib [System ; Window ; Graphics]) ;
flag [ "ocamlmklib" ; "ocaml" ; compilation_mode ; "use_libsfml_audio" ] & link false (libs_of_components lib [System ; Audio ]) ;
flag [ "ocamlmklib" ; "ocaml" ; compilation_mode ; "use_libsfml_network" ] & link false (libs_of_components lib [System ; Network ])
let add_flags lib =
let open SfmlConfiguration in
let includedir = sfml.Sfml.includedir in
CppLibrary.register ~libraries:(libs_of_components lib [System])
~includedir "libsfml_system" compiler ;
CppLibrary.register ~libraries:(libs_of_components lib [System ; Window])
~includedir "libsfml_window" compiler ;
CppLibrary.register ~libraries:(libs_of_components lib [System ; Window ; Graphics])
~includedir "libsfml_graphics" compiler ;
CppLibrary.register ~libraries:(libs_of_components lib [System ; Audio])
~includedir "libsfml_audio" compiler ;
CppLibrary.register ~libraries:(libs_of_components lib [System ; Network])
~includedir "libsfml_network" compiler ;
in


flag [ "c++" ; "compile" ] (A (CppCompiler.BuildFlags.add_include_path sfml.Sfml.includedir compiler)) ;
if static then flag ["c++"; "compile"] (A "-DSFML_STATIC") ;

let stub_dir s =
Printf.sprintf "../Ocsfml%s/ocsfml_%s_stub" (String.capitalize s) s
in
Expand All @@ -72,28 +54,23 @@ let add_sfml_flags static =


List.iter (fun s ->
(*
flag ["link"; "ocaml"; "use_libocsfml"^s]
(S [ A("-LOcsfml" ^ String.capitalize s) ]) ;
flag ["link"; "ocaml"; "use_libocsfml"^s]
(S [ A("-locsfml"^s) ]) ;
*)
let d = Printf.sprintf "Ocsfml%s" (String.capitalize s) in

dep ["link"; "ocaml"; "native"; "use_libocsfml"^s]
[d^"/libocsfml"^s^"."^(!Options.ext_lib)] ;

dep ["link"; "ocaml"; "byte"; "use_libocsfml"^s]
[d^"/dllocsfml"^s^"."^(!Options.ext_dll)] ;

ocaml_lib (d ^ "/ocsfml" ^ s);
) ["system" ; "window" ; "graphics" ; "audio" ; "network"] ;
) ["system" ; "window" ; "graphics" ; "audio" ; "network"] ;

add_flags "release" sfml.Sfml.library ;
add_flags sfml.Sfml.library ;


if compiler = CppCompiler.Clang
then (
flag ["ocamlmklib" ] (S [A"-lc++"]) ;
flag ["ocamlmklib"] (S [A"-lc++"]) ;
)
else if CppCompiler.frontend compiler = CppCompiler.GccCompatible
then (
Expand All @@ -103,13 +80,18 @@ let add_sfml_flags static =

let add_other_flags () =
let open FindBoost.Boost in

let boost = find compiler [] in
flag [ "c++" ; "compile"] (A (CppCompiler.BuildFlags.add_include_path boost.FindBoost.Boost.includedir compiler)) ;
flag [ "c++" ; "compile"]
(A (CppCompiler.BuildFlags.add_include_path boost.FindBoost.Boost.includedir compiler)) ;

let ocaml_dir = input_line (Unix.open_process_in "ocamlc -where") in
flag [ "c++" ; "compile" ] (A (CppCompiler.BuildFlags.add_include_path ocaml_dir compiler)) ;
flag [ "c++" ; "compile" ]
(A (CppCompiler.BuildFlags.add_include_path ocaml_dir compiler)) ;

let camlpp_dir = "../camlpp" in
flag [ "c++" ; "compile" ] (A (CppCompiler.BuildFlags.add_include_path camlpp_dir compiler)) ;
flag [ "c++" ; "compile" ]
(A (CppCompiler.BuildFlags.add_include_path camlpp_dir compiler)) ;

flag [ "c++" ; "compile" ; "gcc"] (A "-std=c++0x") ;
flag [ "c++" ; "compile" ; "mingw"] (A "-std=c++0x") ;
Expand All @@ -127,6 +109,7 @@ let _ = dispatch (function
add_other_flags ()
| After_rules ->
flag ["ocaml"; "doc" ; "colorize_code"] & A "-colorize-code" ;
flag ["ocaml"; "doc" ; "custom_intro"] & S [ A "-intro" ; A "../Documentation/intro.camldoc" ]
flag ["ocaml"; "doc" ; "custom_intro"]
& S [ A "-intro" ; A "../Documentation/intro.camldoc" ]
| _ -> ()
)

0 comments on commit a4cb421

Please sign in to comment.