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