-
Notifications
You must be signed in to change notification settings - Fork 0
/
gen.sh
executable file
·199 lines (172 loc) · 4.27 KB
/
gen.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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
#!/bin/bash
SRC=$(realpath $(cd -P "$(dirname "${BASH_SOURCE[0]}")" && pwd))
set -e
declare -A TARGETS=(
[darwin_amd64]=darwin_x86_64
[darwin_arm64]=darwin_aarch64
[linux_amd64]=linux_x86_64-full
[linux_arm64]=linux_arm64-full
[linux_arm]=linux_armv7
[windows_amd64]=windows_static-x64-posix
# [windows_arm64]=windows_arm64
)
BUILD_TARGETS=
CLEAN=0
CACHE=$SRC/.cache
BUILDS=
UPDATE=0
OPTIND=1
while getopts "t:b:cC:u" opt; do
case "$opt" in
t) BUILD_TARGETS=$OPTARG ;;
b) BUILDS=$OPTARG ;;
c) CLEAN=1 ;;
C) CACHE=$OPTARG ;;
u) UPDATE=1 ;;
esac
done
mkdir -p $CACHE
CACHE=$(realpath "$CACHE")
relname() {
sed -e "s%^$PWD/%%" <<< "$1"
}
osxcross() {
local target=$1 extra=$2
local build_target="${TARGETS[$target]}"
local platform=$(sed -e 's/[-_]/ /' <<< "$build_target"|awk '{print $1}')
local arch=$(sed -e 's/[-_]/ /' <<< "$build_target"|awk '{print $2}')
if [ ! -z "$extra" ]; then
extra+=" "
fi
# add builds
for build in $BUILDS; do
extra+="-b $build "
done
# enable kvazaar for arm64
case $target in
darwin_arm64) extra+="-k ON ";;
esac
# determine osxcross config info
local osxcross_conf=$(type -p osxcross-conf)
if [ -z "$osxcross_conf" ]; then
echo "error: could not find osxcross-conf"
exit 1
fi
eval "$($osxcross_conf)"
if [ -z "$OSXCROSS_TARGET" ]; then
echo "error: OSXCROSS_TARGET is empty!"
exit 1
fi
dockcross linux_amd64 "-D $target.preset"
CROSS_TRIPLE="$arch-apple-$OSXCROSS_TARGET" \
$SRC/build.sh \
-d $SRC/.cache/$target \
-P $target.preset \
$extra
}
dockcross() {
local target=$1 extra=$2
local build_target="${TARGETS[$target]}"
local platform=$(sed -e 's/[-_]/ /' <<< "$build_target"|awk '{print $1}')
local arch=$(sed -e 's/[-_]/ /' <<< "$build_target"|awk '{print $2}')
local image="docker.io/dockcross/$platform-$arch:latest"
if [ ! -z "$extra" ]; then
extra+=" "
fi
# add builds
for build in $BUILDS; do
extra+="-b $build "
done
# disable svt-av1 for arm
case $target in
linux_arm) extra+="-s OFF " ;;
windows_arm64) extra+="-s OFF -k OFF " ;;
esac
if [ "$UPDATE" = "1" ]; then
(set -x;
podman pull $image
)
fi
(set -x;
podman run \
--rm \
$image \
> $CACHE/build-$target.sh
chmod +x $CACHE/build-$target.sh
)
pushd $SRC &> /dev/null
(set -x;
$CACHE/build-$target.sh \
bash -c "./build.sh -d .cache/$target $extra"
)
popd &> /dev/null
}
wincross() {
local target=$1 extra=$2
dockcross linux_amd64 "-D $target.preset"
dockcross "$target" "-P $target.preset $extra"
}
if [ -z "$BUILD_TARGETS" ]; then
BUILD_TARGETS="${!TARGETS[@]}"
fi
BUILD_TARGETS=$(sed -e 's/\s\+/\n/g' <<< "$BUILD_TARGETS"|sort -i|tr '\n' ' ')
echo "TARGETS: $BUILD_TARGETS"
for TARGET in $BUILD_TARGETS; do
BUILD_DIR=$CACHE/$TARGET
BUILD_TARGET="${TARGETS[$TARGET]}"
PLATFORM=$(sed -e 's/[-_]/ /' <<< "$BUILD_TARGET"|awk '{print $1}')
ARCH=$(sed -e 's/[-_]/ /' <<< "$BUILD_TARGET"|awk '{print $2}')
DEST=$SRC/libheif/$TARGET
if [[ -z "$BUILD_TARGET" || -z "$PLATFORM" || -z "$ARCH" ]]; then
echo "error: invalid target '$TARGET'"
exit 1
fi
if [ "$CLEAN" = "1" ]; then
(set -x;
rm -rf $BUILD_DIR $DEST
)
fi
echo "GENERATING: $TARGET -> $(relname "$BUILD_DIR") ($PLATFORM/$ARCH)"
case $TARGET in
darwin*) osxcross "$TARGET" ;;
windows*) wincross "$TARGET" ;;
*) dockcross "$TARGET" ;;
esac
DIST_DIR=$BUILD_DIR/dist
mkdir -p $DEST
(set -x;
cp $DIST_DIR/lib/*.a $DEST
chmod 0644 $DEST/*.a
cp $DIST_DIR/include/libheif/heif{,_version}.h $SRC/libheif
perl -pi -e 's/#define LIBHEIF_PLUGIN_DIRECTORY.*/#define LIBHEIF_PLUGIN_DIRECTORY ""/' $SRC/libheif/heif_version.h
)
done
#cp $WORKDIR/libheif/libheif/heif.h $SRC/libheif
#
## generate supported file types
#BRANDS=$(sed -n 's/^#define heif_brand2_\([a-z0-9]\+\).*/\1/p' < $WORKDIR/libheif/libheif/heif.h)
#
#REG=""
#for brand in $BRANDS; do
# REG+="$(cat << END
# image.RegisterFormat("${brand}", "????ftyp${brand}", Decode, DecodeConfig);
#END
#)"
#done
#
#cat > $SRC/z.go << END
#package heif
#
#import (
# "image"
#)
#
#// REPLACE
#
#func init() {
# $REG
#}
#END
#
#gofumpt -w -extra $SRC/z.go
#perl -pi -e 's/REPLACE/Generated by gen.sh. DO NOT EDIT./' $SRC/z.go