Search code examples
pythonmakefileembedded-linuxopenwrt

Install a python module from OpenWrt makefile


I need to write an openWrt Makefile which installs a module into python, using setuptools, i.e. calls: python setup.py install

I have setup.py file in my package.

Failed to find the answer in OpenWrt package build referrence

I hope there's some infra structure for setuptools in OpenWrt? I suppose I have to include some .mk file $(call include_mk, python-package.mk)?

and then call some target from it?

Will appreciate any sample Makefile/manual


Solution

  • Are you talking about your own private python module or a publicly available one? Here's an example Makefile for the 'idna' library, which I use.

    include $(TOPDIR)/rules.mk
    
    PKG_NAME:=idna
    PKG_VERSION:=2.6
    PKG_RELEASE:=1
    PKG_SOURCE:=idna-2.6.tar.gz
    PKG_SOURCE_URL:=https://pypi.python.org/packages/f4/bd/0467d62790828c23c47fc1dfa1b1f052b24efdf5290f071c7a91d0d82fd3/
    PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION)/
    
    #PKG_BUILD_DEPENDS:=python-setuptools 
    
    include $(INCLUDE_DIR)/package.mk
    $(call include_mk, python-package.mk)
    
    define Package/idna
        SECTION:=lang-python
        CATEGORY:=Languages
        SUBMENU:=Python
        TITLE:=idna
        URL:=https://pypi.python.org/pypi/idna
        DEPENDS:=+python
    endef
    
    define Package/idna/description
        Internationalized Domain Names in Applications (IDNA)
    endef
    
    define Build/Compile
        $(call Build/Compile/PyMod,., \
            install --prefix="/usr" --root="$(PKG_INSTALL_DIR)" \
        )
    endef
    
    define Build/InstallDev
        $(INSTALL_DIR) $(STAGING_DIR)$(PYTHON_PKG_DIR)
        $(CP) \
            $(PKG_INSTALL_DIR)$(PYTHON_PKG_DIR)/* \
            $(STAGING_DIR)$(PYTHON_PKG_DIR)/
        [ ! -e $(PKG_INSTALL_DIR)/usr/include ] || $(CP) \
            $(PKG_INSTALL_DIR)/usr/include/* \
            $(STAGING_DIR)/usr/include/
    endef
    
    define Package/idna/install
        $(INSTALL_DIR) $(1)$(PYTHON_PKG_DIR)/
        $(CP) \
            $(PKG_INSTALL_DIR)$(PYTHON_PKG_DIR)/* \
            $(1)$(PYTHON_PKG_DIR)/
    endef
    
    $(eval $(call BuildPackage,idna))
    

    If you have your own package/source, then host it somewhere like gitlab and use that as your source url etc... something like this..

    PKG_NAME:=myPackage
    PKG_VERSION:=1.0
    PKG_RELEASE=$(PKG_SOURCE_VERSION)
    
    PKG_SOURCE_PROTO:=git
    PKG_SOURCE_URL:=git@gitlab.com:yourprofile/myPackage.git
    PKG_SOURCE_SUBDIR:=$(PKG_NAME)-$(PKG_VERSION)
    PKG_SOURCE_VERSION:=d65acd7649939505ebedd445f301c46b52616532
    PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION)-$(PKG_SOURCE_VERSION).tar.gz