说明
几年前想编译一个helloworld.ipk,由于以下原因当年尝试失败了
当年太水(现在还是很湿)
学校网络太操蛋(ubuntu下借脚本连闪讯,时断时序,编译个固件要纯手工6+H,想想都是泪)
太jb费时间(一个helloworld整了几天没整出来,灰心了)
1. 下载openwrt trunk代码
svn co svn://svn.openwrt.org/openwrt/trunk/
2. 编译openwrt brcm63xx固件,注意勾上sdk
make menuconfig
make V=99
3. 使用brcm63xx平台sdk编译ipk
解压 sdk bin/OpenWrt-SDK-xxx.tar.bz2
tar xvf OpenWrt-SDK-xxx.tar.bz2
在package路径下建立helloworld工程
package
├── helloworld
│ ├── Makefile
│ └── src
│ ├── helloworld.c
│ └── Makefile
└── Makefile
建立staging_dir链接(交叉编译工具)
cd sdk
ln -s ../trunk/staging_dir ./staging_dir
编译
make distclean
make menuconfig
make V=99
bin
├── brcm63xx
│ └── packages
│ ├── helloworld_1.0-1_brcm63xx.ipk
│ ├── Packages
│ └── Packages.gz
└── packages
代码
package/helloworld/Makefile
include $(TOPDIR)/rules.mk
include $(INCLUDE_DIR)/package.mk
PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)
PKG_NAME:=helloworld
# Version: 1.0-1
PKG_VERSION:=1.0
PKG_RELEASE:=1
PKG_MAINTAINER:=JPH
# PKG_SOURCE_URL:=
define Package/helloworld
SECTION:=utils
CATEGORY:=Utilities
DEFAULT:=y
TITLE:=Helloworld -- prints a snarky message
# DEPENDS:=+libmath
endef
define Build/Prepare
@echo "############## Build/Prepare"
$(Build/Prepare/Default)
$(CP) ./src/* $(PKG_BUILD_DIR)
endef
define Package/helloworld/install
@echo "############## Package/helloworld/install"
$(INSTALL_DIR) $(1)/usr/bin
$(INSTALL_BIN) $(PKG_BUILD_DIR)/helloworld $(1)/usr/bin
endef
$(eval $(call BuildPackage,helloworld))
package/helloworld/src/helloworld.c
#include
int main(int argc, const char *argv[])
{
printf("hello world! \n");
return 0;
}
package/helloworld/src/Makefile
helloworld: helloworld.o
$(CC) helloworld.o -o helloworld
helloworld.o: helloworld.c
$(CC) -c helloworld.c
clean:
rm *.o helloworld