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