summaryrefslogtreecommitdiff
path: root/python/config/Make.rules
blob: 549a0d6f2cc41b9d5e7050d59950ac20c89a701b (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
# **********************************************************************
#
# Copyright (c) 2003-2017 ZeroC, Inc. All rights reserved.
#
# This copy of Ice is licensed to you under the terms described in the
# ICE_LICENSE file included in this distribution.
#
# **********************************************************************

#
# 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-call             = $(shell $(PYTHON) -c "import sys; import distutils.sysconfig as ds; sys.stdout.write($1)")

PYTHON_VERSION          ?= python$(PYTHON_BASE_VERSION)
PYTHON_BASE_VERSION     ?= $(call python-call,ds.get_python_version())
PYTHON_INCLUDE_DIR      ?= $(call python-call,ds.get_python_inc())
PYTHON_LIB_DIR          ?= $(call python-call,ds.get_config_var('LIBPL'))
PYTHON_LIB_SUFFIX       ?= $(call python-call,sys.__dict__['abiflags'] if 'abiflags' in sys.__dict__ else '')
PYTHON_LIB_NAME         ?= $(PYTHON_VERSION)$(PYTHON_LIB_SUFFIX)

python_cppflags         := -I$(PYTHON_INCLUDE_DIR)
python_ldflags          := -L$(PYTHON_LIB_DIR) -l$(PYTHON_LIB_NAME)

#
# 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%,%,$(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 --prefix $3_ --checksum $5 $$<

endef