-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
SConstruct
214 lines (172 loc) · 7.04 KB
/
SConstruct
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
#!/usr/bin/env python
import os
import platform as os_platform
import time
LIBS_COMMON = [
'avcodec',
'avformat',
'avdevice',
'avutil',
'swresample',
'swscale']
SLEEP_TIME = 3
env = SConscript('godot_cpp/SConstruct')
env.Append(CPPPATH=['src'])
gpl = ARGUMENTS.get('enable_gpl', 'no')
jobs = ARGUMENTS.get('jobs', 4)
arch = ARGUMENTS.get('arch', 'x86_64')
target = ARGUMENTS.get('target', 'template_debug').replace('template_', '')
platform = ARGUMENTS.get('platform', 'linux')
location = ARGUMENTS.get('location', 'bin')
use_system = ARGUMENTS.get('use_system', 'no')
recompile_ffmpeg = ARGUMENTS.get('recompile_ffmpeg', 'yes')
ffmpeg_args = '--enable-shared --quiet' +\
' --disable-postproc --disable-avfilter --disable-sndio' +\
' --disable-programs --disable-ffmpeg --disable-ffplay' +\
' --disable-ffprobe --disable-doc --disable-htmlpages' +\
' --disable-manpages --disable-podpages --disable-txtpages' +\
f' --arch={arch}'
if gpl == 'yes':
print('GPL3 enabled')
ffmpeg_args += ' --enable-gpl --enable-version3 --enable-lto'
# NOTE: These libraries are needed for rendering and other things, this
# means that rendering right now is only possible on Linux systems.
if 'linux' in platform:
ffmpeg_args += ' --enable-libaom --enable-nvdec --enable-nvenc' +\
' --enable-libopus --enable-libpulse --enable-opencl' +\
' --enable-libtheora --enable-libvpx --enable-libvpl' +\
' --enable-libass --enable-libdav1d --enable-libdrm' +\
' --enable-libsoxr --enable-vulkan --enable-opengl' +\
' --enable-libmp3lame --enable-libvorbis' +\
' --enable-librav1e --enable-libsvtav1' +\
' --enable-libx264 --enable-libx265' +\
' --enable-libxml2 --enable-libxvid' +\
' --enable-libopenmpt --enable-cuda-llvm'
# LINUX ############################################################### LINUX #
# For people who don't need the FFmpeg libs (FFmpeg 6+ already installed)
if 'linux' in platform and use_system == 'yes':
os.makedirs(f'{location}/{platform}/{target}', exist_ok=True)
env.Append(
LINKFLAGS=['-static-libstdc++'],
CPPPATH=['/usr/include/ffmpeg/'],
LIBS=LIBS_COMMON)
# LINUX_FULL ##################################################### LINUX_FULL #
# For people needing FFmpeg binaries (Ubuntu, ... don't have FFmpeg 6+ yet)
elif 'linux' in platform:
platform += '_full'
os.makedirs(f'{location}/{platform}/{target}', exist_ok=True)
if recompile_ffmpeg == 'yes':
print('Compiling FFmpeg for Linux')
ffmpeg_args += ' --extra-cflags="-fPIC" --extra-ldflags="-fpic"' +\
' --target-os=linux'
os.chdir('ffmpeg')
os.system('make distclean')
time.sleep(SLEEP_TIME)
os.system(f'./configure --prefix=./bin {ffmpeg_args}')
time.sleep(SLEEP_TIME)
os.system(f'make -j {jobs}')
os.system(f'make -j {jobs} install')
os.chdir('..')
env.Append(
LINKFLAGS=['-static-libstdc++'],
CPPFLAGS=[
'-Iffmpeg/bin',
'-Iffmpeg/bin/include'],
LIBPATH=[
'ffmpeg/bin/include/libavcodec',
'ffmpeg/bin/include/libavformat',
'ffmpeg/bin/include/libavdevice',
'ffmpeg/bin/include/libavutil',
'ffmpeg/bin/include/libswresample',
'ffmpeg/bin/include/libswscale',
'ffmpeg/bin/lib'],
LIBS=LIBS_COMMON)
os.system(f'cp ffmpeg/bin/lib/*.so* {location}/{platform}/{target}')
# WINDOWS ########################################################### WINDOWS #
# For people who for some reason use Windows
elif 'windows' in platform:
os.makedirs(f'{location}/{platform}/{target}', exist_ok=True)
if recompile_ffmpeg == 'yes':
print('Compiling FFmpeg for Windows')
if os_platform.system().lower() == 'linux':
ffmpeg_args += ' --cross-prefix=x86_64-w64-mingw32-' +\
' --target-os=mingw32 --enable-cross-compile' +\
' --extra-ldflags="-static"' +\
' --extra-cflags="-fPIC" --extra-ldflags="-fpic"'
else:
ffmpeg_args += ' --target-os=windows'
os.chdir('ffmpeg')
os.system('make distclean')
time.sleep(SLEEP_TIME)
os.environ['PATH'] = '/opt/bin:' + os.environ['PATH']
os.system(f'./configure --prefix=./bin {ffmpeg_args}')
time.sleep(SLEEP_TIME)
os.system(f'make -j {jobs}')
os.system(f'make -j {jobs} install')
os.chdir('..')
if os_platform.system().lower() == 'windows':
env.Append(LIBS=[
'avcodec.lib',
'avformat.lib',
'avdevice.lib',
'avutil.lib',
'swresample.lib',
'swscale.lib'])
else:
env.Append(LIBS=LIBS_COMMON)
env.Append(
CPPPATH=['ffmpeg/bin/include'],
LIBPATH=['ffmpeg/bin/bin'])
os.system(f'cp ffmpeg/bin/bin/*.dll {location}/{platform}/{target}')
# MACOS ############################################################### MACOS #
# For the people who don't like money and/or right to repair
# NOTE: Cross compiling not possible, need a MacOS system
elif 'macos' in platform:
os.makedirs(f'{location}/{platform}/{target}/lib', exist_ok=True)
if recompile_ffmpeg == 'yes':
print('Compiling FFmpeg for MacOS')
ffmpeg_args += ' --target-os=darwin' +\
' --extra-cflags="-fPIC -mmacosx-version-min=10.13"' +\
' --extra-ldflags="-mmacosx-version-min=10.13"'
os.chdir('ffmpeg')
os.system('make distclean')
time.sleep(SLEEP_TIME)
os.system(f'./configure --prefix=./bin {ffmpeg_args}')
time.sleep(SLEEP_TIME)
os.system(f'make -j {jobs}')
os.system(f'make -j {jobs} install')
os.chdir('..')
env.Append(
CPPPATH=['ffmpeg/bin/include'],
LIBPATH=[
'ffmpeg/bin/lib',
'/usr/local/lib'], # Default macOS library path
LIBS=LIBS_COMMON,
LINKFLAGS=[ # macOS-specific linking flags
'-stdlib=libc++',
'-framework', 'CoreFoundation',
'-framework', 'CoreVideo',
'-framework', 'CoreMedia',
'-framework', 'AVFoundation',
'-rpath', '@loader_path/lib']
)
os.system(f'cp ffmpeg/bin/lib/*.dylib {location}/{platform}/{target}/lib')
elif 'web' in platform:
print('Exporting for web isn\'t supported yet!')
elif 'android' in platform:
print('Exporting for Android isn\'t supported yet!')
else:
print('Invalid platform!')
# Caching stuff
CacheDir('.scons-cache')
Decider('MD5')
# Godot compiling stuff
src = Glob('src/*.cpp')
libpath = '{}/{}/{}/libgozen{}{}'.format(
location,
platform,
target,
env['suffix'],
env['SHLIBSUFFIX'])
sharedlib = env.SharedLibrary(libpath, src)
Default(sharedlib)