-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSConstruct
171 lines (146 loc) · 6.53 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
#!/usr/bin/env python
import os, subprocess, shutil
opts = Variables([], ARGUMENTS)
# Gets the standard flags CC, CCX, etc.
env = DefaultEnvironment()
# Define our options
opts.Add(EnumVariable('target', "Compilation target", 'debug', ['d', 'debug', 'r', 'release']))
opts.Add(EnumVariable('platform', "Compilation platform", '', ['', 'windows', 'x11', 'linux', 'osx', 'android']))
opts.Add(EnumVariable('arch', "Compilation architecture", 'x86_64', ['x86_64', 'armv7a', 'armv8a']))
opts.Add(EnumVariable('p', "Compilation target, alias for 'platform'", '', ['', 'windows', 'x11', 'linux', 'osx', 'android']))
opts.Add(BoolVariable('use_llvm', "Use the LLVM / Clang compiler", 'no'))
opts.Add(PathVariable('target_path', 'The path where the lib is installed.', 'demo/bin/'))
opts.Add(PathVariable('target_name', 'The library name.', 'libmarkdown', PathVariable.PathAccept))
opts.Add(PathVariable('android_ndk', 'Path to the Android NDK installation', '/opt/android-ndk/', PathVariable.PathAccept))
opts.Add(BoolVariable('build_libcmark_gfm', "Build and deploy libcmark-gfm for current platform.", 'no'))
# only support 64 at this time..
bits = 64
# Updates the environment with the option variables.
opts.Update(env)
# Process some arguments
if env['use_llvm']:
env['CC'] = 'clang'
env['CXX'] = 'clang++'
if env['p'] != '':
env['platform'] = env['p']
if env['platform'] == '':
print("No valid target platform selected.")
quit();
platform = ""
arch = ""
ccflags = ""
linkflags = ""
# Check our platform specifics
if env['platform'] == "osx":
platform = "osx"
arch = "x86_64"
if env['target'] in ('debug', 'd'):
env.Append(CCFLAGS = ['-g','-O2', '-arch', 'x86_64'])
env.Append(LINKFLAGS = ['-arch', 'x86_64'])
else:
env.Append(CCFLAGS = ['-g','-O3', '-arch', 'x86_64', '-std=c11'])
env.Append(LINKFLAGS = ['-arch', 'x86_64'])
elif env['platform'] in ('x11', 'linux'):
platform = "x11"
arch = "x86_64"
if env['target'] in ('debug', 'd'):
env.Append(CCFLAGS = ['-fPIC', '-g3','-Og', '-std=c11'])
else:
env.Append(CCFLAGS = ['-fPIC', '-g','-O3', '-std=c11'])
elif env['platform'] == "windows":
platform = "windows"
arch = "x86_64"
# This makes sure to keep the session environment variables on windows,
# that way you can run scons in a vs 2017 prompt and it will find all the required tools
env.Append(ENV = os.environ)
env['CC'] = 'x86_64-w64-mingw32-gcc'
env['CXX'] = 'x86_64-w64-mingw32-gcc'
env.Append(CCFLAGS = ['-DWIN32', '-D_WIN32', '-D_WINDOWS', '-D_CRT_SECURE_NO_WARNINGS'])
env.Append(LIBS=['advapi32'])
if env['target'] in ('debug', 'd'):
env.Append(CCFLAGS = ['-fPIC', '-g3','-Og', '-std=c11'])
# env.Append(CCFLAGS = ['-EHsc', '-D_DEBUG', '-MDd'])
else:
env.Append(CCFLAGS = ['-fPIC', '-g','-O3', '-std=c11'])
# env.Append(CCFLAGS = ['-O2', '-EHsc', '-DNDEBUG', '-MD'])
elif env['platform'] == "android":
platform = "android"
arch = env['arch']
if arch == "armv7a":
env['CC'] = env['android_ndk'] + "/toolchains/llvm/prebuilt/linux-x86_64/bin/armv7a-linux-androideabi30-clang"
env['CXX'] = env['android_ndk'] + "/toolchains/llvm/prebuilt/linux-x86_64/bin/armv7a-linux-androideabi30-clang++"
elif arch == "armv8a":
env['CC'] = env['android_ndk'] + "/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android30-clang"
env['CXX'] = env['android_ndk'] + "/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android30-clang++"
elif arch == "x86_64":
env['CC'] = env['android_ndk'] + "/toolchains/llvm/prebuilt/linux-x86_64/bin/x86_64-linux-android30-clang"
env['CXX'] = env['android_ndk'] + "/toolchains/llvm/prebuilt/linux-x86_64/bin/x86_64-linux-android30-clang++"
if env['target'] in ('debug', 'd'):
env.Append(CCFLAGS = ['-fPIC', '-g3','-Og', '-std=c11'])
else:
env.Append(CCFLAGS = ['-fPIC', '-g','-O3', '-std=c11'])
if env['target'] in ('debug', 'd'):
target = "debug"
else:
target = "release"
# Local dependency paths, adapt them to your setup
suffix = "{}/{}/{}".format(platform, arch, target)
godot_headers_path = "godot_headers/"
target = os.path.join(env['target_path'], suffix, env['target_name'])
libcmark_gfm_lib_path = "demo/bin/{}".format(suffix)
libcmark_gfm_include_paths = [
"godot_markdown/thirdparty/cmark-gfm/src/", # for cmark-gfm.h
"godot_markdown/thirdparty/cmark-gfm/extensions/", # for all extension headers
"godot_markdown/thirdparty/cmark-gfm/build_{}_{}/src/".format(platform, arch), # for export.h and version.h
"godot_markdown/thirdparty/cmark-gfm/build_{}_{}/extensions/".format(platform, arch), # for extensions_export.h
]
print(suffix)
env.Append(CPPPATH=['.', godot_headers_path])
env.Append(CPPPATH=['godot_markdown/src/', *libcmark_gfm_include_paths])
env.Append(LIBPATH=[libcmark_gfm_lib_path])
env.Append(LIBS=['cmark-gfm-extensions', 'cmark-gfm', 'cmark-gfm-extensions'])
sources = Glob('godot_markdown/src/*.c')
library = env.SharedLibrary(target=target, source=sources)
if env['build_libcmark_gfm']:
cwd = os.getcwd()
os.chdir("godot_markdown/thirdparty/cmark-gfm")
lib_target_path = os.path.join(cwd, libcmark_gfm_lib_path)
build_dir = "build_{}_{}".format(platform, arch)
os.makedirs(lib_target_path, exist_ok=True)
os.makedirs(build_dir, exist_ok=True)
os.chdir(build_dir)
if platform == 'android':
if arch == "armv7a":
android_abi = "-DANDROID_ABI=armeabi-v7a"
elif arch == "armv8a":
android_abi = "-DANDROID_ABI=arm64-v8a"
elif arch == "x86_64":
android_abi = "-DANDROID_ABI=x86_64"
cmake = [
"cmake",
"-DCMAKE_TOOLCHAIN_FILE=/opt/android-ndk/build/cmake/android.toolchain.cmake",
android_abi,
"-DANDROID_NATIVE_API_LEVEL=",
"..",
]
elif platform == 'windows':
cmake = [
"cmake",
"-DCMAKE_TOOLCHAIN_FILE={}/toolchain-mingw32.cmake".format(cwd),
".."
]
else:
cmake = ["cmake", ".."]
make = ["make"]
subprocess.run(cmake)
subprocess.run(make)
if platform == 'windows':
ext = "dll"
else:
ext = "a"
shutil.copy2("extensions/libcmark-gfm-extensions.{}".format(ext), lib_target_path)
shutil.copy2("src/libcmark-gfm.{}".format(ext), lib_target_path)
os.chdir(cwd)
Default(library)
# Generates help for the -h scons option.
Help(opts.GenerateHelpText(env))