-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathapp-bundle.sh
executable file
·140 lines (136 loc) · 6.13 KB
/
app-bundle.sh
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#!/bin/bash
#
# A script to create a self-contained bundle that can
# be put into /Applications
#
. ./config.sh
APP_DIR="${BUILT_PRODUCTS_DIR}/${FULL_PRODUCT_NAME}"
wc=`pwd | wc -c`
echo Bundling `echo "${APP_DIR}" | cut -c${wc}- | sed 's|^[^/]*/||'`
APP_CONTENTS="${APP_DIR}/Contents"
MACOS_BIN="${APP_CONTENTS}/MacOS"
FRAMEWORKS_FOLDER_PATH="${APP_CONTENTS}/Frameworks"
mkdir -p "${MACOS_BIN}"
rm -rf "${APP_CONTENTS}/Resources"
cp -pR "${RESOURCES_DIR}" "${APP_CONTENTS}"
if [ -e "${MACOS_BIN}/${Mod}" -a \
! "${BUILD_BIN}/${Mod}" -nt "${MACOS_BIN}/${Mod}" ]; then
echo `echo "${APP_DIR}" | cut -c${wc}- | sed 's|^[^/]*/||'`/Contents/MacOS/${Mod} is up to date.
exit 0
fi
cp -p "${BUILD_BIN}/${Mod}" "${MACOS_BIN}"
echo 'APPL????' > ${APP_CONTENTS}/PkgInfo
sed < "${RESOURCES_DIR}/Info.plist" > "${APP_CONTENTS}/Info.plist" \
-e 's/\$.EXECUTABLE_NAME./'"${EXECUTABLE_NAME}.sh/g" \
-e 's/\$.PRODUCT_NAME./'"${PRODUCT_NAME}/g" \
-e 's/\$.MACOSX_DEPLOYMENT_TARGET./'"${MACOSX_DEPLOYMENT_TARGET}/g"\
-e 's/\$.PRODUCT_BUNDLE_IDENTIFIER./'"${PRODUCT_BUNDLE_IDENTIFIER}/g"
cat > "${MACOS_BIN}/${EXECUTABLE_NAME}.sh" << EOF
#!/bin/bash
#
# Gtk Wrapper to set up environment
#
if test "x\$GTK_DEBUG_LAUNCHER" != x; then
set -x
fi
if test "x\$GTK_DEBUG_GDB" != x; then
EXEC="lldb --"
else
EXEC=exec
fi
name=$EXECUTABLE_NAME
tmp="\$0"
tmp=\`dirname "\$tmp"\`
tmp=\`dirname "\$tmp"\`
tmp=\`dirname "\$tmp"\`
bundle=\`cd "\$tmp" && pwd\`
bundle_contents="\$bundle"/Contents
bundle_res="\$bundle_contents"/Resources
bundle_frm="\$bundle_contents"/Frameworks
bundle_lib="\$bundle_res"/lib
bundle_bin="\$bundle_res"/bin
bundle_data="\$bundle_res"/share
bundle_etc="\$bundle_res"/etc
export DYLD_LIBRARY_PATH="\${bundle_frm}:\$bundle_lib"
export XDG_CONFIG_DIRS="\$bundle_etc"/xdg
export XDG_DATA_DIRS="\$bundle_data"
export GTK_DATA_PREFIX="\$bundle_res"
export GTK_EXE_PREFIX="\$bundle_res"
export GTK_PATH="\$bundle_res"
export PATH="\$bundle_contents/MacOS:\$bundle_bin:\$PATH"
# Strip out the argument added by the OS.
if /bin/expr "x\$1" : '^x-psn_' > /dev/null; then
shift 1
fi
\$EXEC "\$bundle_contents/MacOS/\$name" "\$@" \$EXTRA_ARGS
EOF
chmod +x "${MACOS_BIN}/${EXECUTABLE_NAME}.sh"
cd "${BUILT_PRODUCTS_DIR}/${FULL_PRODUCT_NAME}/Contents/MacOS"
LOG=/tmp/${Mod}-$$.log
TMPX=/tmp/${Mod}-xfiles.$$
SRTX=/tmp/${Mod}-srt.$$
mkdir -p ../Frameworks
rm -f ${TMPX}
for executable in ${PRODUCT_NAME} ; do
echo "`pwd`/$executable" >> ${TMPX}
for lib in `otool -L ${executable} | grep usr.local.Cellar | cut -f2 | cut -d' ' -f1` ; do
dst=`echo $lib | sed -e 's|/usr/local/.*lib/|@executable_path/../Frameworks/|'`
full=`echo $dst | sed -e "s|@executable_path|${BUILT_PRODUCTS_DIR}/${FULL_PRODUCT_NAME}/Contents/MacOS|"`
echo "${lib}|${dst}|${full}" >> ${TMPX}
echo cp -p "${lib}" "${BUILT_PRODUCTS_DIR}/${FULL_PRODUCT_NAME}/Contents/Frameworks" >> ${LOG}
cp -p "${lib}" "${BUILT_PRODUCTS_DIR}/${FULL_PRODUCT_NAME}/Contents/Frameworks" 2>/dev/null
for sublib in `otool -L ${lib} 2>/dev/null | grep usr.local.Cellar | cut -f2 | cut -d' ' -f1` ; do
dst=`echo $sublib | sed -e 's|/usr/local/.*lib/|@executable_path/../Frameworks/|'`
full=`echo $dst | sed -e "s|@executable_path|${BUILT_PRODUCTS_DIR}/${FULL_PRODUCT_NAME}/Contents/MacOS|"`
echo "${sublib}|${dst}|${full}" >> ${TMPX}
echo cp -p "${sublib}" "${BUILT_PRODUCTS_DIR}/${FULL_PRODUCT_NAME}/Contents/Frameworks" >> ${LOG}
cp -p "${sublib}" "${BUILT_PRODUCTS_DIR}/${FULL_PRODUCT_NAME}/Contents/Frameworks" 2>/dev/null
for ssublib in `otool -L ${sublib} 2>/dev/null | grep usr.local.Cellar | cut -f2 | cut -d' ' -f1` ; do
dst=`echo $ssublib | sed -e 's|/usr/local/.*lib/|@executable_path/../Frameworks/|'`
full=`echo $dst | sed -e "s|@executable_path|${BUILT_PRODUCTS_DIR}/${FULL_PRODUCT_NAME}/Contents/MacOS|"`
echo "${ssublib}|${dst}|${full}" >> ${TMPX}
echo cp -p "${ssublib}" "${BUILT_PRODUCTS_DIR}/${FULL_PRODUCT_NAME}/Contents/Frameworks" >> ${LOG}
cp -p "${ssublib}" "${BUILT_PRODUCTS_DIR}/${FULL_PRODUCT_NAME}/Contents/Frameworks" 2>/dev/null
done
done
done
for lib in `otool -L ${executable} | grep usr.local | cut -f2 | cut -d' ' -f1` ; do
dst=`echo $lib | sed -e 's|/usr/local/.*lib/|@executable_path/../Frameworks/|'`
full=`echo $dst | sed -e "s|@executable_path|${BUILT_PRODUCTS_DIR}/${FULL_PRODUCT_NAME}/Contents/MacOS|"`
echo "${lib}|${dst}|${full}" >> ${TMPX}
echo cp -p "${lib}" "${BUILT_PRODUCTS_DIR}/${FULL_PRODUCT_NAME}/Contents/Frameworks" >> ${LOG}
cp -p "${lib}" "${BUILT_PRODUCTS_DIR}/${FULL_PRODUCT_NAME}/Contents/Frameworks" 2>/dev/null
for sublib in `otool -L ${lib} 2>/dev/null | grep usr.local | cut -f2 | cut -d' ' -f1` ; do
dst=`echo $sublib | sed -e 's|/usr/local/.*lib/|@executable_path/../Frameworks/|'`
full=`echo $dst | sed -e "s|@executable_path|${BUILT_PRODUCTS_DIR}/${FULL_PRODUCT_NAME}/Contents/MacOS|"`
echo "${sublib}|${dst}|${full}" >> ${TMPX}
echo cp -p "${sublib}" "${BUILT_PRODUCTS_DIR}/${FULL_PRODUCT_NAME}/Contents/Frameworks" >> ${LOG}
cp -p "${sublib}" "${BUILT_PRODUCTS_DIR}/${FULL_PRODUCT_NAME}/Contents/Frameworks" 2>/dev/null
for ssublib in `otool -L ${sublib} 2>/dev/null | grep usr.local | cut -f2 | cut -d' ' -f1` ; do
dst=`echo $ssublib | sed -e 's|/usr/local/.*lib/|@executable_path/../Frameworks/|'`
full=`echo $dst | sed -e "s|@executable_path|${BUILT_PRODUCTS_DIR}/${FULL_PRODUCT_NAME}/Contents/MacOS|"`
echo "${ssublib}|${dst}|${full}" >> ${TMPX}
echo cp -p "${ssublib}" "${BUILT_PRODUCTS_DIR}/${FULL_PRODUCT_NAME}/Contents/Frameworks" >> ${LOG}
cp -p "${ssublib}" "${BUILT_PRODUCTS_DIR}/${FULL_PRODUCT_NAME}/Contents/Frameworks" 2>/dev/null
done
done
done
done
sort -u ${TMPX} >${SRTX}
for line in `cat ${SRTX}` ; do
full=`echo $line | cut -d'|' -f3`
if [ -e "$full" ] ; then
for lnk in `cat ${SRTX}` ; do
obj=`echo $lnk | cut -d'|' -f1`
dst=`echo $lnk | cut -d'|' -f2`
chmod +w "$full"
install_name_tool -change "$obj" "$dst" "$full"
#chmod -w "$full"
done
else
echo "'$full' is missing" >> ${LOG}
fi
done
rm -f ${TMPX}
rm -f ${SRTX}
printenv | sort >> ${LOG}