blob: 77cdbdfde3eaf08f2477021fd9590c0fb3086040 [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 },
Daniel Erat65f53982015-08-25 09:21:05 -0600295]
296
297env.Append(
298 CPPPATH=['files'],
299 CCFLAGS=['-g']
300)
301for key in Split('CC CXX AR RANLIB LD NM CFLAGS CXXFLAGS LDFLAGS'):
302 value = os.environ.get(key)
303 if value:
304 env[key] = Split(value)
305if os.environ.has_key('CPPFLAGS'):
306 env['CCFLAGS'] += Split(os.environ['CPPFLAGS'])
307
308env['CCFLAGS'] += ['-DOS_CHROMEOS',
309 '-DUSE_NSS_CERTS',
310 '-DUSE_SYSTEM_LIBEVENT',
Alex Vakulenko45779222016-03-17 10:36:19 -0700311 '-DNO_TCMALLOC',
Daniel Erat65f53982015-08-25 09:21:05 -0600312 '-fPIC',
313 '-fno-exceptions',
314 '-Wall',
315 '-Werror',
316 '-Wno-deprecated-register',
317 '-Wno-narrowing',
318 '-Wno-psabi',
319 '-Wno-unused-local-typedefs',
320 # Various #defines are hardcoded near the top of
321 # build_config.h to ensure that they'll be set both when
322 # libchrome is built and when other packages include
323 # libchrome's headers.
324 '-I%s' % CHROME_INCLUDE_PATH]
325
326env.Append(
327 CXXFLAGS=['-std=c++11']
328)
329
330# Flags for clang taken from build/common.gypi in the clang==1 section.
331CLANG_FLAGS = (
332 '-Wno-char-subscripts',
333)
334
335env['CCFLAGS'] += ['-Xclang-only=%s' % x for x in CLANG_FLAGS]
336
337# Fix issue with scons not passing some vars through the environment.
338for key in Split('PKG_CONFIG SYSROOT'):
339 if os.environ.has_key(key):
340 env['ENV'][key] = os.environ[key]
341
342all_base_libs = []
343all_pc_libs = ''
344all_libs = []
345all_scons_libs = []
346
347# Build all the shared libraries.
348for lib in base_libs:
349 pc_libs = lib['pc_libs'].replace('${bslot}', BASE_VER)
350 all_pc_libs += ' ' + pc_libs
351
352 libs = Split(lib['libs'].replace('${bslot}', BASE_VER))
353 all_libs += libs
354
355 name = '%s-%s-%s' % (base_name, lib['name'], BASE_VER)
356 all_base_libs += [name]
357 corename = '%s-core-%s' % (base_name, BASE_VER)
358 # Automatically link the sub-libs against the main core lib.
359 # This is to keep from having to explicitly mention it in the
360 # table above (i.e. lazy).
361 if name != corename:
362 libs += [corename]
363
364 e = env.Clone()
365 e.Append(
366 LIBS = Split(libs),
367 LIBPATH = ['.'],
368 LINKFLAGS = ['-Wl,--as-needed', '-Wl,-z,defs',
369 '-Wl,-soname,lib%s.so' % name],
370 )
371 if pc_libs:
372 e.ParseConfig(PKG_CONFIG + ' --cflags --libs %s' % pc_libs)
373
374 # Prepend prefix to source filenames.
375 sources = [os.path.join(lib['prefix'], x) for x in Split(lib['sources'])]
376
377 all_scons_libs += [ e.SharedLibrary(name, sources) ]
378
379
380# Build a static library of mocks for unittests to link against.
381# Being static allows us to mask this library out of the image.
382
383all_base_test_libs = []
384all_test_pc_libs = ''
385all_test_libs = []
386
387test_libs = [
388 {
389 'name': 'base_test_support',
390 'sources': """
391 simple_test_clock.cc
392 simple_test_tick_clock.cc
393 test_file_util.cc
394 test_file_util_linux.cc
395 test_switches.cc
396 test_timeouts.cc
397 """,
398 'prefix': 'base/test',
399 'libs': '',
400 'pc_libs': '',
401 },
402 {
403 'name': 'dbus_test_support',
404 'sources': """
405 mock_bus.cc
406 mock_exported_object.cc
407 mock_object_manager.cc
408 mock_object_proxy.cc
409 """,
410 'prefix': 'dbus',
411 'libs': '', # TODO(wiley) what should go here?
412 'pc_libs': 'dbus-1 protobuf-lite',
413 },
414 {
415 'name': 'timer_test_support',
416 'sources': """
417 mock_timer.cc
418 """,
419 'prefix': 'base/timer',
420 'libs': '',
421 'pc_libs': '',
422 },
423]
424
425for lib in test_libs:
426 pc_libs = lib['pc_libs'].replace('${bslot}', BASE_VER)
427 all_test_pc_libs += ' ' + pc_libs
428
429 libs = Split(lib['libs'].replace('${bslot}', BASE_VER))
430 all_test_libs += libs
431
432 name = '%s-%s-%s' % (base_name, lib['name'], BASE_VER)
433 all_base_test_libs += [name]
434
435 static_env = env.Clone()
436 if pc_libs:
437 static_env.ParseConfig(PKG_CONFIG + ' --cflags --libs %s' % pc_libs)
438 sources = [os.path.join(lib['prefix'], x)
439 for x in Split(lib['sources'])]
440 static_env.StaticLibrary(name, sources)
441
442# Build the random text files (pkg-config and linker script).
443
444def lib_list(libs):
445 return ' '.join(['-l' + l for l in libs])
446
447prod_subst_dict = {
448 '@BSLOT@': BASE_VER,
449 '@PRIVATE_PC@': all_pc_libs,
450 '@BASE_LIBS@': lib_list(all_base_libs),
451 '@LIBS@': lib_list(all_libs),
452 '@NAME@': 'libchrome',
453 '@PKG_CFG_NAME@': 'libchrome-%s.pc' % BASE_VER,
454 '@LIB_NAME@': 'libbase-%s.so' % BASE_VER,
455 '@DESCRIPTION@': 'chrome base library',
456 # scons, in its infinite wisdom sees fit to expand this string if
457 # if we don't escape the $.
458 '@TARGET_LIB@': 'base-$${bslot}',
459}
460
461# Similarly, build text files related to the test libraries.
462test_subst_dict = {
463 '@BSLOT@': BASE_VER,
464 '@PRIVATE_PC@': all_test_pc_libs,
465 '@BASE_LIBS@': lib_list(all_base_test_libs),
466 '@LIBS@': lib_list(all_test_libs),
467 '@NAME@': 'libchrome-test',
468 '@PKG_CFG_NAME@': 'libchrome-test-%s.pc' % BASE_VER,
469 '@LIB_NAME@': 'libbase-test-%s.a' % BASE_VER,
470 '@DESCRIPTION@': 'chrome base test library',
471 # scons, in its infinite wisdom sees fit to expand this string if
472 # if we don't escape the $.
473 '@TARGET_LIB@': 'base-test-$${bslot}',
474}
475
476pc_file_contents = """
477prefix=/usr
478includedir=${prefix}/include
479bslot=@BSLOT@
480
481Name: @NAME@
482Description: @DESCRIPTION@
483Version: ${bslot}
484Requires:
485Requires.private: @PRIVATE_PC@
486Libs: -l@TARGET_LIB@
487Libs.private: @BASE_LIBS@ @LIBS@
488Cflags: -I${includedir}/@TARGET_LIB@ -Wno-c++11-extensions -Wno-unused-local-typedefs -DBASE_VER=${bslot}
489"""
490
491# https://sourceware.org/binutils/docs/ld/Scripts.html
492so_file_contents = """GROUP ( AS_NEEDED ( @BASE_LIBS@ ) )"""
493
494for subst_dict in (test_subst_dict, prod_subst_dict):
495 env = Environment(tools=['textfile'], SUBST_DICT=subst_dict)
496 env.Substfile(subst_dict['@LIB_NAME@'], [Value(so_file_contents)])
497 env.Substfile(subst_dict['@PKG_CFG_NAME@'], [Value(pc_file_contents)])