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