forked from google/or-tools
-
Notifications
You must be signed in to change notification settings - Fork 2
/
universal.sh
executable file
·69 lines (60 loc) · 1.45 KB
/
universal.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
#!/usr/bin/env bash
set -xeuo pipefail
while [[ $# -gt 0 ]]; do
case $1 in
-a|--arm64)
ARM64_TAR="$2"
shift # past argument
shift # past value
;;
-x|--x86_64)
X86_64_TAR="$2"
shift # past argument
shift # past value
;;
-o|--out)
OUT_TAR="$2"
shift # past argument
shift # past value
;;
-*|--*)
echo "Unknown option $1"
exit 1
;;
esac
done
echo "ARM64_TAR = ${ARM64_TAR}"
echo "X86_64_TAR = ${X86_64_TAR}"
echo "OUT_TAR = ${OUT_TAR}"
PROJECT_DIR=$(pwd -P)
UNIVERSAL_DIR=${PROJECT_DIR}/universal
A_DIR=${UNIVERSAL_DIR}/a
X_DIR=${UNIVERSAL_DIR}/x
L_DIR=${UNIVERSAL_DIR}/lib
# create dir tree
mkdir -p "${UNIVERSAL_DIR}"
mkdir -p "${A_DIR}"
mkdir -p "${X_DIR}"
mkdir -p "${L_DIR}"
# extract
tar xzvf ${ARM64_TAR} --strip 1 -C ${A_DIR}
tar xzvf ${X86_64_TAR} --strip 1 -C ${X_DIR}
SYM_LINKS=$(find ${X_DIR} -mindepth 1 -type l)
X_COMBINE=$(find ${X_DIR} -mindepth 1 ! -type l)
A_COMBINE=$(find ${A_DIR} -mindepth 1 ! -type l)
SYM_ARR=(${SYM_LINKS})
X_ARR=(${X_COMBINE})
A_ARR=(${A_COMBINE})
# create universal files for each
for i in "${!X_ARR[@]}"; do
NAME=$(basename "${X_ARR[$i]}")
lipo -create -output ${L_DIR}/${NAME} "${X_ARR[$i]}" "${A_ARR[$i]}"
done
# copy over symlinks
for i in "${SYM_ARR[@]}"; do
cp -R "$i" ${L_DIR}
done
# create output tarball
tar czvf ${OUT_TAR} --no-same-owner -C ${UNIVERSAL_DIR} lib
# cleanup
rm -rf "${UNIVERSAL_DIR}"