lede-packages-rs

git clone git://archive.git.mtrnord.blog/MTRNord/lede-packages-rs.git
Log | Files | Refs | README | LICENSE

python-package.mk (3834B)


      1 #
      2 # Copyright (C) 2006-2016 OpenWrt.org
      3 #
      4 # This is free software, licensed under the GNU General Public License v2.
      5 # See /LICENSE for more information.
      6 #
      7 
      8 $(call include_mk, python-version.mk)
      9 
     10 PYTHON_DIR:=$(STAGING_DIR)/usr
     11 PYTHON_BIN_DIR:=$(PYTHON_DIR)/bin
     12 PYTHON_INC_DIR:=$(PYTHON_DIR)/include/python$(PYTHON_VERSION)
     13 PYTHON_LIB_DIR:=$(PYTHON_DIR)/lib/python$(PYTHON_VERSION)
     14 
     15 PYTHON_PKG_DIR:=/usr/lib/python$(PYTHON_VERSION)/site-packages
     16 
     17 PYTHON:=python$(PYTHON_VERSION)
     18 
     19 PYTHONPATH:=$(PYTHON_LIB_DIR):$(STAGING_DIR)/$(PYTHON_PKG_DIR):$(PKG_INSTALL_DIR)/$(PYTHON_PKG_DIR)
     20 
     21 # These configure args are needed in detection of path to Python header files
     22 # using autotools.
     23 CONFIGURE_ARGS += \
     24 	_python_sysroot="$(STAGING_DIR)" \
     25 	_python_prefix="/usr" \
     26 	_python_exec_prefix="/usr"
     27 
     28 PKG_USE_MIPS16:=0
     29 # This is required in addition to PKG_USE_MIPS16:=0 because otherwise MIPS16
     30 # flags are inherited from the Python base package (via sysconfig module)
     31 ifdef CONFIG_USE_MIPS16
     32   TARGET_CFLAGS += -mno-mips16 -mno-interlink-mips16
     33 endif
     34 
     35 define PyPackage
     36 
     37   define Package/$(1)-src
     38     $(call Package/$(1))
     39     TITLE+= (sources)
     40     DEPENDS:=$$$$(foreach dep,$$$$(filter +python-%,$$$$(DEPENDS)),$$$$(dep)-src)
     41   endef
     42 
     43   define Package/$(1)-src/description
     44     $(call Package/$(1)/description).
     45     (Contains the Python sources for this package).
     46   endef
     47 
     48   # Add default PyPackage filespec none defined
     49   ifndef PyPackage/$(1)/filespec
     50     define PyPackage/$(1)/filespec
     51       +|$(PYTHON_PKG_DIR)
     52     endef
     53   endif
     54 
     55   ifndef PyPackage/$(1)/install
     56     define PyPackage/$(1)/install
     57 		if [ -d $(PKG_INSTALL_DIR)/usr/bin ]; then \
     58 			$(INSTALL_DIR) $$(1)/usr/bin ; \
     59 			$(CP) $(PKG_INSTALL_DIR)/usr/bin/* $$(1)/usr/bin/ ; \
     60 		fi
     61     endef
     62   endif
     63 
     64   $(call shexport,PyPackage/$(1)/filespec)
     65 
     66   define Package/$(1)/install
     67 	$(call PyPackage/$(1)/install,$$(1))
     68 	find $(PKG_INSTALL_DIR) -name "*\.exe" | xargs rm -f
     69 	if [ -e files/python-package-install.sh ] ; then \
     70 		$(SHELL) files/python-package-install.sh \
     71 			"$(PKG_INSTALL_DIR)" "$$(1)" \
     72 			"$(HOST_PYTHON_BIN)" "$$(2)" \
     73 			"$$$$$$$$$$(call shvar,PyPackage/$(1)/filespec)" ; \
     74 	elif [ -e $(STAGING_DIR)/mk/python-package-install.sh ] ; then \
     75 		$(SHELL) $(STAGING_DIR)/mk/python-package-install.sh \
     76 			"$(PKG_INSTALL_DIR)" "$$(1)" \
     77 			"$(HOST_PYTHON_BIN)" "$$(2)" \
     78 			"$$$$$$$$$$(call shvar,PyPackage/$(1)/filespec)" ; \
     79 	else \
     80 		echo "No 'python-package-install.sh' script found" ; \
     81 		exit 1 ; \
     82 	fi
     83   endef
     84 
     85   define Package/$(1)-src/install
     86 	$$(call Package/$(1)/install,$$(1),sources)
     87   endef
     88 endef
     89 
     90 $(call include_mk, python-host.mk)
     91 
     92 # $(1) => commands to execute before running pythons script
     93 # $(2) => python script and its arguments
     94 # $(3) => additional variables
     95 define Build/Compile/HostPyRunTarget
     96 	$(call HostPython, \
     97 		$(if $(1),$(1);) \
     98 		CC="$(TARGET_CC)" \
     99 		CCSHARED="$(TARGET_CC) $(FPIC)" \
    100 		CXX="$(TARGET_CXX)" \
    101 		LD="$(TARGET_CC)" \
    102 		LDSHARED="$(TARGET_CC) -shared" \
    103 		CFLAGS="$(TARGET_CFLAGS)" \
    104 		CPPFLAGS="$(TARGET_CPPFLAGS) -I$(PYTHON_INC_DIR)" \
    105 		LDFLAGS="$(TARGET_LDFLAGS) -lpython$(PYTHON_VERSION)" \
    106 		_PYTHON_HOST_PLATFORM=linux2 \
    107 		__PYVENV_LAUNCHER__="/usr/bin/$(PYTHON)" \
    108 		$(3) \
    109 		, \
    110 		$(2) \
    111 	)
    112 endef
    113 
    114 # $(1) => build subdir
    115 # $(2) => additional arguments to setup.py
    116 # $(3) => additional variables
    117 define Build/Compile/PyMod
    118 	$(INSTALL_DIR) $(PKG_INSTALL_DIR)/$(PYTHON_PKG_DIR)
    119 	$(call Build/Compile/HostPyRunTarget, \
    120 		cd $(PKG_BUILD_DIR)/$(strip $(1)), \
    121 		./setup.py $(2), \
    122 		$(3))
    123 	find $(PKG_INSTALL_DIR) -name "*\.exe" | xargs rm -f
    124 endef
    125 
    126 define PyBuild/Compile/Default
    127 	$(call Build/Compile/PyMod,, \
    128 		install --prefix="/usr" --root="$(PKG_INSTALL_DIR)" \
    129 		--single-version-externally-managed \
    130 	)
    131 endef
    132 
    133 ifeq ($(BUILD_VARIANT),python)
    134 define Build/Compile
    135 	$(call PyBuild/Compile/Default)
    136 endef
    137 endif # python