Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit a99196e

Browse files
hannesmmato
authored andcommittedApr 11, 2018
respect ld from pkg-config (#898)
* respect ld from pkg-config * mirage: unify link step of solo5-*, add solo5_pkt : target -> string, string * mirage: avoid calling the linker twice (in the ukvm case), thx @mato
1 parent 0db7a05 commit a99196e

File tree

1 file changed

+47
-52
lines changed

1 file changed

+47
-52
lines changed
 

‎lib/mirage.ml

+47-52
Original file line numberDiff line numberDiff line change
@@ -1856,6 +1856,26 @@ let ldflags pkg = pkg_config pkg ["--variable=ldflags"]
18561856

18571857
let ldpostflags pkg = pkg_config pkg ["--variable=ldpostflags"]
18581858

1859+
let find_ld pkg =
1860+
match pkg_config pkg ["--variable=ld"] with
1861+
| Ok (ld::_) ->
1862+
Log.warn (fun m -> m "using %s as ld (pkg-config %s --variable=ld)" ld pkg) ;
1863+
ld
1864+
| Ok [] ->
1865+
Log.warn (fun m -> m "pkg-config %s --variable=ld returned nothing, using ld" pkg) ;
1866+
"ld"
1867+
| Error msg ->
1868+
Log.warn (fun m -> m "error %a while pkg-config %s --variable=ld, using ld"
1869+
Rresult.R.pp_msg msg pkg) ;
1870+
"ld"
1871+
1872+
let solo5_pkg = function
1873+
| `Virtio -> "solo5-kernel-virtio", ".virtio"
1874+
| `Muen -> "solo5-kernel-muen", ".muen"
1875+
| `Ukvm -> "solo5-kernel-ukvm", ".ukvm"
1876+
| `Unix | `MacOSX | `Xen | `Qubes ->
1877+
invalid_arg "solo5_kernel only defined for solo5 targets"
1878+
18591879
let link info name target target_debug =
18601880
let libs = Info.libraries info in
18611881
match target with
@@ -1890,60 +1910,37 @@ let link info name target target_debug =
18901910
Bos.OS.Cmd.run link >>= fun () ->
18911911
Ok out
18921912
end
1893-
| `Virtio ->
1894-
extra_c_artifacts "freestanding" libs >>= fun c_artifacts ->
1895-
static_libs "mirage-solo5" >>= fun static_libs ->
1896-
ldflags "solo5-kernel-virtio" >>= fun ldflags ->
1897-
ldpostflags "solo5-kernel-virtio" >>= fun ldpostflags ->
1898-
let out = name ^ ".virtio" in
1899-
let linker =
1900-
Bos.Cmd.(v "ld" %% of_list ldflags % "_build/main.native.o" %%
1901-
of_list c_artifacts %% of_list static_libs % "-o" % out
1902-
%% of_list ldpostflags)
1903-
in
1904-
Log.info (fun m -> m "linking with %a" Bos.Cmd.pp linker);
1905-
Bos.OS.Cmd.run linker >>= fun () ->
1906-
Ok out
1907-
| `Muen ->
1913+
| `Virtio | `Muen | `Ukvm ->
1914+
let pkg, post = solo5_pkg target in
19081915
extra_c_artifacts "freestanding" libs >>= fun c_artifacts ->
19091916
static_libs "mirage-solo5" >>= fun static_libs ->
1910-
ldflags "solo5-kernel-muen" >>= fun ldflags ->
1911-
ldpostflags "solo5-kernel-muen" >>= fun ldpostflags ->
1912-
let out = name ^ ".muen" in
1917+
ldflags pkg >>= fun ldflags ->
1918+
ldpostflags pkg >>= fun ldpostflags ->
1919+
let out = name ^ post in
1920+
let ld = find_ld pkg in
19131921
let linker =
1914-
Bos.Cmd.(v "ld" %% of_list ldflags % "_build/main.native.o" %%
1922+
Bos.Cmd.(v ld %% of_list ldflags % "_build/main.native.o" %%
19151923
of_list c_artifacts %% of_list static_libs % "-o" % out
19161924
%% of_list ldpostflags)
19171925
in
19181926
Log.info (fun m -> m "linking with %a" Bos.Cmd.pp linker);
19191927
Bos.OS.Cmd.run linker >>= fun () ->
1920-
Ok out
1921-
| `Ukvm ->
1922-
extra_c_artifacts "freestanding" libs >>= fun c_artifacts ->
1923-
static_libs "mirage-solo5" >>= fun static_libs ->
1924-
ldflags "solo5-kernel-ukvm" >>= fun ldflags ->
1925-
ldpostflags "solo5-kernel-ukvm" >>= fun ldpostflags ->
1926-
let out = name ^ ".ukvm" in
1927-
let linker =
1928-
Bos.Cmd.(v "ld" %% of_list ldflags % "_build/main.native.o" %%
1929-
of_list c_artifacts %% of_list static_libs % "-o" % out
1930-
%% of_list ldpostflags)
1931-
in
1932-
let ukvm_mods =
1933-
List.fold_left (fun acc -> function
1934-
| "mirage-net-solo5" -> "net" :: acc
1935-
| "mirage-block-solo5" -> "blk" :: acc
1936-
| _ -> acc)
1937-
[] libs @ (if target_debug then ["gdb"] else [])
1938-
in
1939-
pkg_config "solo5-kernel-ukvm" ["--variable=libdir"] >>= function
1940-
| [ libdir ] ->
1941-
Bos.OS.Cmd.run Bos.Cmd.(v "ukvm-configure" % (libdir ^ "/src/ukvm") %% of_list ukvm_mods) >>= fun () ->
1942-
Bos.OS.Cmd.run Bos.Cmd.(v "make" % "-f" % "Makefile.ukvm" % "ukvm-bin") >>= fun () ->
1943-
Log.info (fun m -> m "linking with %a" Bos.Cmd.pp linker);
1944-
Bos.OS.Cmd.run linker >>= fun () ->
1928+
if target = `Ukvm then
1929+
let ukvm_mods =
1930+
List.fold_left (fun acc -> function
1931+
| "mirage-net-solo5" -> "net" :: acc
1932+
| "mirage-block-solo5" -> "blk" :: acc
1933+
| _ -> acc)
1934+
[] libs @ (if target_debug then ["gdb"] else [])
1935+
in
1936+
pkg_config pkg ["--variable=libdir"] >>= function
1937+
| [ libdir ] ->
1938+
Bos.OS.Cmd.run Bos.Cmd.(v "ukvm-configure" % (libdir ^ "/src/ukvm") %% of_list ukvm_mods) >>= fun () ->
1939+
Bos.OS.Cmd.run Bos.Cmd.(v "make" % "-f" % "Makefile.ukvm" % "ukvm-bin") >>= fun () ->
1940+
Ok out
1941+
| _ -> R.error_msg ("pkg-config " ^ pkg ^ " --variable=libdir failed")
1942+
else
19451943
Ok out
1946-
| _ -> R.error_msg "pkg-config solo5-kernel-ukvm --variable=libdir failed"
19471944

19481945
let build i =
19491946
let name = Info.name i in
@@ -2015,14 +2012,12 @@ module Project = struct
20152012
package ~build:true "ocamlbuild" ;
20162013
] in
20172014
Key.match_ Key.(value target) @@ function
2018-
| `Xen | `Qubes -> [ package ~min:"3.0.4" "mirage-xen" ] @ common
2019-
| `Virtio -> [ package ~min:"0.2.1" ~ocamlfind:[] "solo5-kernel-virtio" ;
2020-
package ~min:"0.2.0" "mirage-solo5" ] @ common
2021-
| `Ukvm -> [ package ~min:"0.2.1" ~ocamlfind:[] "solo5-kernel-ukvm" ;
2022-
package ~min:"0.2.0" "mirage-solo5" ] @ common
2023-
| `Muen -> [ package ~ocamlfind:[] "solo5-kernel-muen" ;
2024-
package ~min:"0.2.0" "mirage-solo5" ] @ common
20252015
| `Unix | `MacOSX -> [ package ~min:"3.0.0" "mirage-unix" ] @ common
2016+
| `Xen | `Qubes -> [ package ~min:"3.0.4" "mirage-xen" ] @ common
2017+
| `Virtio | `Ukvm | `Muen as tgt ->
2018+
let pkg, _ = solo5_pkg tgt in
2019+
[ package ~min:"0.2.1" ~ocamlfind:[] pkg ;
2020+
package ~min:"0.2.0" "mirage-solo5" ] @ common
20262021

20272022
method! build = build
20282023
method! configure = configure

0 commit comments

Comments
 (0)
Please sign in to comment.