Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
emscripten-core
GitHub Repository: emscripten-core/emscripten
Path: blob/main/tools/ports/sdl2_mixer.py
6178 views
1
# Copyright 2016 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
8
TAG = 'release-2.8.0'
9
HASH = '494ccd74540f74e717f7e4f1dc7f96398c0f4b1883ab00c4a76b0c7239bd2c185cb4358a35ef47819c49e7c14dac7c37b98a29c7b5237478121571f5e7ac4dfc'
10
11
deps = ['sdl2']
12
variants = {
13
'sdl2_mixer-mp3': {'SDL2_MIXER_FORMATS': ['mp3']},
14
'sdl2_mixer-none': {'SDL2_MIXER_FORMATS': []},
15
'sdl2_mixer-mp3-mt': {'SDL2_MIXER_FORMATS': ['mp3'], 'PTHREADS': 1},
16
'sdl2_mixer-none-mt': {'SDL2_MIXER_FORMATS': [], 'PTHREADS': 1},
17
}
18
19
OPTIONS = {
20
'formats': 'A comma separated list of formats (ex: --use-port=sdl2_mixer:formats=ogg,mp3)',
21
}
22
23
SUPPORTED_FORMATS = {'ogg', 'mp3', 'mod', 'mid'}
24
25
# user options (from --use-port)
26
opts: dict[str, set] = {
27
'formats': set(),
28
}
29
30
31
def needed(settings):
32
return settings.USE_SDL_MIXER == 2
33
34
35
def get_formats(settings):
36
return opts['formats'].union(settings.SDL2_MIXER_FORMATS)
37
38
39
def get_lib_name(settings):
40
formats = '-'.join(sorted(get_formats(settings)))
41
42
libname = 'libSDL2_mixer'
43
if formats != '':
44
libname += '-' + formats
45
if settings.PTHREADS:
46
libname += '-mt'
47
libname += '.a'
48
49
return libname
50
51
52
def get(ports, settings, shared):
53
ports.fetch_project('sdl2_mixer', f'https://github.com/libsdl-org/SDL_mixer/archive/{TAG}.zip', sha512hash=HASH)
54
libname = get_lib_name(settings)
55
56
def create(final):
57
source_path = ports.get_dir('sdl2_mixer', 'SDL_mixer-' + TAG)
58
59
formats = get_formats(settings)
60
61
flags = [
62
'-sUSE_SDL=2',
63
'-DMUSIC_WAV',
64
]
65
66
if "ogg" in formats:
67
flags += [
68
'-sUSE_VORBIS',
69
'-DMUSIC_OGG',
70
]
71
72
if "mp3" in formats:
73
flags += [
74
'-sUSE_MPG123',
75
'-DMUSIC_MP3_MPG123',
76
]
77
78
if "mod" in formats:
79
flags += [
80
'-sUSE_MODPLUG',
81
'-DMUSIC_MOD_MODPLUG',
82
]
83
84
if "mid" in formats:
85
flags += [
86
'-DMUSIC_MID_TIMIDITY',
87
]
88
89
if settings.PTHREADS:
90
flags.append('-pthread')
91
92
include_path = os.path.join(source_path, 'include')
93
includes = [
94
include_path,
95
os.path.join(source_path, 'src'),
96
os.path.join(source_path, 'src', 'codecs'),
97
]
98
ports.build_port(
99
source_path,
100
final,
101
'sdl2_mixer',
102
flags=flags,
103
exclude_files=[
104
'playmus.c',
105
'playwave.c',
106
'main.c',
107
],
108
exclude_dirs=[
109
'native_midi',
110
'external',
111
'Xcode',
112
],
113
includes=includes,
114
)
115
116
ports.install_headers(include_path, target='SDL2')
117
118
return [shared.cache.get_lib(libname, create, what='port')]
119
120
121
def clear(ports, settings, shared):
122
shared.cache.erase_lib(get_lib_name(settings))
123
124
125
def process_dependencies(settings):
126
settings.USE_SDL = 2
127
formats = get_formats(settings)
128
if "ogg" in formats:
129
deps.append('vorbis')
130
settings.USE_VORBIS = 1
131
if "mp3" in formats:
132
deps.append('mpg123')
133
settings.USE_MPG123 = 1
134
if "mod" in formats:
135
deps.append('libmodplug')
136
settings.USE_MODPLUG = 1
137
138
139
def handle_options(options, error_handler):
140
formats = options['formats'].split(',')
141
for format in formats:
142
format = format.lower().strip()
143
if format not in SUPPORTED_FORMATS:
144
error_handler(f'{format} is not a supported format')
145
else:
146
opts['formats'].add(format)
147
148
149
def show():
150
return 'sdl2_mixer (-sUSE_SDL_MIXER=2 or --use-port=sdl2_mixer; zlib license)'
151
152