Tizen 2.0 Release
[profile/ivi/osmesa.git] / src / mapi / shared-glapi / SConscript
1 #######################################################################
2 # SConscript for shared-glapi/es1api/es2api
3
4 from sys import executable as python_cmd
5
6 Import('*')
7
8 def mapi_objects(env, printer, mode):
9     """Return mapi objects built for the given printer and mode."""
10     mapi_sources = {
11         'glapi': ['entry.c', 'mapi_glapi.c', 'stub.c', 'table.c',
12                   'u_current.c', 'u_execmem.c', 'u_thread.c'],
13         'bridge': ['entry.c'],
14     }
15     mapi_defines = {
16         'glapi': ['MAPI_MODE_GLAPI'],
17         'bridge': ['MAPI_MODE_BRIDGE'],
18     }
19
20     header_name = '%s-tmp.h' % (printer)
21
22     # generate ABI header
23     header = env.CodeGenerate(
24         target = header_name,
25         script = '../mapi/mapi_abi.py',
26         source = '../glapi/gen/gl_and_es_API.xml',
27         command = python_cmd + ' $SCRIPT ' + \
28                 '--printer %s --mode lib $SOURCE > $TARGET' % (printer),
29     )
30
31     cpppath = [
32         header[0].dir,
33         '#/include',
34         '#/src/mapi',
35     ]
36     
37     cppdefines = mapi_defines[mode] + [
38         'MAPI_ABI_HEADER=\\"%s\\"' % (header_name),
39     ]
40
41     if env['platform'] == 'windows':
42         if mode == 'glapi':
43             cppdefines += [
44                 '_GLAPI_DLL_EXPORTS', # declare _glapi_* as __declspec(dllexport) in glapi.h
45             ]
46         else:
47             cppdefines += [
48                 '_GDI32_', # prevent gl* being declared __declspec(dllimport) in MS headers
49                 'BUILD_GL32', # declare gl* as __declspec(dllexport) in Mesa headers
50             ]
51
52     objects = []
53     for s in mapi_sources[mode]:
54         o = env.SharedObject(
55             target = '%s-%s' % (printer, s[:-2]),
56             source = '../mapi/' + s,
57             CPPPATH = cpppath,
58             CPPDEFINES = cppdefines,
59         )
60         objects.append(o[0])
61
62     env.Depends(objects, header)
63
64     return objects
65
66 if env['platform'] != 'winddk':
67     env = env.Clone()
68
69     env['SHLIBPREFIX'] = 'lib'
70     env['LIBPREFIX'] = 'lib'
71
72     shared_glapi_objects = mapi_objects(env, 'shared-glapi', 'glapi')
73     shared_glapi = env.SharedLibrary(
74         target = 'glapi',
75         source = shared_glapi_objects,
76     )
77
78     # manually add LIBPREFIX on windows
79     if env['platform'] == 'windows':
80         libs = ['libglapi']
81     else:
82         libs = ['glapi']
83
84     es1api_objects = mapi_objects(env, 'es1api', 'bridge')
85     es1api = env.SharedLibrary(
86         target = 'GLESv1_CM',
87         source = es1api_objects,
88         LIBPATH = ['.'],
89         LIBS = libs,
90     )
91
92     es2api_objects = mapi_objects(env, 'es2api', 'bridge')
93     es2api = env.SharedLibrary(
94         target = 'GLESv2',
95         source = es2api_objects,
96         LIBPATH = ['.'],
97         LIBS = libs,
98     )
99
100     env.InstallSharedLibrary(shared_glapi, version=(0, 0, 0))
101     env.InstallSharedLibrary(es1api, version=(1, 0, 0))
102     env.InstallSharedLibrary(es2api, version=(2, 0, 0))
103
104     if env['platform'] == 'windows':
105         shared_glapi = env.FindIxes(shared_glapi, 'LIBPREFIX', 'LIBSUFFIX')
106     else:
107         shared_glapi = env.FindIxes(shared_glapi, 'SHLIBPREFIX', 'SHLIBSUFFIX')
108
109     # build glapi bridge as a convenience libarary for libgl-xlib/libgl-gdi
110     bridge_glapi_objects = mapi_objects(env, 'glapi', 'bridge')
111     bridge_glapi = env.ConvenienceLibrary(
112         target = 'glapi_bridge',
113         source = bridge_glapi_objects,
114     )
115
116     Export(['shared_glapi', 'bridge_glapi'])