This repository was archived by the owner on Apr 13, 2024. It is now read-only.
forked from kidrigger/godot-videodecoder
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild_gdextension.sh
executable file
·237 lines (205 loc) · 8.9 KB
/
build_gdextension.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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
#! /bin/bash
# For osx you must download XCode 7 and extract/generate ./darwin_sdk/MacOSX10.11.sdk.tar.gz
# by following these instructions: https://github.com/tpoechtrager/osxcross#packaging-the-sdk
# NOTE: for darwin15 support use: https://developer.apple.com/download/more/?name=Xcode%207.3.1
# To use a different MacOSX*.*.sdk.tar.gz sdk set XCODE_SDK
# e.g. XCODE_SDK=$PWD/darwin_sdk/MacOSX10.15.sdk.tar.gz ./build_gdextension.sh
# usage: ADDON_BIN_DIR=$PWD/godot/addons/bin ./contrib/godot-videodecoder/build_gdextension.sh
# (from within your project where this is a submodule installed at ./contrib/godot-videodecoder/build_gdextension.sh/)
# The Dockerfile will run a container to compile everything:
# http://docs.godotengine.org/en/3.2/development/compiling/compiling_for_x11.html
# http://docs.godotengine.org/en/3.2/development/compiling/compiling_for_windows.html#cross-compiling-for-windows-from-other-operating-systems
# http://docs.godotengine.org/en/3.2/development/compiling/compiling_for_osx.html#cross-compiling-for-macos-from-linux
DIR="$(cd $(dirname "$0") && pwd)"
ADDON_BIN_DIR=${ADDON_BIN_DIR:-$DIR/target}
THIRDPARTY_DIR=${THIRDPARTY_DIR:-$DIR/thirdparty}
# COPY can't use variables, so pre-copy the file
XCODE_SDK_FOR_COPY=./darwin_sdk/MacOSX12.3.sdk.tar.xz
XCODE_SDK="${XCODE_SDK:-$XCODE_SDK_FOR_COPY}"
# set FF_ENABLE=everything to make a 14MiB build with all the LGPL features
FF_ENABLE="vp8 vp9 opus vorbis"
SUBMODULES_OK=1
if ! [ -f "$DIR/godot-cpp/gdextension/gdextension_interface.h" ]; then
echo "godot-cpp headers are missing."
echo " Please run the following:"
echo ""
echo " git submodule update --init godot-cpp"
echo ""
SUBMODULES_OK=
fi
if ! [ -f "$DIR/ffmpeg-static/build.sh" ]; then
echo "ffmpeg-static headers are missing."
echo " Please run the following:"
echo ""
echo " git submodule update --init ffmpeg-static"
echo ""
SUBMODULES_OK=
fi
if ! [ $SUBMODULES_OK ]; then
echo "Aborting due to missing submodules"
exit 1
fi
if [ -z "$PLATFORMS" ]; then
PLATFORM_LIST=(windows_32 windows_64 macos_x86 macos_arm64 linux_64 linux_32)
else
IFS=',' read -r -a PLATFORM_LIST <<< "$PLATFORMS"
fi
declare -A PLATMAP
for p in "${PLATFORM_LIST[@]}"; do
PLATMAP[$p]=1
done
echo "Building for ${PLATFORM_LIST[@]}"
plat_windows_64=${PLATMAP['windows_64']}
plat_windows_32=${PLATMAP['windows_32']}
plat_macos_x86=${PLATMAP['macos_x86']}
plat_macos_arm64=${PLATMAP['macos_arm64']}
plat_linux_64=${PLATMAP['linux_64']}
plat_linux_32=${PLATMAP['linux_32']}
plat_windows_any=${PLATMAP['windows_64']}${PLATMAP['windows_32']}
plat_macos_any=${PLATMAP['macos_x86']}${PLATMAP['macos_arm64']}
plat_linux_any=${PLATMAP['linux_64']}${PLATMAP['linux_32']}
if ! [ "$JOBS" ]; then
if [ -f /proc/cpuinfo ]; then
JOBS=$(expr $(cat /proc/cpuinfo | grep processor | wc -l) - 1)
elif type sysctl > /dev/null; then
# osx logical cores
JOBS=$(sysctl -n hw.ncpu)
else
JOBS=4
echo "Unable to determine how many logical cores are available."
fi
fi
echo "Using JOBS=$JOBS"
#img_version="$(git describe 2>/dev/null || git rev-parse HEAD)"
# TODO : pass in img_version like https://github.com/godotengine/build-containers/blob/master/Dockerfile.osx#L1
if [ $plat_macos_any ]; then
echo "XCODE_SDK=$XCODE_SDK"
if [ ! -f "$XCODE_SDK" ]; then
ls -l "$XCODE_SDK"
echo "Unable to find $XCODE_SDK"
exit 1
fi
if [ ! "$XCODE_SDK" = "$XCODE_SDK_FOR_COPY" ]; then
mkdir -p $(dirname "$XCODE_SDK_FOR_COPY")
cp "$XCODE_SDK" "$XCODE_SDK_FOR_COPY"
fi
fi
set -e
# ideally we'd run these at the same time but ... https://github.com/moby/moby/issues/2776
if [ $plat_linux_any ]; then
docker build ./ -f Dockerfile.ubuntu-linux -t "godot-videodecoder-ubuntu-linux"
fi
# bionic is for cross compiles, use xenial for linux
# (for ubuntu 16 compatibility even though it's outdated already)
if [ $plat_macos_any ]; then
echo "building with xcode sdk"
docker build ./ -f Dockerfile.ubuntu-macos -t "godot-videodecoder-ubuntu-macos" \
--build-arg XCODE_SDK=$XCODE_SDK
elif [ $plat_windows_any ]; then
echo "building without xcode sdk"
docker build ./ -f Dockerfile.ubuntu-windows -t "godot-videodecoder-ubuntu-windows"
fi
if [ $plat_macos_x86 ]; then
echo "Building for macOS - x86_64"
docker build ./ -f Dockerfile.macos_x86 --build-arg JOBS=$JOBS -t "godot-videodecoder-macos_x86"
fi
if [ $plat_macos_arm64 ]; then
echo "Building for macOS - arm64"
docker build ./ -f Dockerfile.macos_arm64 --build-arg JOBS=$JOBS -t "godot-videodecoder-macos_arm64"
fi
if [ $plat_linux_64 ]; then
echo "Building for Linux - 64 bits"
docker build ./ -f Dockerfile.linux_64 --build-arg JOBS=$JOBS -t "godot-videodecoder-linux_64"
fi
if [ $plat_linux_32 ]; then
echo "Building for Linux - 32 bits"
docker build ./ -f Dockerfile.linux_32 --build-arg JOBS=$JOBS -t "godot-videodecoder-linux_32"
fi
if [ $plat_windows_64 ]; then
echo "Building for Windows - 64 bits"
docker build ./ -f Dockerfile.windows_64 --build-arg JOBS=$JOBS -t "godot-videodecoder-windows_64"
fi
if [ $plat_windows_32 ]; then
echo "Building for Windows - 32 bits"
docker build ./ -f Dockerfile.windows_32 --build-arg JOBS=$JOBS -t "godot-videodecoder-windows_32"
fi
set -x
# precreate the target directory because otherwise
# docker cp will copy x11/* -> $ADDON_BIN_DIR/* instead of x11/* -> $ADDON_BIN_DIR/x11/*
mkdir -p $ADDON_BIN_DIR/
# copy the thirdparty dir in case you want to try building the lib against the ffmpeg libs directly e.g. in MSVC
mkdir -p $THIRDPARTY_DIR
if [ "$(uname -o)" = "Msys" ]; then
export MSYS=winsymlinks:native
fi
# TODO: this should be a loop over all the platforms
if [ $plat_linux_64 ]; then
echo "extracting $ADDON_BIN_DIR/linux_64"
id=$(docker create godot-videodecoder-linux_64)
docker cp $id:/opt/target/linux_64 $ADDON_BIN_DIR/
mkdir -p $THIRDPARTY_DIR/linux_64
# tar because copying a symlink on windows will fail if you don't run as administrator
docker cp -L $id:/opt/godot-videodecoder/thirdparty/linux_64 - | tar -xhC $THIRDPARTY_DIR/
docker rm -v $id
fi
if [ $plat_linux_64 ]; then
echo "extracting $ADDON_BIN_DIR/linux_64"
id=$(docker create godot-videodecoder-linux_64)
docker cp $id:/opt/target/linux_64 $ADDON_BIN_DIR/
mkdir -p $THIRDPARTY_DIR/linux_64
# tar because copying a symlink on windows will fail if you don't run as administrator
docker cp -L $id:/opt/godot-videodecoder/thirdparty/linux_64 - | tar -xhC $THIRDPARTY_DIR/
docker rm -v $id
fi
if [ $plat_linux_32 ]; then
echo "extracting $ADDON_BIN_DIR/linux_32"
id=$(docker create godot-videodecoder-linux_32)
docker cp $id:/opt/target/linux_32 $ADDON_BIN_DIR/
mkdir -p $THIRDPARTY_DIR/linux_32
# tar because copying a symlink on windows will fail if you don't run as administrator
docker cp -L $id:/opt/godot-videodecoder/thirdparty/linux_32 - | tar -xhC $THIRDPARTY_DIR/
docker rm -v $id
fi
if [ $plat_macos_x86 ]; then
echo "extracting $ADDON_BIN_DIR/macos_x86"
id=$(docker create godot-videodecoder-macos_x86)
docker cp $id:/opt/target/macos_x86 $ADDON_BIN_DIR/
mkdir -p $THIRDPARTY_DIR/macos_x86
# tar because copying a symlink on windows will fail if you don't run as administrator
docker cp -L $id:/opt/godot-videodecoder/thirdparty/macos_x86 - | tar -xhC $THIRDPARTY_DIR/
docker rm -v $id
fi
if [ $plat_macos_arm64 ]; then
echo "extracting $ADDON_BIN_DIR/macos_arm64"
id=$(docker create godot-videodecoder-macos_arm64)
docker cp $id:/opt/target/macos_arm64 $ADDON_BIN_DIR/
mkdir -p $THIRDPARTY_DIR/macos_arm64
# tar because copying a symlink on windows will fail if you don't run as administrator
docker cp -L $id:/opt/godot-videodecoder/thirdparty/macos_arm64 - | tar -xhC $THIRDPARTY_DIR/
docker rm -v $id
fi
if [ $plat_windows_64 ]; then
echo "extracting $ADDON_BIN_DIR/windows_64"
id=$(docker create godot-videodecoder-windows_64)
docker cp $id:/opt/target/windows_64 $ADDON_BIN_DIR/
mkdir -p $THIRDPARTY_DIR/windows_64
# tar because copying a symlink on windows will fail if you don't run as administrator
docker cp -L $id:/opt/godot-videodecoder/thirdparty/windows_64 - | tar -xhC $THIRDPARTY_DIR/
docker rm -v $id
fi
if [ $plat_windows_32 ]; then
echo "extracting $ADDON_BIN_DIR/windows_32"
id=$(docker create godot-videodecoder-windows_32)
docker cp $id:/opt/target/windows_32 $ADDON_BIN_DIR/
mkdir -p $THIRDPARTY_DIR/windows_32
# tar because copying a symlink on windows will fail if you don't run as administrator
docker cp -L $id:/opt/godot-videodecoder/thirdparty/windows_32 - | tar -xhC $THIRDPARTY_DIR/
docker rm -v $id
fi
if type tree 2> /dev/null; then
tree $THIRDPARTY_DIR -L 2 -hD
tree $ADDON_BIN_DIR -hD
else
find $THIRDPARTY_DIR -maxdepth 2 -print -exec ls -lh {} \;
find $ADDON_BIN_DIR -maxdepth 1 -print -exec ls -lh {} \;
fi