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 # Source node that allows us to easily obtain paths and directories
29 # related to this source directory.
30 src_node = File(SConscript).Dir(os.curdir).srcnode()
32 # Absolute path of the source directory.
33 this_src_dir = src_node.abspath
35 # Build (variant) directory corresponding to this source directory.
36 this_build_dir = os.path.join(root_build_dir, src_node.path)
38 # The Linux BLE transport exports its GATT and LE advertisement
39 # related D-Bus interfaces to the D-Bus system bus so that they may be
40 # accessed by BlueZ. Set the bus names here, i.e. in one place, to
41 # avoid potential mismatches, and generate the D-Bus policy
42 # configuration file and related C preprocessor symbol definitions.
43 service_name = '\"org.iotivity.gatt.service\"'
45 dbus_policy_in = 'org.iotivity.gatt.service.conf.in'
48 subst_env = env.Clone(tools = [ 'default', 'textfile' ],
49 SUBST_DICT = conf_dict)
51 conf_dict = { '@service_name@' : service_name }
53 subst_env.Substfile(dbus_policy_in, SUBST_DICT = conf_dict)
55 # The resulting D-Bus policy file should go in to the appropriate
56 # D-Bus configuration directory, such as /etc/dbus-1/system.d/.
58 dbus_policy = os.path.splitext(dbus_policy_in)[0] # Drop '.in' extension.
59 generated_dbus_policy = os.path.join(this_build_dir, dbus_policy)
60 env.Clean(dbus_policy, generated_dbus_policy)
62 # Define the D-Bus bus name as a preprocessor symbol. Note the
63 # multiple quote levels to ensure that the double quotes surrounding
64 # the string are included as part of the preprocess symbol.
66 # Also add a minimum required version of GLib 2.32, which is what the
67 # older GNU/Linux distributions supported by IoTivity shipped with.
70 ('CA_DBUS_GATT_SERVICE_NAME', "'%s'" % service_name),
71 ('GLIB_VERSION_MIN_REQUIRED', 'GLIB_VERSION_2_32')
74 # The Linux BLE adapter implementation uses GDBus to make D-Bus based
75 # method calls to BlueZ. Pull in the necessary dependencies.
76 env.ParseConfig("pkg-config gio-unix-2.0 --cflags --libs")
78 # Set up commands to generate GDBus code from the D-Bus introspection
80 freedesktop_prefix = 'org.freedesktop.DBus.'
81 bluez_prefix = 'org.bluez.'
83 dbus_introspection_xml = {
84 'object_manager' : freedesktop_prefix,
85 'bluez' : bluez_prefix,
88 # The source files to be compiled as part of the connectivity
89 # abstraction library.
90 src_files = [ 'characteristic.c',
105 for file, prefix in dbus_introspection_xml.items():
106 source_xml = file + '.xml'
107 glue = file + '-glue'
108 glue_source = glue + '.c'
109 glue_header = glue + '.h'
111 glue_files.append(glue_source)
113 # Generate GDBus skeletons in the variant (build) directory.
115 # A link to the generated GDBus glue header is also created in the
116 # source directory to avoid having to explicitly add the variant
117 # directory to the preprocessor include path.
118 targets = [ glue_source, glue_header ]
119 glue_header_gen = os.path.join(this_build_dir, glue_header)
120 glue_header_copy = os.path.join(this_src_dir, glue_header)
122 gen = env.Command(targets,
125 '&& gdbus-codegen --generate-c-code %s '
126 ' --interface-prefix %s ${SOURCE.abspath} '
131 glue_header_gen, glue_header_copy))
133 # Mark generated file for cleaning when running "scons -c".
134 for target in targets:
135 generated_target = os.path.join(this_build_dir, target)
136 env.Clean(target, generated_target)
138 env.Clean(glue_source, glue_header_copy)
140 # Force a dependency on copied glue header to make sure it exists
141 # before compilation of the non-generated source files begins.
142 env.Depends(src_files, gen)
144 src_files += glue_files
151 # indent-tabs-mode: nil