From e19b55e9101b77146a9b71d3299097f6b23b0ea6 Mon Sep 17 00:00:00 2001 From: Klaus Aehlig Date: Wed, 27 Sep 2023 17:04:45 +0200 Subject: ["CC/pkgconfig", "system_library"] Add -rpath When a shared library is picked up from the host system via pkg-config that is located at a non-standard location, binaries linked against this library by a standard linker either need LD_LIBRARY_PATH set appropriately, or -rpath set at link time. However, not all custom installations set -rpath in the link flags in their pkg-config file. Therefore, in order to get working binaries (and not have to set custom paths in tests), add a -rpath for every -L option found in the ldflags provided by pkg-config. --- CC/pkgconfig/EXPRESSIONS | 73 +++++++++++++++++++++++++++++++++--------------- 1 file changed, 51 insertions(+), 22 deletions(-) (limited to 'CC/pkgconfig/EXPRESSIONS') diff --git a/CC/pkgconfig/EXPRESSIONS b/CC/pkgconfig/EXPRESSIONS index 535faf6..b835b58 100644 --- a/CC/pkgconfig/EXPRESSIONS +++ b/CC/pkgconfig/EXPRESSIONS @@ -3,6 +3,7 @@ , "imports": { "default-ENV": ["./", "..", "default-ENV"] , "default-PATH": ["./", "..", "default-PATH"] + , "stage": ["", "stage_singleton_field"] } , "expression": { "type": "let*" @@ -98,41 +99,69 @@ , [ "ldflags-filename" , {"type": "join", "$1": [{"type": "var", "name": "name"}, ".ldflags"]} ] + , [ "ldflags-files" + , { "type": "ACTION" + , "inputs": {"type": "empty_map"} + , "cmd": + [ "/bin/sh" + , "-c" + , { "type": "join" + , "separator": " " + , "$1": + { "type": "++" + , "$1": + [ ["pkg-config"] + , [ { "type": "join_cmd" + , "$1": + { "type": "++" + , "$1": + [ {"type": "var", "name": "args", "default": []} + , ["--libs", {"type": "var", "name": "name"}] + ] + } + } + ] + , [">", "ldflags.raw"] + ] + } + } + ] + , "env": {"type": "var", "name": "ENV"} + , "outs": ["ldflags.raw"] + } + ] + , [ "add_rpath" + , { "type": "let*" + , "bindings": [["fieldname", "add_rpath"], ["location", "add_rpath"]] + , "body": {"type": "CALL_EXPRESSION", "name": "stage"} + } + ] , [ "ldflags-files" , { "type": "to_subdir" , "subdir": {"type": "var", "name": "stage"} , "$1": { "type": "ACTION" - , "inputs": {"type": "empty_map"} + , "inputs": + { "type": "map_union" + , "$1": + [ {"type": "var", "name": "add_rpath"} + , {"type": "var", "name": "ldflags-files"} + ] + } , "cmd": [ "/bin/sh" , "-c" , { "type": "join" , "separator": " " , "$1": - { "type": "++" - , "$1": - [ ["pkg-config"] - , [ { "type": "join_cmd" - , "$1": - { "type": "++" - , "$1": - [ {"type": "var", "name": "args", "default": []} - , ["--libs", {"type": "var", "name": "name"}] - ] - } - } - ] - , [">"] - , [ { "type": "join_cmd" - , "$1": {"type": "var", "name": "ldflags-filename"} - } - ] - ] - } + [ "./add_rpath $(cat ldflags.raw)" + , ">" + , { "type": "join_cmd" + , "$1": {"type": "var", "name": "ldflags-filename"} + } + ] } ] - , "env": {"type": "var", "name": "ENV"} , "outs": [{"type": "var", "name": "ldflags-filename"}] } } -- cgit v1.2.3