| 1 | # SPDX-License-Identifier: MIT |
| 2 | |
| 3 | # Since the shared object used by the python bindings is not built with |
| 4 | # libtool, we need to add the directory containing libbabeltrace2 to the |
| 5 | # linker path. |
| 6 | AM_LDFLAGS += -L$(top_builddir)/src/lib/.libs |
| 7 | |
| 8 | INSTALLED_FILES=$(builddir)/installed_files.txt |
| 9 | |
| 10 | SWIG_INTERFACE_FILES = \ |
| 11 | bt2/native_bt.i \ |
| 12 | bt2/native_bt_autodisc.i \ |
| 13 | bt2/native_bt_autodisc.i.h \ |
| 14 | bt2/native_bt_bt2_objects.h \ |
| 15 | bt2/native_bt_clock_class.i \ |
| 16 | bt2/native_bt_clock_snapshot.i \ |
| 17 | bt2/native_bt_component.i \ |
| 18 | bt2/native_bt_component_class.i \ |
| 19 | bt2/native_bt_component_class.i.h \ |
| 20 | bt2/native_bt_connection.i \ |
| 21 | bt2/native_bt_error.i \ |
| 22 | bt2/native_bt_error.i.h \ |
| 23 | bt2/native_bt_event.i \ |
| 24 | bt2/native_bt_event_class.i \ |
| 25 | bt2/native_bt_field.i \ |
| 26 | bt2/native_bt_field_class.i \ |
| 27 | bt2/native_bt_field_path.i \ |
| 28 | bt2/native_bt_graph.i \ |
| 29 | bt2/native_bt_graph.i.h \ |
| 30 | bt2/native_bt_integer_range_set.i \ |
| 31 | bt2/native_bt_interrupter.i \ |
| 32 | bt2/native_bt_log_and_append_error.h \ |
| 33 | bt2/native_bt_logging.i \ |
| 34 | bt2/native_bt_message.i \ |
| 35 | bt2/native_bt_message_iterator.i \ |
| 36 | bt2/native_bt_message_iterator.i.h \ |
| 37 | bt2/native_bt_mip.i \ |
| 38 | bt2/native_bt_mip.i.h \ |
| 39 | bt2/native_bt_packet.i \ |
| 40 | bt2/native_bt_plugin.i \ |
| 41 | bt2/native_bt_plugin.i.h \ |
| 42 | bt2/native_bt_port.i \ |
| 43 | bt2/native_bt_query_exec.i \ |
| 44 | bt2/native_bt_query_exec.i.h \ |
| 45 | bt2/native_bt_stream.i \ |
| 46 | bt2/native_bt_stream_class.i \ |
| 47 | bt2/native_bt_trace.i \ |
| 48 | bt2/native_bt_trace.i.h \ |
| 49 | bt2/native_bt_trace_class.i \ |
| 50 | bt2/native_bt_trace_class.i.h \ |
| 51 | bt2/native_bt_value.i \ |
| 52 | bt2/native_bt_value.i.h \ |
| 53 | bt2/native_bt_version.i |
| 54 | |
| 55 | # Non-generated files built into the native library. |
| 56 | STATIC_NATIVE_LIB_SRCS = \ |
| 57 | bt2/logging.c \ |
| 58 | bt2/logging.h |
| 59 | |
| 60 | STATIC_BINDINGS_DEPS = \ |
| 61 | bt2/__init__.py \ |
| 62 | bt2/clock_class.py \ |
| 63 | bt2/clock_snapshot.py \ |
| 64 | bt2/component.py \ |
| 65 | bt2/component_descriptor.py \ |
| 66 | bt2/connection.py \ |
| 67 | bt2/error.py \ |
| 68 | bt2/event.py \ |
| 69 | bt2/event_class.py \ |
| 70 | bt2/field.py \ |
| 71 | bt2/field_class.py \ |
| 72 | bt2/field_path.py \ |
| 73 | bt2/graph.py \ |
| 74 | bt2/integer_range_set.py \ |
| 75 | bt2/interrupter.py \ |
| 76 | bt2/logging.py \ |
| 77 | bt2/message.py \ |
| 78 | bt2/message_iterator.py \ |
| 79 | bt2/mip.py \ |
| 80 | bt2/object.py \ |
| 81 | bt2/packet.py \ |
| 82 | bt2/plugin.py \ |
| 83 | bt2/port.py \ |
| 84 | bt2/py_plugin.py \ |
| 85 | bt2/query_executor.py \ |
| 86 | bt2/stream.py \ |
| 87 | bt2/stream_class.py \ |
| 88 | bt2/trace.py \ |
| 89 | bt2/trace_class.py \ |
| 90 | bt2/trace_collection_message_iterator.py \ |
| 91 | bt2/utils.py \ |
| 92 | bt2/value.py |
| 93 | |
| 94 | # Convenience static libraries on which the Python bindings library depends. |
| 95 | # These are listed in the setup.py(.in) file. |
| 96 | STATIC_LIBRARIES_DEPS = \ |
| 97 | $(top_builddir)/src/autodisc/libautodisc.la \ |
| 98 | $(top_builddir)/src/logging/liblogging.la \ |
| 99 | $(top_builddir)/src/common/libbabeltrace2-common.la \ |
| 100 | $(top_builddir)/src/py-common/libpy-common.la \ |
| 101 | $(top_builddir)/src/string-format/libstring-format.la |
| 102 | |
| 103 | GENERATED_BINDINGS_DEPS = \ |
| 104 | bt2/native_bt.c \ |
| 105 | bt2/version.py \ |
| 106 | setup.py |
| 107 | |
| 108 | # Some versions of SWIG (like 3.0.12) generate code where a parameter called |
| 109 | # `swig_this` shadows a global of the same name. Later versions (like 4.0.1) |
| 110 | # have renamed this global to `Swig_This_global`. |
| 111 | # |
| 112 | # Disable -Wshadow for that file. |
| 113 | WARN_CFLAGS = -Wno-shadow |
| 114 | |
| 115 | WARN_CFLAGS += -Wno-null-dereference |
| 116 | |
| 117 | # Python 3.8 with SWIG 4.0.2 generates a deprecated warning for 'tp_print' |
| 118 | # and in general there is not much we can do about deprecations in generated |
| 119 | # code. |
| 120 | WARN_CFLAGS += -Wno-deprecated-declarations |
| 121 | |
| 122 | # Python 3.11 + gcc 12.2.0 gave warnings of this kind in Python.h. |
| 123 | WARN_CFLAGS += -Wno-redundant-decls |
| 124 | |
| 125 | # For SWIG generated code |
| 126 | WARN_CFLAGS += -Wno-missing-field-initializers |
| 127 | |
| 128 | BUILD_FLAGS=CC="$(CC)" \ |
| 129 | CFLAGS="$(GLIB_CFLAGS) $(AM_CFLAGS) $(CFLAGS) $(WARN_CFLAGS)" \ |
| 130 | CPPFLAGS="$(AM_CPPFLAGS) $(CPPFLAGS) -I$(srcdir)/bt2" \ |
| 131 | LDFLAGS="$(AM_LDFLAGS) $(LDFLAGS) $(GLIB_LIBS) $(PYTHON_LDFLAGS) $(LIBS)" |
| 132 | |
| 133 | all-local: build-python-bindings.stamp |
| 134 | |
| 135 | copy-static-deps.stamp: $(addprefix $(srcdir)/, $(STATIC_BINDINGS_DEPS)) |
| 136 | @if [ x"$(srcdir)" != x"$(builddir)" ]; then \ |
| 137 | for file in $(STATIC_BINDINGS_DEPS); do \ |
| 138 | cp -f $(srcdir)/$$file $(builddir)/$$file; \ |
| 139 | done; \ |
| 140 | fi |
| 141 | touch $@ |
| 142 | |
| 143 | build-python-bindings.stamp: copy-static-deps.stamp $(GENERATED_BINDINGS_DEPS) \ |
| 144 | $(STATIC_NATIVE_LIB_SRCS) $(STATIC_LIBRARIES_DEPS) |
| 145 | $(BUILD_FLAGS) $(PYTHON) $(builddir)/setup.py build --force |
| 146 | touch $@ |
| 147 | |
| 148 | swig_verbose = $(swig_verbose_@AM_V@) |
| 149 | swig_verbose_ = $(swig_verbose_@AM_DEFAULT_V@) |
| 150 | swig_verbose_0 = @echo " SWIG " $@; |
| 151 | |
| 152 | $(builddir)/bt2/native_bt.c: $(SWIG_INTERFACE_FILES) |
| 153 | $(swig_verbose)$(SWIG) -MD -python -I"$(top_srcdir)/include" -o "$@" "$<" |
| 154 | |
| 155 | -include bt2/native_bt.d |
| 156 | |
| 157 | pyinstall_verbose = $(pyinstall_verbose_@AM_V@) |
| 158 | pyinstall_verbose_ = $(pyinstall_verbose_@AM_DEFAULT_V@) |
| 159 | pyinstall_verbose_0 = @ |
| 160 | |
| 161 | # For Python < 3.12, force the use of distutils even if setuptools is |
| 162 | # installed. For Python >= 3.12, set the externally managed option to allow |
| 163 | # installation in a directory which isn't in the current PYTHONPATH. |
| 164 | if HAVE_PYTHON_312_OR_GREATER |
| 165 | PY_INSTALL_OPTS = --single-version-externally-managed |
| 166 | else |
| 167 | export SETUPTOOLS_USE_DISTUTILS=stdlib |
| 168 | endif |
| 169 | |
| 170 | install-exec-local: build-python-bindings.stamp |
| 171 | $(pyinstall_verbose)opts="--prefix=$(prefix) --exec-prefix=$(exec_prefix) --record $(INSTALLED_FILES) --verbose --no-compile $(DISTSETUPOPTS)"; \ |
| 172 | if [ "$(DESTDIR)" != "" ]; then \ |
| 173 | opts="$$opts --root=$(DESTDIR)"; \ |
| 174 | fi; \ |
| 175 | $(PYTHON) $(builddir)/setup.py install $(PY_INSTALL_OPTS) $$opts; |
| 176 | |
| 177 | clean-local: |
| 178 | rm -rf $(builddir)/build |
| 179 | @if [ x"$(srcdir)" != x"$(builddir)" ]; then \ |
| 180 | for file in $(STATIC_BINDINGS_DEPS); do \ |
| 181 | rm -f $(builddir)/$$file; \ |
| 182 | done; \ |
| 183 | fi |
| 184 | |
| 185 | # Distutils' setup.py does not include an uninstall target, we thus need to do |
| 186 | # it manually. We save the path of the files that were installed during the install target |
| 187 | # and delete them during the uninstallation. |
| 188 | uninstall-local: |
| 189 | if [ "$(DESTDIR)" != "" ]; then \ |
| 190 | $(SED) -i "s|^|$(DESTDIR)/|g" $(INSTALLED_FILES); \ |
| 191 | fi |
| 192 | cat $(INSTALLED_FILES) | xargs rm -rf || true |
| 193 | $(GREP) "__init__.py" $(INSTALLED_FILES) | xargs dirname | xargs rm -rf || true |
| 194 | rm -f $(INSTALLED_FILES) |
| 195 | |
| 196 | # distribute: extra Python modules and SWIG interface files |
| 197 | EXTRA_DIST = $(STATIC_BINDINGS_DEPS) $(SWIG_INTERFACE_FILES) $(STATIC_NATIVE_LIB_SRCS) |
| 198 | |
| 199 | # clean: generated C and Python files (by SWIG) |
| 200 | CLEANFILES = \ |
| 201 | build-python-bindings.stamp \ |
| 202 | bt2/native_bt.c \ |
| 203 | bt2/native_bt.d \ |
| 204 | bt2/native_bt.py \ |
| 205 | copy-static-deps.stamp |