summaryrefslogtreecommitdiff
path: root/contrib/SDL-3.2.8/src/hidapi/testgui/copy_to_bundle.sh
diff options
context:
space:
mode:
author3gg <3gg@shellblade.net>2025-12-27 12:03:39 -0800
committer3gg <3gg@shellblade.net>2025-12-27 12:03:39 -0800
commit5a079a2d114f96d4847d1ee305d5b7c16eeec50e (patch)
tree8926ab44f168acf787d8e19608857b3af0f82758 /contrib/SDL-3.2.8/src/hidapi/testgui/copy_to_bundle.sh
Initial commit
Diffstat (limited to 'contrib/SDL-3.2.8/src/hidapi/testgui/copy_to_bundle.sh')
-rwxr-xr-xcontrib/SDL-3.2.8/src/hidapi/testgui/copy_to_bundle.sh98
1 files changed, 98 insertions, 0 deletions
diff --git a/contrib/SDL-3.2.8/src/hidapi/testgui/copy_to_bundle.sh b/contrib/SDL-3.2.8/src/hidapi/testgui/copy_to_bundle.sh
new file mode 100755
index 0000000..ddff64f
--- /dev/null
+++ b/contrib/SDL-3.2.8/src/hidapi/testgui/copy_to_bundle.sh
@@ -0,0 +1,98 @@
1#!/bin/bash
2
3#### Configuration:
4# The name of the executable. It is assumed
5# that it is in the current working directory.
6EXE_NAME=hidapi-testgui
7# Path to the executable directory inside the bundle.
8# This must be an absolute path, so use $PWD.
9EXEPATH=$PWD/TestGUI.app/Contents/MacOS
10# Libraries to explicitly bundle, even though they
11# may not be in /opt/local. One per line. These
12# are used with grep, so only a portion of the name
13# is required. eg: libFOX, libz, etc.
14LIBS_TO_BUNDLE=libFOX
15
16
17function copydeps {
18 local file=$1
19 # echo "Copying deps for $file...."
20 local BASE_OF_EXE=`basename $file`
21
22 # A will contain the dependencies of this library
23 local A=`otool -LX $file |cut -f 1 -d " "`
24 local i
25 for i in $A; do
26 local BASE=`basename $i`
27
28 # See if it's a lib we specifically want to bundle
29 local bundle_this_lib=0
30 local j
31 for j in $LIBS_TO_BUNDLE; do
32 echo $i |grep -q $j
33 if [ $? -eq 0 ]; then
34 bundle_this_lib=1
35 echo "bundling $i because it's in the list."
36 break;
37 fi
38 done
39
40 # See if it's in /opt/local. Bundle all in /opt/local
41 local isOptLocal=0
42 echo $i |grep -q /opt/local
43 if [ $? -eq 0 ]; then
44 isOptLocal=1
45 echo "bundling $i because it's in /opt/local."
46 fi
47
48 # Bundle the library
49 if [ $isOptLocal -ne 0 ] || [ $bundle_this_lib -ne 0 ]; then
50
51 # Copy the file into the bundle if it exists.
52 if [ -f $EXEPATH/$BASE ]; then
53 z=0
54 else
55 cp $i $EXEPATH
56 chmod 755 $EXEPATH/$BASE
57 fi
58
59
60 # echo "$BASE_OF_EXE depends on $BASE"
61
62 # Fix the paths using install_name_tool and then
63 # call this function recursively for each dependency
64 # of this library.
65 if [ $BASE_OF_EXE != $BASE ]; then
66
67 # Fix the paths
68 install_name_tool -id @executable_path/$BASE $EXEPATH/$BASE
69 install_name_tool -change $i @executable_path/$BASE $EXEPATH/$BASE_OF_EXE
70
71 # Call this function (recursive) on
72 # on each dependency of this library.
73 copydeps $EXEPATH/$BASE
74 fi
75 fi
76 done
77}
78
79rm -f $EXEPATH/*
80mkdir -p $EXEPATH
81
82# Copy the binary into the bundle. Use ../libtool to do this if it's
83# available because if $EXE_NAME was built with autotools, it will be
84# necessary. If ../libtool not available, just use cp to do the copy, but
85# only if $EXE_NAME is a binary.
86if [ -x ../libtool ]; then
87 ../libtool --mode=install cp $EXE_NAME $EXEPATH
88else
89 file -bI $EXE_NAME |grep binary
90 if [ $? -ne 0 ]; then
91 echo "There is no ../libtool and $EXE_NAME is not a binary."
92 echo "I'm not sure what to do."
93 exit 1
94 else
95 cp $EXE_NAME $EXEPATH
96 fi
97fi
98copydeps $EXEPATH/$EXE_NAME