blob: 49cef6f434b034f622ae78bcb8a54f9388f4f001 [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' : """
Alex Vakulenko24854742016-01-22 16:55:13 -080029 allocator/allocator_extension.cc
Luis Hector Chavez94ffa552016-05-25 15:29:35 -070030 allocator/allocator_shim.cc
31 allocator/allocator_shim_default_dispatch_to_glibc.cc
Daniel Erat65f53982015-08-25 09:21:05 -060032 at_exit.cc
Alex Vakulenko42b71bb2016-01-20 16:24:55 -080033 base64.cc
34 base64url.cc
Daniel Erat65f53982015-08-25 09:21:05 -060035 base_switches.cc
36 bind_helpers.cc
37 build_time.cc
38 callback_helpers.cc
39 callback_internal.cc
40 command_line.cc
41 cpu.cc
42 debug/alias.cc
43 debug/debugger.cc
44 debug/debugger_posix.cc
45 debug/stack_trace.cc
46 debug/stack_trace_posix.cc
47 debug/task_annotator.cc
48 environment.cc
49 files/file.cc
50 files/file_enumerator.cc
51 files/file_enumerator_posix.cc
52 files/file_path.cc
53 files/file_path_constants.cc
54 files/file_path_watcher.cc
55 files/file_path_watcher_linux.cc
56 files/file_posix.cc
57 files/file_tracing.cc
58 files/file_util.cc
59 files/file_util_linux.cc
60 files/file_util_posix.cc
61 files/important_file_writer.cc
Alex Vakulenko1ac3a5e2016-01-25 12:28:19 -080062 files/memory_mapped_file.cc
63 files/memory_mapped_file_posix.cc
Daniel Erat65f53982015-08-25 09:21:05 -060064 files/scoped_file.cc
65 files/scoped_temp_dir.cc
66 guid.cc
Alex Vakulenko45779222016-03-17 10:36:19 -070067 hash.cc
Alex Vakulenko42b71bb2016-01-20 16:24:55 -080068 json/json_file_value_serializer.cc
Daniel Erat65f53982015-08-25 09:21:05 -060069 json/json_parser.cc
70 json/json_reader.cc
71 json/json_string_value_serializer.cc
Alex Vakulenko42b71bb2016-01-20 16:24:55 -080072 json/json_value_converter.cc
Daniel Erat65f53982015-08-25 09:21:05 -060073 json/json_writer.cc
74 json/string_escape.cc
75 lazy_instance.cc
76 location.cc
77 logging.cc
78 md5.cc
henryhsufc7fe5e2016-04-14 15:40:50 +080079 memory/aligned_memory.cc
Daniel Erat65f53982015-08-25 09:21:05 -060080 memory/ref_counted.cc
81 memory/ref_counted_memory.cc
Alex Vakulenko45779222016-03-17 10:36:19 -070082 memory/shared_memory_posix.cc
Daniel Erat65f53982015-08-25 09:21:05 -060083 memory/singleton.cc
84 memory/weak_ptr.cc
85 message_loop/incoming_task_queue.cc
86 message_loop/message_loop.cc
Alex Vakulenko42b71bb2016-01-20 16:24:55 -080087 message_loop/message_loop_task_runner.cc
Daniel Erat65f53982015-08-25 09:21:05 -060088 message_loop/message_pump.cc
89 message_loop/message_pump_default.cc
90 message_loop/message_pump_glib.cc
91 message_loop/message_pump_libevent.cc
92 metrics/bucket_ranges.cc
93 metrics/field_trial.cc
Alex Vakulenko42b71bb2016-01-20 16:24:55 -080094 metrics/metrics_hashes.cc
Daniel Erat65f53982015-08-25 09:21:05 -060095 metrics/histogram_base.cc
96 metrics/histogram.cc
97 metrics/histogram_samples.cc
98 metrics/histogram_snapshot_manager.cc
Alex Vakulenko45779222016-03-17 10:36:19 -070099 metrics/persistent_histogram_allocator.cc
100 metrics/persistent_memory_allocator.cc
101 metrics/persistent_sample_map.cc
Daniel Erat65f53982015-08-25 09:21:05 -0600102 metrics/sample_map.cc
103 metrics/sample_vector.cc
104 metrics/sparse_histogram.cc
105 metrics/statistics_recorder.cc
106 pending_task.cc
107 pickle.cc
108 posix/file_descriptor_shuffle.cc
Alex Vakulenko1ac3a5e2016-01-25 12:28:19 -0800109 posix/global_descriptors.cc
Daniel Erat65f53982015-08-25 09:21:05 -0600110 posix/safe_strerror.cc
111 posix/unix_domain_socket_linux.cc
112 process/internal_linux.cc
113 process/kill.cc
114 process/kill_posix.cc
115 process/launch.cc
116 process/launch_posix.cc
117 process/process_handle_linux.cc
118 process/process_iterator.cc
119 process/process_iterator_linux.cc
120 process/process_handle_posix.cc
121 process/process_metrics.cc
122 process/process_metrics_linux.cc
123 process/process_metrics_posix.cc
124 process/process_posix.cc
Daniel Erat65f53982015-08-25 09:21:05 -0600125 profiler/scoped_profile.cc
126 profiler/scoped_tracker.cc
127 profiler/tracked_time.cc
128 rand_util.cc
129 rand_util_posix.cc
130 run_loop.cc
131 sequence_checker_impl.cc
132 sequenced_task_runner.cc
133 sha1_portable.cc
Alex Vakulenko42b71bb2016-01-20 16:24:55 -0800134 strings/pattern.cc
Daniel Erat65f53982015-08-25 09:21:05 -0600135 strings/safe_sprintf.cc
136 strings/string16.cc
137 strings/string_number_conversions.cc
138 strings/string_piece.cc
139 strings/stringprintf.cc
140 strings/string_split.cc
141 strings/string_util.cc
142 strings/string_util_constants.cc
143 strings/sys_string_conversions_posix.cc
144 strings/utf_string_conversions.cc
145 strings/utf_string_conversion_utils.cc
146 synchronization/cancellation_flag.cc
147 synchronization/condition_variable_posix.cc
148 synchronization/lock.cc
149 synchronization/lock_impl_posix.cc
Luis Hector Chavez0c4f26a2016-07-15 16:23:21 -0700150 synchronization/read_write_lock_posix.cc
Daniel Erat65f53982015-08-25 09:21:05 -0600151 synchronization/waitable_event_posix.cc
Alex Vakulenko1ac3a5e2016-01-25 12:28:19 -0800152 synchronization/waitable_event_watcher_posix.cc
Daniel Erat65f53982015-08-25 09:21:05 -0600153 sync_socket_posix.cc
154 sys_info.cc
155 sys_info_chromeos.cc
156 sys_info_linux.cc
157 sys_info_posix.cc
158 task_runner.cc
159 task/cancelable_task_tracker.cc
Alex Vakulenko45779222016-03-17 10:36:19 -0700160 task_scheduler/scheduler_lock_impl.cc
161 task_scheduler/sequence.cc
162 task_scheduler/sequence_sort_key.cc
163 task_scheduler/task.cc
164 task_scheduler/task_traits.cc
Daniel Erat65f53982015-08-25 09:21:05 -0600165 third_party/icu/icu_utf.cc
166 third_party/nspr/prtime.cc
Daniel Erat65f53982015-08-25 09:21:05 -0600167 threading/non_thread_safe_impl.cc
168 threading/platform_thread_internal_posix.cc
169 threading/platform_thread_linux.cc
170 threading/platform_thread_posix.cc
171 threading/post_task_and_reply_impl.cc
Luis Hector Chavez94ffa552016-05-25 15:29:35 -0700172 threading/sequenced_task_runner_handle.cc
Daniel Erat65f53982015-08-25 09:21:05 -0600173 threading/sequenced_worker_pool.cc
174 threading/simple_thread.cc
175 threading/thread.cc
176 threading/thread_checker_impl.cc
177 threading/thread_collision_warner.cc
178 threading/thread_id_name_manager.cc
179 threading/thread_local_posix.cc
180 threading/thread_local_storage.cc
181 threading/thread_local_storage_posix.cc
182 threading/thread_restrictions.cc
Luis Hector Chavez94ffa552016-05-25 15:29:35 -0700183 threading/thread_task_runner_handle.cc
Daniel Erat65f53982015-08-25 09:21:05 -0600184 threading/worker_pool.cc
185 threading/worker_pool_posix.cc
Daniel Erat65f53982015-08-25 09:21:05 -0600186 timer/elapsed_timer.cc
187 timer/timer.cc
188 time/clock.cc
189 time/default_clock.cc
190 time/default_tick_clock.cc
191 time/tick_clock.cc
192 time/time.cc
193 time/time_posix.cc
Alex Vakulenko24854742016-01-22 16:55:13 -0800194 trace_event/heap_profiler_allocation_context.cc
195 trace_event/heap_profiler_allocation_context_tracker.cc
Luis Hector Chavez94ffa552016-05-25 15:29:35 -0700196 trace_event/heap_profiler_allocation_register.cc
197 trace_event/heap_profiler_allocation_register_posix.cc
198 trace_event/heap_profiler_heap_dump_writer.cc
Alex Vakulenko24854742016-01-22 16:55:13 -0800199 trace_event/heap_profiler_stack_frame_deduplicator.cc
200 trace_event/heap_profiler_type_name_deduplicator.cc
Luis Hector Chavez0c4f26a2016-07-15 16:23:21 -0700201 trace_event/malloc_dump_provider.cc
Daniel Erat65f53982015-08-25 09:21:05 -0600202 trace_event/memory_allocator_dump.cc
203 trace_event/memory_allocator_dump_guid.cc
204 trace_event/memory_dump_manager.cc
Alex Vakulenko42b71bb2016-01-20 16:24:55 -0800205 trace_event/memory_dump_request_args.cc
Daniel Erat65f53982015-08-25 09:21:05 -0600206 trace_event/memory_dump_session_state.cc
Luis Hector Chavez0c4f26a2016-07-15 16:23:21 -0700207 trace_event/memory_infra_background_whitelist.cc
Daniel Erat65f53982015-08-25 09:21:05 -0600208 trace_event/process_memory_dump.cc
209 trace_event/process_memory_maps.cc
Daniel Erat65f53982015-08-25 09:21:05 -0600210 trace_event/process_memory_totals.cc
Alex Vakulenko42b71bb2016-01-20 16:24:55 -0800211 trace_event/trace_buffer.cc
Daniel Erat65f53982015-08-25 09:21:05 -0600212 trace_event/trace_config.cc
213 trace_event/trace_event_argument.cc
214 trace_event/trace_event_impl.cc
Daniel Erat65f53982015-08-25 09:21:05 -0600215 trace_event/trace_event_memory_overhead.cc
216 trace_event/trace_event_synthetic_delay.cc
Alex Vakulenko24854742016-01-22 16:55:13 -0800217 trace_event/trace_log.cc
218 trace_event/trace_log_constants.cc
219 trace_event/trace_sampling_thread.cc
Daniel Erat65f53982015-08-25 09:21:05 -0600220 tracked_objects.cc
221 tracking_info.cc
222 values.cc
Luis Hector Chavez0c4f26a2016-07-15 16:23:21 -0700223 version.cc
Daniel Erat65f53982015-08-25 09:21:05 -0600224 vlog.cc
225 """,
226 'prefix' : 'base',
Alex Vakulenko24854742016-01-22 16:55:13 -0800227 'libs' : 'pthread rt libmodp_b64',
Daniel Erat65f53982015-08-25 09:21:05 -0600228 'pc_libs' : 'glib-2.0 libevent',
229 },
230 {
231 'name' : 'dl',
232 'sources' : """
233 native_library_posix.cc
234 """,
235 'prefix' : 'base',
236 'libs' : 'dl',
237 'pc_libs' : '',
238 },
239 {
240 'name' : 'dbus',
241 'sources' : """
242 bus.cc
243 dbus_statistics.cc
244 exported_object.cc
245 file_descriptor.cc
246 message.cc
247 object_manager.cc
248 object_path.cc
249 object_proxy.cc
250 property.cc
251 scoped_dbus_error.cc
252 string_util.cc
253 util.cc
254 values_util.cc
255 """,
256 'prefix' : 'dbus',
257 'libs' : '',
258 'pc_libs' : 'dbus-1 protobuf-lite',
259 },
260 {
261 'name' : 'timers',
262 'sources' : """
263 alarm_timer_chromeos.cc
264 """,
265 'prefix' : 'components/timers',
266 'libs' : '',
267 'pc_libs' : '',
268 },
269 {
270 'name' : 'crypto',
271 'sources' : """
272 hmac.cc
Daniel Erat65f53982015-08-25 09:21:05 -0600273 nss_key_util.cc
274 nss_util.cc
Darren Krahn16334162016-03-01 14:38:19 -0800275 openssl_util.cc
Daniel Erat65f53982015-08-25 09:21:05 -0600276 p224.cc
277 p224_spake.cc
278 random.cc
279 rsa_private_key.cc
280 rsa_private_key_nss.cc
281 scoped_test_nss_db.cc
Luis Hector Chavez94ffa552016-05-25 15:29:35 -0700282 secure_hash.cc
Daniel Erat65f53982015-08-25 09:21:05 -0600283 secure_util.cc
284 sha2.cc
Hidehiko Abe36040ed2017-12-13 18:59:30 +0900285 signature_creator.cc
286 signature_verifier.cc
287 symmetric_key.cc
Daniel Erat65f53982015-08-25 09:21:05 -0600288 third_party/nss/rsawrapr.c
289 third_party/nss/sha512.cc
290 """,
291 'prefix' : 'crypto',
292 'libs' : '%s-dl-%s' % (base_name, BASE_VER),
Darren Krahn16334162016-03-01 14:38:19 -0800293 'pc_libs' : 'nss openssl',
Daniel Erat65f53982015-08-25 09:21:05 -0600294 },
295 {
296 'name' : 'sandbox',
297 'sources' : """
298 linux/bpf_dsl/bpf_dsl.cc
299 linux/bpf_dsl/codegen.cc
300 linux/bpf_dsl/dump_bpf.cc
301 linux/bpf_dsl/policy.cc
302 linux/bpf_dsl/policy_compiler.cc
303 linux/bpf_dsl/syscall_set.cc
304 linux/bpf_dsl/verifier.cc
305 linux/seccomp-bpf/die.cc
Daniel Erat65f53982015-08-25 09:21:05 -0600306 linux/seccomp-bpf/sandbox_bpf.cc
307 linux/seccomp-bpf/syscall.cc
308 linux/seccomp-bpf/trap.cc
309
310 linux/seccomp-bpf-helpers/baseline_policy.cc
Hidehiko Abe36040ed2017-12-13 18:59:30 +0900311 linux/seccomp-bpf-helpers/sigsys_handlers.cc
Daniel Erat65f53982015-08-25 09:21:05 -0600312 linux/seccomp-bpf-helpers/syscall_parameters_restrictions.cc
313 linux/seccomp-bpf-helpers/syscall_sets.cc
314
315 linux/services/init_process_reaper.cc
316 linux/services/proc_util.cc
317 linux/services/resource_limits.cc
318 linux/services/scoped_process.cc
319 linux/services/syscall_wrappers.cc
320 linux/services/thread_helpers.cc
321 linux/services/yama.cc
322 linux/syscall_broker/broker_channel.cc
323 linux/syscall_broker/broker_client.cc
324 linux/syscall_broker/broker_file_permission.cc
325 linux/syscall_broker/broker_host.cc
326 linux/syscall_broker/broker_policy.cc
327 linux/syscall_broker/broker_process.cc
328
329 linux/services/credentials.cc
330 linux/services/namespace_sandbox.cc
331 linux/services/namespace_utils.cc
332 """,
333 'prefix' : 'sandbox',
334 'libs' : '',
335 'pc_libs' : '',
336 },
337]
338
339env.Append(
340 CPPPATH=['files'],
341 CCFLAGS=['-g']
342)
343for key in Split('CC CXX AR RANLIB LD NM CFLAGS CXXFLAGS LDFLAGS'):
344 value = os.environ.get(key)
345 if value:
346 env[key] = Split(value)
347if os.environ.has_key('CPPFLAGS'):
348 env['CCFLAGS'] += Split(os.environ['CPPFLAGS'])
349
350env['CCFLAGS'] += ['-DOS_CHROMEOS',
351 '-DUSE_NSS_CERTS',
352 '-DUSE_SYSTEM_LIBEVENT',
Alex Vakulenko45779222016-03-17 10:36:19 -0700353 '-DNO_TCMALLOC',
Daniel Erat65f53982015-08-25 09:21:05 -0600354 '-fPIC',
355 '-fno-exceptions',
356 '-Wall',
357 '-Werror',
358 '-Wno-deprecated-register',
359 '-Wno-narrowing',
360 '-Wno-psabi',
361 '-Wno-unused-local-typedefs',
362 # Various #defines are hardcoded near the top of
363 # build_config.h to ensure that they'll be set both when
364 # libchrome is built and when other packages include
365 # libchrome's headers.
366 '-I%s' % CHROME_INCLUDE_PATH]
367
368env.Append(
369 CXXFLAGS=['-std=c++11']
370)
371
372# Flags for clang taken from build/common.gypi in the clang==1 section.
373CLANG_FLAGS = (
374 '-Wno-char-subscripts',
375)
376
377env['CCFLAGS'] += ['-Xclang-only=%s' % x for x in CLANG_FLAGS]
378
379# Fix issue with scons not passing some vars through the environment.
380for key in Split('PKG_CONFIG SYSROOT'):
381 if os.environ.has_key(key):
382 env['ENV'][key] = os.environ[key]
383
384all_base_libs = []
385all_pc_libs = ''
386all_libs = []
387all_scons_libs = []
388
389# Build all the shared libraries.
390for lib in base_libs:
391 pc_libs = lib['pc_libs'].replace('${bslot}', BASE_VER)
392 all_pc_libs += ' ' + pc_libs
393
394 libs = Split(lib['libs'].replace('${bslot}', BASE_VER))
395 all_libs += libs
396
397 name = '%s-%s-%s' % (base_name, lib['name'], BASE_VER)
398 all_base_libs += [name]
399 corename = '%s-core-%s' % (base_name, BASE_VER)
400 # Automatically link the sub-libs against the main core lib.
401 # This is to keep from having to explicitly mention it in the
402 # table above (i.e. lazy).
403 if name != corename:
404 libs += [corename]
405
406 e = env.Clone()
407 e.Append(
408 LIBS = Split(libs),
409 LIBPATH = ['.'],
410 LINKFLAGS = ['-Wl,--as-needed', '-Wl,-z,defs',
411 '-Wl,-soname,lib%s.so' % name],
412 )
413 if pc_libs:
414 e.ParseConfig(PKG_CONFIG + ' --cflags --libs %s' % pc_libs)
415
416 # Prepend prefix to source filenames.
417 sources = [os.path.join(lib['prefix'], x) for x in Split(lib['sources'])]
418
419 all_scons_libs += [ e.SharedLibrary(name, sources) ]
420
421
422# Build a static library of mocks for unittests to link against.
423# Being static allows us to mask this library out of the image.
424
425all_base_test_libs = []
426all_test_pc_libs = ''
427all_test_libs = []
428
429test_libs = [
430 {
431 'name': 'base_test_support',
432 'sources': """
433 simple_test_clock.cc
434 simple_test_tick_clock.cc
435 test_file_util.cc
436 test_file_util_linux.cc
437 test_switches.cc
438 test_timeouts.cc
439 """,
440 'prefix': 'base/test',
441 'libs': '',
442 'pc_libs': '',
443 },
444 {
445 'name': 'dbus_test_support',
446 'sources': """
447 mock_bus.cc
448 mock_exported_object.cc
449 mock_object_manager.cc
450 mock_object_proxy.cc
451 """,
452 'prefix': 'dbus',
453 'libs': '', # TODO(wiley) what should go here?
454 'pc_libs': 'dbus-1 protobuf-lite',
455 },
456 {
457 'name': 'timer_test_support',
458 'sources': """
459 mock_timer.cc
460 """,
461 'prefix': 'base/timer',
462 'libs': '',
463 'pc_libs': '',
464 },
465]
466
467for lib in test_libs:
468 pc_libs = lib['pc_libs'].replace('${bslot}', BASE_VER)
469 all_test_pc_libs += ' ' + pc_libs
470
471 libs = Split(lib['libs'].replace('${bslot}', BASE_VER))
472 all_test_libs += libs
473
474 name = '%s-%s-%s' % (base_name, lib['name'], BASE_VER)
475 all_base_test_libs += [name]
476
477 static_env = env.Clone()
478 if pc_libs:
479 static_env.ParseConfig(PKG_CONFIG + ' --cflags --libs %s' % pc_libs)
480 sources = [os.path.join(lib['prefix'], x)
481 for x in Split(lib['sources'])]
482 static_env.StaticLibrary(name, sources)
483
484# Build the random text files (pkg-config and linker script).
485
486def lib_list(libs):
487 return ' '.join(['-l' + l for l in libs])
488
489prod_subst_dict = {
490 '@BSLOT@': BASE_VER,
491 '@PRIVATE_PC@': all_pc_libs,
492 '@BASE_LIBS@': lib_list(all_base_libs),
493 '@LIBS@': lib_list(all_libs),
494 '@NAME@': 'libchrome',
495 '@PKG_CFG_NAME@': 'libchrome-%s.pc' % BASE_VER,
496 '@LIB_NAME@': 'libbase-%s.so' % BASE_VER,
497 '@DESCRIPTION@': 'chrome base library',
498 # scons, in its infinite wisdom sees fit to expand this string if
499 # if we don't escape the $.
500 '@TARGET_LIB@': 'base-$${bslot}',
501}
502
503# Similarly, build text files related to the test libraries.
504test_subst_dict = {
505 '@BSLOT@': BASE_VER,
506 '@PRIVATE_PC@': all_test_pc_libs,
507 '@BASE_LIBS@': lib_list(all_base_test_libs),
508 '@LIBS@': lib_list(all_test_libs),
509 '@NAME@': 'libchrome-test',
510 '@PKG_CFG_NAME@': 'libchrome-test-%s.pc' % BASE_VER,
511 '@LIB_NAME@': 'libbase-test-%s.a' % BASE_VER,
512 '@DESCRIPTION@': 'chrome base test library',
513 # scons, in its infinite wisdom sees fit to expand this string if
514 # if we don't escape the $.
515 '@TARGET_LIB@': 'base-test-$${bslot}',
516}
517
518pc_file_contents = """
519prefix=/usr
520includedir=${prefix}/include
521bslot=@BSLOT@
522
523Name: @NAME@
524Description: @DESCRIPTION@
525Version: ${bslot}
526Requires:
527Requires.private: @PRIVATE_PC@
528Libs: -l@TARGET_LIB@
529Libs.private: @BASE_LIBS@ @LIBS@
530Cflags: -I${includedir}/@TARGET_LIB@ -Wno-c++11-extensions -Wno-unused-local-typedefs -DBASE_VER=${bslot}
531"""
532
533# https://sourceware.org/binutils/docs/ld/Scripts.html
534so_file_contents = """GROUP ( AS_NEEDED ( @BASE_LIBS@ ) )"""
535
536for subst_dict in (test_subst_dict, prod_subst_dict):
537 env = Environment(tools=['textfile'], SUBST_DICT=subst_dict)
538 env.Substfile(subst_dict['@LIB_NAME@'], [Value(so_file_contents)])
539 env.Substfile(subst_dict['@PKG_CFG_NAME@'], [Value(pc_file_contents)])