File: change-rpath.sh

package info (click to toggle)
obs-command-source 0.5.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 284 kB
  • sloc: ansic: 400; python: 80; sh: 75; makefile: 21; cpp: 16
file content (74 lines) | stat: -rwxr-xr-x 1,770 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#! /bin/bash

libdir=''
obsver=''

while (($# > 0)); do
	case "$1" in
		-lib)
			libdir="$2"
			shift 2;;
		-obs)
			obsver="$2"
			shift 2;;
		*)
			break ;;
	esac
done

set -e

function copy_local_dylib
{
	local dylib
	t=$(mktemp)
	otool -L $1 > $t
	awk '/^	\/usr\/local\/(opt|Cellar)\/.*\.dylib/{print $1}' $t |
	while read -r dylib; do
		echo "Changing dependency $1 -> $dylib"
		local b=$(basename $dylib)
		if test ! -e $libdir/$b; then
			mkdir -p $libdir
			cp $dylib $libdir
			chmod +rwx $libdir/$b
			install_name_tool -id "@loader_path/$b" $libdir/$b
			copy_local_dylib $libdir/$b
		fi
		install_name_tool -change "$dylib" "@loader_path/../$libdir/$b" $1
	done
	rm -f "$t"
}

function change_obs27_libs
{
	# obs-frontend-api:
	# OBS 27.2 provides only `libobs-frontend-api.dylib`.
	# OBS 28.0 will provide `libobs-frontend-api.1.dylib` and `libobs-frontend-api.dylib`.
	# libobs:
	# Both OBS 27.2 and 28.0 provides `libobs.dylib`, `libobs.0.dylib`, `libobs.framework/Versions/A/libobs`.

	install_name_tool \
		-change @rpath/QtWidgets.framework/Versions/5/QtWidgets \
			@executable_path/../Frameworks/QtWidgets.framework/Versions/5/QtWidgets \
		-change @rpath/QtGui.framework/Versions/5/QtGui \
			@executable_path/../Frameworks/QtGui.framework/Versions/5/QtGui \
		-change @rpath/QtCore.framework/Versions/5/QtCore \
			@executable_path/../Frameworks/QtCore.framework/Versions/5/QtCore \
		-change @rpath/libobs.framework/Versions/A/libobs \
			@rpath/libobs.0.dylib \
		-change @rpath/libobs-frontend-api.0.dylib \
			@rpath/libobs-frontend-api.dylib \
		"$1"
}

for i in "$@"; do
	case "$obsver" in
		27 | 27.*)
			change_obs27_libs "$i"
			;;
		28 | 28.*)
			: # Not necessary to change dylib paths for OBS 28
			;;
	esac
	copy_local_dylib "$i"
done