lede-packages-rs

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

Makefile (4985B)


      1 #
      2 # Copyright (C) 2016 Yousong Zhou <yszhou4tech@gmail.com>
      3 #
      4 # This is free software, licensed under the GNU General Public License v2.
      5 # See /LICENSE for more information.
      6 #
      7 
      8 include $(TOPDIR)/rules.mk
      9 
     10 PKG_NAME:=python-packages
     11 PKG_VERSION:=1.0
     12 PKG_RELEASE:=1
     13 
     14 PKG_MAINTAINER:=Yousong Zhou <yszhou4tech@gmail.com>
     15 
     16 #
     17 # NOTE: move the host module installation to Host/Compile when
     18 # HOST_CONFIG_DEPENDS is supported
     19 #
     20 # NOTE: PKG_CONFIG_DEPENDS cannot correctly track changes of string type config
     21 # options, so you may want to do manual cleanup on config change.
     22 #
     23 PKG_CONFIG_DEPENDS:= \
     24 	CONFIG_PACKAGE_python-packages-list-host \
     25 	CONFIG_PACKAGE_python-packages-list \
     26 	CONFIG_PACKAGE_python-packages-list-cleanup \
     27 	CONFIG_PACKAGE_python-packages-envs \
     28 	CONFIG_PACKAGE_python-packages-extra-deps \
     29 	CONFIG_PACKAGE_python-packages-index-url \
     30 	CONFIG_PACKAGE_python-packages-pip-opts \
     31 
     32 PKG_BUILD_DEPENDS:=python python/host
     33 
     34 include $(INCLUDE_DIR)/package.mk
     35 $(call include_mk, python-package.mk)
     36 
     37 define Package/python-packages
     38   SUBMENU:=Python
     39   SECTION:=lang
     40   CATEGORY:=Languages
     41   TITLE:=A dummy package for packaging python modules with pip
     42   DEPENDS:=@DEVEL +python
     43 endef
     44 
     45 define Package/python-packages/config
     46 if PACKAGE_python-packages
     47 config PACKAGE_python-packages-list-host
     48 	string "List of python packages to install on host"
     49 config PACKAGE_python-packages-list
     50 	string "List of python packages to install on target"
     51 config PACKAGE_python-packages-list-cleanup
     52 	string "List of python packages to cleanup to avoid clash with existing packages"
     53 config PACKAGE_python-packages-envs
     54 	string "Extra environment variables to pass on to pip and its children on target build"
     55 config PACKAGE_python-packages-extra-deps
     56 	string "List of deps fulfilled but not tracked by the build system"
     57 config PACKAGE_python-packages-index-url
     58 	string "Index URL passed to pip with --index-url"
     59 config PACKAGE_python-packages-pip-opts
     60 	string "Additional arguments to pip command line"
     61 endif
     62 endef
     63 
     64 CONFIG_PACKAGE_python-packages-list-host:=$(call qstrip,$(CONFIG_PACKAGE_python-packages-list-host))
     65 CONFIG_PACKAGE_python-packages-list:=$(call qstrip,$(CONFIG_PACKAGE_python-packages-list))
     66 CONFIG_PACKAGE_python-packages-list-cleanup:=$(call qstrip,$(CONFIG_PACKAGE_python-packages-list-cleanup))
     67 CONFIG_PACKAGE_python-packages-envs:=$(call qstrip,$(CONFIG_PACKAGE_python-packages-envs))
     68 CONFIG_PACKAGE_python-packages-extra-deps:=$(call qstrip,$(CONFIG_PACKAGE_python-packages-extra-deps))
     69 CONFIG_PACKAGE_python-packages-pip-opts:=$(call qstrip,$(CONFIG_PACKAGE_python-packages-pip-opts))
     70 
     71 HOST_PYTHON_PIP:=$(STAGING_DIR_HOSTPKG)/bin/pip$(PYTHON_VERSION)
     72 
     73 decr=$(word $(1),0 1 2 3 4 5 6 7 8 9 10)
     74 recur=$(if $(subst 0,,$(2)),$(call recur,$(1),$(call decr,$(2)),$(call $(1)$(2),$(3))),$(3))
     75 _req2dir1=$(subst >,gt,$(1))
     76 _req2dir2=$(subst <,lt,$(1))
     77 _req2dir3=$(subst >=,geq,$(1))
     78 _req2dir4=$(subst <=,leq,$(1))
     79 _req2dir5=$(subst ://,:::,$(1))
     80 _req2dir6=$(subst *,_,$(1))
     81 _req2dir7=$(subst ?,_,$(1))
     82 req2dir=$(call recur,_req2dir,7,$(1))
     83 
     84 # --ignore-installed, it may happen that host pip will ignore target install if
     85 #  it was already installed as host module, e.g. cffi deps of cryptograph
     86 HOST_PYTHON_PIP_INSTALL=$(HOST_PYTHON_PIP) install \
     87 	--root=$(1) \
     88 	--prefix=$(2) \
     89 	--ignore-installed \
     90 	--no-compile \
     91 	$(if $(CONFIG_PACKAGE_python-packages-index-url), --index-url $(CONFIG_PACKAGE_python-packages-index-url)) \
     92 	$(if $(CONFIG_PACKAGE_python-packages-pip-opts), $(CONFIG_PACKAGE_python-packages-pip-opts)) \
     93 
     94 HOST_PYTHON_PIP_INSTALL_HOST:=$(call HOST_PYTHON_PIP_INSTALL,$(STAGING_DIR_HOSTPKG),"")
     95 HOST_PYTHON_PIP_INSTALL_TARGET=$(call HOST_PYTHON_PIP_INSTALL,$(PKG_INSTALL_DIR)/$(call req2dir,$(pkg)),/usr)
     96 HOST_PYTHON_PIP_INSTALL_CLEANUP:=$(call HOST_PYTHON_PIP_INSTALL,$(PKG_INSTALL_DIR)/_cleanup,/usr)
     97 
     98 define Build/Compile
     99 	$(foreach pkg,$(CONFIG_PACKAGE_python-packages-list-host),
    100 		$(call Build/Compile/HostPyRunHost,,$(HOST_PYTHON_PIP_INSTALL_HOST) $(pkg))
    101 	)
    102 	$(foreach pkg,$(CONFIG_PACKAGE_python-packages-list),
    103 		$(call Build/Compile/HostPyRunTarget,,$(call HOST_PYTHON_PIP_INSTALL_TARGET,$(pkg)) $(pkg),$(CONFIG_PACKAGE_python-packages-envs))
    104 	)
    105 	$(foreach pkg,$(CONFIG_PACKAGE_python-packages-list-cleanup),
    106 		$(call Build/Compile/HostPyRunTarget,,$(HOST_PYTHON_PIP_INSTALL_CLEANUP) $(pkg),$(CONFIG_PACKAGE_python-packages-envs))
    107 	)
    108 endef
    109 
    110 define Package/python-packages/install
    111 	$(foreach pkg,$(CONFIG_PACKAGE_python-packages-list),
    112 		$(CP) "$(PKG_INSTALL_DIR)/$(call req2dir,$(pkg))"/* $(1)
    113 	)
    114 
    115 	find "$(PKG_INSTALL_DIR)/_cleanup" -mindepth 1 -depth | while read sf; do \
    116 		tf="$$$${sf#$(PKG_INSTALL_DIR)/_cleanup/}"; \
    117 		tf="$(1)/$$$$tf"; \
    118 		if [ -f "$$$$tf" -o -L "$$$$tf" ]; then \
    119 			rm -vf "$$$$tf"; \
    120 		elif [ -d "$$$$tf" ]; then \
    121 			rmdir -v -p "$$$$tf" || true; \
    122 		fi \
    123 	done
    124 endef
    125 
    126 define Package/python-packages/extra_provides
    127 	echo $(CONFIG_PACKAGE_python-packages-extra-deps) | tr ' ' '\n'
    128 endef
    129 
    130 $(eval $(call BuildPackage,python-packages))