python,python3: add Py[3]Shebang functions & move outside of script

Some packages just install some Python binaries, that may need their
shebang fixed.
This change adds some utilities to help with that and try to centralize the
sed rules a bit.

It also removes the logic from the `python-package-install.sh` into the
`python-package[3].mk` files. This does 2 things:
1. It minimizes the need for the shell script to know the Python
   version 2/3
2. Makes the logic re-usable in packages; especially if the install rules
   differ a bit

Signed-off-by: Alexandru Ardelean <ardeleanalex@gmail.com>
This commit is contained in:
Alexandru Ardelean
2019-09-12 15:03:50 +03:00
parent ed0e77f3c3
commit 721642908c
3 changed files with 17 additions and 13 deletions

View File

@@ -35,6 +35,10 @@ ifdef CONFIG_USE_MIPS16
TARGET_CFLAGS += -mno-mips16 -mno-interlink-mips16
endif
define PyShebang
$(SED) "1"'!'"b;s,^#"'!'".*python.*,#"'!'"/usr/bin/python2," -i --follow-symlinks $(1)
endef
define PyPackage
define Package/$(1)-src
@@ -74,11 +78,13 @@ define PyPackage
define Package/$(1)/install
$$(call PyPackage/$(1)/install,$$(1))
SED="$(SED)" \
$(SHELL) $(python_mk_path)python-package-install.sh "2" \
"$(PKG_INSTALL_DIR)" "$$(1)" \
"$(HOST_PYTHON_BIN)" "$$(2)" \
"$$$$$$$$$$(call shvar,PyPackage/$(1)/filespec)"
"$$$$$$$$$$(call shvar,PyPackage/$(1)/filespec)" && \
if [ -d "$$(1)/usr/bin" ]; then \
$(call PyShebang,$$(1)/usr/bin/*) ; \
fi
endef
define Package/$(1)-src/install