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