# # Copyright (c) ZeroC, Inc. All rights reserved. # # # If multiple versions of Python are installed and you want a specific # version to be used for building the Ice extension, set PYTHON to the # location of the python interpreter. # PYTHON ?= python3 # ---------------------------------------------------------------------- # Don't change anything below this line! # ---------------------------------------------------------------------- -include $(lang_srcdir)/config/Make.rules.$(os) # PYTHON must be set to a value that has a corresponding PYTHON-config python-config := $(PYTHON)-config ifeq ($(os),Linux) cppflags := $(filter-out -Wredundant-decls,$(cppflags)) endif python_cppflags := $(or $(PYTHON_CPPFLAGS),$(shell $(python-config) --cflags)) python_ldflags := $(or $(PYTHON_LDLFLAGS),$(shell $(python-config) --ldflags)) # Use .so as default value --extension-suffix is not supported by python-config in all platforms python_extsuffix := $(or $(shell $(python-config) --extension-suffix 2> /dev/null),.so) # As of Python 3.8 the python library is not included in the ldflags # This is also the same behavior used by pip allow-undefined-symbols := yes # Debian packaging complains if these libraries are included ifneq ($(filter debian ubuntu,$(linux_id)),) python_ldflags := $(filter-out -lpython% -ldl -lutil,$(python_ldflags)) endif ifeq ($(os),AIX) # We use an attribute (not an export file) to export the entry point link-with-python-exp := -Wl,-bE:Modules/python.exp python_ldflags := $(filter-out $(link-with-python-exp),$(python_ldflags)) # $(call mkshlib,$1=target,$2=objects,$3=libname,$4=version,$5=soversion,$6=ldflags,$7=platform) mkshlib = $(or $($7_cxx),$(CXX)) -shared -o $1 $2 $6 endif ifneq ($(OPTIMIZE),yes) # Remove optimization options if building debug build python_cppflags := $(filter-out -O% -DNDEBUG -Wp$(comma)-D_FORTIFY_SOURCE=%,$(python_cppflags)) endif # Remove the -Wstrict-prototypes option which is not valid with C++ and # -Wunreachable-code which is causing a compilation error with Slice/Parser.cpp python_cppflags := $(filter-out -Wunreachable-code -Wstrict-prototypes,$(python_cppflags)) -Wno-missing-field-initializers # # Python installation directory # install_pythondir = $(or $(PYTHON_INSTALLDIR),$(shell $(PYTHON) $(lang_srcdir)/config/install_dir $(prefix))) # # Rules to build a python module. We just compute the name of the python module # and delegate to make-shared-module. # mkpymodulename ?= $(patsubst lib%.so,%$(python_extsuffix),$(call mkshlibname,$(1))) make-shared-python-module = $(call make-shared-module,$(call mkpymodulename,$1),$2,$3,$4,$5,$6,$7,$8,$9) get-shared-python-module-targets = $(call get-shared-module-targets,$(call mkpymodulename,$1),$2,$3,$4) install-shared-python-module = $(call install-shared-module,$(call mkpymodulename,$1),$2,$3,$4,$5) $(DESTDIR)$(install_pythondir): $(Q)$(MKDIR) -p $@ installdirs += $(install_pythondir) # # $(call make-python-package,$1=slicedir,$2=generateddir,$3=package,$4=sliceflags) # # Compile slice files from $(slicedir)/ to python/. # define make-python-package $2/$3/.depend/%.ice.d: | $2/$3/.depend ; $2/$3/.depend: $(Q)$(MKDIR) -p $$@ .PRECIOUS: $2/$3/.depend/%.ice.d ifeq ($(filter %clean,$(MAKECMDGOALS)),) # Include the dependencies -include $(addprefix $2/.depend/,$(call source-to-dependency,$(wildcard $1/$3/*.ice))) endif $$(eval $$(call make-python-slice,$1,$2,$3,,$4)) distclean clean:: $(E) "Cleaning package $3" $(Q)$(RM) -r $2/$3/.depend $(Q)$(if $(findstring --no-package,$4),,$(RM) $2/$3/__init__.py) $(Q)$(RM) $(patsubst $1/$3/%.ice,$2/$3/%_ice.py,$(wildcard $1/$3/*.ice)) generate-srcs srcs all:: $(patsubst $1/$3/%.ice,$2/$3/%_ice.py,$(wildcard $1/$3/*.ice)) $$(eval $$(call install-data-files,$(patsubst $1/$3/%.ice,$2/$3/%_ice.py,$(wildcard $1/$3/*.ice)),$2,$(install_pythondir),install)) # If we also generate a package directory with an __init__.py, install it. ifeq ($(findstring --no-package,$4),) $$(eval $$(call install-data-files,$2/$3/__init__.py,$2,$(install_pythondir),install)) endif endef # # $(call make-python-slice,$1=slicedir,$2=generateddir,$3=package,$4=file,$5=sliceflags) # define make-python-slice $2/$3/$(or $4,%)_ice.py: $1/$3/$(or $4,%).ice $2/$3/.depend/$(or $4,%).ice.d $(slice2py_path) $(E) "Compiling $$<" $(Q)$(slice2py_path) -I$1 --output-dir $2 $5 --depend $$< > $2/$3/.depend/$(or $4,$$(*F)).ice.d $(Q)$(slice2py_path) -I$1 --output-dir $2 --checksum $5 $$< endef