| 1 |
#!/usr/bin/env bash |
| 2 |
|
| 3 |
# This file is part of the LibreOffice project. |
| 4 |
# |
| 5 |
# This Source Code Form is subject to the terms of the Mozilla Public |
| 6 |
# License, v. 2.0. If a copy of the MPL was not distributed with this |
| 7 |
# file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 8 |
|
| 9 |
# Exit on errors |
| 10 |
set -e |
| 11 |
|
| 12 |
# Use of unset variable is an error |
| 13 |
set -u |
| 14 |
|
| 15 |
# If any part of a pipeline of commands fails, the whole pipeline fails |
| 16 |
set -o pipefail |
| 17 |
|
| 18 |
if [ `uname` != Darwin ]; then |
| 19 |
echo This is for macOS only >&2 |
| 20 |
exit 1 |
| 21 |
fi |
| 22 |
|
| 23 |
if [ $# != 3 ]; then |
| 24 |
echo Usage: $0 app-bundle-1 app-bundle-2 output-app-bundle |
| 25 |
exit 1 |
| 26 |
fi |
| 27 |
|
| 28 |
if [ -d "$3" ]; then |
| 29 |
echo The directory $3 exists already |
| 30 |
exit 1 |
| 31 |
fi |
| 32 |
|
| 33 |
if [ -f "$3" ]; then |
| 34 |
echo $3 exists and is a file |
| 35 |
exit 1 |
| 36 |
fi |
| 37 |
|
| 38 |
if [ ! -d "$1" ]; then |
| 39 |
echo No such directory: $1 |
| 40 |
exit 1 |
| 41 |
fi |
| 42 |
|
| 43 |
if [ ! -d "$2" ]; then |
| 44 |
echo No such directory: $2 |
| 45 |
exit 1 |
| 46 |
fi |
| 47 |
|
| 48 |
ONE=$(cd "$1" && /bin/pwd) |
| 49 |
TWO=$(cd "$2" && /bin/pwd) |
| 50 |
mkdir "$3" |
| 51 |
OUT=$(cd "$3" && /bin/pwd) |
| 52 |
|
| 53 |
# Create all directories |
| 54 |
( |
| 55 |
cd "$ONE" |
| 56 |
find . -type d -print |
| 57 |
) | |
| 58 |
( |
| 59 |
cd "$OUT" |
| 60 |
while read dirname; do |
| 61 |
mkdir -p "$dirname" |
| 62 |
done |
| 63 |
) |
| 64 |
|
| 65 |
# Check which files in 1 exist in 2, and if they are executable, merge them into a fat copy. For |
| 66 |
# other files, just use one copy, assuming they are equivalent in most cases. |
| 67 |
( |
| 68 |
cd "$ONE" |
| 69 |
find . -type l -or -type f |
| 70 |
) | |
| 71 |
( |
| 72 |
cd "$TWO" |
| 73 |
while read fname; do |
| 74 |
if test -L "$fname"; then |
| 75 |
ln -s $(readlink "$fname") "$OUT/$fname" |
| 76 |
elif test -f "$fname"; then |
| 77 |
case "$fname" in |
| 78 |
*.so | \ |
| 79 |
*.jnilib | \ |
| 80 |
*.jnilib.* | \ |
| 81 |
*.dylib | \ |
| 82 |
*.dylib.* | \ |
| 83 |
*/Frameworks/LibreOfficePython.framework/Versions/*/LibreOfficePython | \ |
| 84 |
*/Frameworks/LibreOfficePython.framework/Versions/*/Resources/Python.app/Contents/MacOS/LibreOfficePython | \ |
| 85 |
*/Library/Spotlight/OOoSpotlightImporter.mdimporter/Contents/MacOS/OOoSpotlightImporter) |
| 86 |
lipo -create -output "$OUT/$fname" "$fname" "$ONE/$fname" |
| 87 |
;; |
| 88 |
# Ignore differences in these files. Let's hope it's just the timestamps. |
| 89 |
*.ot[tp] | \ |
| 90 |
*.bau | \ |
| 91 |
*.pyc | \ |
| 92 |
*/_sysconfigdata_m_darwin_darwin.py | \ |
| 93 |
*/Contents/Resources/firebird/security3.fdb | \ |
| 94 |
*/Contents/Resources/autocorr/acor_*.dat | \ |
| 95 |
*/Contents/Resources/resource/*/LC_MESSAGES/*.mo | \ |
| 96 |
*/Contents/Resources/config/images_*.zip) |
| 97 |
cp "$fname" "$OUT/$fname" |
| 98 |
;; |
| 99 |
*) |
| 100 |
case $(file --brief "$fname") in |
| 101 |
Mach-O\ 64-bit\ executable\ *) |
| 102 |
lipo -create -output "$OUT/$fname" "$fname" "$ONE/$fname" |
| 103 |
;; |
| 104 |
*) |
| 105 |
cmp -s "$fname" "$ONE/$fname" || |
| 106 |
echo "$fname differs and is not an executable!?" >&2 |
| 107 |
cp "$fname" "$OUT/$fname" |
| 108 |
esac |
| 109 |
esac |
| 110 |
else |
| 111 |
# We ignore some files that can't be built for macOS on arm64 for now |
| 112 |
case "$fname" in |
| 113 |
./Contents/Frameworks/LibreOfficePython.framework/Versions/3.*/lib/python*/lib-dynload/_ctypes.cpython-*m.so) |
| 114 |
;; |
| 115 |
*) |
| 116 |
echo "$fname does not exist in $TWO" >&2 |
| 117 |
;; |
| 118 |
esac |
| 119 |
cp "$ONE/$fname" "$OUT/$fname" |
| 120 |
fi |
| 121 |
done |
| 122 |
) |
| 123 |
|
| 124 |
# Look for files in 2 that don't exist in 1 |
| 125 |
( |
| 126 |
cd "$TWO" |
| 127 |
find . -type f -print |
| 128 |
) | |
| 129 |
( |
| 130 |
cd "$ONE" |
| 131 |
while read fname; do |
| 132 |
if test -f "$fname"; then |
| 133 |
: |
| 134 |
else |
| 135 |
echo "$fname does not exist in $ONE" >&2 |
| 136 |
cp "$TWO/$fname" "$OUT/$fname" |
| 137 |
fi |
| 138 |
done |
| 139 |
) |
| 140 |
|
| 141 |
# Local Variables: |
| 142 |
# tab-width: 4 |
| 143 |
# indent-tabs-mode: nil |
| 144 |
# fill-column: 100 |
| 145 |
# End: |