This repository has been archived by the owner on Apr 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGenerateCompilerOptions.py
82 lines (58 loc) · 2.15 KB
/
GenerateCompilerOptions.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
import os
from os.path import join
from regex import P
Import("env")
AddOption("--platform", dest="platform", type=str)
def getPlatformList() -> dict:
ret = {}
for file in env.recursiveGlob("engine/src/platform/", None, "SConscript"):
file = str(file)
if file.endswith("engine/src/platform/SConscript") or os.path.isdir(file):
continue
ret[os.path.dirname(file).split("/")[-1]] = os.path.join(env.DIRECTORY, file)
return ret
env.PLATFORM_LIST = getPlatformList()
if not GetOption("platform") in env.PLATFORM_LIST:
if GetOption("platform"):
print(f"'{GetOption('platform')}' is not a valid platform. Available platforms:")
else:
print("A valid platform must be specified. Available platforms:")
for platform in env.PLATFORM_LIST:
print(" ", platform)
exit()
env.PLATFORM_NAME = GetOption("platform")
env.BUILD_DIR = join(env.BUILD_DIR, env.PLATFORM_NAME)
env.OBJ_DIR = join(env.BUILD_DIR, env.OBJ_SUBDIR)
env.LIB_DIR = join(env.BUILD_DIR, env.LIB_SUBDIR)
file = open("engine/compiler_settings.h", "r")
generate_settings = True
for line in file.readlines():
line = line.strip()
if line.strip().startswith("#define DISABLE_GENERATION true"):
generate_settings = False
break
if generate_settings:
data = \
"""#ifndef INCLUDED_COMPILER_OPTIONS
#define INCLUDED_COMPILER_OPTIONS
/*
Automatically generated before compilation
Define 'DISABLE_GENERATION' as true to disable generation
*/
#define DISABLE_GENERATION false
"""
file.close()
file = open("engine/compiler_settings.h", "w")
data += "/* Available platforms */\n\n"
i = 2
for platform in env.PLATFORM_LIST:
data += f"#define PLATFORM_{platform.upper()} {i}\n"
i += 1
data += "\n/* Platform in use */\n\n"
data += f"#define PLATFORM PLATFORM_{env.PLATFORM_NAME.upper()}"
data += f"\n\n/* Enable debug mode */\n\n#define DEBUG_ENABLED {str(GetOption('target') == 'debug').lower()}"
# TODO
data += "\n\n#define PHYSICS_2D_ENABLED false\n#define PHYSICS_3D_ENABLED true"
data += "\n\n#endif\n"
file.write(data)
file.close()