Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
emscripten-core
GitHub Repository: emscripten-core/emscripten
Path: blob/main/tools/ports/cocos2d.py
6170 views
1
# Copyright 2017 The Emscripten Authors. All rights reserved.
2
# Emscripten is available under two separate licenses, the MIT license and the
3
# University of Illinois/NCSA Open Source License. Both these licenses can be
4
# found in the LICENSE file.
5
6
import os
7
import re
8
9
from tools import diagnostics
10
11
TAG = 'version_3_3'
12
HASH = 'd7b22660036c684f09754fcbbc7562984f02aa955eef2b76555270c63a717e6672c4fe695afb16280822e8b7c75d4b99ae21975a01a4ed51cad957f7783722cd'
13
14
deps = ['libpng', 'zlib']
15
16
17
def needed(settings):
18
return settings.USE_COCOS2D == 3
19
20
21
def get(ports, settings, shared):
22
ports.fetch_project('cocos2d', f'https://github.com/emscripten-ports/Cocos2d/archive/{TAG}.zip', sha512hash=HASH)
23
24
def create(final):
25
diagnostics.warning('experimental', 'cocos2d: library is experimental, do not expect that it will work out of the box')
26
27
cocos2d_src = ports.get_dir('cocos2d')
28
cocos2d_root = os.path.join(cocos2d_src, 'Cocos2d-' + TAG)
29
cocos2dx_root = os.path.join(cocos2d_root, 'cocos2dx')
30
31
srcs = make_source_list(cocos2d_root, cocos2dx_root)
32
includes = make_includes(cocos2d_root)
33
flags = [
34
'-w',
35
'-D__CC_PLATFORM_FILEUTILS_CPP__',
36
'-DCC_ENABLE_CHIPMUNK_INTEGRATION',
37
'-DCC_KEYBOARD_SUPPORT',
38
'-DGL_ES=1',
39
'-DNDEBUG', # '-DCOCOS2D_DEBUG=1' 1 - error/warn, 2 - verbose
40
# Cocos2d source code hasn't switched to __EMSCRIPTEN__.
41
# See https://github.com/emscripten-ports/Cocos2d/pull/3
42
'-DEMSCRIPTEN',
43
'-DCP_USE_DOUBLES=0',
44
'-sUSE_ZLIB',
45
'-sUSE_LIBPNG',
46
]
47
48
for dirname in includes:
49
target = os.path.join('cocos2d', os.path.relpath(dirname, cocos2d_root))
50
ports.install_header_dir(dirname, target=target)
51
52
ports.build_port(cocos2d_src, final, 'cocos2d',
53
flags=flags,
54
cxxflags=['-std=c++14'],
55
includes=includes,
56
srcs=srcs)
57
58
return [shared.cache.get_lib('libcocos2d.a', create, what='port')]
59
60
61
def clear(ports, settings, shared):
62
shared.cache.erase_lib('libcocos2d.a')
63
64
65
def process_dependencies(settings):
66
settings.USE_LIBPNG = 1
67
settings.USE_ZLIB = 1
68
69
70
def process_args(ports):
71
args = []
72
for include in make_includes(ports.get_include_dir('cocos2d')):
73
args += ['-isystem', include]
74
return args
75
76
77
def show():
78
return 'cocos2d (-sUSE_COCOS2D=3 or --use-port=cocos2d)'
79
80
81
def make_source_list(cocos2d_root, cocos2dx_root):
82
sources = []
83
84
def add_makefile(makefile):
85
with open(makefile) as infile:
86
add_next = False
87
for line in infile:
88
if line.startswith('SOURCES'):
89
file = re.search(r'=\s*(.*?)(\s*\\$|\s*$)', line, re.IGNORECASE).group(1)
90
absfile = os.path.abspath(os.path.join(os.path.dirname(makefile), file))
91
sources.append(absfile)
92
add_next = line.endswith('\\\n')
93
continue
94
if add_next:
95
file = re.search(r'\s*(.*?)(\s*\\$|\s*$)', line, re.IGNORECASE).group(1)
96
absfile = os.path.abspath(os.path.join(os.path.dirname(makefile), file))
97
sources.append(absfile)
98
add_next = line.endswith('\\\n')
99
100
# core
101
add_makefile(os.path.join(cocos2dx_root, 'proj.emscripten', 'Makefile'))
102
# extensions
103
add_makefile(os.path.join(cocos2d_root, 'extensions', 'proj.emscripten', 'Makefile'))
104
# external
105
add_makefile(os.path.join(cocos2d_root, 'external', 'Box2D', 'proj.emscripten', 'Makefile'))
106
add_makefile(os.path.join(cocos2d_root, 'external', 'chipmunk', 'proj.emscripten', 'Makefile'))
107
add_makefile(os.path.join(cocos2dx_root, 'platform', 'third_party', 'Makefile'))
108
# misc
109
sources.append(os.path.join(cocos2d_root, 'CocosDenshion', 'emscripten', 'SimpleAudioEngine.cpp'))
110
sources.append(os.path.join(cocos2dx_root, 'CCDeprecated.cpp')) # subset of cocos2d v2
111
return sources
112
113
114
def make_includes(root):
115
return [os.path.join(root, 'CocosDenshion', 'include'),
116
os.path.join(root, 'extensions'),
117
os.path.join(root, 'extensions', 'AssetsManager'),
118
os.path.join(root, 'extensions', 'CCArmature'),
119
os.path.join(root, 'extensions', 'CCBReader'),
120
os.path.join(root, 'extensions', 'GUI', 'CCControlExtension'),
121
os.path.join(root, 'extensions', 'GUI', 'CCEditBox'),
122
os.path.join(root, 'extensions', 'GUI', 'CCScrollView'),
123
os.path.join(root, 'extensions', 'network'),
124
os.path.join(root, 'extensions', 'Components'),
125
os.path.join(root, 'extensions', 'LocalStorage'),
126
os.path.join(root, 'extensions', 'physics_nodes'),
127
os.path.join(root, 'extensions', 'spine'),
128
os.path.join(root, 'external'),
129
os.path.join(root, 'external', 'chipmunk', 'include', 'chipmunk'),
130
os.path.join(root, 'cocos2dx'),
131
os.path.join(root, 'cocos2dx', 'cocoa'),
132
os.path.join(root, 'cocos2dx', 'include'),
133
os.path.join(root, 'cocos2dx', 'kazmath', 'include'),
134
os.path.join(root, 'cocos2dx', 'platform'),
135
os.path.join(root, 'cocos2dx', 'platform', 'emscripten'),
136
os.path.join(root, 'cocos2dx', 'platform', 'third_party', 'linux', 'libfreetype2'),
137
os.path.join(root, 'cocos2dx', 'platform', 'third_party', 'common', 'etc'),
138
os.path.join(root, 'cocos2dx', 'platform', 'third_party', 'emscripten', 'libtiff', 'include'),
139
os.path.join(root, 'cocos2dx', 'platform', 'third_party', 'emscripten', 'libjpeg'),
140
os.path.join(root, 'cocos2dx', 'platform', 'third_party', 'emscripten', 'libwebp')]
141
142