Commit a3425ea6 authored by Roman Haefeli's avatar Roman Haefeli
Browse files

add flags -d, -s to localdeps scripts:

  * -d: put localdeps into subfolder named $arch
  * -s: codesign compiled binaries and localdeps
parent e5a5ee3b
......@@ -26,10 +26,30 @@ else
# was copied from 'localdeps.utilities.source'.
# changes you make to this section will be lost.
#@BEGIN_UTILITIES@
sign=false
subdir=false
verbose=${verbose:-0}
error() {
echo "$@" 1>&2
echo "$@" 1>&2
}
print_arch() {
# conflation of arch names follows rules
# from deken-plugin.tcl
arch=$(uname -m)
case $arch in
x86_64)
arch=amd64
;;
i486 | i586 | i686)
arch=i386
;;
armv6 | arm6l | arm7 | arm7l)
arch=arm
;;
esac
echo $arch
}
substitute() {
......@@ -115,6 +135,8 @@ usage: $0 [-I <includepath>] [-X <excludepath>] <binary> [<binary2> ...]
-I <includepath>: adds one include path entry
-X <excludepath>: adds one exclude path entry
-d: put localdeps into subdirectory named \$arch (Linux and macOS)
-s: codesign resulting binaries (macOS only)
-v: raise verbosity
-q: lower verbosity
......@@ -157,8 +179,7 @@ EOF
exit 1
}
while getopts "hqvI:X:" arg; do
while getopts "dhqsvI:X:" arg; do
case $arg in
h)
usage
......@@ -177,9 +198,15 @@ while getopts "hqvI:X:" arg; do
fi
include_paths=$(echo :${include_paths}: | substitute ":${p}:" ":" | sed -e 's|^:*||' -e 's|:*$||' -e 's|::*|:|g')
;;
d)
subdir=true
;;
q)
verbose=$((verbose-1))
;;
s)
sign=true
;;
v)
verbose=$((verbose+1))
;;
......@@ -199,23 +226,6 @@ fi
#@END_UTILITIES@
fi
library_in_exclude_list() {
# arg1: library name
# returns 0 if arg1 is found in exclude list, otherwise 1
local libexname="$1"
skip=1
set -f
for expat in $(echo "${ld_exclude_list}"); do
if echo "$(basename $libexname)" | grep "${expat}" > /dev/null; then
skip=0
break
fi
done
set +f
return $skip
}
list_deps() {
local libpath
local inc
......@@ -223,18 +233,22 @@ list_deps() {
| grep ' => ' \
| while read _ _ libpath _; do
inc=$(check_includedep "${libpath}")
if [ "x${inc}" != "x" ]; then
echo "${inc}"
fi
if [ "x${inc}" != "x" ]; then
echo "${inc}"
fi
done
}
install_deps () {
# make a local copy of all linked libraries of given binary
# and set RUNPATH to $ORIGIN (exclude "standard" libraries)
# arg1: binary to check
local outdir=$(dirname "$1")
local outdir
local outfile
if $subdir; then
outdir="$(dirname "$1")/$(print_arch)"
else
outdir="$(dirname "$1")"
fi
if [ ! -d "${outdir}" ]; then
outdir=.
fi
......@@ -253,7 +267,11 @@ install_deps () {
patchelf --set-rpath \$ORIGIN "${outfile}"
fi
done
patchelf --set-rpath \$ORIGIN "${1}"
if $subdir; then
patchelf --set-rpath "\$ORIGIN/$(print_arch)" "${1}"
else
patchelf --set-rpath \$ORIGIN "${1}"
fi
}
......@@ -267,5 +285,8 @@ for f in "$@"; do
error "Skipping '${f}'. Is it a binary file?"
continue
fi
if $subdir; then
mkdir -p "$(dirname ${f})/$(print_arch)"
fi
install_deps "${f}"
done
......@@ -17,10 +17,30 @@ else
# was copied from 'localdeps.utilities.source'.
# changes you make to this section will be lost.
#@BEGIN_UTILITIES@
sign=false
subdir=false
verbose=${verbose:-0}
error() {
echo "$@" 1>&2
echo "$@" 1>&2
}
print_arch() {
# conflation of arch names follows rules
# from deken-plugin.tcl
arch=$(uname -m)
case $arch in
x86_64)
arch=amd64
;;
i486 | i586 | i686)
arch=i386
;;
armv6 | arm6l | arm7 | arm7l)
arch=arm
;;
esac
echo $arch
}
substitute() {
......@@ -106,6 +126,8 @@ usage: $0 [-I <includepath>] [-X <excludepath>] <binary> [<binary2> ...]
-I <includepath>: adds one include path entry
-X <excludepath>: adds one exclude path entry
-d: put localdeps into subdirectory named \$arch (Linux and macOS)
-s: codesign resulting binaries (macOS only)
-v: raise verbosity
-q: lower verbosity
......@@ -148,8 +170,7 @@ EOF
exit 1
}
while getopts "hqvI:X:" arg; do
while getopts "dhqsvI:X:" arg; do
case $arg in
h)
usage
......@@ -168,9 +189,15 @@ while getopts "hqvI:X:" arg; do
fi
include_paths=$(echo :${include_paths}: | substitute ":${p}:" ":" | sed -e 's|^:*||' -e 's|:*$||' -e 's|::*|:|g')
;;
d)
subdir=true
;;
q)
verbose=$((verbose-1))
;;
s)
sign=true
;;
v)
verbose=$((verbose+1))
;;
......@@ -236,12 +263,20 @@ install_deps () {
if [ ! -d "${outdir}" ]; then
outdir=.
fi
if $subdir; then
outdir="${outdir}/$(print_arch)"
mkdir -p "${outdir}"
fi
list_deps "$1" | while read dep; do
infile=$(basename "$1")
depfile=$(basename "${dep}")
if $subdir; then
loaderpath="@loader_path/$(print_arch)/${depfile}"
else
loaderpath="@loader_path/${depfile}"
fi
# make sure the binary looks for the dependency in the local path
install_name_tool -change "${dep}" "@loader_path/${depfile}" "$1"
install_name_tool -change "${dep}" "${loaderpath}" "$1"
if [ -e "${outdir}/${depfile}" ]; then
error "DEP: ${INSTALLDEPS_INDENT} ${dep} SKIPPED"
......@@ -251,7 +286,7 @@ install_deps () {
chmod u+w "${outdir}/${depfile}"
# make sure the dependency announces itself with the local path
install_name_tool -id "@loader_path/${depfile}" "${outdir}/${depfile}"
install_name_tool -id "${loaderpath}" "${outdir}/${depfile}"
# recursively call ourselves, to resolve higher-order dependencies
INSTALLDEPS_INDENT="${INSTALLDEPS_INDENT} " $0 "${outdir}/${depfile}"
fi
......@@ -269,3 +304,21 @@ for f in "$@"; do
install_deps "${f}"
fi
done
# Code signing
# On Monterey, binaries are automatically codesigned. Modifying them with this script renders the signature
# invalid. When Pd loads an external with an invalid signature, it exits immediately. Thus, we need to make sure
# that we codesign them again _after_ the localdeps process
# This needs to be the absolutely last step. We don't do it while we're still inside a recursion.
if $sign; then
echo -n "Code signing in progress... "
if $subdir; then
outdir="$(dirname "$1")/$(print_arch)"
else
outdir="$(dirname "$1")"
fi
codesign --remove-signature "${ARGS[@]}" ${outdir}/*.dylib
codesign -s - "${ARGS[@]}" ${outdir}/*.dylib
echo "Done"
fi
sign=false
subdir=false
verbose=${verbose:-0}
error() {
echo "$@" 1>&2
echo "$@" 1>&2
}
print_arch() {
# conflation of arch names follows rules
# from deken-plugin.tcl
arch=$(uname -m)
case $arch in
x86_64)
arch=amd64
;;
i486 | i586 | i686)
arch=i386
;;
armv6 | arm6l | arm7 | arm7l)
arch=arm
;;
esac
echo $arch
}
substitute() {
......@@ -87,6 +107,8 @@ usage: $0 [-I <includepath>] [-X <excludepath>] <binary> [<binary2> ...]
-I <includepath>: adds one include path entry
-X <excludepath>: adds one exclude path entry
-d: put localdeps into subdirectory named \$arch (Linux and macOS)
-s: codesign resulting binaries (macOS only)
-v: raise verbosity
-q: lower verbosity
......@@ -129,8 +151,7 @@ EOF
exit 1
}
while getopts "hqvI:X:" arg; do
while getopts "dhqsvI:X:" arg; do
case $arg in
h)
usage
......@@ -149,9 +170,15 @@ while getopts "hqvI:X:" arg; do
fi
include_paths=$(echo :${include_paths}: | substitute ":${p}:" ":" | sed -e 's|^:*||' -e 's|:*$||' -e 's|::*|:|g')
;;
d)
subdir=true
;;
q)
verbose=$((verbose-1))
;;
s)
sign=true
;;
v)
verbose=$((verbose+1))
;;
......
......@@ -28,10 +28,30 @@ else
# was copied from 'localdeps.utilities.source'.
# changes you make to this section will be lost.
#@BEGIN_UTILITIES@
sign=false
subdir=false
verbose=${verbose:-0}
error() {
echo "$@" 1>&2
echo "$@" 1>&2
}
print_arch() {
# conflation of arch names follows rules
# from deken-plugin.tcl
arch=$(uname -m)
case $arch in
x86_64)
arch=amd64
;;
i486 | i586 | i686)
arch=i386
;;
armv6 | arm6l | arm7 | arm7l)
arch=arm
;;
esac
echo $arch
}
substitute() {
......@@ -117,6 +137,8 @@ usage: $0 [-I <includepath>] [-X <excludepath>] <binary> [<binary2> ...]
-I <includepath>: adds one include path entry
-X <excludepath>: adds one exclude path entry
-d: put localdeps into subdirectory named \$arch (Linux and macOS)
-s: codesign resulting binaries (macOS only)
-v: raise verbosity
-q: lower verbosity
......@@ -159,8 +181,7 @@ EOF
exit 1
}
while getopts "hqvI:X:" arg; do
while getopts "dhqsvI:X:" arg; do
case $arg in
h)
usage
......@@ -179,9 +200,15 @@ while getopts "hqvI:X:" arg; do
fi
include_paths=$(echo :${include_paths}: | substitute ":${p}:" ":" | sed -e 's|^:*||' -e 's|:*$||' -e 's|::*|:|g')
;;
d)
subdir=true
;;
q)
verbose=$((verbose-1))
;;
s)
sign=true
;;
v)
verbose=$((verbose+1))
;;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment