1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
|
#!/usr/bin/python3
"""
Support for building rlvm objects
"""
import os
def _MakeStaticName(lib_name):
return 'STATIC_' + lib_name + "_LIBS"
def RlvmLibrary(env, lib_name, *args, **kwargs):
"""
Psuedo-builder for rlvm's internal libraries to speed up development.
"""
# if env['BUILD_TYPE'] == "Debug":
# return env.SharedLibrary(lib_name, args)
# else:
return env.StaticLibrary(lib_name, *args, **kwargs)
def RlvmProgram(env, prog_name, *args, **kwargs):
"""Psuedo-builder for rlvm programs to handle special static linking on per
platform basis.
RlvmProgram should be invoked per this example:
env.RlvmProgram("rlvm", [rlvm objects files], use_lib_set = ["SDL", "LUA"],
rlvm_libs = ['guichan_platform', 'rlvm'])
This will build the 'rlvm' binary with component libs libguichan_platform and
librlvm while including all the static libraries necessary for SDL and for
LUA.
Environment Variables Responded to:
- FULL_STATIC_BUILD: Checks to see if this is set and will attempt to link
the static
- STATIC_{string in set use_lib_set}_LIBS: Passing a string in the
use_lib_set will add the static libraries in that set to
- BUILD_TYPE: In "Debug" mode, all the values passed into RLVM_LIBS are
assumed to be
Returns:
Output node list from env.Program().
"""
# Need to be smarter about cloning
cloned_env = env.Clone()
# All the objects to link into the program. Note the order by which we add
# all these
objects = [ ]
# Add the actual program files
objects.extend(args)
# TODO: Deal with RLVM_LIBS in a shared objecty way
if 'rlvm_libs' in kwargs.keys():
for lib_name in kwargs['rlvm_libs']:
objects.append(env['LIBPREFIX'] + lib_name + env['LIBSUFFIX'])
# Add all static libraries from the various categories
if 'use_lib_set' in kwargs.keys():
for lib_set_name in kwargs['use_lib_set']:
lib_set = cloned_env[_MakeStaticName(lib_set_name)]
if lib_set:
objects.extend(lib_set)
# First, we need to see if this is a static build
if "full_static_build" in kwargs.keys() and kwargs['full_static_build'] == True:
# We must unpack each entry in LIBS and try to locate a static library to
old_libs = cloned_env['LIBS']
libpaths = cloned_env['LIBPATH']
no_static_library_libs = [ ]
for lib in old_libs:
found = False
if isinstance(lib, str):
for libpath in libpaths:
absolute_path = libpath + "/" + env['LIBPREFIX'] + lib + env['LIBSUFFIX']
if os.path.exists(absolute_path):
objects.append(absolute_path)
found = True
break
if found == False:
no_static_library_libs.append(lib)
# Put libraries with no static version back into the path
cloned_env['LIBS'] = no_static_library_libs
out_nodes = cloned_env.Program(prog_name, objects)
return out_nodes
def AddStaticLibraryTo(env, name, type):
"""
Adds a library to one of the internal STATIC_name_LIBS tables.
"""
path = env['LIBRARY_DIR'] + "/" + env['LIBPREFIX'] + name + env['LIBSUFFIX']
env[_MakeStaticName(type)].insert(0, path)
def BuildSubcomponent(env, component_name):
"""
Builds the subcomponent |name| and puts the resultant libraries in
build/libraries/|name| and exposes that subcomponent's headers to |env|.
"""
component_env = env.Clone()
component_env.Append(
CPPFLAGS = [
"-Os"
]
)
component_env.SConscript("vendor/" + component_name + "/SConscript",
variant_dir="build/libraries/" + component_name,
duplicate=0,
exports=["component_env", "env"])
# Make sure the main compilation can see the includes to these files
env.Append(CPPPATH = [ "#vendor/" + component_name + "/include/" ])
def generate(env, **kw):
env.Append(
# A list of absolute paths to static sdl libraries to make things that need
# SDL work.
STATIC_SDL_LIBS = [ ],
# A list of absolute paths to static lua objects to make that subsystem
# work.
STATIC_LUA_LIBS = [ ],
# A list of absolute paths to static google testing libraries.
STATIC_TEST_LIBS = [ ]
)
env.AddMethod(RlvmLibrary)
env.AddMethod(RlvmProgram)
env.AddMethod(AddStaticLibraryTo)
env.AddMethod(BuildSubcomponent)
def exists(env):
return True
|