@@ -15,33 +15,38 @@ let is_excluded name =
1515 | None -> false
1616 | Some excluded -> List. mem name (String. split_on_char ' ' excluded)
1717
18- let set_pkg_config_path_for_context context_name =
18+ let set_pkg_config_for_context context_name =
1919 let sanitized =
2020 String. map (fun c -> if c = '.' then '_' else c) context_name
2121 in
22- match Sys. getenv_opt (" PKG_CONFIG_PATH_" ^ sanitized) with
22+ ( match Sys. getenv_opt (" PKG_CONFIG_PATH_" ^ sanitized) with
2323 | Some path -> Unix. putenv " PKG_CONFIG_PATH" path
24+ | None -> () );
25+ match Sys. getenv_opt (" PKG_CONFIG_" ^ sanitized) with
26+ | Some path -> Unix. putenv " PKG_CONFIG" path
2427 | None -> ()
2528
2629let () =
27- match Array. to_list Sys. argv |> List. tl with
28- | "--context" :: context_name :: _ ->
29- set_pkg_config_path_for_context context_name;
30- let open Configurator.V1 in
31- let c = create " ao-detect" in
32- let available, cflags, libs =
33- if is_excluded " ao" then (false , [] , [] )
34- else (
35- match Pkg_config. get c with
30+ let argv = Array. to_list Sys. argv |> List. tl in
31+ (match Sys. getenv_opt " LIQUIDSOAP_DUNE_TARGET" with
32+ | Some ctx -> set_pkg_config_for_context ctx
33+ | None -> (
34+ match argv with
35+ | "--context" :: context_name :: _ ->
36+ set_pkg_config_for_context context_name
37+ | _ -> () ));
38+ let open Configurator.V1 in
39+ let c = create " ao-detect" in
40+ let available, cflags, libs =
41+ if is_excluded " ao" then (false , [] , [] )
42+ else (
43+ match Pkg_config. get c with
44+ | None -> (false , [] , [] )
45+ | Some pc -> (
46+ match Pkg_config. query pc ~package: " ao" with
3647 | None -> (false , [] , [] )
37- | Some pc -> (
38- match Pkg_config. query pc ~package: " ao" with
39- | None -> (false , [] , [] )
40- | Some conf -> (true , conf.cflags, conf.libs)))
41- in
42- write_bool " ao_available" available;
43- write_sexp " ao_c_flags.sexp" cflags;
44- write_sexp " ao_c_library_flags.sexp" libs
45- | _ ->
46- Printf. eprintf " Usage: detect --context <context>\n " ;
47- exit 1
48+ | Some conf -> (true , conf.cflags, conf.libs)))
49+ in
50+ write_bool " ao_available" available;
51+ write_sexp " ao_c_flags.sexp" cflags;
52+ write_sexp " ao_c_library_flags.sexp" libs
0 commit comments