Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
emscripten-core
GitHub Repository: emscripten-core/emscripten
Path: blob/main/tools/ports/libpng.py
4130 views
1
# Copyright 2015 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 shutil
8
9
TAG = '1.6.39'
10
HASH = '19851afffbe2ffde62d918f7e9017dec778a7ce9c60c75cdc65072f086e6cdc9d9895eb7b207535a84cb5f4ead77ebc2aa9d80025f153662903023e1f7ab9bae'
11
12
deps = ['zlib']
13
variants = {
14
'libpng-mt': {'PTHREADS': 1},
15
'libpng-legacysjlj': {'SUPPORT_LONGJMP': 'wasm', 'WASM_LEGACY_EXCEPTIONS': 1},
16
'libpng-mt-legacysjlj': {'PTHREADS': 1, 'SUPPORT_LONGJMP': 'wasm', 'WASM_LEGACY_EXCEPTIONS': 1},
17
}
18
19
20
def needed(settings):
21
return settings.USE_LIBPNG
22
23
24
def get_lib_name(settings):
25
suffix = ''
26
if settings.PTHREADS:
27
suffix += '-mt'
28
if settings.SUPPORT_LONGJMP == 'wasm':
29
suffix += '-legacysjlj'
30
return f'libpng{suffix}.a'
31
32
33
def get(ports, settings, shared):
34
# This is an emscripten-hosted mirror of the libpng repo from Sourceforge.
35
ports.fetch_project('libpng', f'https://storage.googleapis.com/webassembly/emscripten-ports/libpng-{TAG}.tar.gz', sha512hash=HASH)
36
37
def create(final):
38
source_path = ports.get_dir('libpng', 'libpng-' + TAG)
39
pnglibconf_h = os.path.join(os.path.dirname(__file__), 'libpng/pnglibconf.h')
40
shutil.copyfile(pnglibconf_h, os.path.join(source_path, 'pnglibconf.h'))
41
ports.install_headers(source_path)
42
43
flags = ['-sUSE_ZLIB']
44
if settings.PTHREADS:
45
flags += ['-pthread']
46
if settings.SUPPORT_LONGJMP == 'wasm':
47
flags.append('-sSUPPORT_LONGJMP=wasm')
48
49
ports.build_port(source_path, final, 'libpng', flags=flags, exclude_files=['pngtest'], exclude_dirs=['scripts', 'contrib'])
50
51
return [shared.cache.get_lib(get_lib_name(settings), create, what='port')]
52
53
54
def clear(ports, settings, shared):
55
shared.cache.erase_lib(get_lib_name(settings))
56
57
58
def process_dependencies(settings):
59
settings.USE_ZLIB = 1
60
61
62
def show():
63
return 'libpng (-sUSE_LIBPNG or --use-port=libpng; zlib license)'
64
65