bbf16741bd054c3ad7fa2a7a0e06c3d36b22b477
[platform/upstream/iotivity.git] / resource / csdk / connectivity / src / bt_le_adapter / linux / SConscript
1 # ------------------------------------------------------------------------
2 # Copyright 2015 Intel Corporation
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 #      http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 # ------------------------------------------------------------------------
16
17 ##########################################
18 #       Build BLE adapter for Linux
19 ##########################################
20
21 Import('env')
22
23 import os.path
24
25 # Top-level build (variant) directory.
26 root_build_dir = env['BUILD_DIR']
27
28 # Build (variant) directory corresponding to this source directory.
29 this_build_dir = os.path.join(root_build_dir,
30                               os.path.dirname(File(SConscript).srcnode().path))
31
32 # The Linux BLE adapter implementation uses GDBus to make D-Bus based
33 # method calls to BlueZ.  Pull in the necessary dependencies.
34 env.ParseConfig("pkg-config gio-unix-2.0 --cflags --libs")
35
36 # Set up commands to generate GDBus code from the D-Bus introspection
37 # XML.
38 freedesktop_prefix = 'org.freedesktop.DBus.'
39 bluez_prefix = 'org.bluez.'
40
41 dbus_introspection_xml = {
42     'object_manager' : freedesktop_prefix,
43     'bluez'          : bluez_prefix,
44 }
45
46 # The source files to be compiled as part of the connectivity
47 # abstraction library.
48 glue_files = []
49
50 for file, prefix in dbus_introspection_xml.items():
51     source_xml  = file + '.xml'
52     glue        = file + '-glue'
53     glue_source = glue + '.c'
54     glue_header = glue + '.h'
55     targets     = [ glue_source, glue_header ]
56
57     # Include the glue header in the list as well to make sure it is
58     # generated before other source files that depend on it are
59     # compiled.
60     glue_files += targets
61
62     # Generate GDBus skeletons in the variant (build) directory.
63     env.Command(targets,
64                 source_xml,
65                 'cd %s '
66                 '&& gdbus-codegen --generate-c-code %s --interface-prefix %s %s '
67                 '&& cd -'
68                 % (this_build_dir,
69                    glue,
70                    prefix,
71                    os.path.join(env['SRC_DIR'], '$SOURCE')))
72
73     # Mark generated file for cleaning when running "scons -c".
74     #
75     # @todo Verify that the generated *-glue.[ch] files are removed on
76     #       running "scons -c" once that is working in the master
77     #       branch again.
78     for target in targets:
79         generated_target = os.path.join(this_build_dir, target)
80         env.Clean(target, generated_target)
81
82 # The generated "glue" headers are found in the build directory
83 # corresponding to this source directory.
84 env.AppendUnique(CPPPATH = this_build_dir)
85
86 # The Linux BLE transport exports its GATT and LE advertisement
87 # related D-Bus interfaces to the D-Bus system bus so that they may be
88 # accessed by BlueZ.  Set the bus names here, i.e. in one place, to
89 # avoid potential mismatches, and generate the D-Bus policy
90 # configuration file and related C preprocessor symbol definitions.
91 service_name = '\"org.iotivity.gatt.service\"'
92
93 dbus_policy_in = 'org.iotivity.gatt.service.conf.in'
94
95 conf_dict = {}
96 subst_env = env.Clone(tools = [ 'default', 'textfile' ],
97                       SUBST_DICT = conf_dict)
98
99 conf_dict = { '@service_name@' : service_name }
100
101 subst_env.Substfile(dbus_policy_in, SUBST_DICT = conf_dict)
102
103 # The resulting D-Bus policy file should go in to the appropriate
104 # D-Bus configuration directory, such as /etc/dbus-1/system.d/.
105
106 dbus_policy    = os.path.splitext(dbus_policy_in)[0]  # Drop '.in' extension.
107 generated_dbus_policy = os.path.join(this_build_dir, dbus_policy)
108 env.Clean(dbus_policy, generated_dbus_policy)
109
110 # Define the D-Bus bus name as a preprocessor symbol.  Note the
111 # multiple quote levels to ensure that the double quotes surrounding
112 # the string are included as part of the preprocess symbol.
113 #
114 # Also add a minimum required version of GLib 2.32, which is what the
115 # older GNU/Linux distributions supported by IoTivity shipped with.
116 env.AppendUnique(
117     CPPDEFINES = [
118         ('CA_DBUS_GATT_SERVICE_NAME', "'%s'" % service_name),
119         ('GLIB_VERSION_MIN_REQUIRED', 'GLIB_VERSION_2_32')
120     ])
121
122 src_files = [ 'characteristic.c',
123               'descriptor.c',
124               'service.c',
125               'advertisement.c',
126               'utils.c',
127               'central.c',
128               'peripheral.c',
129               'client.c',
130               'server.c',
131               'recv.c',
132               'caleinterface.c'
133           ]
134 src_files = glue_files + src_files
135
136 Return('src_files')
137
138
139 # Local Variables:
140 # mode:python
141 # indent-tabs-mode: nil
142 # End: