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 ...@@ -26,10 +26,30 @@ else
# was copied from 'localdeps.utilities.source'. # was copied from 'localdeps.utilities.source'.
# changes you make to this section will be lost. # changes you make to this section will be lost.
#@BEGIN_UTILITIES@ #@BEGIN_UTILITIES@
sign=false
subdir=false
verbose=${verbose:-0} verbose=${verbose:-0}
error() { 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() { substitute() {
...@@ -115,6 +135,8 @@ usage: $0 [-I <includepath>] [-X <excludepath>] <binary> [<binary2> ...] ...@@ -115,6 +135,8 @@ usage: $0 [-I <includepath>] [-X <excludepath>] <binary> [<binary2> ...]
-I <includepath>: adds one include path entry -I <includepath>: adds one include path entry
-X <excludepath>: adds one exclude 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 -v: raise verbosity
-q: lower verbosity -q: lower verbosity
...@@ -157,8 +179,7 @@ EOF ...@@ -157,8 +179,7 @@ EOF
exit 1 exit 1
} }
while getopts "dhqsvI:X:" arg; do
while getopts "hqvI:X:" arg; do
case $arg in case $arg in
h) h)
usage usage
...@@ -177,9 +198,15 @@ while getopts "hqvI:X:" arg; do ...@@ -177,9 +198,15 @@ while getopts "hqvI:X:" arg; do
fi fi
include_paths=$(echo :${include_paths}: | substitute ":${p}:" ":" | sed -e 's|^:*||' -e 's|:*$||' -e 's|::*|:|g') include_paths=$(echo :${include_paths}: | substitute ":${p}:" ":" | sed -e 's|^:*||' -e 's|:*$||' -e 's|::*|:|g')
;; ;;
d)
subdir=true
;;
q) q)
verbose=$((verbose-1)) verbose=$((verbose-1))
;; ;;
s)
sign=true
;;
v) v)
verbose=$((verbose+1)) verbose=$((verbose+1))
;; ;;
...@@ -199,23 +226,6 @@ fi ...@@ -199,23 +226,6 @@ fi
#@END_UTILITIES@ #@END_UTILITIES@
fi 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() { list_deps() {
local libpath local libpath
local inc local inc
...@@ -223,18 +233,22 @@ list_deps() { ...@@ -223,18 +233,22 @@ list_deps() {
| grep ' => ' \ | grep ' => ' \
| while read _ _ libpath _; do | while read _ _ libpath _; do
inc=$(check_includedep "${libpath}") inc=$(check_includedep "${libpath}")
if [ "x${inc}" != "x" ]; then if [ "x${inc}" != "x" ]; then
echo "${inc}" echo "${inc}"
fi fi
done done
} }
install_deps () { install_deps () {
# make a local copy of all linked libraries of given binary # make a local copy of all linked libraries of given binary
# and set RUNPATH to $ORIGIN (exclude "standard" libraries) # and set RUNPATH to $ORIGIN (exclude "standard" libraries)
# arg1: binary to check # arg1: binary to check
local outdir=$(dirname "$1") local outdir
local outfile local outfile
if $subdir; then
outdir="$(dirname "$1")/$(print_arch)"
else
outdir="$(dirname "$1")"
fi
if [ ! -d "${outdir}" ]; then if [ ! -d "${outdir}" ]; then
outdir=. outdir=.
fi fi
...@@ -253,7 +267,11 @@ install_deps () { ...@@ -253,7 +267,11 @@ install_deps () {
patchelf --set-rpath \$ORIGIN "${outfile}" patchelf --set-rpath \$ORIGIN "${outfile}"
fi fi
done 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 ...@@ -267,5 +285,8 @@ for f in "$@"; do
error "Skipping '${f}'. Is it a binary file?" error "Skipping '${f}'. Is it a binary file?"
continue continue
fi fi
if $subdir; then
mkdir -p "$(dirname ${f})/$(print_arch)"
fi
install_deps "${f}" install_deps "${f}"
done done
...@@ -17,10 +17,30 @@ else ...@@ -17,10 +17,30 @@ else
# was copied from 'localdeps.utilities.source'. # was copied from 'localdeps.utilities.source'.
# changes you make to this section will be lost. # changes you make to this section will be lost.
#@BEGIN_UTILITIES@ #@BEGIN_UTILITIES@
sign=false
subdir=false
verbose=${verbose:-0} verbose=${verbose:-0}
error() { 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() { substitute() {
...@@ -106,6 +126,8 @@ usage: $0 [-I <includepath>] [-X <excludepath>] <binary> [<binary2> ...] ...@@ -106,6 +126,8 @@ usage: $0 [-I <includepath>] [-X <excludepath>] <binary> [<binary2> ...]
-I <includepath>: adds one include path entry -I <includepath>: adds one include path entry
-X <excludepath>: adds one exclude 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 -v: raise verbosity
-q: lower verbosity -q: lower verbosity
...@@ -148,8 +170,7 @@ EOF ...@@ -148,8 +170,7 @@ EOF
exit 1 exit 1
} }
while getopts "dhqsvI:X:" arg; do
while getopts "hqvI:X:" arg; do
case $arg in case $arg in
h) h)
usage usage
...@@ -168,9 +189,15 @@ while getopts "hqvI:X:" arg; do ...@@ -168,9 +189,15 @@ while getopts "hqvI:X:" arg; do
fi fi
include_paths=$(echo :${include_paths}: | substitute ":${p}:" ":" | sed -e 's|^:*||' -e 's|:*$||' -e 's|::*|:|g') include_paths=$(echo :${include_paths}: | substitute ":${p}:" ":" | sed -e 's|^:*||' -e 's|:*$||' -e 's|::*|:|g')
;; ;;
d)
subdir=true
;;
q) q)
verbose=$((verbose-1)) verbose=$((verbose-1))
;; ;;
s)
sign=true
;;
v) v)
verbose=$((verbose+1)) verbose=$((verbose+1))
;; ;;
...@@ -236,12 +263,20 @@ install_deps () { ...@@ -236,12 +263,20 @@ install_deps () {
if [ ! -d "${outdir}" ]; then if [ ! -d "${outdir}" ]; then
outdir=. outdir=.
fi fi
if $subdir; then
outdir="${outdir}/$(print_arch)"
mkdir -p "${outdir}"
fi
list_deps "$1" | while read dep; do list_deps "$1" | while read dep; do
infile=$(basename "$1") infile=$(basename "$1")
depfile=$(basename "${dep}") 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 # 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 if [ -e "${outdir}/${depfile}" ]; then
error "DEP: ${INSTALLDEPS_INDENT} ${dep} SKIPPED" error "DEP: ${INSTALLDEPS_INDENT} ${dep} SKIPPED"
...@@ -251,7 +286,7 @@ install_deps () { ...@@ -251,7 +286,7 @@ install_deps () {
chmod u+w "${outdir}/${depfile}" chmod u+w "${outdir}/${depfile}"
# make sure the dependency announces itself with the local path # 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 # recursively call ourselves, to resolve higher-order dependencies
INSTALLDEPS_INDENT="${INSTALLDEPS_INDENT} " $0 "${outdir}/${depfile}" INSTALLDEPS_INDENT="${INSTALLDEPS_INDENT} " $0 "${outdir}/${depfile}"
fi fi
...@@ -269,3 +304,21 @@ for f in "$@"; do ...@@ -269,3 +304,21 @@ for f in "$@"; do
install_deps "${f}" install_deps "${f}"
fi fi
done 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} verbose=${verbose:-0}
error() { 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() { substitute() {
...@@ -87,6 +107,8 @@ usage: $0 [-I <includepath>] [-X <excludepath>] <binary> [<binary2> ...] ...@@ -87,6 +107,8 @@ usage: $0 [-I <includepath>] [-X <excludepath>] <binary> [<binary2> ...]
-I <includepath>: adds one include path entry -I <includepath>: adds one include path entry
-X <excludepath>: adds one exclude 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 -v: raise verbosity
-q: lower verbosity -q: lower verbosity
...@@ -129,8 +151,7 @@ EOF ...@@ -129,8 +151,7 @@ EOF
exit 1 exit 1
} }
while getopts "dhqsvI:X:" arg; do
while getopts "hqvI:X:" arg; do
case $arg in case $arg in
h) h)
usage usage
...@@ -149,9 +170,15 @@ while getopts "hqvI:X:" arg; do ...@@ -149,9 +170,15 @@ while getopts "hqvI:X:" arg; do
fi fi
include_paths=$(echo :${include_paths}: | substitute ":${p}:" ":" | sed -e 's|^:*||' -e 's|:*$||' -e 's|::*|:|g') include_paths=$(echo :${include_paths}: | substitute ":${p}:" ":" | sed -e 's|^:*||' -e 's|:*$||' -e 's|::*|:|g')
;; ;;
d)
subdir=true
;;
q) q)
verbose=$((verbose-1)) verbose=$((verbose-1))
;; ;;
s)
sign=true
;;
v) v)
verbose=$((verbose+1)) verbose=$((verbose+1))
;; ;;
......
...@@ -28,10 +28,30 @@ else ...@@ -28,10 +28,30 @@ else
# was copied from 'localdeps.utilities.source'. # was copied from 'localdeps.utilities.source'.
# changes you make to this section will be lost. # changes you make to this section will be lost.
#@BEGIN_UTILITIES@ #@BEGIN_UTILITIES@
sign=false
subdir=false
verbose=${verbose:-0} verbose=${verbose:-0}
error() { 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() { substitute() {
...@@ -117,6 +137,8 @@ usage: $0 [-I <includepath>] [-X <excludepath>] <binary> [<binary2> ...] ...@@ -117,6 +137,8 @@ usage: $0 [-I <includepath>] [-X <excludepath>] <binary> [<binary2> ...]
-I <includepath>: adds one include path entry -I <includepath>: adds one include path entry
-X <excludepath>: adds one exclude 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 -v: raise verbosity
-q: lower verbosity -q: lower verbosity
...@@ -159,8 +181,7 @@ EOF ...@@ -159,8 +181,7 @@ EOF
exit 1 exit 1
} }
while getopts "dhqsvI:X:" arg; do
while getopts "hqvI:X:" arg; do
case $arg in case $arg in
h) h)
usage usage
...@@ -179,9 +200,15 @@ while getopts "hqvI:X:" arg; do ...@@ -179,9 +200,15 @@ while getopts "hqvI:X:" arg; do
fi fi
include_paths=$(echo :${include_paths}: | substitute ":${p}:" ":" | sed -e 's|^:*||' -e 's|:*$||' -e 's|::*|:|g') include_paths=$(echo :${include_paths}: | substitute ":${p}:" ":" | sed -e 's|^:*||' -e 's|:*$||' -e 's|::*|:|g')
;; ;;
d)
subdir=true
;;
q) q)
verbose=$((verbose-1)) verbose=$((verbose-1))
;; ;;
s)
sign=true
;;
v) v)
verbose=$((verbose+1)) 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