summaryrefslogtreecommitdiff
path: root/CC
diff options
context:
space:
mode:
authorKlaus Aehlig <klaus.aehlig@huawei.com>2023-09-27 17:04:45 +0200
committerKlaus Aehlig <klaus.aehlig@huawei.com>2023-09-28 12:58:09 +0200
commite19b55e9101b77146a9b71d3299097f6b23b0ea6 (patch)
tree99882b8e849a589882c76f0d7300934a72170e3b /CC
parent7a7bdef2344c4982d35493a6ce8c5be7b9dfa812 (diff)
downloadrules-cc-e19b55e9101b77146a9b71d3299097f6b23b0ea6.tar.gz
["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.
Diffstat (limited to 'CC')
-rw-r--r--CC/pkgconfig/EXPRESSIONS73
-rw-r--r--CC/pkgconfig/RULES3
-rw-r--r--CC/pkgconfig/TARGETS1
-rwxr-xr-xCC/pkgconfig/add_rpath24
4 files changed, 78 insertions, 23 deletions
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*"
@@ -99,40 +100,68 @@
, {"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"}]
}
}
diff --git a/CC/pkgconfig/RULES b/CC/pkgconfig/RULES
index 4424cb2..1d3b613 100644
--- a/CC/pkgconfig/RULES
+++ b/CC/pkgconfig/RULES
@@ -1,7 +1,8 @@
{ "system_library":
{ "doc": ["A system library via pkg-config"]
, "string_fields": ["name", "args", "stage"]
- , "implicit": {"defaults": [["./", "..", "defaults"]]}
+ , "implicit":
+ {"defaults": [["./", "..", "defaults"]], "add_rpath": ["add_rpath"]}
, "config_vars": ["PKG_CONFIG_ARGS", "ENV"]
, "field_doc":
{ "name": ["The pkg-config name of the library."]
diff --git a/CC/pkgconfig/TARGETS b/CC/pkgconfig/TARGETS
new file mode 100644
index 0000000..0967ef4
--- /dev/null
+++ b/CC/pkgconfig/TARGETS
@@ -0,0 +1 @@
+{}
diff --git a/CC/pkgconfig/add_rpath b/CC/pkgconfig/add_rpath
new file mode 100755
index 0000000..d020f2b
--- /dev/null
+++ b/CC/pkgconfig/add_rpath
@@ -0,0 +1,24 @@
+#!/bin/sh
+# Copyright 2023 Huawei Cloud Computing Technology Co., Ltd.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+for x in "$@"
+do
+ echo -n '' "$x"
+ case $x in
+ -L*) echo -n '' -Xlinker -rpath -Xlinker "$(expr "$x" : "..\(.*\)")"
+ ;;
+ esac
+done
+echo