@@ -1856,6 +1856,26 @@ let ldflags pkg = pkg_config pkg ["--variable=ldflags"]
1856
1856
1857
1857
let ldpostflags pkg = pkg_config pkg [" --variable=ldpostflags" ]
1858
1858
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
+
1859
1879
let link info name target target_debug =
1860
1880
let libs = Info. libraries info in
1861
1881
match target with
@@ -1890,60 +1910,37 @@ let link info name target target_debug =
1890
1910
Bos.OS.Cmd. run link >> = fun () ->
1891
1911
Ok out
1892
1912
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
1908
1915
extra_c_artifacts " freestanding" libs >> = fun c_artifacts ->
1909
1916
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
1913
1921
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" %%
1915
1923
of_list c_artifacts %% of_list static_libs % " -o" % out
1916
1924
%% of_list ldpostflags)
1917
1925
in
1918
1926
Log. info (fun m -> m " linking with %a" Bos.Cmd. pp linker);
1919
1927
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
1945
1943
Ok out
1946
- | _ -> R. error_msg " pkg-config solo5-kernel-ukvm --variable=libdir failed"
1947
1944
1948
1945
let build i =
1949
1946
let name = Info. name i in
@@ -2015,14 +2012,12 @@ module Project = struct
2015
2012
package ~build: true " ocamlbuild" ;
2016
2013
] in
2017
2014
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
2025
2015
| `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
2026
2021
2027
2022
method! build = build
2028
2023
method! configure = configure
0 commit comments