|
1 | 1 | module C = Configurator.V1 |
2 | 2 |
|
| 3 | +[@@@warning "-40"] |
| 4 | + |
3 | 5 | module List = struct |
4 | 6 | (* Compatibility with OCaml < 4.10 *) |
5 | 7 | let [@warning "-32"] rec concat_map f = function |
@@ -389,16 +391,34 @@ let extract_all_declarations c ~cflags ~libs = |
389 | 391 | extract_declarations c ~cflags ~libs ~declarations:curl_h_declarations ~includes:[ "#include <curl/curl.h>" ] |
390 | 392 | @ extract_declarations c ~cflags ~libs ~declarations:header_h_declarations ~includes:[ "#include <curl/curl.h>"; "#include <curl/header.h>" ] |
391 | 393 |
|
| 394 | +(* naive (what if some lib requires -L) *) |
| 395 | +let dynamic over libs = |
| 396 | + (* NB adding all as dynamic, not only the ones present, because libcurl.pc misses sasl dep *) |
| 397 | + let (_over,libs) = List.partition (fun l -> List.mem l over) libs in |
| 398 | + (if over <> [] then ["-Wl,--push-state"; "-Wl,-Bdynamic"] @ over @ ["-Wl,--pop-state"] else []) @ libs |
| 399 | + |
| 400 | +(* basically Pkg_config.query_expr_err with --static and no smartness finding pkg-config itself (it is up to the host owner to set it up properly) *) |
| 401 | +let pkg_config ~package ?(expr=package) c = |
| 402 | + let open C in |
| 403 | + let run args = |
| 404 | + Flags.extract_blank_separated_words @@ String.trim @@ Process.run_capture_exn c "pkg-config" @@ [ "--print-errors"] @ args @ [ package ] |
| 405 | + in |
| 406 | + match Process.run c "pkg-config" [ "--print-errors"; expr ] with |
| 407 | + | { exit_code = 0; _ } -> Ok { Pkg_config.libs = run ["--static"; "--libs"]; cflags = run ["--static"; "--cflags"] } |
| 408 | + | { stderr; _ } -> Error stderr |
| 409 | + |
392 | 410 | let main c = |
393 | 411 | let cflags, libs = |
394 | 412 | match C.ocaml_config_var c "ccomp_type" with |
395 | 413 | | Some "cc" -> |
396 | 414 | let {C.Pkg_config.cflags; libs} = |
397 | 415 | match C.Pkg_config.get c with |
398 | 416 | | None -> { cflags = []; C.Pkg_config.libs = [ "-lcurl" ]} |
399 | | - | Some pc -> |
400 | | - (match C.Pkg_config.query_expr_err pc ~package:"libcurl" ~expr:"libcurl >= 7.28.0" with |
401 | | - | Ok c -> c |
| 417 | + | Some _pc -> |
| 418 | + (match pkg_config c ~package:"libcurl" ~expr:"libcurl >= 7.28.0" with |
| 419 | + (* static sasl is unusable (requires a lot of dependencies), p11-kit doesn't provide static lib *) |
| 420 | + (* TODO figure the absence of static lib automatically *) |
| 421 | + | Ok c -> { c with libs = dynamic ["-lsasl2";"-lp11-kit"] c.libs } |
402 | 422 | | Error err -> C.die "%s" err) |
403 | 423 | in |
404 | 424 | "-Wall" :: "-Wno-deprecated-declarations" :: cflags, libs |
|
0 commit comments