OpenWrt package method

From WRTnode Wiki Site
Jump to: navigation, search
This page contains changes which are not marked for translation.

Other languages:
English 100% • ‎中文(中国大陆)‎ 100%

To make a ipk package opencv

opencv ipk源码

Use openwrt package compilation mechanism requires only a Makefile to compile opencv

Why is it so simple magic, the following Detailed on Makefile (personal opinion, please correct me):

$vim Makefile
include $(TOPDIR)/rules.mk 
PKG_NAME:=opencv
# PKG_NAME - package name in menuconfig and ipkg displayPKG_VERSION:=2.4.8
# PKG_VERSION - version of the package, version trunk branch is exactly what we want to download
PKG_RELEASE:=1 
# PKG_RELEASE - This version of the makefilePKG_USE_MIPS16:=0 
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).zip
# PKG_SOURCE - to download the package name, is generally composed by PKG_NAME and PKG_VERSION
PKG_SOURCE_URL:=http://downloads.sourceforge.net/project/opencvlibrary/opencv-unix/2.4.8/
# PKG_SOURCE_URL - link to download this package, obtained from the Internet
PKG_MD5SUM:=50cc1433b3654074206f5b3dbfd49848
##################################################
MD5 value, check the value of the package, get the value of the MD5 method
#$ ./scripts/update-package-md5sum ....../opencv/
#PKG_CAT:= unzip#PKG_CAT - Unzip the package method (zcat, bzcat, unzip)
##################################################
include $(INCLUDE_DIR)/package.mk 
include $(INCLUDE_DIR)/cmake.mk 
define Package/opencv/Default/description 
    the Open Source Computer Vision Library for linux 
endef 
define Package/opencv 
    SECTION:=libs 
    CATEGORY:=Libraries 
    TITLE:= opencv-2.4.8 
    DEPENDS:=+libpthread +librt +libstdcpp +zlib +libjpeg 
endef
##################################################
#SECTION -- Package Type 
#CATEGORY -- menuconfig in the package belongs to a directory, such as Libraries 
# SUBMENU -- secondary directory menuconfig in the package belongs (not used) 
#TITLE -- software title 
#DESCRIPTION -- Packages details 
#URL -- software original location, usually the software author's homepage 
#MAINTAINER -- (optional) package maintainers
#DEPENDS -- other packages (optional) dependencies, run the software dependencies
##################################################
PKG_INSTALL:=1 
CMAKE_OPTIONS += -DWITH_LIBV4L:BOOL=OFF -DBUILD_opencv_ts:BOOL=OFF
#################################################
#CMAKE_OPTIONS 
#For example do not want to compile libv4l library, ts, etc., choose OFF.
#################################################
define Build/InstallDev 
    $(INSTALL_DIR) $(1)/usr/include 
    $(CP) $(PKG_INSTALL_DIR)/usr/include/opencv $(1)/usr/include/ 
    $(CP) $(PKG_INSTALL_DIR)/usr/include/opencv2 $(1)/usr/include/ 
    $(INSTALL_DIR) $(1)/usr/lib 
    $(CP) $(PKG_INSTALL_DIR)/usr/lib/libopencv* $(1)/usr/lib/ 
endef 
#################################################
# define Build/InstallDev 
#The generated header files and libraries into   ./staging_dir/target- mipsel_24kec+dsp_uClibc-0.9.33.2/usr/include and ./staging_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/usr/lib 
#PKG_INSTALL_DIR  ./trunk/build_dir/target-mipsel_24kec+dsp_uClibc- 0.9.33.2/opencv-2.4.8/ipkg-install 
#################################################
define Package/opencv/install 
    $(INSTALL_DIR) $(1)/usr/include 
    $(CP) $(PKG_INSTALL_DIR)/usr/include/* $(1)/usr/include/ 
    $(INSTALL_DIR) $(1)/usr/lib 
    $(CP) $(PKG_INSTALL_DIR)/usr/lib/libopencv* $(1)/usr/lib/ 
endef 
$(eval $(call BuildPackage,opencv))
#################################################
#This is the most critical BuildPackage macros. It is in the  $(INCLUDE_DIR)/package.mk defined in the file. BuildPackage macro requires only  one parameter, namely to compile the package name, in this case, the “opencv”. All other information from macro to obtain, which provides an inherent simplicity. Such as BuildPackage need to pack a bunch of DESCRIPTION, we don't want to pass the parameters of the long, because we have agreed to describe information defined in the DESCRIPTION of macros, BuildPackage reads from the inside.
# the Build/Compile (optional)
#Compile the source code.
#Package/install
#Software installation command, mainly is the related documents copy to the  specified directory, such as the configuration file.
#################################################

The compilation of opencv test program

opencv-test ipk源码

Here we also established a opencv-test ipk to test opencv libs, this process is similar to the helloworld ipk.

Test procedures to achieve function is to read images from a camera, stored in the current directory. Since storage space is limited, save six pictures here.

Here is generated Makefile opencv-test ipk package needed, its methods and compile method to compile any other ipk package exactly the same.

$vim Makefile
include $(TOPDIR)/rules.mk
PKG_NAME:=opencv-test
PKG_RELEASE:=1
PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)
PKG_INSTALL_DIR:=$(PKG_BUILD_DIR)/ipkg-install
include $(INCLUDE_DIR)/kernel.mk
include $(INCLUDE_DIR)/package.mk
define Package/opencv-test
  SECTION:=wrtnode
  CATEGORY:=WRTnode
  SUBMENU :=demos
  TITLE:=opencv demo app
  DEPENDS := +opencv
endef
#################################################
#DEPENDS := +opencv --depend on opencv lib
#################################################
define Package/opencv-test/description
    WRTnode test program for opencv lib
endef
define Build/Prepare
    mkdir -p $(PKG_BUILD_DIR)
    $(CP) ./src/* $(PKG_BUILD_DIR)/
endef
define Build/Compile
    $(MAKE) -C $(PKG_BUILD_DIR) \
    $(TARGET_CONFIGURE_OPTS) CFLAGS="$(TARGET_CFLAGS)" \
                               LDFLAGS="$(TARGET_LDFLAGS)"
endef
#################################################
#$ (TARGET_CONFIGURE_OPTS), $ (TARGET_CFLAGS), $ (TARGET_LDFLAGS) and other defined rules.mk 
#################################################
define Package/opencv-test/install
    $(INSTALL_DIR) $(1)/usr/bin
    $(INSTALL_BIN) $(PKG_BUILD_DIR)/cv_test $(1)/usr/bin/
endef
#################################################
#cv_test --Compiled executable file
#################################################
$(eval $(call BuildPackage,opencv-test))

opencv-test source code and Makefile in the src directory, interested students can further study.

Note: opencv application can be considered almost a cross-platform, we can develop the following in windows or Mac x86, and will work with the graphics window display and keyboard input, etc. after OpenWrt not support code removed, to ensure the smooth compiled on WRTnode adoption and implementation.