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