blob: 170d4b1ac49e254ced34b9add35bcb257378fe10 [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
150 synchronization/waitable_event_posix.cc
Alex Vakulenko1ac3a5e2016-01-25 12:28:19 -0800151 synchronization/waitable_event_watcher_posix.cc
Daniel Erat65f53982015-08-25 09:21:05 -0600152 sync_socket_posix.cc
153 sys_info.cc
154 sys_info_chromeos.cc
155 sys_info_linux.cc
156 sys_info_posix.cc
157 task_runner.cc
158 task/cancelable_task_tracker.cc
Alex Vakulenko45779222016-03-17 10:36:19 -0700159 task_scheduler/scheduler_lock_impl.cc
160 task_scheduler/sequence.cc
161 task_scheduler/sequence_sort_key.cc
162 task_scheduler/task.cc
163 task_scheduler/task_traits.cc
Daniel Erat65f53982015-08-25 09:21:05 -0600164 third_party/icu/icu_utf.cc
165 third_party/nspr/prtime.cc
Daniel Erat65f53982015-08-25 09:21:05 -0600166 threading/non_thread_safe_impl.cc
167 threading/platform_thread_internal_posix.cc
168 threading/platform_thread_linux.cc
169 threading/platform_thread_posix.cc
170 threading/post_task_and_reply_impl.cc
Luis Hector Chavez94ffa552016-05-25 15:29:35 -0700171 threading/sequenced_task_runner_handle.cc
Daniel Erat65f53982015-08-25 09:21:05 -0600172 threading/sequenced_worker_pool.cc
173 threading/simple_thread.cc
174 threading/thread.cc
175 threading/thread_checker_impl.cc
176 threading/thread_collision_warner.cc
177 threading/thread_id_name_manager.cc
178 threading/thread_local_posix.cc
179 threading/thread_local_storage.cc
180 threading/thread_local_storage_posix.cc
181 threading/thread_restrictions.cc
Luis Hector Chavez94ffa552016-05-25 15:29:35 -0700182 threading/thread_task_runner_handle.cc
Daniel Erat65f53982015-08-25 09:21:05 -0600183 threading/worker_pool.cc
184 threading/worker_pool_posix.cc
Daniel Erat65f53982015-08-25 09:21:05 -0600185 timer/elapsed_timer.cc
186 timer/timer.cc
187 time/clock.cc
188 time/default_clock.cc
189 time/default_tick_clock.cc
190 time/tick_clock.cc
191 time/time.cc
192 time/time_posix.cc
193 trace_event/malloc_dump_provider.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
Daniel Erat65f53982015-08-25 09:21:05 -0600201 trace_event/memory_allocator_dump.cc
202 trace_event/memory_allocator_dump_guid.cc
203 trace_event/memory_dump_manager.cc
Alex Vakulenko42b71bb2016-01-20 16:24:55 -0800204 trace_event/memory_dump_request_args.cc
Daniel Erat65f53982015-08-25 09:21:05 -0600205 trace_event/memory_dump_session_state.cc
206 trace_event/process_memory_dump.cc
207 trace_event/process_memory_maps.cc
Daniel Erat65f53982015-08-25 09:21:05 -0600208 trace_event/process_memory_totals.cc
Alex Vakulenko42b71bb2016-01-20 16:24:55 -0800209 trace_event/trace_buffer.cc
Daniel Erat65f53982015-08-25 09:21:05 -0600210 trace_event/trace_config.cc
211 trace_event/trace_event_argument.cc
212 trace_event/trace_event_impl.cc
Daniel Erat65f53982015-08-25 09:21:05 -0600213 trace_event/trace_event_memory_overhead.cc
214 trace_event/trace_event_synthetic_delay.cc
Alex Vakulenko24854742016-01-22 16:55:13 -0800215 trace_event/trace_log.cc
216 trace_event/trace_log_constants.cc
217 trace_event/trace_sampling_thread.cc
Daniel Erat65f53982015-08-25 09:21:05 -0600218 tracked_objects.cc
219 tracking_info.cc
220 values.cc
221 vlog.cc
222 """,
223 'prefix' : 'base',
Alex Vakulenko24854742016-01-22 16:55:13 -0800224 'libs' : 'pthread rt libmodp_b64',
Daniel Erat65f53982015-08-25 09:21:05 -0600225 'pc_libs' : 'glib-2.0 libevent',
226 },
227 {
228 'name' : 'dl',
229 'sources' : """
230 native_library_posix.cc
231 """,
232 'prefix' : 'base',
233 'libs' : 'dl',
234 'pc_libs' : '',
235 },
236 {
237 'name' : 'dbus',
238 'sources' : """
239 bus.cc
240 dbus_statistics.cc
241 exported_object.cc
242 file_descriptor.cc
243 message.cc
244 object_manager.cc
245 object_path.cc
246 object_proxy.cc
247 property.cc
248 scoped_dbus_error.cc
249 string_util.cc
250 util.cc
251 values_util.cc
252 """,
253 'prefix' : 'dbus',
254 'libs' : '',
255 'pc_libs' : 'dbus-1 protobuf-lite',
256 },
257 {
258 'name' : 'timers',
259 'sources' : """
260 alarm_timer_chromeos.cc
261 """,
262 'prefix' : 'components/timers',
263 'libs' : '',
264 'pc_libs' : '',
265 },
266 {
267 'name' : 'crypto',
268 'sources' : """
269 hmac.cc
270 hmac_nss.cc
271 nss_key_util.cc
272 nss_util.cc
Darren Krahn16334162016-03-01 14:38:19 -0800273 openssl_util.cc
Daniel Erat65f53982015-08-25 09:21:05 -0600274 p224.cc
275 p224_spake.cc
276 random.cc
277 rsa_private_key.cc
278 rsa_private_key_nss.cc
279 scoped_test_nss_db.cc
Luis Hector Chavez94ffa552016-05-25 15:29:35 -0700280 secure_hash.cc
Daniel Erat65f53982015-08-25 09:21:05 -0600281 secure_util.cc
282 sha2.cc
283 signature_creator_nss.cc
284 signature_verifier_nss.cc
285 symmetric_key_nss.cc
286 third_party/nss/rsawrapr.c
287 third_party/nss/sha512.cc
288 """,
289 'prefix' : 'crypto',
290 'libs' : '%s-dl-%s' % (base_name, BASE_VER),
Darren Krahn16334162016-03-01 14:38:19 -0800291 'pc_libs' : 'nss openssl',
Daniel Erat65f53982015-08-25 09:21:05 -0600292 },
293 {
294 'name' : 'sandbox',
295 'sources' : """
296 linux/bpf_dsl/bpf_dsl.cc
297 linux/bpf_dsl/codegen.cc
298 linux/bpf_dsl/dump_bpf.cc
299 linux/bpf_dsl/policy.cc
300 linux/bpf_dsl/policy_compiler.cc
301 linux/bpf_dsl/syscall_set.cc
302 linux/bpf_dsl/verifier.cc
303 linux/seccomp-bpf/die.cc
Daniel Erat65f53982015-08-25 09:21:05 -0600304 linux/seccomp-bpf/sandbox_bpf.cc
305 linux/seccomp-bpf/syscall.cc
306 linux/seccomp-bpf/trap.cc
307
308 linux/seccomp-bpf-helpers/baseline_policy.cc
309 linux/seccomp-bpf-helpers/sigsys_handlers.cc
310 linux/seccomp-bpf-helpers/syscall_parameters_restrictions.cc
311 linux/seccomp-bpf-helpers/syscall_sets.cc
312
313 linux/services/init_process_reaper.cc
314 linux/services/proc_util.cc
315 linux/services/resource_limits.cc
316 linux/services/scoped_process.cc
317 linux/services/syscall_wrappers.cc
318 linux/services/thread_helpers.cc
319 linux/services/yama.cc
320 linux/syscall_broker/broker_channel.cc
321 linux/syscall_broker/broker_client.cc
322 linux/syscall_broker/broker_file_permission.cc
323 linux/syscall_broker/broker_host.cc
324 linux/syscall_broker/broker_policy.cc
325 linux/syscall_broker/broker_process.cc
326
327 linux/services/credentials.cc
328 linux/services/namespace_sandbox.cc
329 linux/services/namespace_utils.cc
330 """,
331 'prefix' : 'sandbox',
332 'libs' : '',
333 'pc_libs' : '',
334 },
335]
336
337env.Append(
338 CPPPATH=['files'],
339 CCFLAGS=['-g']
340)
341for key in Split('CC CXX AR RANLIB LD NM CFLAGS CXXFLAGS LDFLAGS'):
342 value = os.environ.get(key)
343 if value:
344 env[key] = Split(value)
345if os.environ.has_key('CPPFLAGS'):
346 env['CCFLAGS'] += Split(os.environ['CPPFLAGS'])
347
348env['CCFLAGS'] += ['-DOS_CHROMEOS',
349 '-DUSE_NSS_CERTS',
350 '-DUSE_SYSTEM_LIBEVENT',
Alex Vakulenko45779222016-03-17 10:36:19 -0700351 '-DNO_TCMALLOC',
Daniel Erat65f53982015-08-25 09:21:05 -0600352 '-fPIC',
353 '-fno-exceptions',
354 '-Wall',
355 '-Werror',
356 '-Wno-deprecated-register',
357 '-Wno-narrowing',
358 '-Wno-psabi',
359 '-Wno-unused-local-typedefs',
360 # Various #defines are hardcoded near the top of
361 # build_config.h to ensure that they'll be set both when
362 # libchrome is built and when other packages include
363 # libchrome's headers.
364 '-I%s' % CHROME_INCLUDE_PATH]
365
366env.Append(
367 CXXFLAGS=['-std=c++11']
368)
369
370# Flags for clang taken from build/common.gypi in the clang==1 section.
371CLANG_FLAGS = (
372 '-Wno-char-subscripts',
373)
374
375env['CCFLAGS'] += ['-Xclang-only=%s' % x for x in CLANG_FLAGS]
376
377# Fix issue with scons not passing some vars through the environment.
378for key in Split('PKG_CONFIG SYSROOT'):
379 if os.environ.has_key(key):
380 env['ENV'][key] = os.environ[key]
381
382all_base_libs = []
383all_pc_libs = ''
384all_libs = []
385all_scons_libs = []
386
387# Build all the shared libraries.
388for lib in base_libs:
389 pc_libs = lib['pc_libs'].replace('${bslot}', BASE_VER)
390 all_pc_libs += ' ' + pc_libs
391
392 libs = Split(lib['libs'].replace('${bslot}', BASE_VER))
393 all_libs += libs
394
395 name = '%s-%s-%s' % (base_name, lib['name'], BASE_VER)
396 all_base_libs += [name]
397 corename = '%s-core-%s' % (base_name, BASE_VER)
398 # Automatically link the sub-libs against the main core lib.
399 # This is to keep from having to explicitly mention it in the
400 # table above (i.e. lazy).
401 if name != corename:
402 libs += [corename]
403
404 e = env.Clone()
405 e.Append(
406 LIBS = Split(libs),
407 LIBPATH = ['.'],
408 LINKFLAGS = ['-Wl,--as-needed', '-Wl,-z,defs',
409 '-Wl,-soname,lib%s.so' % name],
410 )
411 if pc_libs:
412 e.ParseConfig(PKG_CONFIG + ' --cflags --libs %s' % pc_libs)
413
414 # Prepend prefix to source filenames.
415 sources = [os.path.join(lib['prefix'], x) for x in Split(lib['sources'])]
416
417 all_scons_libs += [ e.SharedLibrary(name, sources) ]
418
419
420# Build a static library of mocks for unittests to link against.
421# Being static allows us to mask this library out of the image.
422
423all_base_test_libs = []
424all_test_pc_libs = ''
425all_test_libs = []
426
427test_libs = [
428 {
429 'name': 'base_test_support',
430 'sources': """
431 simple_test_clock.cc
432 simple_test_tick_clock.cc
433 test_file_util.cc
434 test_file_util_linux.cc
435 test_switches.cc
436 test_timeouts.cc
437 """,
438 'prefix': 'base/test',
439 'libs': '',
440 'pc_libs': '',
441 },
442 {
443 'name': 'dbus_test_support',
444 'sources': """
445 mock_bus.cc
446 mock_exported_object.cc
447 mock_object_manager.cc
448 mock_object_proxy.cc
449 """,
450 'prefix': 'dbus',
451 'libs': '', # TODO(wiley) what should go here?
452 'pc_libs': 'dbus-1 protobuf-lite',
453 },
454 {
455 'name': 'timer_test_support',
456 'sources': """
457 mock_timer.cc
458 """,
459 'prefix': 'base/timer',
460 'libs': '',
461 'pc_libs': '',
462 },
463]
464
465for lib in test_libs:
466 pc_libs = lib['pc_libs'].replace('${bslot}', BASE_VER)
467 all_test_pc_libs += ' ' + pc_libs
468
469 libs = Split(lib['libs'].replace('${bslot}', BASE_VER))
470 all_test_libs += libs
471
472 name = '%s-%s-%s' % (base_name, lib['name'], BASE_VER)
473 all_base_test_libs += [name]
474
475 static_env = env.Clone()
476 if pc_libs:
477 static_env.ParseConfig(PKG_CONFIG + ' --cflags --libs %s' % pc_libs)
478 sources = [os.path.join(lib['prefix'], x)
479 for x in Split(lib['sources'])]
480 static_env.StaticLibrary(name, sources)
481
482# Build the random text files (pkg-config and linker script).
483
484def lib_list(libs):
485 return ' '.join(['-l' + l for l in libs])
486
487prod_subst_dict = {
488 '@BSLOT@': BASE_VER,
489 '@PRIVATE_PC@': all_pc_libs,
490 '@BASE_LIBS@': lib_list(all_base_libs),
491 '@LIBS@': lib_list(all_libs),
492 '@NAME@': 'libchrome',
493 '@PKG_CFG_NAME@': 'libchrome-%s.pc' % BASE_VER,
494 '@LIB_NAME@': 'libbase-%s.so' % BASE_VER,
495 '@DESCRIPTION@': 'chrome base library',
496 # scons, in its infinite wisdom sees fit to expand this string if
497 # if we don't escape the $.
498 '@TARGET_LIB@': 'base-$${bslot}',
499}
500
501# Similarly, build text files related to the test libraries.
502test_subst_dict = {
503 '@BSLOT@': BASE_VER,
504 '@PRIVATE_PC@': all_test_pc_libs,
505 '@BASE_LIBS@': lib_list(all_base_test_libs),
506 '@LIBS@': lib_list(all_test_libs),
507 '@NAME@': 'libchrome-test',
508 '@PKG_CFG_NAME@': 'libchrome-test-%s.pc' % BASE_VER,
509 '@LIB_NAME@': 'libbase-test-%s.a' % BASE_VER,
510 '@DESCRIPTION@': 'chrome base test library',
511 # scons, in its infinite wisdom sees fit to expand this string if
512 # if we don't escape the $.
513 '@TARGET_LIB@': 'base-test-$${bslot}',
514}
515
516pc_file_contents = """
517prefix=/usr
518includedir=${prefix}/include
519bslot=@BSLOT@
520
521Name: @NAME@
522Description: @DESCRIPTION@
523Version: ${bslot}
524Requires:
525Requires.private: @PRIVATE_PC@
526Libs: -l@TARGET_LIB@
527Libs.private: @BASE_LIBS@ @LIBS@
528Cflags: -I${includedir}/@TARGET_LIB@ -Wno-c++11-extensions -Wno-unused-local-typedefs -DBASE_VER=${bslot}
529"""
530
531# https://sourceware.org/binutils/docs/ld/Scripts.html
532so_file_contents = """GROUP ( AS_NEEDED ( @BASE_LIBS@ ) )"""
533
534for subst_dict in (test_subst_dict, prod_subst_dict):
535 env = Environment(tools=['textfile'], SUBST_DICT=subst_dict)
536 env.Substfile(subst_dict['@LIB_NAME@'], [Value(so_file_contents)])
537 env.Substfile(subst_dict['@PKG_CFG_NAME@'], [Value(pc_file_contents)])