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