Source

pysdl-cffi / sdl / builder.py

Full commit
# code generator - only required at build time
from __future__ import (print_function, division, absolute_import)

import os
from autobind import AutoBind

THISDIR = os.path.dirname(__file__)
BIN_PATH = os.path.abspath(os.path.join(THISDIR, '..', 'sdl-bin'))
INCLUDE_PATH = os.path.abspath(os.path.join(BIN_PATH, 'include'))
CDEF_PATH = os.path.abspath(os.path.join(INCLUDE_PATH, 'SDL2'))
LIB_PATH = os.path.abspath(os.path.join(BIN_PATH, 'lib'))
LIBS = [
    'SDL2',
]
STATIC_LIBS = [os.path.join(LIB_PATH, 'lib' + lib + '.a') for lib in LIBS]
VERIFY_OPTIONS = dict(
    #extra_link_args = STATIC_LIBS,
    extra_link_args = [
        '-fPIC',
    ] + STATIC_LIBS,
    library_dirs = [
        LIB_PATH
    ],
    include_dirs = [
        INCLUDE_PATH,
    ],
    extra_compile_args = [
        #'-Wfatal-errors',
    ],
    tmpdir = os.path.abspath(os.path.join(THISDIR, '..', '__pycache__'))
)

SDL_DEFS = '../../../sdl_defs/'

autobind = AutoBind(options=dict(
    CDEF_PATH = CDEF_PATH,
    CDEF_FILES = [ 
        '../../../sdl_defs/prefix.h',
         'SDL_stdinc.h',
         'SDL_blendmode.h',
         'SDL_scancode.h',
    #    'SDL_config.h',
         SDL_DEFS + 'SDL_pixels.h',
         'SDL_rect.h',
         'SDL_rwops.h',
         'SDL_surface.h',
         SDL_DEFS + 'SDL_keycode.h',
         'SDL_error.h',
    #    'SDL_endian.h',
    #    'SDL_mutex.h',
    #    'SDL_thread.h',
         SDL_DEFS + 'SDL_video.h',
         'SDL_keyboard.h',
         'SDL_mouse.h',
         'SDL_joystick.h',
         'SDL_gamecontroller.h',
         'SDL_quit.h',
         'SDL_touch.h',
         'SDL_gesture.h',
    #    'SDL_main.h',
    #    'SDL_assert.h',
    #    'SDL_atomic.h',
    #    'SDL_audio.h',
         'SDL_clipboard.h',
    #    'SDL_cpuinfo.h',
         SDL_DEFS + 'SDL_events.h',
    #    'SDL_hints.h',
    #    'SDL_loadso.h',
    #    'SDL_log.h',
    #    'SDL_power.h',
    #    'SDL_render.h',
    #    'SDL_system.h',
    #    'SDL_timer.h',
    #    'SDL_version.h',
        'SDL.h'
    ],
    DEFINES_BLACKLIST = [
        'SDL_BlitScaled',
        'SDL_BlitSurface',
    ],
    DEFINES = [],
    PRIVATE_SYMBOLS = [
        'SDL_GetError',
        'SDL_Init',
        'SDL_PollEvent',
        'SDL_GetMouseState',
        'SDL_GetWindowSize',
        'SDL_GetCurrentDisplayMode',
        'SDL_GetDisplayMode',
        'SDL_GetDesktopDisplayMode',
        'SDL_GL_GetAttribute',
        'SDL_GetClipboardText',
    ],
    AUTOCHECK_BLACKLIST = [
        'SDL_GetError',
        'SDL_ClearError',
        'SDL_Init',
        'SDL_Quit',
    ],
    REPLACES = [
        ('DECLSPEC', ''),
        ('SDLCALL', ''),
        ('SDL_COMPILE_TIME_ASSERT(uint8, sizeof(Uint8) == 1);', ''),
        ('SDL_COMPILE_TIME_ASSERT(sint8, sizeof(Sint8) == 1);', ''),
        ('SDL_COMPILE_TIME_ASSERT(uint16, sizeof(Uint16) == 2);', ''),
        ('SDL_COMPILE_TIME_ASSERT(sint16, sizeof(Sint16) == 2);', ''),
        ('SDL_COMPILE_TIME_ASSERT(uint32, sizeof(Uint32) == 4);', ''),
        ('SDL_COMPILE_TIME_ASSERT(sint32, sizeof(Sint32) == 4);', ''),
        ('SDL_COMPILE_TIME_ASSERT(uint64, sizeof(Uint64) == 8);', ''),
        ('SDL_COMPILE_TIME_ASSERT(sint64, sizeof(Sint64) == 8);', ''),
    ],
    VERIFY_SOURCE = '#include "SDL2/SDL.h"\n',
    VERIFY_OPTIONS = VERIFY_OPTIONS,
    AUTOMANGLE = False,
    #FINDERROR = True,
    PYPREDEFS = os.path.join(THISDIR, '..', 'predefs', 'sdl.pypredef'),
    OUTMODULE = os.path.join(THISDIR, '_sdl.py'),
))

################################################################################

if __name__ == '__main__':
    autobind.build()