Exemple #1
0
def main():
    global force
    parser = argparse.ArgumentParser(
        description=__doc__,
        formatter_class=argparse.RawDescriptionHelpFormatter,
        epilog=get_help())
    parser.add_argument('--lto',
                        action='store_true',
                        help='build bitcode object for LTO')
    parser.add_argument(
        '--pic',
        action='store_true',
        help='build relocatable objects for suitable for dynamic linking')
    parser.add_argument('--force',
                        action='store_true',
                        help='force rebuild of target (by removing it first)')
    parser.add_argument('operation',
                        help='currently only "build" is supported')
    parser.add_argument('targets', nargs='+', help='see below')
    args = parser.parse_args()

    if args.operation != 'build':
        shared.exit_with_error('unfamiliar operation: ' + args.operation)

    # process flags

    # Check sanity so that if settings file has changed, the cache is cleared here.
    # Otherwise, the cache will clear in an emcc process, which is invoked while building
    # a system library into the cache, causing trouble.
    shared.check_sanity()

    if args.lto:
        shared.Settings.LTO = "full"
        # Reconfigure the cache dir to reflect the change
        shared.reconfigure_cache()

    if args.pic:
        shared.Settings.RELOCATABLE = 1
        # Reconfigure the cache dir to reflect the change
        shared.reconfigure_cache()

    if args.force:
        force = True

    # process tasks
    libname = system_libs.Ports.get_lib_name

    auto_tasks = False
    tasks = args.targets
    if 'SYSTEM' in tasks:
        tasks = SYSTEM_TASKS
        auto_tasks = True
    elif 'USER' in tasks:
        tasks = USER_TASKS
        auto_tasks = True
    elif 'MINIMAL' in tasks:
        tasks = MINIMAL_TASKS
        auto_tasks = True
    elif 'ALL' in tasks:
        tasks = SYSTEM_TASKS + USER_TASKS
        auto_tasks = True
    if auto_tasks:
        if shared.Settings.WASM_BACKEND:
            skip_tasks = []
            if shared.Settings.RELOCATABLE:
                # we don't support PIC + pthreads yet
                for task in SYSTEM_TASKS + USER_TASKS:
                    if '-mt' in task:
                        skip_tasks.append(task)
                    if 'pthread' in task and 'stub' not in task:
                        skip_tasks.append(task)
                print(
                    'Skipping building of %s, because we don\'t support threads and PIC code.'
                    % ', '.join(skip_tasks))
            # cocos2d: must be ported, errors on
            # "Cannot recognize the target platform; are you targeting an unsupported platform?"
            skip_tasks += ['cocos2d']
            tasks = [x for x in tasks if x not in skip_tasks]
        else:
            if os.environ.get('EMSCRIPTEN_NATIVE_OPTIMIZER'):
                print(
                    'Skipping building of native-optimizer; EMSCRIPTEN_NATIVE_OPTIMIZER is environment.'
                )
            elif shared.EMSCRIPTEN_NATIVE_OPTIMIZER:
                print(
                    'Skipping building of native-optimizer; EMSCRIPTEN_NATIVE_OPTIMIZER set in .emscripten config.'
                )
            else:
                tasks += ['native_optimizer']
        print('Building targets: %s' % ' '.join(tasks))
    for what in tasks:
        logger.info('building and verifying ' + what)
        if what in SYSTEM_LIBRARIES:
            library = SYSTEM_LIBRARIES[what]
            if force:
                library.erase()
            library.get_path()
        elif what == 'struct_info':
            if force:
                shared.Cache.erase_file('generated_struct_info.json')
            emscripten.generate_struct_info()
        elif what == 'native_optimizer':
            if force:
                shared.Cache.erase_file('optimizer.2.exe')
            js_optimizer.get_native_optimizer()
        elif what == 'icu':
            build_port('icu', libname('libicuuc'))
        elif what == 'zlib':
            shared.Settings.USE_ZLIB = 1
            build_port('zlib', 'libz.a')
            shared.Settings.USE_ZLIB = 0
        elif what == 'bzip2':
            build_port('bzip2', 'libbz2.a')
        elif what == 'bullet':
            build_port('bullet', libname('libbullet'))
        elif what == 'vorbis':
            build_port('vorbis', libname('libvorbis'))
        elif what == 'ogg':
            build_port('ogg', libname('libogg'))
        elif what == 'libjpeg':
            build_port('libjpeg', libname('libjpeg'))
        elif what == 'libpng':
            build_port('libpng', libname('libpng'))
        elif what == 'sdl2':
            build_port('sdl2', libname('libSDL2'))
        elif what == 'sdl2-mt':
            shared.Settings.USE_PTHREADS = 1
            build_port('sdl2', libname('libSDL2-mt'))
            shared.Settings.USE_PTHREADS = 0
        elif what == 'sdl2-gfx':
            build_port('sdl2_gfx', libname('libSDL2_gfx'))
        elif what == 'sdl2-image':
            build_port('sdl2_image', libname('libSDL2_image'))
        elif what == 'sdl2-image-png':
            shared.Settings.SDL2_IMAGE_FORMATS = ["png"]
            build_port('sdl2_image', libname('libSDL2_image_png'))
            shared.Settings.SDL2_IMAGE_FORMATS = []
        elif what == 'sdl2-image-jpg':
            shared.Settings.SDL2_IMAGE_FORMATS = ["jpg"]
            build_port('sdl2_image', libname('libSDL2_image_jpg'))
            shared.Settings.SDL2_IMAGE_FORMATS = []
        elif what == 'sdl2-net':
            build_port('sdl2_net', libname('libSDL2_net'))
        elif what == 'sdl2-mixer':
            old_formats = shared.Settings.SDL2_MIXER_FORMATS
            shared.Settings.SDL2_MIXER_FORMATS = []
            build_port('sdl2_mixer', libname('libSDL2_mixer'))
            shared.Settings.SDL2_MIXER_FORMATS = old_formats
        elif what == 'sdl2-mixer-ogg':
            old_formats = shared.Settings.SDL2_MIXER_FORMATS
            shared.Settings.SDL2_MIXER_FORMATS = ["ogg"]
            build_port('sdl2_mixer', libname('libSDL2_mixer_ogg'))
            shared.Settings.SDL2_MIXER_FORMATS = old_formats
        elif what == 'sdl2-mixer-mp3':
            old_formats = shared.Settings.SDL2_MIXER_FORMATS
            shared.Settings.SDL2_MIXER_FORMATS = ["mp3"]
            build_port('sdl2_mixer', libname('libSDL2_mixer_mp3'))
            shared.Settings.SDL2_MIXER_FORMATS = old_formats
        elif what == 'freetype':
            build_port('freetype', 'libfreetype.a')
        elif what == 'harfbuzz':
            build_port('harfbuzz', 'libharfbuzz.a')
        elif what == 'harfbuzz-mt':
            shared.Settings.USE_PTHREADS = 1
            build_port('harfbuzz', 'libharfbuzz-mt.a')
            shared.Settings.USE_PTHREADS = 0
        elif what == 'sdl2-ttf':
            build_port('sdl2_ttf', libname('libSDL2_ttf'))
        elif what == 'cocos2d':
            build_port('cocos2d', libname('libcocos2d'))
        elif what == 'regal':
            build_port('regal', libname('libregal'))
        elif what == 'regal-mt':
            shared.Settings.USE_PTHREADS = 1
            build_port('regal', libname('libregal-mt'))
            shared.Settings.USE_PTHREADS = 0
        elif what == 'boost_headers':
            build_port('boost_headers', libname('libboost_headers'))
        else:
            logger.error('unfamiliar build target: ' + what)
            return 1

        logger.info('...success')
    return 0
def main():
    if len(sys.argv) < 2 or sys.argv[1] in [
            '-v', '-help', '--help', '-?', '?'
    ]:
        print_help()
        return 0

    operation = sys.argv[1]
    if operation != 'build':
        shared.exit_with_error('unfamiliar operation: ' + operation)

    # process flags

    args = sys.argv[2:]

    def is_flag(arg):
        return arg.startswith('--')

    # Check sanity so that if settings file has changed, the cache is cleared here.
    # Otherwise, the cache will clear in an emcc process, which is invoked while building
    # a system library into the cache, causing trouble.
    shared.check_sanity()

    for arg in args:
        if is_flag(arg):
            arg = arg[2:]
            if arg == 'lto':
                shared.Settings.WASM_OBJECT_FILES = 0
            elif arg == 'pic':
                shared.Settings.RELOCATABLE = 1
            # Reconfigure the cache dir to reflect the change
            shared.reconfigure_cache()

    args = [a for a in args if not is_flag(a)]

    # process tasks
    libname = shared.static_library_name

    auto_tasks = False
    tasks = args
    if 'SYSTEM' in tasks:
        tasks = SYSTEM_TASKS
        auto_tasks = True
    elif 'USER' in tasks:
        tasks = USER_TASKS
        auto_tasks = True
    elif 'ALL' in tasks:
        tasks = SYSTEM_TASKS + USER_TASKS
        auto_tasks = True
    if auto_tasks:
        if shared.Settings.WASM_BACKEND:
            skip_tasks = []
            if shared.Settings.RELOCATABLE:
                # we don't support PIC + pthreads yet
                skip_tasks += [
                    task for task in SYSTEM_TASKS + USER_TASKS
                    if '-mt' in task or 'thread' in task
                ]
            # cocos2d: must be ported, errors on
            # "Cannot recognize the target platform; are you targeting an unsupported platform?"
            skip_tasks += ['cocos2d']
            print(
                'Skipping building of %s, because WebAssembly does not support pthreads.'
                % ', '.join(skip_tasks))
            tasks = [x for x in tasks if x not in skip_tasks]
        else:
            if os.environ.get('EMSCRIPTEN_NATIVE_OPTIMIZER'):
                print(
                    'Skipping building of native-optimizer; EMSCRIPTEN_NATIVE_OPTIMIZER is environment.'
                )
            elif shared.EMSCRIPTEN_NATIVE_OPTIMIZER:
                print(
                    'Skipping building of native-optimizer; EMSCRIPTEN_NATIVE_OPTIMIZER set in .emscripten config.'
                )
            else:
                tasks += ['native_optimizer']
        print('Building targets: %s' % ' '.join(tasks))
    for what in tasks:
        logger.info('building and verifying ' + what)
        if what in SYSTEM_LIBRARIES:
            library = SYSTEM_LIBRARIES[what]
            library.get_path()
        elif what == 'struct_info':
            build(C_BARE, ['generated_struct_info.json'])
        elif what == 'native_optimizer':
            build(C_BARE, ['optimizer.2.exe'], ['-O2', '-s', 'WASM=0'])
        elif what == 'icu':
            build_port('icu', libname('libicuuc'), ['-s', 'USE_ICU=1'])
        elif what == 'zlib':
            build_port('zlib', 'libz.a', ['-s', 'USE_ZLIB=1'])
        elif what == 'bzip2':
            build_port('bzip2', 'libbz2.a', ['-s', 'USE_BZIP2=1'])
        elif what == 'bullet':
            build_port('bullet', libname('libbullet'), ['-s', 'USE_BULLET=1'])
        elif what == 'vorbis':
            build_port('vorbis', libname('libvorbis'), ['-s', 'USE_VORBIS=1'])
        elif what == 'ogg':
            build_port('ogg', libname('libogg'), ['-s', 'USE_OGG=1'])
        elif what == 'libjpeg':
            build_port('libjpeg', libname('libjpeg'), ['-s', 'USE_LIBJPEG=1'])
        elif what == 'libpng':
            build_port('libpng', libname('libpng'),
                       ['-s', 'USE_ZLIB=1', '-s', 'USE_LIBPNG=1'])
        elif what == 'sdl2':
            build_port('sdl2', libname('libSDL2'), ['-s', 'USE_SDL=2'])
        elif what == 'sdl2-mt':
            build_port('sdl2', libname('libSDL2-mt'),
                       ['-s', 'USE_SDL=2', '-s', 'USE_PTHREADS=1'])
        elif what == 'sdl2-gfx':
            build_port('sdl2-gfx', libname('libSDL2_gfx'), [
                '-s', 'USE_SDL=2', '-s', 'USE_SDL_IMAGE=2', '-s',
                'USE_SDL_GFX=2'
            ])
        elif what == 'sdl2-image':
            build_port('sdl2-image', libname('libSDL2_image'),
                       ['-s', 'USE_SDL=2', '-s', 'USE_SDL_IMAGE=2'])
        elif what == 'sdl2-image-png':
            build_port('sdl2-image', libname('libSDL2_image'), [
                '-s', 'USE_SDL=2', '-s', 'USE_SDL_IMAGE=2', '-s',
                'SDL2_IMAGE_FORMATS=["png"]'
            ])
        elif what == 'sdl2-image-jpg':
            build_port('sdl2-image', libname('libSDL2_image'), [
                '-s', 'USE_SDL=2', '-s', 'USE_SDL_IMAGE=2', '-s',
                'SDL2_IMAGE_FORMATS=["jpg"]'
            ])
        elif what == 'sdl2-net':
            build_port('sdl2-net', libname('libSDL2_net'),
                       ['-s', 'USE_SDL=2', '-s', 'USE_SDL_NET=2'])
        elif what == 'sdl2-mixer':
            build_port('sdl2-mixer', 'libSDL2_mixer.a', [
                '-s', 'USE_SDL=2', '-s', 'USE_SDL_MIXER=2', '-s',
                'USE_VORBIS=1'
            ])
        elif what == 'freetype':
            build_port('freetype', 'libfreetype.a', ['-s', 'USE_FREETYPE=1'])
        elif what == 'harfbuzz':
            build_port('harfbuzz', 'libharfbuzz.a', ['-s', 'USE_HARFBUZZ=1'])
        elif what == 'sdl2-ttf':
            build_port('sdl2-ttf', libname('libSDL2_ttf'), [
                '-s', 'USE_SDL=2', '-s', 'USE_SDL_TTF=2', '-s',
                'USE_FREETYPE=1'
            ])
        elif what == 'binaryen':
            build_port('binaryen', None, ['-s', 'WASM=1'])
        elif what == 'cocos2d':
            build_port('cocos2d', libname('libcocos2d'), [
                '-s', 'USE_COCOS2D=3', '-s', 'USE_ZLIB=1', '-s',
                'USE_LIBPNG=1', '-s', 'ERROR_ON_UNDEFINED_SYMBOLS=0'
            ])
        elif what == 'regal':
            build_port('regal', libname('libregal'), ['-s', 'USE_REGAL=1'])
        elif what == 'boost_headers':
            build_port('boost_headers', libname('libboost_headers'),
                       ['-s', 'USE_BOOST_HEADERS=1'])
        else:
            logger.error('unfamiliar build target: ' + what)
            return 1

        logger.info('...success')
    return 0
Exemple #3
0
def main():
    global force
    parser = argparse.ArgumentParser(description=__doc__, usage=get_usage())
    parser.add_argument('--lto',
                        action='store_true',
                        help='build bitcode object for LTO')
    parser.add_argument(
        '--pic',
        action='store_true',
        help='build relocatable objects for suitable for dynamic linking')
    parser.add_argument('--force',
                        action='store_true',
                        help='force rebuild of target (by removing it first)')
    parser.add_argument('operation',
                        help='currently only "build" is supported')
    parser.add_argument('targets', nargs='+', help='see above')
    args = parser.parse_args()

    if args.operation != 'build':
        shared.exit_with_error('unfamiliar operation: ' + args.operation)

    # process flags

    # Check sanity so that if settings file has changed, the cache is cleared here.
    # Otherwise, the cache will clear in an emcc process, which is invoked while building
    # a system library into the cache, causing trouble.
    shared.check_sanity()

    if args.lto:
        shared.Settings.WASM_OBJECT_FILES = 0
        # Reconfigure the cache dir to reflect the change
        shared.reconfigure_cache()

    if args.pic:
        shared.Settings.RELOCATABLE = 1
        # Reconfigure the cache dir to reflect the change
        shared.reconfigure_cache()

    if args.force:
        force = True

    # process tasks
    libname = shared.static_library_name

    auto_tasks = False
    tasks = args.targets
    if 'SYSTEM' in tasks:
        tasks = SYSTEM_TASKS
        auto_tasks = True
    elif 'USER' in tasks:
        tasks = USER_TASKS
        auto_tasks = True
    elif 'ALL' in tasks:
        tasks = SYSTEM_TASKS + USER_TASKS
        auto_tasks = True
    if auto_tasks:
        if shared.Settings.WASM_BACKEND:
            skip_tasks = []
            if shared.Settings.RELOCATABLE:
                # we don't support PIC + pthreads yet
                skip_tasks += [
                    task for task in SYSTEM_TASKS + USER_TASKS
                    if '-mt' in task or 'thread' in task
                ]
            # cocos2d: must be ported, errors on
            # "Cannot recognize the target platform; are you targeting an unsupported platform?"
            skip_tasks += ['cocos2d']
            print(
                'Skipping building of %s, because WebAssembly does not support pthreads.'
                % ', '.join(skip_tasks))
            tasks = [x for x in tasks if x not in skip_tasks]
        else:
            if os.environ.get('EMSCRIPTEN_NATIVE_OPTIMIZER'):
                print(
                    'Skipping building of native-optimizer; EMSCRIPTEN_NATIVE_OPTIMIZER is environment.'
                )
            elif shared.EMSCRIPTEN_NATIVE_OPTIMIZER:
                print(
                    'Skipping building of native-optimizer; EMSCRIPTEN_NATIVE_OPTIMIZER set in .emscripten config.'
                )
            else:
                tasks += ['native_optimizer']
        print('Building targets: %s' % ' '.join(tasks))
    for what in tasks:
        logger.info('building and verifying ' + what)
        if what in SYSTEM_LIBRARIES:
            library = SYSTEM_LIBRARIES[what]
            if force:
                library.erase()
            library.get_path()
        elif what == 'struct_info':
            build(C_BARE, ['generated_struct_info.json'])
        elif what == 'native_optimizer':
            build(C_BARE, ['optimizer.2.exe'], ['-O2', '-s', 'WASM=0'])
        elif what == 'icu':
            build_port('icu', libname('libicuuc'), ['-s', 'USE_ICU=1'],
                       '#include "unicode/ustring.h"')
        elif what == 'zlib':
            build_port('zlib', 'libz.a', ['-s', 'USE_ZLIB=1'])
        elif what == 'bzip2':
            build_port('bzip2', 'libbz2.a', ['-s', 'USE_BZIP2=1'])
        elif what == 'bullet':
            build_port('bullet', libname('libbullet'), ['-s', 'USE_BULLET=1'])
        elif what == 'vorbis':
            build_port('vorbis', libname('libvorbis'), ['-s', 'USE_VORBIS=1'])
        elif what == 'ogg':
            build_port('ogg', libname('libogg'), ['-s', 'USE_OGG=1'])
        elif what == 'libjpeg':
            build_port('libjpeg', libname('libjpeg'), ['-s', 'USE_LIBJPEG=1'])
        elif what == 'libpng':
            build_port('libpng', libname('libpng'),
                       ['-s', 'USE_ZLIB=1', '-s', 'USE_LIBPNG=1'])
        elif what == 'sdl2':
            build_port('sdl2', libname('libSDL2'), ['-s', 'USE_SDL=2'])
        elif what == 'sdl2-mt':
            build_port('sdl2', libname('libSDL2-mt'),
                       ['-s', 'USE_SDL=2', '-s', 'USE_PTHREADS=1'])
        elif what == 'sdl2-gfx':
            build_port('sdl2-gfx', libname('libSDL2_gfx'), [
                '-s', 'USE_SDL=2', '-s', 'USE_SDL_IMAGE=2', '-s',
                'USE_SDL_GFX=2'
            ])
        elif what == 'sdl2-image':
            build_port('sdl2-image', libname('libSDL2_image'),
                       ['-s', 'USE_SDL=2', '-s', 'USE_SDL_IMAGE=2'])
        elif what == 'sdl2-image-png':
            build_port('sdl2-image', libname('libSDL2_image_png'), [
                '-s', 'USE_SDL=2', '-s', 'USE_SDL_IMAGE=2', '-s',
                'SDL2_IMAGE_FORMATS=["png"]'
            ])
        elif what == 'sdl2-image-jpg':
            build_port('sdl2-image', libname('libSDL2_image_jpg'), [
                '-s', 'USE_SDL=2', '-s', 'USE_SDL_IMAGE=2', '-s',
                'SDL2_IMAGE_FORMATS=["jpg"]'
            ])
        elif what == 'sdl2-net':
            build_port('sdl2-net', libname('libSDL2_net'),
                       ['-s', 'USE_SDL=2', '-s', 'USE_SDL_NET=2'])
        elif what == 'sdl2-mixer':
            build_port('sdl2-mixer', libname('libSDL2_mixer'), [
                '-s', 'USE_SDL=2', '-s', 'USE_SDL_MIXER=2', '-s',
                'USE_VORBIS=1'
            ])
        elif what == 'freetype':
            build_port('freetype', 'libfreetype.a', ['-s', 'USE_FREETYPE=1'])
        elif what == 'harfbuzz':
            build_port('harfbuzz', 'libharfbuzz.a', ['-s', 'USE_HARFBUZZ=1'])
        elif what == 'harfbuzz-mt':
            build_port('harfbuzz-mt', 'libharfbuzz-mt.a',
                       ['-s', 'USE_HARFBUZZ=1', '-s', 'USE_PTHREADS=1'])
        elif what == 'sdl2-ttf':
            build_port('sdl2-ttf', libname('libSDL2_ttf'), [
                '-s', 'USE_SDL=2', '-s', 'USE_SDL_TTF=2', '-s',
                'USE_FREETYPE=1'
            ])
        elif what == 'binaryen':
            build_port('binaryen', None, ['-s', 'WASM=1'])
        elif what == 'cocos2d':
            build_port('cocos2d', libname('libcocos2d'), [
                '-s', 'USE_COCOS2D=3', '-s', 'USE_ZLIB=1', '-s',
                'USE_LIBPNG=1', '-s', 'ERROR_ON_UNDEFINED_SYMBOLS=0'
            ])
        elif what == 'regal':
            build_port('regal', libname('libregal'), ['-s', 'USE_REGAL=1'])
        elif what == 'regal-mt':
            build_port(
                'regal', libname('libregal'),
                ['-s', 'USE_REGAL=1', '-s', 'USE_PTHREADS=1', '-pthread'])
        elif what == 'boost_headers':
            build_port('boost_headers', libname('libboost_headers'),
                       ['-s', 'USE_BOOST_HEADERS=1'])
        elif what == 'libsockets':
            build(
                '''
        #include <sys/socket.h>
        int main() {
          return socket(0,0,0);
        }
      ''', [libname('libsockets')])
        elif what == 'libsockets_proxy':
            build(
                '''
        #include <sys/socket.h>
        int main() {
          return socket(0,0,0);
        }
      ''', [libname('libsockets_proxy')], [
                    '-s', 'PROXY_POSIX_SOCKETS=1', '-s', 'USE_PTHREADS=1',
                    '-s', 'PROXY_TO_PTHREAD=1'
                ])
        else:
            logger.error('unfamiliar build target: ' + what)
            return 1

        logger.info('...success')
    return 0
Exemple #4
0
def main():
    if len(sys.argv) < 2 or sys.argv[1] in [
            '-v', '-help', '--help', '-?', '?'
    ]:
        print_help()
        return 0

    operation = sys.argv[1]
    if operation != 'build':
        shared.exit_with_error('unfamiliar operation: ' + operation)

    # process flags

    args = sys.argv[2:]

    def is_flag(arg):
        return arg.startswith('--')

    for arg in args:
        if is_flag(arg):
            arg = arg[2:]
            if arg == 'lto':
                shared.Settings.WASM_OBJECT_FILES = 0
                # Reconfigure the cache dir to reflect the change
                shared.reconfigure_cache()

    args = [a for a in args if not is_flag(a)]

    # process tasks
    libname = shared.static_library_name

    auto_tasks = False
    tasks = args
    if 'SYSTEM' in tasks:
        tasks = SYSTEM_TASKS
        auto_tasks = True
    elif 'USER' in tasks:
        tasks = USER_TASKS
        auto_tasks = True
    elif 'ALL' in tasks:
        tasks = SYSTEM_TASKS + USER_TASKS
        auto_tasks = True
    if auto_tasks:
        if shared.Settings.WASM_BACKEND:
            skip_tasks = [
                task for task in SYSTEM_TASKS + USER_TASKS
                if '-mt' in task or 'thread' in task
            ]
            # cocos2d: must be ported, errors on
            # "Cannot recognize the target platform; are you targeting an unsupported platform?"
            skip_tasks += ['cocos2d']
            print(
                'Skipping building of %s, because WebAssembly does not support pthreads.'
                % ', '.join(skip_tasks))
            tasks = [x for x in tasks if x not in skip_tasks]
        else:
            if os.environ.get('EMSCRIPTEN_NATIVE_OPTIMIZER'):
                print(
                    'Skipping building of native-optimizer; EMSCRIPTEN_NATIVE_OPTIMIZER is environment.'
                )
            elif shared.EMSCRIPTEN_NATIVE_OPTIMIZER:
                print(
                    'Skipping building of native-optimizer; EMSCRIPTEN_NATIVE_OPTIMIZER set in .emscripten config.'
                )
            else:
                tasks += ['native_optimizer']
        print('Building targets: %s' % ' '.join(tasks))
    for what in tasks:
        logger.info('building and verifying ' + what)
        if what == 'compiler-rt':
            build(
                '''
        int main() {
          double _Complex a, b, c;
          c = a / b;
          return 0;
        }
      ''', ['libcompiler_rt.a'])
        elif what == 'libc':
            build(C_WITH_MALLOC, [libname('libc')])
        elif what == 'libc-extras':
            build(
                '''
        extern char **environ;
        int main() {
          return (int)environ;
        }
      ''', [libname('libc-extras')])
        elif what == 'struct_info':
            build(C_BARE, ['generated_struct_info.json'])
        elif what == 'emmalloc':
            build(C_WITH_MALLOC, [libname('libemmalloc')],
                  ['-s', 'MALLOC="emmalloc"'])
        elif what == 'emmalloc_debug':
            build(C_WITH_MALLOC, [libname('libemmalloc_debug')],
                  ['-s', 'MALLOC="emmalloc"', '-g'])
        elif what.startswith('dlmalloc'):
            cmd = ['-s', 'MALLOC="dlmalloc"']
            if '_debug' in what:
                cmd += ['-g']
            if '_noerrno' in what:
                cmd += ['-s', 'SUPPORT_ERRNO=0']
            if '_threadsafe' in what:
                cmd += ['-s', 'USE_PTHREADS=1']
            if '_tracing' in what:
                cmd += ['-s', 'EMSCRIPTEN_TRACING=1']
            build(C_WITH_MALLOC, [libname('lib' + what)], cmd)
        elif what in ('libc-mt', 'pthreads'):
            build(C_WITH_MALLOC, [libname('libc-mt'),
                                  libname('libpthreads')],
                  ['-s', 'USE_PTHREADS=1'])
        elif what == 'libc-wasm':
            build(C_WITH_STDLIB, [libname('libc-wasm')], ['-s', 'WASM=1'])
        elif what == 'libc++':
            build(CXX_WITH_STDLIB, ['libc++.a'],
                  ['-s', 'DISABLE_EXCEPTION_CATCHING=0'])
        elif what == 'libc++_noexcept':
            build(CXX_WITH_STDLIB, ['libc++_noexcept.a'])
        elif what == 'libc++abi':
            build(
                '''
        struct X { int x; virtual void a() {} };
        struct Y : X { int y; virtual void a() { y = 10; }};
        int main(int argc, char **argv) {
          Y* y = dynamic_cast<Y*>((X*)argv[1]);
          y->a();
          return y->y;
        }
      ''', [libname('libc++abi')])
        elif what == 'gl' or what.startswith('gl-'):
            opts = []
            if '-mt' in what:
                opts += ['-s', 'USE_PTHREADS=1']
            if '-emu' in what:
                opts += ['-s', 'LEGACY_GL_EMULATION=1']
            if '-webgl2' in what:
                opts += ['-s', 'USE_WEBGL2=1']
            build(
                '''
        extern "C" { extern void* emscripten_GetProcAddress(const char *x); }
        int main() {
          return int(emscripten_GetProcAddress("waka waka"));
        }
      ''', [libname('lib' + what)], opts)
        elif what == 'native_optimizer':
            build(C_BARE, ['optimizer.2.exe'], ['-O2', '-s', 'WASM=0'])
        elif what == 'compiler_rt_wasm':
            if shared.Settings.WASM_BACKEND:
                build(C_BARE, ['libcompiler_rt_wasm.a'], ['-s', 'WASM=1'])
            else:
                logger.warning(
                    'compiler_rt_wasm not built when using JSBackend')
        elif what == 'html5':
            build(
                '''
        #include <stdlib.h>
        #include "emscripten/key_codes.h"
        int main() {
          return emscripten_compute_dom_pk_code(NULL);
        }

      ''', [libname('libhtml5')])
        elif what == 'pthreads_stub':
            build(
                '''
        #include <emscripten/threading.h>
        int main() {
          return emscripten_is_main_runtime_thread();
        }

      ''', [libname('libpthreads_stub')])
        elif what == 'al':
            build(
                '''
        #include "AL/al.h"
        int main() {
          alGetProcAddress(0);
          return 0;
        }
      ''', [libname('libal')])
        elif what == 'icu':
            build_port('icu', libname('libicuuc'), ['-s', 'USE_ICU=1'])
        elif what == 'zlib':
            build_port('zlib', 'libz.a', ['-s', 'USE_ZLIB=1'])
        elif what == 'bullet':
            build_port('bullet', libname('libbullet'), ['-s', 'USE_BULLET=1'])
        elif what == 'vorbis':
            build_port('vorbis', libname('libvorbis'), ['-s', 'USE_VORBIS=1'])
        elif what == 'ogg':
            build_port('ogg', libname('libogg'), ['-s', 'USE_OGG=1'])
        elif what == 'libpng':
            build_port('libpng', libname('libpng'),
                       ['-s', 'USE_ZLIB=1', '-s', 'USE_LIBPNG=1'])
        elif what == 'sdl2':
            build_port('sdl2', libname('libSDL2'), ['-s', 'USE_SDL=2'])
        elif what == 'sdl2-gfx':
            build_port('sdl2-gfx', libname('libSDL2_gfx'), [
                '-s', 'USE_SDL=2', '-s', 'USE_SDL_IMAGE=2', '-s',
                'USE_SDL_GFX=2'
            ])
        elif what == 'sdl2-image':
            build_port('sdl2-image', libname('libSDL2_image'),
                       ['-s', 'USE_SDL=2', '-s', 'USE_SDL_IMAGE=2'])
        elif what == 'sdl2-image-png':
            build_port('sdl2-image', libname('libSDL2_image'), [
                '-s', 'USE_SDL=2', '-s', 'USE_SDL_IMAGE=2', '-s',
                'SDL2_IMAGE_FORMATS=["png"]'
            ])
        elif what == 'sdl2-net':
            build_port('sdl2-net', libname('libSDL2_net'),
                       ['-s', 'USE_SDL=2', '-s', 'USE_SDL_NET=2'])
        elif what == 'sdl2-mixer':
            build_port('sdl2-mixer', 'libSDL2_mixer.a', [
                '-s', 'USE_SDL=2', '-s', 'USE_SDL_MIXER=2', '-s',
                'USE_VORBIS=1'
            ])
        elif what == 'freetype':
            build_port('freetype', 'libfreetype.a', ['-s', 'USE_FREETYPE=1'])
        elif what == 'harfbuzz':
            build_port('harfbuzz', 'libharfbuzz.a', ['-s', 'USE_HARFBUZZ=1'])
        elif what == 'sdl2-ttf':
            build_port('sdl2-ttf', libname('libSDL2_ttf'), [
                '-s', 'USE_SDL=2', '-s', 'USE_SDL_TTF=2', '-s',
                'USE_FREETYPE=1'
            ])
        elif what == 'binaryen':
            build_port('binaryen', None, ['-s', 'WASM=1'])
        elif what == 'cocos2d':
            build_port('cocos2d', libname('libcocos2d'), [
                '-s', 'USE_COCOS2D=3', '-s', 'USE_ZLIB=1', '-s',
                'USE_LIBPNG=1', '-s', 'ERROR_ON_UNDEFINED_SYMBOLS=0'
            ])
        elif what == 'regal':
            build_port('regal', libname('libregal'), ['-s', 'USE_REGAL=1'])
        elif what == 'libc-sockets':
            build(
                '''
        #include <sys/socket.h>
        int main() {
          return socket(0,0,0);
        }
      ''', [static_library_name('libc-sockets')])
        elif what == 'libc-sockets-proxy':
            build(
                '''
        #include <sys/socket.h>
        int main() {
          return socket(0,0,0);
        }
      ''', [static_library_name('libc-sockets-proxy')], [
                    '-s', 'PROXY_POSIX_SOCKETS=1', '-s', 'USE_PTHREADS=1',
                    '-s', 'PROXY_TO_PTHREAD=1'
                ])
        else:
            logger.error('unfamiliar build target: ' + what)
            return 1

        logger.info('...success')
    return 0