summaryrefslogtreecommitdiff
path: root/python/config/Make.rules
blob: ee53f40d516af5e4c8c84383085d2737ea70b7e8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#
# 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              ?= python

# ----------------------------------------------------------------------
# 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-version := $(shell $(PYTHON) -c "import sys; print(\"{0}.{1}\".format(sys.version_info[0], sys.version_info[1]))")
python-config := $(PYTHON)-config

ifeq ($(os),Linux)
   cppflags   := $(filter-out -Wredundant-decls,$(cppflags))
endif

python_cppflags         := $(shell $(python-config) --cflags)
python_ldflags          := $(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)

ifneq ($(filter debian ubuntu,$(linux_id)),)
allow-undefined-symbols := yes
python_ldflags          := $(filter-out -lpython% -ldl -lutil,$(python_ldflags))
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       = $(if $(usr_dir_install),$(shell $(PYTHON) $(lang_srcdir)/config/install_dir),$(prefix)/python)

#
# 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)/<package> to python/<package>.
#
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