-
Notifications
You must be signed in to change notification settings - Fork 49
/
awtk_config_common.py
352 lines (283 loc) · 11 KB
/
awtk_config_common.py
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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
import os
import os.path
import platform
import shutil
import compile_config
complie_helper = compile_config.get_curr_config_for_awtk()
import sys
if sys.version_info.major == 2:
import cPickle as pickle
else:
import pickle
OS_NAME = platform.system()
import subprocess
def is_raspberrypi():
if OS_NAME == "Windows":
return False
result = str(subprocess.check_output(["uname", "-a"]))
return result.find('Linux raspberrypi') >= 0
#######################################################
# XXX: This file can be edited only in tkc project
#######################################################
TOOLS_PREFIX = ''
MACH = platform.machine()
ARCH = platform.architecture()
is32bit = (ARCH[0] == '32bit')
if is32bit:
if MACH == 'i686' or MACH == 'i386' or MACH == 'x86':
TARGET_ARCH = 'x86'
else:
TARGET_ARCH = ''
else:
TARGET_ARCH = ''
print('MACH=' + MACH + ' ARCH=' + str(ARCH) + ' TARGET_ARCH=' + TARGET_ARCH)
def addLibPrefix(iter):
print(iter)
return '-l'+iter
def toWholeArchive(libs):
wa = ' '.join(list(map(addLibPrefix, libs)))
return ' -Wl,--whole-archive ' + wa + ' -Wl,--no-whole-archive'
def getTkcOnly():
env = os.environ
if 'TKC_ONLY' in env:
return env['TKC_ONLY'] == 'True'
else:
return False
def joinPath(root, subdir):
return os.path.normpath(os.path.join(root, subdir))
TK_ROOT = os.path.dirname(os.path.normpath(os.path.abspath(__file__)))
print('TK_ROOT: ' + TK_ROOT)
TK_SRC = joinPath(TK_ROOT, 'src')
TK_BIN_DIR = joinPath(TK_ROOT, 'bin')
TK_LIB_DIR = joinPath(TK_ROOT, 'lib')
TK_3RD_ROOT = joinPath(TK_ROOT, '3rd')
TK_TOOLS_ROOT = joinPath(TK_ROOT, 'tools')
TK_DEMO_ROOT = joinPath(TK_ROOT, 'demos')
GTEST_ROOT = joinPath(TK_ROOT, '3rd/gtest/googletest')
TKC_STATIC_LIBS = ['debugger', 'fscript_ext', 'romfs', 'conf_io', 'hal', 'xml', 'charset',
'csv', 'streams', 'ubjson', 'compressors', 'miniz', 'tkc_core', 'mbedtls']
TOOLS_NAME = ''
NANOVG_BACKEND = ''
NATIVE_WINDOW = ''
#TOOLS_NAME = 'mingw'
TOOLS_NAME = complie_helper.get_value('TOOLS_NAME', TOOLS_NAME)
if OS_NAME == 'Windows':
TK_ROOT = TK_ROOT.replace('\\', '\\\\')
OS_FLAGS = ''
OS_LIBS = []
OS_LIBPATH = []
OS_CPPPATH = []
OS_LINKFLAGS = ''
OS_SUBSYSTEM_CONSOLE = ''
OS_SUBSYSTEM_WINDOWS = ''
OS_PROJECTS = []
# only for c compiler flags
COMMON_CFLAGS = ''
OS_DEBUG = complie_helper.get_value('DEBUG', True)
if OS_NAME == 'Darwin':
# Find the correct SDL2 version
sdl_path = "/opt/homebrew/Cellar/sdl2/"
if not os.path.exists(sdl_path) :
# Compatible with old systems
sdl_path = '/usr/local/Cellar/sdl2/'
sdl_versions = os.listdir(sdl_path)
if len(sdl_versions)==0:
print("Can not find the SDL version")
exit(-1)
sdl_lib = sdl_path + sdl_versions[0] + "/lib"
TOOLS_NAME = ''
OS_FLAGS = '-Wall -Wno-unused-function -fPIC -DWITHOUT_GLAD=1 '
OS_LIBS = ['stdc++', 'iconv', 'pthread', 'm', 'dl']
OS_LINKFLAGS = '-framework IOKit -framework Cocoa -framework QuartzCore -framework OpenGL -weak_framework Metal -weak_framework MetalKit'
OS_FLAGS = OS_FLAGS + ' -DHAS_SEM_OPEN '
OS_FLAGS = OS_FLAGS + ' -D__APPLE__ -DHAS_PTHREAD -DMACOS '
OS_FLAGS = OS_FLAGS + ' -D__STDC_LIMIT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_CONSTANT_MACROS -DBGFX_CONFIG_RENDERER_METAL=1 '
OS_LIBPATH = ['/usr/local/lib/', sdl_lib]
elif OS_NAME == 'Linux':
TOOLS_NAME = ''
OS_FLAGS = ' -Wall -Wno-unused-function -fPIC '
OS_LIBS = ['sndio', 'stdc++', 'asound', 'pthread', 'm', 'dl']
COMMON_CFLAGS = COMMON_CFLAGS+' -std=gnu99 '
OS_FLAGS = OS_FLAGS + ' -DLINUX -DHAS_PTHREAD'
OS_PROJECTS = ['3rd/SDL/SConscript']
if TARGET_ARCH == 'x86':
OS_FLAGS = OS_FLAGS + ' -U__FLT_EVAL_METHOD__ -D__FLT_EVAL_METHOD__=0 '
else:
OS_FLAGS = OS_FLAGS + ' -DWITH_64BIT_CPU '
OS_LINKFLAGS = ' -Wl,-rpath=./bin -Wl,-rpath=./ '
if is_raspberrypi():
OS_FLAGS = OS_FLAGS + ' -DRASPBERRYPI '
os.environ['RASPBERRYPI'] = 'true'
SDL_VIDEODRIVER=os.getenv('SDL_VIDEODRIVER');
if SDL_VIDEODRIVER is None:
SDL_VIDEODRIVER = 'x11'
if SDL_VIDEODRIVER == 'wayland':
OS_LIBS = ['GL', 'xkbcommon', 'wayland-cursor', 'wayland-egl', 'wayland-client'] + OS_LIBS;
OS_FLAGS += '-DWITHOUT_NATIVE_FILE_DIALOG '
else:
OS_LIBS = ['GL', 'gtk-3', 'gdk-3', 'glib-2.0', 'gobject-2.0', 'Xext', 'X11'] + OS_LIBS;
elif OS_NAME == 'Windows':
if not os.path.exists(os.path.abspath(TK_BIN_DIR)):
os.makedirs(os.path.abspath(TK_BIN_DIR))
if not os.path.exists(os.path.abspath(TK_LIB_DIR)):
os.makedirs(os.path.abspath(TK_LIB_DIR))
if TOOLS_NAME == '':
OS_LIBS = ['gdi32', 'user32', 'winmm.lib', 'imm32.lib', 'version.lib', 'shell32.lib', 'Setupapi',
'ole32.lib', 'Oleaut32.lib', 'Advapi32.lib', 'DelayImp.lib', 'psapi.lib', "ws2_32"]
OS_FLAGS = '-DWIN32 -D_WIN32 -DWINDOWS /EHsc -D_CONSOLE /FS /Z7 /utf-8 '
if TARGET_ARCH == 'x86':
OS_LINKFLAGS = '/MACHINE:X86 '
OS_SUBSYSTEM_CONSOLE = '/SUBSYSTEM:CONSOLE,5.01 '
OS_SUBSYSTEM_WINDOWS = '/SUBSYSTEM:WINDOWS,5.01 '
OS_FLAGS = OS_FLAGS + ' -D_WIN32 '
else:
OS_FLAGS = OS_FLAGS + ' -DWITH_64BIT_CPU '
OS_LINKFLAGS = '/MACHINE:X64 '
OS_SUBSYSTEM_CONSOLE = '/SUBSYSTEM:CONSOLE '
OS_SUBSYSTEM_WINDOWS = '/SUBSYSTEM:WINDOWS '
OS_FLAGS = OS_FLAGS + ' -D_WIN64 '
OS_FLAGS = OS_FLAGS + ' -DHAVE_LIBC '
elif TOOLS_NAME == 'mingw':
OS_LIBS = ['kernel32', 'gdi32', 'user32', 'winmm', 'imm32', 'version', 'shell32', 'Setupapi',
'ole32', 'Oleaut32', 'Advapi32', 'oleaut32', 'uuid', 'stdc++', "ws2_32"]
OS_FLAGS = '-DMINGW -DWINDOWS -D_CONSOLE -Wall'
OS_LINKFLAGS = ' -Wl,-rpath=./bin -Wl,-rpath=./ '
OS_SUBSYSTEM_CONSOLE = ' -mconsole '
OS_SUBSYSTEM_WINDOWS = ' -mwindows '
COMMON_CFLAGS = COMMON_CFLAGS+' -std=gnu99 '
OS_FLAGS = OS_FLAGS+' -U__FLT_EVAL_METHOD__ -D__FLT_EVAL_METHOD__=0 -DDECLSPEC= '
#OS_FLAGS='-DWIN32 -D_WIN32 -DWINDOWS /EHsc -D_CONSOLE /DEBUG /Od /FS /Z7 -D_DEBUG /MDd '
OS_FLAGS = OS_FLAGS + '-D__STDC_LIMIT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_CONSTANT_MACROS -D_HAS_EXCEPTIONS=0 -D_HAS_ITERATOR_DEBUGGING=0 -D_ITERATOR_DEBUG_LEVEL=0 -D_SCL_SECURE=0'
OS_FLAGS = OS_FLAGS + \
'-D_SECURE_SCL=0 -D_SCL_SECURE_NO_WARNINGS -D_CRT_SECURE_NO_WARNINGS -D_CRT_SECURE_NO_DEPRECATE '
OS_PROJECTS = ['3rd/SDL/SConscript']
def has_custom_cc():
return False
def cleanSharedLib(dst, name):
if OS_NAME == 'Darwin':
dst = os.path.join(dst, 'lib'+name+'.dylib')
elif OS_NAME == 'Linux':
dst = os.path.join(dst, 'lib'+name+'.so')
elif OS_NAME == 'Windows':
dst = os.path.join(dst, name+'.dll')
else:
print('not support ' + OS_NAME)
return
dst = os.path.normpath(dst)
if os.path.exists(dst):
os.remove(dst)
print('Removed ' + dst)
if OS_NAME == 'Windows':
dst=dst.replace('.dll', '.lib')
if os.path.exists(dst):
os.remove(dst)
print('Removed ' + dst)
def copySharedLib(src, dst, name):
mingw_src = src
if OS_NAME == 'Darwin':
src = os.path.join(src, 'bin/lib'+name+'.dylib')
elif OS_NAME == 'Linux':
src = os.path.join(src, 'bin/lib'+name+'.so')
elif OS_NAME == 'Windows':
src = os.path.join(src, 'bin/'+name+'.dll')
else:
print('not support ' + OS_NAME)
return
src = os.path.normpath(src)
dst = os.path.normpath(dst)
if os.path.dirname(src) == dst:
return
if not os.path.exists(src):
print('Can\'t find ' + src + '. Please build '+name+' before!')
else:
if not os.path.exists(dst):
os.makedirs(dst)
shutil.copy(src, dst)
print(src + '==>' + dst)
if OS_NAME == 'Windows':
if TOOLS_NAME == 'mingw':
src = os.path.join(mingw_src, 'bin/lib'+name+'.a')
else:
src = src.replace('dll', 'lib')
if os.path.exists(src):
shutil.copy(src, dst)
print(src + '==>' + dst)
def isBuildShared():
return 'WITH_AWTK_SO' in os.environ and os.environ['WITH_AWTK_SO'] == 'true'
def genIdlAndDefEx(withAWTK):
cmds = [
'node tools/idl_gen/tkc.js tools/idl_gen/tkc.json',
'node tools/dll_def_gen/index.js tools/idl_gen/tkc.json dllexports/tkc.def false'
]
if withAWTK:
cmds += [
'node tools/idl_gen/index.js tools/idl_gen/idl.json',
'node tools/dll_def_gen/index.js tools/idl_gen/idl.json dllexports/awtk.def false',
]
for cmd in cmds:
print(cmd)
if os.system(cmd) != 0:
print('exe cmd: ' + cmd + ' failed.')
os.environ['TK_ROOT'] = TK_ROOT
os.environ['TOOLS_NAME'] = TOOLS_NAME
os.environ['GTEST_ROOT'] = GTEST_ROOT
os.environ['TK_3RD_ROOT'] = TK_3RD_ROOT
def setEnvSpawn(env):
if env['PLATFORM'] == 'win32' and os.environ['TOOLS_NAME'] != '':
import subprocess
class ourSpawn:
def ourspawn(self, sh, escape, cmd, args, env):
newargs = ' '.join(args[1:])
cmdline = cmd + " " + newargs
startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
proc = subprocess.Popen(cmdline, stdin=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, startupinfo=startupinfo, shell=False, env=env)
data, err = proc.communicate()
rv = proc.wait()
if rv:
print("=====")
print(err)
print("=====")
return rv
buf = ourSpawn()
buf.ourenv = env
env['SPAWN'] = buf.ourspawn
def genDllLinkFlags(libs, defFile):
linkFlags = ''
wholeArch = toWholeArchive(libs)
if OS_NAME == 'Windows':
if TOOLS_NAME == '':
linkFlags += ' /DEF:"dllexports/'+defFile+'.def" '
elif TOOLS_NAME == 'mingw':
linkFlags += wholeArch
elif OS_NAME == 'Darwin':
linkFlags += ' -all_load '
elif OS_NAME == 'Linux':
linkFlags += wholeArch
return linkFlags
def get_scons_db_files(root):
scons_db_files = []
scons_db_filename = ".sconsign.dblite"
for f in os.listdir(root):
full_path = joinPath(root, f)
if os.path.isfile(full_path) and f == scons_db_filename:
scons_db_files.append(full_path)
elif os.path.isdir(full_path) and f != "." and f != "..":
get_scons_db_files(full_path)
return scons_db_files
def scons_db_check_and_remove():
scons_db_files = []
scons_db_files = get_scons_db_files(TK_ROOT)
for f in scons_db_files:
try:
with open(f, "rb") as fs:
pickle.load(fs)
fs.close()
except Exception as e :
fs.close()
print(e)
try:
os.remove(f)
except Exception as e :
print(e)