6 #######################################################
7 # reusable functions and data structures
8 #######################################################
9 def LoadTool(name, env, **kw):
10 config_path = GetBuildPath('#/Build/Tools/SCons')
11 file, path, desc = imp.find_module(name, [config_path])
12 module = imp.load_module(name, file, path, desc)
13 module.generate(env, **kw)
15 def MergeListUnique(item_list, items):
17 if not item in item_list: item_list.append(item)
19 def MergeItemUnique(item_list, item):
20 if not item in item_list: item_list.append(item)
22 def GlobSources(drct, patterns, excluded_files=[]):
23 root = GetBuildPath('#'+drct)
25 for pattern in Split(patterns):
26 files += glob(root+'/'+pattern)
27 return [drct+'/'+os.path.basename(x) for x in files if os.path.basename(x) not in excluded_files]
32 def DeclareBuildDir(dir):
33 env.VariantDir(dir, GetDirPath(dir), duplicate=0)
35 def GetIncludeDirs(modules, exclude=None):
37 for module in Split(modules):
38 if Modules.has_key(module) and not module == exclude:
39 dirs += Modules[module].GetIncludeDirs()
41 dirs += [GetDirPath(module)]
44 def GetLibraries(modules):
46 for module in Split(modules):
47 if Modules.has_key(module):
48 libs += Modules[module].GetLibraries()
55 def __init__(self, name, included_modules = [], linked_modules = []):
57 self.included_modules = included_modules
58 self.linked_modules = linked_modules
61 def GetLibraries(self):
62 return self.product+GetLibraries(self.linked_modules)
64 def GetIncludeDirs(self):
65 return GetIncludeDirs(self.included_modules+self.build_include_dirs, self.name)
67 class LibraryModule(Module):
68 def __init__(self, name,
69 build_source_dirs = ['.'],
70 build_source_files = {},
71 source_root = 'Source',
72 build_source_pattern = ['*.c', '*.cpp'],
73 build_include_dirs = [],
74 included_modules = [],
75 included_only_modules = [],
79 extra_cpp_defines = [],
82 build_source_dirs = [source_root+'/'+drct for drct in build_source_dirs]
85 Split(included_modules)+Split(included_only_modules)+Split(build_source_dirs),
86 Split(linked_modules)+Split(included_modules))
87 self.build_include_dirs = build_include_dirs
88 if environment is None:
89 self.env = env.Clone()
91 self.env = environment.Clone()
92 self.env.AppendUnique(CPPDEFINES = extra_cpp_defines)
94 # store this new object in the module dictionary
97 # for each source drct to build, create a VariantDir
98 # to say where we want the object files to be built,
99 # and compute the list of source files to build
101 for drct in Split(build_source_dirs):
102 DeclareBuildDir(drct)
103 sources += GlobSources(drct, build_source_pattern, excluded_files)
105 # add cherry-picked files
106 for drct in build_source_files.keys():
107 pattern = build_source_files[drct]
108 drct_path = source_root+'/'+drct
109 DeclareBuildDir(drct_path)
110 sources += GlobSources(drct_path, pattern)
112 # calculate our build include path
113 cpp_path = GetIncludeDirs(Split(self.build_include_dirs) + Split(build_source_dirs) + self.included_modules + self.linked_modules)
115 # the product is a library
116 self.env.AppendUnique(CPPPATH=cpp_path)
118 self.product = self.env.Library(target=name, source=sources)
120 libs = GetLibraries(Split(linked_modules))
121 self.product = self.env.SharedLibrary(target=name, LIBS=libs, source=sources)
122 self.env.Alias(name, self.product)
124 # copy to Targets folder
126 inst = env.Install(dir=env.GetBuildPath('#/Targets/'+env['target']+'/'+env['build_config']), source=self.product)
127 if env['build_config'] == 'Release' and env.has_key('STRIP'):
128 env.AddPostAction(inst, env['STRIP']+' $TARGETS');
130 def Application(name, dir, deps, install = False):
132 libs = GetLibraries(deps)
133 cpp_path = GetIncludeDirs(deps)
135 prog = env.Program(name,
136 GlobSources(dir, ['*.c', '*.cpp']) + env['NPT_EXTRA_EXECUTABLE_OBJECTS'],
137 LIBS=libs, CPPPATH=cpp_path)
138 #env.Alias(name, prog)
139 if env.has_key('NPT_EXECUTABLE_POST_PROCESSOR'):
140 env.AddPostAction(prog, env['NPT_EXECUTABLE_POST_PROCESSOR'])
142 # copy to Targets folder
144 inst = env.Install(dir=env.GetBuildPath('#/Targets/'+env['target']+'/'+env['build_config']), source=prog)
145 if env['build_config'] == 'Release' and env.has_key('STRIP'):
146 env.AddPostAction(inst, env['STRIP']+' $TARGETS');
148 #######################################################
150 #######################################################
154 env['NPT_EXTRA_LIBS'] = []
155 env['NPT_EXTRA_EXECUTABLE_OBJECTS'] = []
157 if (env['build_config'] == 'Debug'):
158 env.AppendUnique(CPPDEFINES=['NPT_DEBUG', 'NPT_CONFIG_ENABLE_LOGGING', 'PLATINUM_UPNP_SPECS_STRICT'])
160 env.AppendUnique(CPPDEFINES=['NDEBUG', 'NPT_CONFIG_ENABLE_LOGGING', 'PLATINUM_UPNP_SPECS_STRICT'])
162 ### try to read in any target specific configuration
163 target_config_file = env.GetBuildPath('#/Build/Targets/'+env['target']+'/Config.scons')
164 if os.path.exists(target_config_file):
165 # Load the target-specific config file
166 execfile(target_config_file)
168 #######################################################
173 # The LibraryModule() function declares a code module
174 # The included_modules parameter is a list of all the modules and/or directories
175 # that will be added to the include path when building this module AND to
176 # the include path of any other module that depends on this one.
177 # The linked_modules parameter is a list of all the modules and/or directories
178 # that are necessary to build this module. These modules will be added to
179 # the include path of this module, but not to that of the modules that depend
180 # on this module. The modules that depend on this module, however, will
181 # automatically link with the linked_modules.
182 # Note that the included_modules list is automatically added to the
183 # linked_modules list, so that you do not need to list in linked_modules
184 # the modules that are already listed in included_modules.
185 # If a module needs to export an include path to its dependents that
186 # is not a module that the dependent can link with (ex: an include dir),
187 # list it in the included_only_modules.
188 # To summarize: included_modules should list all the modules that users
189 # of the public interface should depend on; linked_modules should list
190 # all the modules not listed in included_modules that are used by the
191 # module's implementation only.
192 #######################################################
194 NPT_SOURCE_ROOT = 'ThirdParty/Neptune'
197 neptune_extra_linked_modules = []
198 if not env.has_key('NPT_CONFIG_NO_ZIP'):
199 extra_cpp_flags = ['NPT_CONFIG_ENABLE_ZIP']
200 neptune_extra_linked_modules += ['Zlib']
202 LibraryModule(name = 'Zlib',
203 source_root = NPT_SOURCE_ROOT,
204 build_source_dirs = ['ThirdParty/zlib-1.2.3'])
206 if not env.has_key('NPT_CONFIG_NO_SSL'):
207 extra_cpp_flags += ['NPT_CONFIG_ENABLE_TLS']
208 tls_data_dirs = ['Data/TLS']
210 neptune_extra_linked_modules += ['axTLS']
212 LibraryModule(name = 'axTLS',
213 source_root = NPT_SOURCE_ROOT,
214 build_source_dirs = ['ThirdParty/axTLS/crypto', 'ThirdParty/axTLS/ssl', 'ThirdParty/axTLS/config/Generic'])
219 if not env.has_key('NPT_CONFIG_NO_CRYPTO'):
220 extra_cpp_flags += ['NPT_CONFIG_ENABLE_CRYPTO']
221 neptune_excluded_files = []
223 neptune_excluded_files = ['NptCrypto.cpp', 'NptDigest.cpp']
225 LibraryModule(name = 'Neptune',
226 build_source_dirs = ['Core']+tls_data_dirs,
227 build_source_files = env['NPT_SYSTEM_SOURCES'],
228 excluded_files = neptune_excluded_files,
229 extra_cpp_defines = extra_cpp_flags,
230 linked_modules = env['NPT_EXTRA_LIBS']+neptune_extra_linked_modules,
231 source_root = NPT_SOURCE_ROOT + '/Source')
234 LibraryModule(name = 'Platinum',
235 build_source_dirs = ['Core', 'Extras'],
236 build_include_dirs = ['Source/Platinum'],
237 extra_cpp_defines = extra_cpp_flags,
238 included_modules = ['Neptune'])
240 # Platinum MediaServer
241 LibraryModule(name = 'PltMediaServer',
242 build_source_dirs = ['MediaServer'],
243 included_modules = ['Platinum'],
244 source_root = 'Source/Devices')
246 # Platinum MediaRenderer
247 LibraryModule(name = 'PltMediaRenderer',
248 build_source_dirs = ['MediaRenderer'],
249 included_modules = ['Platinum', 'PltMediaServer'],
250 source_root = 'Source/Devices')
252 # Platinum MediaConnect
253 LibraryModule(name = 'PltMediaConnect',
254 build_source_dirs = ['MediaConnect'],
255 included_modules = ['Platinum', 'PltMediaServer', 'PltMediaRenderer'],
256 excluded_files = ['MACFromIP.cpp'],
257 source_root = 'Source/Devices')
259 for app in ['MicroMediaController', 'MediaCrawler', 'MediaConnect', 'FrameStreamer']:
260 Application(name = app,
261 dir = 'Source/Apps/' + app,
262 deps = ['Platinum', 'PltMediaServer', 'PltMediaRenderer', 'PltMediaConnect'],
265 for test in ['FileMediaServer', 'MediaRenderer', 'LightSample', 'Http', 'Time']:
266 Application(name = test+'Test',
267 dir = 'Source/Tests/' + test,
268 deps = ['Platinum', 'PltMediaServer', 'PltMediaRenderer', 'PltMediaConnect'],
271 for tool in ['TextToHeader']:
272 Application(name = tool,
273 dir = 'Source/Tools/' + tool,