#
# PKG_CONFIG_PATH may be required to be set if libibverbs.pc is not installed.
-pkg-config --libs-only-l --static libibverbs |
+lib='libibverbs'
+deps='pthread|nl'
+
+pkg-config --libs --static $lib |
tr '[:space:]' '\n' |
- sed -r '/^-l(pthread|nl)/! s,(^-l)(.*),\1:lib\2.a,'
+ sed -r "/^-l($deps)/! s,(^-l)(.*),\1:lib\2.a," | # explicit .a
+ sed -n '/^-[Ll]/p' | # extra link options may break with make
+ tac |
+ awk "/^-l:$lib.a/&&c++ {next} 1" | # drop first duplicates of main lib
+ tac