SConscript revision 848b8605
1848b8605Smrg#######################################################################
2848b8605Smrg# SConscript for shared-glapi/es1api/es2api
3848b8605Smrg
4848b8605Smrgfrom sys import executable as python_cmd
5848b8605Smrg
6848b8605SmrgImport('*')
7848b8605Smrg
8848b8605Smrgdef mapi_objects(env, printer, mode):
9848b8605Smrg    """Return mapi objects built for the given printer and mode."""
10848b8605Smrg    mapi_sources = {
11848b8605Smrg        'glapi': [
12848b8605Smrg            'entry.c',
13848b8605Smrg            'mapi_glapi.c',
14848b8605Smrg            'stub.c',
15848b8605Smrg            'table.c',
16848b8605Smrg            'u_current.c',
17848b8605Smrg            'u_execmem.c',
18848b8605Smrg        ],
19848b8605Smrg        'bridge': ['entry.c'],
20848b8605Smrg    }
21848b8605Smrg    mapi_defines = {
22848b8605Smrg        'glapi': ['MAPI_MODE_GLAPI'],
23848b8605Smrg        'bridge': ['MAPI_MODE_BRIDGE'],
24848b8605Smrg    }
25848b8605Smrg
26848b8605Smrg    header_name = '%s-tmp.h' % (printer)
27848b8605Smrg
28848b8605Smrg    # generate ABI header
29848b8605Smrg    header = env.CodeGenerate(
30848b8605Smrg        target = header_name,
31848b8605Smrg        script = '../mapi_abi.py',
32848b8605Smrg        source = '../glapi/gen/gl_and_es_API.xml',
33848b8605Smrg        command = python_cmd + ' $SCRIPT ' + \
34848b8605Smrg                '--printer %s --mode lib $SOURCE > $TARGET' % (printer),
35848b8605Smrg    )
36848b8605Smrg
37848b8605Smrg    cpppath = [
38848b8605Smrg        header[0].dir,
39848b8605Smrg        '#/include',
40848b8605Smrg        '#/src/mapi',
41848b8605Smrg    ]
42848b8605Smrg    
43848b8605Smrg    cppdefines = mapi_defines[mode] + [
44848b8605Smrg        'MAPI_ABI_HEADER=\\"%s\\"' % (header_name),
45848b8605Smrg    ]
46848b8605Smrg
47848b8605Smrg    if env['platform'] == 'windows':
48848b8605Smrg        if mode == 'glapi':
49848b8605Smrg            cppdefines += [
50848b8605Smrg                '_GLAPI_DLL_EXPORTS', # declare _glapi_* as __declspec(dllexport) in glapi.h
51848b8605Smrg            ]
52848b8605Smrg        else:
53848b8605Smrg            cppdefines += [
54848b8605Smrg                '_GDI32_', # prevent gl* being declared __declspec(dllimport) in MS headers
55848b8605Smrg                'BUILD_GL32', # declare gl* as __declspec(dllexport) in Mesa headers
56848b8605Smrg            ]
57848b8605Smrg
58848b8605Smrg    objects = []
59848b8605Smrg    for s in mapi_sources[mode]:
60848b8605Smrg        o = env.SharedObject(
61848b8605Smrg            target = '%s-%s' % (printer, s[:-2]),
62848b8605Smrg            source = '../' + s,
63848b8605Smrg            CPPPATH = cpppath,
64848b8605Smrg            CPPDEFINES = cppdefines,
65848b8605Smrg        )
66848b8605Smrg        objects.append(o[0])
67848b8605Smrg
68848b8605Smrg    env.Depends(objects, header)
69848b8605Smrg
70848b8605Smrg    return objects
71848b8605Smrg
72848b8605Smrgenv = env.Clone()
73848b8605Smrg
74848b8605Smrgenv['SHLIBPREFIX'] = 'lib'
75848b8605Smrgenv['LIBPREFIX'] = 'lib'
76848b8605Smrg
77848b8605Smrgshared_glapi_objects = mapi_objects(env, 'shared-glapi', 'glapi')
78848b8605Smrgshared_glapi = env.SharedLibrary(
79848b8605Smrg    target = 'glapi',
80848b8605Smrg    source = shared_glapi_objects,
81848b8605Smrg)
82848b8605Smrg
83848b8605Smrg# manually add LIBPREFIX on windows
84848b8605Smrgif env['platform'] == 'windows':
85848b8605Smrg    libs = ['libglapi']
86848b8605Smrgelse:
87848b8605Smrg    libs = ['glapi']
88848b8605Smrg
89848b8605Smrges1api_objects = mapi_objects(env, 'es1api', 'bridge')
90848b8605Smrges1api = env.SharedLibrary(
91848b8605Smrg    target = 'GLESv1_CM',
92848b8605Smrg    source = es1api_objects,
93848b8605Smrg    LIBPATH = ['.'],
94848b8605Smrg    LIBS = libs,
95848b8605Smrg)
96848b8605Smrg
97848b8605Smrges2api_objects = mapi_objects(env, 'es2api', 'bridge')
98848b8605Smrges2api = env.SharedLibrary(
99848b8605Smrg    target = 'GLESv2',
100848b8605Smrg    source = es2api_objects,
101848b8605Smrg    LIBPATH = ['.'],
102848b8605Smrg    LIBS = libs,
103848b8605Smrg)
104848b8605Smrg
105848b8605Smrgenv.InstallSharedLibrary(shared_glapi, version=(0, 0, 0))
106848b8605Smrgenv.InstallSharedLibrary(es1api, version=(1, 0, 0))
107848b8605Smrgenv.InstallSharedLibrary(es2api, version=(2, 0, 0))
108848b8605Smrg
109848b8605Smrgif env['platform'] == 'windows':
110848b8605Smrg    shared_glapi = env.FindIxes(shared_glapi, 'LIBPREFIX', 'LIBSUFFIX')
111848b8605Smrgelse:
112848b8605Smrg    shared_glapi = env.FindIxes(shared_glapi, 'SHLIBPREFIX', 'SHLIBSUFFIX')
113848b8605Smrg
114848b8605Smrg# build glapi bridge as a convenience libarary for libgl-xlib/libgl-gdi
115848b8605Smrgbridge_glapi_objects = mapi_objects(env, 'glapi', 'bridge')
116848b8605Smrgbridge_glapi = env.ConvenienceLibrary(
117848b8605Smrg    target = 'glapi_bridge',
118848b8605Smrg    source = bridge_glapi_objects,
119848b8605Smrg)
120848b8605Smrg
121848b8605SmrgExport(['shared_glapi', 'bridge_glapi'])
122