Fix build error with scons-4.4.0 version which is based on python3
[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 # 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()
31
32 # Absolute path of the source directory.
33 this_src_dir = src_node.abspath
34
35 # Build (variant) directory corresponding to this source directory.
36 this_build_dir = os.path.join(root_build_dir, src_node.path)
37
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\"'
44
45 dbus_policy_in = 'org.iotivity.gatt.service.conf.in'
46
47 conf_dict = {}
48 subst_env = env.Clone(tools = [ 'default', 'textfile' ],
49                       SUBST_DICT = conf_dict)
50
51 conf_dict = { '@service_name@' : service_name }
52
53 subst_env.Substfile(dbus_policy_in, SUBST_DICT = conf_dict)
54
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/.
57
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)
61
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.
65 #
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.
68 env.AppendUnique(
69     CPPDEFINES = [
70         ('CA_DBUS_GATT_SERVICE_NAME', "'%s'" % service_name),
71         ('GLIB_VERSION_MIN_REQUIRED', 'GLIB_VERSION_2_32')
72     ])
73
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")
77
78 # Set up commands to generate GDBus code from the D-Bus introspection
79 # XML.
80 freedesktop_prefix = 'org.freedesktop.DBus.'
81 bluez_prefix = 'org.bluez.'
82
83 dbus_introspection_xml = {
84     'object_manager' : freedesktop_prefix,
85     'bluez'          : bluez_prefix,
86 }
87
88 # The source files to be compiled as part of the connectivity
89 # abstraction library.
90 src_files = [ 'characteristic.c',
91               'descriptor.c',
92               'service.c',
93               'advertisement.c',
94               'utils.c',
95               'central.c',
96               'peripheral.c',
97               'client.c',
98               'server.c',
99               'recv.c',
100               'caleinterface.c'
101           ]
102
103 glue_files = []
104
105 for file, prefix in list(dbus_introspection_xml.items()):
106     source_xml  = file + '.xml'
107     glue        = file + '-glue'
108     glue_source = glue + '.c'
109     glue_header = glue + '.h'
110
111     glue_files.append(glue_source)
112
113     # Generate GDBus skeletons in the variant (build) directory.
114     #
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)
121
122     gen = env.Command(targets,
123                       source_xml,
124                       'cd %s '
125                       '&& gdbus-codegen --generate-c-code %s '
126                       '   --interface-prefix %s ${SOURCE.abspath} '
127                       '&& ln -sf %s %s '
128                       '&& cd -'
129                       % (this_build_dir,
130                          glue, prefix,
131                          glue_header_gen, glue_header_copy))
132
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)
137
138     env.Clean(glue_source, glue_header_copy)
139
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)
143
144 src_files += glue_files
145
146 Return('src_files')
147
148
149 # Local Variables:
150 # mode:python
151 # indent-tabs-mode: nil
152 # End: