1 # ------------------------------------------------------------------------
2 # Copyright 2015 Intel Corporation
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
8 # http://www.apache.org/licenses/LICENSE-2.0
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 # ------------------------------------------------------------------------
17 ##########################################
18 # Build BLE adapter for Linux
19 ##########################################
25 # Top-level build (variant) directory.
26 root_build_dir = env['BUILD_DIR']
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))
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")
36 # Set up commands to generate GDBus code from the D-Bus introspection
38 freedesktop_prefix = 'org.freedesktop.DBus.'
39 bluez_prefix = 'org.bluez.'
41 dbus_introspection_xml = {
42 'object_manager' : freedesktop_prefix,
43 'bluez' : bluez_prefix,
46 # The source files to be compiled as part of the connectivity
47 # abstraction library.
50 for file, prefix in dbus_introspection_xml.items():
51 source_xml = file + '.xml'
53 glue_source = glue + '.c'
54 glue_header = glue + '.h'
55 targets = [ glue_source, glue_header ]
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
62 # Generate GDBus skeletons in the variant (build) directory.
66 '&& gdbus-codegen --generate-c-code %s --interface-prefix %s %s '
71 os.path.join(env['SRC_DIR'], '$SOURCE')))
73 # Mark generated file for cleaning when running "scons -c".
75 # @todo Verify that the generated *-glue.[ch] files are removed on
76 # running "scons -c" once that is working in the master
78 for target in targets:
79 generated_target = os.path.join(this_build_dir, target)
80 env.Clean(target, generated_target)
82 # The generated "glue" headers are found in the build directory
83 # corresponding to this source directory.
84 env.AppendUnique(CPPPATH = this_build_dir)
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\"'
93 dbus_policy_in = 'org.iotivity.gatt.service.conf.in'
96 subst_env = env.Clone(tools = [ 'default', 'textfile' ],
97 SUBST_DICT = conf_dict)
99 conf_dict = { '@service_name@' : service_name }
101 subst_env.Substfile(dbus_policy_in, SUBST_DICT = conf_dict)
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/.
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)
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.
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.
118 ('CA_DBUS_GATT_SERVICE_NAME', "'%s'" % service_name),
119 ('GLIB_VERSION_MIN_REQUIRED', 'GLIB_VERSION_2_32')
122 src_files = [ 'characteristic.c',
134 src_files = glue_files + src_files
141 # indent-tabs-mode: nil