同样在openwrt目录下,执行
勾选bulid the openwrt sdk,退出并保存
编译完成后,在bin/ramips下出现一个OpenWrt-SDK-ramips-mt7620_gcc-4.8-linaro_uClibc-0.9.33.2.Linux-x86_64.tar.bz2,这就是我们需要的SDK包
解压SDK,并进入package目录
- tar -jxvf OpenWrt-SDK-ramips-mt7620_gcc-4.8-linaro_uClibc-0.9.33.2.Linux-x86_64.tar.bz2
然后建立如下目录树
- .
- ├── helloworld
- │ ├── Makefile
- │ └── src
- │ ├── helloworld.c
- │ └── Makefile
- └── Makefile
编写helloworld.c
- #include <stdio.h>
- #include <unistd.h>
-
- int main(void)
- {
- printf("Hello World!\n");
- return 0;
- }
编写src/Makefile
- #build a Makefile for hellowrold.c
- helloworld: helloworld.o
- $(CC) $(LDFLAGS) helloworld.o -o helloworld
- helloworld.o: helloworld.c
- $(CC) $(CFLAGS) -c helloworld.c
- clean:
- rm *.o helloworld
编写helloworld/Makefile
- include $(TOPDIR)/rules.mk
-
- PKG_NAME:=helloworld
- PKG_RELEASE:=1
-
- PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)
-
- include $(INCLUDE_DIR)/package.mk
-
- define Package/helloworld
- SECTION:=utils
- CATEGORY:=Utilities
- TITLE:=Helloworld -- prints a snarky message
- endef
-
- define Package/helloworld/description
- It's my first package demo.
- endef
-
- define Build/Prepare
- echo "Here is Package/Prepare"
- mkdir -p $(PKG_BUILD_DIR)
- $(CP) ./src/* $(PKG_BUILD_DIR)/
- endef
-
- define Package/helloworld/install
- echo "Here is Package/install"
- $(INSTALL_DIR) $(1)/bin
- $(INSTALL_BIN) $(PKG_BUILD_DIR)/helloworld $(1)/bin/
- endef
-
- $(eval $(call BuildPackage,helloworld))
回到sdk目录,
ipk包会放在
/bin目录下- └── ramips
- └── packages
- ├── base
- │ ├── helloworld_1_ramips_24kec.ipk
- │ ├── Packages
- │ └── Packages.gz
- ├── luci
- │ ├── Packages
- │ └── Packages.gz
- ├── management
- │ ├── Packages
- │ └── Packages.gz
- ├── packages
- │ ├── Packages
- │ └── Packages.gz
- ├── routing
- │ ├── Packages
- │ └── Packages.gz
- └── telephony
- ├── Packages
- └── Packages.gz
上newifi测试:- cd tmp/
- wget ftp://ll@192.168.1.216/linux_workspace/helloworld_1_ramips_24kec.ipk
- opkg install ./helloworld_1_ramips_24kec.ipk
-
- helloworld
Hello World!
本帖最后由 le062 于 2015-10-1 10:40 编辑