| # Copyright (c) 2011 The Chromium OS Authors. All rights reserved. |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| |
| import os |
| import re |
| import sys |
| |
| def GlibMarshalEmitter(target, source, env): |
| """ Inputs: |
| target: unused |
| source: list containing the source .list file |
| env: the scons environment in which we are compiling |
| Outputs: |
| target: the list of targets we'll emit |
| source: the list of sources we'll process""" |
| output = str(source[0]) |
| output = output[0:output.rfind('.list')] |
| target = [ |
| output + '.glibmarshal.c', |
| output + '.glibmarshal.h' |
| ] |
| return target, source |
| |
| def GlibMarshalGenerator(source, target, env, for_signature): |
| """ Inputs: |
| source: list of sources to process |
| target: list of targets to generate |
| env: scons environment in which we are working |
| for_signature: unused |
| Outputs: a list of commands to execute to generate the targets from |
| the sources.""" |
| commands = [] |
| for target_file in target: |
| if str(target_file).endswith('.glibmarshal.h'): |
| mode_flag = '--header ' |
| else: |
| mode_flag = '--body ' |
| cmd = '/usr/bin/glib-genmarshal %s --prefix=marshal ' \ |
| '%s > %s' % (mode_flag, str(source[0]), str(target_file)) |
| commands.append(cmd) |
| return commands |
| |
| glib_marshal_builder = Builder(generator = GlibMarshalGenerator, |
| emitter = GlibMarshalEmitter, |
| single_source = 1, |
| suffix = 'glibmarshal.c') |
| |
| base_env = Environment() |
| base_env['BUILDERS']['GlibMarshal'] = glib_marshal_builder |
| for key in Split('CC CXX AR RANLIB LD NM CFLAGS CCFLAGS LINKFLAGS'): |
| value = os.environ.get(key) |
| if value != None: |
| base_env[key] = Split(value) |
| |
| # Fix issue with scons not passing some vars through the environment. |
| for key in Split('PKG_CONFIG PKG_CONFIG_LIBDIR PKG_CONFIG_PATH SYSROOT'): |
| if os.environ.has_key(key): |
| base_env['ENV'][key] = os.environ[key] |
| |
| # Append these after pulling in the stuff from the environment so they |
| # don't get overwritten. |
| base_env.Append(CPPPATH=Split('. ..')) |
| base_env.Append(CCFLAGS=Split('-ggdb -fPIC -fno-exceptions -Wall -Werror')) |
| base_env.Append(LINKFLAGS=Split('-fPIC')) |
| |
| SOURCES = Split('''\ |
| chromeos_network.cc |
| marshal.glibmarshal.c |
| version_check.cc |
| ''') |
| |
| env = base_env.Clone() |
| |
| # glib and dbus environment |
| env.ParseConfig('%s --cflags --libs dbus-1 glib-2.0 dbus-glib-1 ' |
| 'libchrome libchromeos libpcrecpp x11' % |
| env['ENV']['PKG_CONFIG']) |
| |
| env.GlibMarshal('marshal.glibmarshal.c', 'marshal.list') |
| |
| # test_libbase_ndebug is built to catch NDEBUG mismatches between this |
| # library and libbase. It is not installed. |
| Default(env.SharedLibrary('cros', SOURCES), |
| env.Program('test_libbase_ndebug', 'test_libbase_ndebug.cc')) |
| |
| env_test = base_env.Clone() |
| env_test.Append(LIBS=['nss3']) |
| |
| env_test.ParseConfig('%s --cflags --libs gobject-2.0 dbus-glib-1 dbus-1 ' |
| 'libchrome nss' |
| % (env_test['ENV']['PKG_CONFIG'])) |
| env_test.Append(CCFLAGS=['-DOS_CHROMEOS']) |
| |
| env_gtest = env_test.Clone() |
| env_gtest.Append(LIBS=['gtest']) |
| |
| env_gtest_main = env_test.Clone() |
| env_gtest_main.Append(LIBS=['gtest', 'gtest_main']) |
| env_gtest_main.ParseConfig('%s --cflags --libs libchrome libchromeos ' |
| 'libpcrecpp x11' % (env_test['ENV']['PKG_CONFIG'])) |
| |
| env_network_monitor = env_test.Clone() |
| env_network_monitor.ParseConfig('%s --cflags --libs dbus-glib-1' % |
| env['ENV']['PKG_CONFIG']) |
| |
| env_load = base_env.Clone() |
| env_load.ParseConfig('%s --cflags --libs dbus-glib-1' % env['ENV']['PKG_CONFIG']) |
| Load = env_load.Object('load.cc') |
| |
| # Tests that do require libcros.so. |
| tests = [ |
| env_network_monitor.Program('monitor_sms', ['monitor_sms.cc', Load]), |
| ] |
| test_alias = Alias('test', tests) |
| AlwaysBuild(test_alias) |
| |
| Alias('crosapi', env_load.StaticLibrary('crosapi', Load), CCFLAGS='-ggdb') |