blob: 791f40674ea4abef78953f4a1475515713c0c306 [file] [log] [blame]
Daniel Erat65f53982015-08-25 09:21:05 -06001# -*- python -*-
2
3# Copyright 2014 The Chromium OS Authors. All rights reserved.
4# Use of this source code is governed by a BSD-style license that can be
5# found in the LICENSE file.
6
7# This file is used to build the libchrome package for Chrome OS:
8# https://www.chromium.org/chromium-os/packages/libchrome
9
10import os
11
12env = Environment()
13
14BASE_VER = os.environ.get('BASE_VER', '0')
15PKG_CONFIG = os.environ.get('PKG_CONFIG', 'pkg-config')
16CHROME_INCLUDE_PATH = os.environ.get('CHROME_INCLUDE_PATH', '.')
17
18# This block will need updating whenever libchrome gets updated. The order of
19# the libs below doesn't matter (as scons will take care of building things in
20# the required order). The split between them is purely to reduce excess
21# linking of third-party libraries, i.e. 'core' should require only a minimal
22# set of libraries, and other third-party libraries should get a unique 'xxx'
23# name.
24base_name = 'base'
25base_libs = [
26 {
27 'name' : 'core',
28 'sources' : """
29 allocator/type_profiler_control.cc
30 at_exit.cc
31 atomicops_internals_x86_gcc.cc
32 base_switches.cc
33 bind_helpers.cc
34 build_time.cc
35 callback_helpers.cc
36 callback_internal.cc
37 command_line.cc
38 cpu.cc
39 debug/alias.cc
40 debug/debugger.cc
41 debug/debugger_posix.cc
42 debug/stack_trace.cc
43 debug/stack_trace_posix.cc
44 debug/task_annotator.cc
45 environment.cc
46 files/file.cc
47 files/file_enumerator.cc
48 files/file_enumerator_posix.cc
49 files/file_path.cc
50 files/file_path_constants.cc
51 files/file_path_watcher.cc
52 files/file_path_watcher_linux.cc
53 files/file_posix.cc
54 files/file_tracing.cc
55 files/file_util.cc
56 files/file_util_linux.cc
57 files/file_util_posix.cc
58 files/important_file_writer.cc
59 files/scoped_file.cc
60 files/scoped_temp_dir.cc
61 guid.cc
62 guid_posix.cc
63 hash.cc
64 json/json_parser.cc
65 json/json_reader.cc
66 json/json_string_value_serializer.cc
67 json/json_writer.cc
68 json/string_escape.cc
69 lazy_instance.cc
70 location.cc
71 logging.cc
72 md5.cc
73 memory/ref_counted.cc
74 memory/ref_counted_memory.cc
75 memory/singleton.cc
76 memory/weak_ptr.cc
77 message_loop/incoming_task_queue.cc
78 message_loop/message_loop.cc
79 message_loop/message_loop_proxy.cc
80 message_loop/message_loop_proxy_impl.cc
81 message_loop/message_pump.cc
82 message_loop/message_pump_default.cc
83 message_loop/message_pump_glib.cc
84 message_loop/message_pump_libevent.cc
85 metrics/bucket_ranges.cc
86 metrics/field_trial.cc
87 metrics/histogram_base.cc
88 metrics/histogram.cc
89 metrics/histogram_samples.cc
90 metrics/histogram_snapshot_manager.cc
91 metrics/sample_map.cc
92 metrics/sample_vector.cc
93 metrics/sparse_histogram.cc
94 metrics/statistics_recorder.cc
95 pending_task.cc
96 pickle.cc
97 posix/file_descriptor_shuffle.cc
98 posix/safe_strerror.cc
99 posix/unix_domain_socket_linux.cc
100 process/internal_linux.cc
101 process/kill.cc
102 process/kill_posix.cc
103 process/launch.cc
104 process/launch_posix.cc
105 process/process_handle_linux.cc
106 process/process_iterator.cc
107 process/process_iterator_linux.cc
108 process/process_handle_posix.cc
109 process/process_metrics.cc
110 process/process_metrics_linux.cc
111 process/process_metrics_posix.cc
112 process/process_posix.cc
113 profiler/alternate_timer.cc
114 profiler/scoped_profile.cc
115 profiler/scoped_tracker.cc
116 profiler/tracked_time.cc
117 rand_util.cc
118 rand_util_posix.cc
119 run_loop.cc
120 sequence_checker_impl.cc
121 sequenced_task_runner.cc
122 sha1_portable.cc
123 strings/safe_sprintf.cc
124 strings/string16.cc
125 strings/string_number_conversions.cc
126 strings/string_piece.cc
127 strings/stringprintf.cc
128 strings/string_split.cc
129 strings/string_util.cc
130 strings/string_util_constants.cc
131 strings/sys_string_conversions_posix.cc
132 strings/utf_string_conversions.cc
133 strings/utf_string_conversion_utils.cc
134 synchronization/cancellation_flag.cc
135 synchronization/condition_variable_posix.cc
136 synchronization/lock.cc
137 synchronization/lock_impl_posix.cc
138 synchronization/waitable_event_posix.cc
139 sync_socket_posix.cc
140 sys_info.cc
141 sys_info_chromeos.cc
142 sys_info_linux.cc
143 sys_info_posix.cc
144 task_runner.cc
145 task/cancelable_task_tracker.cc
146 third_party/dmg_fp/dtoa.cc
147 third_party/dmg_fp/g_fmt.cc
148 third_party/dynamic_annotations/dynamic_annotations.c
149 third_party/icu/icu_utf.cc
150 third_party/nspr/prtime.cc
151 third_party/superfasthash/superfasthash.c
152 threading/non_thread_safe_impl.cc
153 threading/platform_thread_internal_posix.cc
154 threading/platform_thread_linux.cc
155 threading/platform_thread_posix.cc
156 threading/post_task_and_reply_impl.cc
157 threading/sequenced_worker_pool.cc
158 threading/simple_thread.cc
159 threading/thread.cc
160 threading/thread_checker_impl.cc
161 threading/thread_collision_warner.cc
162 threading/thread_id_name_manager.cc
163 threading/thread_local_posix.cc
164 threading/thread_local_storage.cc
165 threading/thread_local_storage_posix.cc
166 threading/thread_restrictions.cc
167 threading/worker_pool.cc
168 threading/worker_pool_posix.cc
169 thread_task_runner_handle.cc
170 timer/elapsed_timer.cc
171 timer/timer.cc
172 time/clock.cc
173 time/default_clock.cc
174 time/default_tick_clock.cc
175 time/tick_clock.cc
176 time/time.cc
177 time/time_posix.cc
178 trace_event/malloc_dump_provider.cc
179 trace_event/memory_allocator_dump.cc
180 trace_event/memory_allocator_dump_guid.cc
181 trace_event/memory_dump_manager.cc
182 trace_event/memory_dump_session_state.cc
183 trace_event/process_memory_dump.cc
184 trace_event/process_memory_maps.cc
185 trace_event/process_memory_maps_dump_provider.cc
186 trace_event/process_memory_totals.cc
187 trace_event/process_memory_totals_dump_provider.cc
188 trace_event/trace_config.cc
189 trace_event/trace_event_argument.cc
190 trace_event/trace_event_impl.cc
191 trace_event/trace_event_impl_constants.cc
192 trace_event/trace_event_memory.cc
193 trace_event/trace_event_memory_overhead.cc
194 trace_event/trace_event_synthetic_delay.cc
195 tracked_objects.cc
196 tracking_info.cc
197 values.cc
198 vlog.cc
199 """,
200 'prefix' : 'base',
201 'libs' : 'pthread rt',
202 'pc_libs' : 'glib-2.0 libevent',
203 },
204 {
205 'name' : 'dl',
206 'sources' : """
207 native_library_posix.cc
208 """,
209 'prefix' : 'base',
210 'libs' : 'dl',
211 'pc_libs' : '',
212 },
213 {
214 'name' : 'dbus',
215 'sources' : """
216 bus.cc
217 dbus_statistics.cc
218 exported_object.cc
219 file_descriptor.cc
220 message.cc
221 object_manager.cc
222 object_path.cc
223 object_proxy.cc
224 property.cc
225 scoped_dbus_error.cc
226 string_util.cc
227 util.cc
228 values_util.cc
229 """,
230 'prefix' : 'dbus',
231 'libs' : '',
232 'pc_libs' : 'dbus-1 protobuf-lite',
233 },
234 {
235 'name' : 'timers',
236 'sources' : """
237 alarm_timer_chromeos.cc
238 """,
239 'prefix' : 'components/timers',
240 'libs' : '',
241 'pc_libs' : '',
242 },
243 {
244 'name' : 'crypto',
245 'sources' : """
246 hmac.cc
247 hmac_nss.cc
248 nss_key_util.cc
249 nss_util.cc
250 p224.cc
251 p224_spake.cc
252 random.cc
253 rsa_private_key.cc
254 rsa_private_key_nss.cc
255 scoped_test_nss_db.cc
256 secure_hash_default.cc
257 secure_util.cc
258 sha2.cc
259 signature_creator_nss.cc
260 signature_verifier_nss.cc
261 symmetric_key_nss.cc
262 third_party/nss/rsawrapr.c
263 third_party/nss/sha512.cc
264 """,
265 'prefix' : 'crypto',
266 'libs' : '%s-dl-%s' % (base_name, BASE_VER),
267 'pc_libs' : 'nss',
268 },
269 {
270 'name' : 'sandbox',
271 'sources' : """
272 linux/bpf_dsl/bpf_dsl.cc
273 linux/bpf_dsl/codegen.cc
274 linux/bpf_dsl/dump_bpf.cc
275 linux/bpf_dsl/policy.cc
276 linux/bpf_dsl/policy_compiler.cc
277 linux/bpf_dsl/syscall_set.cc
278 linux/bpf_dsl/verifier.cc
279 linux/seccomp-bpf/die.cc
280 linux/seccomp-bpf/errorcode.cc
281 linux/seccomp-bpf/sandbox_bpf.cc
282 linux/seccomp-bpf/syscall.cc
283 linux/seccomp-bpf/trap.cc
284
285 linux/seccomp-bpf-helpers/baseline_policy.cc
286 linux/seccomp-bpf-helpers/sigsys_handlers.cc
287 linux/seccomp-bpf-helpers/syscall_parameters_restrictions.cc
288 linux/seccomp-bpf-helpers/syscall_sets.cc
289
290 linux/services/init_process_reaper.cc
291 linux/services/proc_util.cc
292 linux/services/resource_limits.cc
293 linux/services/scoped_process.cc
294 linux/services/syscall_wrappers.cc
295 linux/services/thread_helpers.cc
296 linux/services/yama.cc
297 linux/syscall_broker/broker_channel.cc
298 linux/syscall_broker/broker_client.cc
299 linux/syscall_broker/broker_file_permission.cc
300 linux/syscall_broker/broker_host.cc
301 linux/syscall_broker/broker_policy.cc
302 linux/syscall_broker/broker_process.cc
303
304 linux/services/credentials.cc
305 linux/services/namespace_sandbox.cc
306 linux/services/namespace_utils.cc
307 """,
308 'prefix' : 'sandbox',
309 'libs' : '',
310 'pc_libs' : '',
311 },
312]
313
314env.Append(
315 CPPPATH=['files'],
316 CCFLAGS=['-g']
317)
318for key in Split('CC CXX AR RANLIB LD NM CFLAGS CXXFLAGS LDFLAGS'):
319 value = os.environ.get(key)
320 if value:
321 env[key] = Split(value)
322if os.environ.has_key('CPPFLAGS'):
323 env['CCFLAGS'] += Split(os.environ['CPPFLAGS'])
324
325env['CCFLAGS'] += ['-DOS_CHROMEOS',
326 '-DUSE_NSS_CERTS',
327 '-DUSE_SYSTEM_LIBEVENT',
328 '-fPIC',
329 '-fno-exceptions',
330 '-Wall',
331 '-Werror',
332 '-Wno-deprecated-register',
333 '-Wno-narrowing',
334 '-Wno-psabi',
335 '-Wno-unused-local-typedefs',
336 # Various #defines are hardcoded near the top of
337 # build_config.h to ensure that they'll be set both when
338 # libchrome is built and when other packages include
339 # libchrome's headers.
340 '-I%s' % CHROME_INCLUDE_PATH]
341
342env.Append(
343 CXXFLAGS=['-std=c++11']
344)
345
346# Flags for clang taken from build/common.gypi in the clang==1 section.
347CLANG_FLAGS = (
348 '-Wno-char-subscripts',
349)
350
351env['CCFLAGS'] += ['-Xclang-only=%s' % x for x in CLANG_FLAGS]
352
353# Fix issue with scons not passing some vars through the environment.
354for key in Split('PKG_CONFIG SYSROOT'):
355 if os.environ.has_key(key):
356 env['ENV'][key] = os.environ[key]
357
358all_base_libs = []
359all_pc_libs = ''
360all_libs = []
361all_scons_libs = []
362
363# Build all the shared libraries.
364for lib in base_libs:
365 pc_libs = lib['pc_libs'].replace('${bslot}', BASE_VER)
366 all_pc_libs += ' ' + pc_libs
367
368 libs = Split(lib['libs'].replace('${bslot}', BASE_VER))
369 all_libs += libs
370
371 name = '%s-%s-%s' % (base_name, lib['name'], BASE_VER)
372 all_base_libs += [name]
373 corename = '%s-core-%s' % (base_name, BASE_VER)
374 # Automatically link the sub-libs against the main core lib.
375 # This is to keep from having to explicitly mention it in the
376 # table above (i.e. lazy).
377 if name != corename:
378 libs += [corename]
379
380 e = env.Clone()
381 e.Append(
382 LIBS = Split(libs),
383 LIBPATH = ['.'],
384 LINKFLAGS = ['-Wl,--as-needed', '-Wl,-z,defs',
385 '-Wl,-soname,lib%s.so' % name],
386 )
387 if pc_libs:
388 e.ParseConfig(PKG_CONFIG + ' --cflags --libs %s' % pc_libs)
389
390 # Prepend prefix to source filenames.
391 sources = [os.path.join(lib['prefix'], x) for x in Split(lib['sources'])]
392
393 all_scons_libs += [ e.SharedLibrary(name, sources) ]
394
395
396# Build a static library of mocks for unittests to link against.
397# Being static allows us to mask this library out of the image.
398
399all_base_test_libs = []
400all_test_pc_libs = ''
401all_test_libs = []
402
403test_libs = [
404 {
405 'name': 'base_test_support',
406 'sources': """
407 simple_test_clock.cc
408 simple_test_tick_clock.cc
409 test_file_util.cc
410 test_file_util_linux.cc
411 test_switches.cc
412 test_timeouts.cc
413 """,
414 'prefix': 'base/test',
415 'libs': '',
416 'pc_libs': '',
417 },
418 {
419 'name': 'dbus_test_support',
420 'sources': """
421 mock_bus.cc
422 mock_exported_object.cc
423 mock_object_manager.cc
424 mock_object_proxy.cc
425 """,
426 'prefix': 'dbus',
427 'libs': '', # TODO(wiley) what should go here?
428 'pc_libs': 'dbus-1 protobuf-lite',
429 },
430 {
431 'name': 'timer_test_support',
432 'sources': """
433 mock_timer.cc
434 """,
435 'prefix': 'base/timer',
436 'libs': '',
437 'pc_libs': '',
438 },
439]
440
441for lib in test_libs:
442 pc_libs = lib['pc_libs'].replace('${bslot}', BASE_VER)
443 all_test_pc_libs += ' ' + pc_libs
444
445 libs = Split(lib['libs'].replace('${bslot}', BASE_VER))
446 all_test_libs += libs
447
448 name = '%s-%s-%s' % (base_name, lib['name'], BASE_VER)
449 all_base_test_libs += [name]
450
451 static_env = env.Clone()
452 if pc_libs:
453 static_env.ParseConfig(PKG_CONFIG + ' --cflags --libs %s' % pc_libs)
454 sources = [os.path.join(lib['prefix'], x)
455 for x in Split(lib['sources'])]
456 static_env.StaticLibrary(name, sources)
457
458# Build the random text files (pkg-config and linker script).
459
460def lib_list(libs):
461 return ' '.join(['-l' + l for l in libs])
462
463prod_subst_dict = {
464 '@BSLOT@': BASE_VER,
465 '@PRIVATE_PC@': all_pc_libs,
466 '@BASE_LIBS@': lib_list(all_base_libs),
467 '@LIBS@': lib_list(all_libs),
468 '@NAME@': 'libchrome',
469 '@PKG_CFG_NAME@': 'libchrome-%s.pc' % BASE_VER,
470 '@LIB_NAME@': 'libbase-%s.so' % BASE_VER,
471 '@DESCRIPTION@': 'chrome base library',
472 # scons, in its infinite wisdom sees fit to expand this string if
473 # if we don't escape the $.
474 '@TARGET_LIB@': 'base-$${bslot}',
475}
476
477# Similarly, build text files related to the test libraries.
478test_subst_dict = {
479 '@BSLOT@': BASE_VER,
480 '@PRIVATE_PC@': all_test_pc_libs,
481 '@BASE_LIBS@': lib_list(all_base_test_libs),
482 '@LIBS@': lib_list(all_test_libs),
483 '@NAME@': 'libchrome-test',
484 '@PKG_CFG_NAME@': 'libchrome-test-%s.pc' % BASE_VER,
485 '@LIB_NAME@': 'libbase-test-%s.a' % BASE_VER,
486 '@DESCRIPTION@': 'chrome base test library',
487 # scons, in its infinite wisdom sees fit to expand this string if
488 # if we don't escape the $.
489 '@TARGET_LIB@': 'base-test-$${bslot}',
490}
491
492pc_file_contents = """
493prefix=/usr
494includedir=${prefix}/include
495bslot=@BSLOT@
496
497Name: @NAME@
498Description: @DESCRIPTION@
499Version: ${bslot}
500Requires:
501Requires.private: @PRIVATE_PC@
502Libs: -l@TARGET_LIB@
503Libs.private: @BASE_LIBS@ @LIBS@
504Cflags: -I${includedir}/@TARGET_LIB@ -Wno-c++11-extensions -Wno-unused-local-typedefs -DBASE_VER=${bslot}
505"""
506
507# https://sourceware.org/binutils/docs/ld/Scripts.html
508so_file_contents = """GROUP ( AS_NEEDED ( @BASE_LIBS@ ) )"""
509
510for subst_dict in (test_subst_dict, prod_subst_dict):
511 env = Environment(tools=['textfile'], SUBST_DICT=subst_dict)
512 env.Substfile(subst_dict['@LIB_NAME@'], [Value(so_file_contents)])
513 env.Substfile(subst_dict['@PKG_CFG_NAME@'], [Value(pc_file_contents)])