OLD | NEW |
1 # Copyright (c) 2009 The Chromium OS Authors. All rights reserved. | 1 # Copyright (c) 2009 The Chromium OS Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 import os | 5 import os |
6 import sys | 6 import sys |
7 | 7 |
| 8 # Borrowed from updater |
| 9 # Protobuffer compilation |
| 10 def ProtocolBufferEmitter(target, source, env): |
| 11 """ Inputs: |
| 12 target: list of targets to compile to |
| 13 source: list of sources to compile |
| 14 env: the scons environment in which we are compiling |
| 15 Outputs: |
| 16 target: the list of targets we'll emit |
| 17 source: the list of sources we'll compile""" |
| 18 output = str(source[0]) |
| 19 output = output[0:output.rfind('.proto')] |
| 20 target = [ |
| 21 output + '.pb.cc', |
| 22 output + '.pb.h', |
| 23 ] |
| 24 return target, source |
| 25 |
| 26 def ProtocolBufferGenerator(source, target, env, for_signature): |
| 27 """ Inputs: |
| 28 source: list of sources to process |
| 29 target: list of targets to generate |
| 30 env: scons environment in which we are working |
| 31 for_signature: unused |
| 32 Outputs: a list of commands to execute to generate the targets from |
| 33 the sources.""" |
| 34 commands = [ |
| 35 '/usr/bin/protoc ' |
| 36 ' --proto_path . ${SOURCES} --cpp_out .'] |
| 37 return commands |
| 38 |
| 39 proto_builder = Builder(generator = ProtocolBufferGenerator, |
| 40 emitter = ProtocolBufferEmitter, |
| 41 single_source = 1, |
| 42 suffix = '.pb.cc') |
| 43 |
8 env = Environment() | 44 env = Environment() |
9 | 45 |
10 # setup sources | 46 # setup sources |
11 lib_sources = env.Split("""crypto.cc | 47 lib_sources = env.Split("""crypto.cc |
| 48 platform.cc |
12 secure_blob.cc | 49 secure_blob.cc |
13 tpm.cc | 50 tpm.cc |
14 tpm_init.cc | 51 tpm_init.cc |
| 52 tpm_status.pb.cc |
15 """) | 53 """) |
16 client_sources = env.Split("""main.cc | 54 client_sources = env.Split("""main.cc |
17 """) + lib_sources | 55 """) + lib_sources |
18 | 56 |
19 env.Append( | 57 env.Append( |
20 CPPPATH=['.', '..'], | 58 CPPPATH=['.', '..'], |
21 CPPFLAGS=['-pie', '-fstack-protector-all', '-fPIC', | 59 CPPFLAGS=['-pie', '-fstack-protector-all', '-fPIC', |
22 '-fno-exceptions', '-O2', '-Wall', '-Werror'], | 60 '-fno-exceptions', '-O2', '-Wall', '-Werror'], |
23 LIBS = ['base', 'chromeos', 'crypto', 'rt', 'pthread', 'tspi'], | 61 LIBS = ['base', 'chromeos', 'crypto', 'rt', 'protobuf', 'pthread', 'tspi'], |
24 ) | 62 ) |
25 for key in Split('CC CXX AR RANLIB LD NM CFLAGS CCFLAGS'): | 63 for key in Split('CC CXX AR RANLIB LD NM CFLAGS CCFLAGS'): |
26 value = os.environ.get(key) | 64 value = os.environ.get(key) |
27 if value != None: | 65 if value != None: |
28 env[key] = value | 66 env[key] = value |
29 | 67 |
30 # Fix issue with scons not passing some vars through the environment. | 68 # Fix issue with scons not passing some vars through the environment. |
31 for key in Split('PKG_CONFIG_LIBDIR PKG_CONFIG_PATH SYSROOT'): | 69 for key in Split('PKG_CONFIG_LIBDIR PKG_CONFIG_PATH SYSROOT'): |
32 if os.environ.has_key(key): | 70 if os.environ.has_key(key): |
33 env['ENV'][key] = os.environ[key] | 71 env['ENV'][key] = os.environ[key] |
34 | 72 |
| 73 env['BUILDERS']['ProtocolBuffer'] = proto_builder |
| 74 |
35 env.Append(LIBPATH = ['.']) | 75 env.Append(LIBPATH = ['.']) |
36 | 76 |
37 env_lib = env.Clone() | 77 env_lib = env.Clone() |
| 78 env_lib.ProtocolBuffer('tpm_status.pb.cc', 'tpm_status.proto') |
38 env_lib.Library('tpm_init', lib_sources) | 79 env_lib.Library('tpm_init', lib_sources) |
39 | 80 |
OLD | NEW |