I've compiled the openwrt source and run it on my device (HC5661).Then I wrote a helloword.cpp (an example, any other name) using Eclipse IDE,helloword.bin was successfully generated by compilation and debugged on the target device using sftp and gdb.Now I want to compile helloword into an ipk package. What can I do to package bin files into ipk packages?
You have to use the SDK
. You can follow this steps:
1) Download the OpenWrt-SDK
2) In the OpenWrt-SDK
folder run ./scripts/feeds/update -a && ./scripts/feeds/install -a
3) Create a folder called helloworld
in the path OpenWrt-SDK/feeds/packages/utils/
4) Inside this folder create a file called Makefile
and new folder called src
.
5) Inside the src
folder put your helloworld.cpp
and the Makefile
which allows to compile it.
6) Your Makefile
in the folder OpenWrt-SDK/scripts/feeds/packages/utils/
should look like the following:
include $(TOPDIR)/rules.mk
# Name and release number of this package
PKG_NAME:=helloworld
PKG_VERSION:=1.0
PKG_RELEASE:=0
# This specifies the directory where we're going to build the program.
# The root build directory, $(BUILD_DIR), is by default the build_mipsel
# directory in your OpenWrt SDK directory
PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)
include $(INCLUDE_DIR)/uclibc++.mk
include $(INCLUDE_DIR)/package.mk
# Specify package information for this program.
# The variables defined here should be self explanatory.
define Package/helloworld
SECTION:=utils
CATEGORY:=Utilities
TITLE:=helloworld exampke
endef
define Build/Prepare
mkdir -p $(PKG_BUILD_DIR)
$(CP) ./src/* $(PKG_BUILD_DIR)/
endef
TARGET_CFLAGS += \
-I$(STAGING_DIR)/usr/include \
-D_GNU_SOURCE \
-ggdb3
MAKE_FLAGS += \
CFLAGS="$(TARGET_CFLAGS)" \
LDFLAGS="$(TARGET_LDFLAGS)"
define Build/Compile
$(call Build/Compile/Default, \
CCOPTS="$(TARGET_CFLAGS)" \
INCLUDE="$(EXTRA_CFLAGS)" \
LDFLAGS="$(EXTRA_LDFLAGS)" \
)
endef
define Package/helloworld/install
$(INSTALL_DIR) $(1)/bin
$(CP) $(PKG_BUILD_DIR)/$(PKG_NAME) $(1)/bin/
endef
# This line executes the necessary commands to compile our program.
# The above define directives specify all the information needed, but this
# line calls BuildPackage which in turn actually uses this information to
# build a package.
$(eval $(call BuildPackage,helloworld))
7) In the OpenWrt-SDK
folder run ./scripts/feeds update -i && ./scripts/feeds install helloworld
8) In the same folder run make package/helloworld/compile
9) You can find your .ipk
package in OpenWrt-SDK/bin/ar71xx/packages/packages/
PS: You may have to install ccache
by typing (Ubuntu) sudo apt-get install ccache
. You must not type your makefiles using spaces, you must use tabulator.