forked from SynoCommunity/spksrc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspksrc.python-module.mk
57 lines (48 loc) · 1.97 KB
/
spksrc.python-module.mk
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
### Python module rules
# Invoke make to (cross-) compile a python module.
# You can do some customization through python-cc.mk
# Python module targets
ifeq ($(strip $(CONFIGURE_TARGET)),)
CONFIGURE_TARGET = nop
endif
ifeq ($(strip $(COMPILE_TARGET)),)
COMPILE_TARGET = compile_python_module
endif
ifeq ($(strip $(INSTALL_TARGET)),)
INSTALL_TARGET = install_python_module
endif
# Resume with standard spksrc.cross-cc.mk
include ../../mk/spksrc.cross-cc.mk
# Fetch python variables
-include $(WORK_DIR)/python-cc.mk
# Python module variables
ifneq ($(wildcard $(PYTHONPATH)),)
PYTHONPATH = $(PYTHON_SITE_PACKAGES_NATIVE):$(PYTHON_LIB_NATIVE):$(INSTALL_DIR)$(INSTALL_PREFIX)/$(PYTHON_LIB_DIR)/site-packages/
endif
### Python module rules
compile_python_module:
ifeq ($(strip $(CROSSENV)),)
# Python 2 way
@$(RUN) PYTHONPATH=$(PYTHONPATH) $(HOSTPYTHON) setup.py build_ext -I $(STAGING_INSTALL_PREFIX)/include -L $(STAGING_INSTALL_PREFIX)/lib $(BUILD_ARGS)
else
# Python 3 case: using crossenv helper
@. $(CROSSENV) && $(RUN) PYTHONPATH=$(PYTHONPATH) python setup.py build_ext -I $(STAGING_INSTALL_PREFIX)/include -L $(STAGING_INSTALL_PREFIX)/lib $(BUILD_ARGS)
endif
install_python_module:
ifeq ($(strip $(CROSSENV)),)
# Python 2 way
@$(RUN) PYTHONPATH=$(PYTHONPATH) $(HOSTPYTHON) setup.py install --root $(INSTALL_DIR) --prefix $(INSTALL_PREFIX) $(INSTALL_ARGS)
else
# Python 3 case: using crossenv helper
@. $(CROSSENV) && $(RUN) PYTHONPATH=$(PYTHONPATH) python setup.py install --root $(INSTALL_DIR) --prefix $(INSTALL_PREFIX) $(INSTALL_ARGS)
endif
fix_shebang_python_module:
@cat PLIST | sed 's/:/ /' | while read type file ; do \
for script in $(INSTALL_DIR)$(INSTALL_PREFIX)/$${file} ; do \
if file $${script} | grep -iq "python script" ; then \
echo -n "Fixing shebang for $${script} ... " ; \
sed -i -e '1 s|^#!.*$$|#!$(PYTHON_INTERPRETER)|g' $${script} > /dev/null 2>&1 && echo "ok" || echo "failed!" ; \
fi ; \
done ; \
done
all: install fix_shebang_python_module