操作系统:deepin linux 2013 或 ubuntu 13.04
1、安装交叉编译前。须要安装的包
sudo apt-get install build-essential subversion git-core libncurses5-dev zlib1g-dev gawk flex quilt xsltproc
2、下载OpenWrt的源码
git clone git://git.openwrt.org/openwrt.git cd openwrt ./scripts/feeds update -a ./scripts/feeds install -a make defconfig make prereq make menuconfig
依照下图选择相应的项目
3.关键的一步
cd package mkdir node sudo gedit Makefile
# # Copyright (C) 2006-2011 OpenWrt.org # # This is free software, licensed under the GNU General Public License v2. # See /LICENSE for more information. # include $(TOPDIR)/rules.mk PKG_NAME:=node #眼下最新版本号 PKG_VERSION:=v0.10.28 PKG_RELEASE:=2 PKG_SOURCE:=node-$(PKG_VERSION).tar.gz PKG_SOURCE_URL:=http://nodejs.org/dist/${PKG_VERSION} #更改版本号时也要改动 PKG_MD5SUM:=87768be7065d2120e71619948ab4bb2d GYP_DEFINES:=v8_use_mips_abi_hardfloat=false v8_can_use_fpu_instructions=false LIBS:=-I$(TOOLCHAIN_DIR)/mipsel-openwrt-linux-uclibc/include/c++/4.8.3/ -I$(TOOLCHAIN_DIR)/mipsel-openwrt-linux-uclibc/include/c++/4.8.3/mipsel-openwrt-linux-uclibc/ include $(INCLUDE_DIR)/package.mk define Package/node DEPENDS:=+libpthread +librt +uclibcxx SECTION:=lang CATEGORY:=Languages TITLE:=Node.js is a platform built on Chrome's JavaScript runtime URL:=http://nodejs.org/ endef define Package/node/description Node.js is a platform built on Chrome's JavaScript runtime for easily building fast, scalable network applications. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices. endef define Build/Prepare $(call Build/Prepare/Default) $(CP) node.patch $(PKG_BUILD_DIR)/ (cd $(PKG_BUILD_DIR); patch -p1 < node.patch; ); endef define Build/Configure (cd $(PKG_BUILD_DIR); export LIBS="$(LIBS)"; export CFLAGS="$(TARGET_CFLAGS) $(LIBS)"; export CXXFLAGS="$(TARGET_CXXFLAGS) $(LIBS)"; export GYPFLAGS="$(GYPFLAGS)"; ./configure --dest-cpu=mipsel --dest-os=linux --without-ssl --without-snapshot --with-arm-float-abi=soft; ); endef define Build/Compile $(MAKE) $(PKG_JOBS) -C $(PKG_BUILD_DIR) GYP_DEFINES="$(GYP_DEFINES)" CC="$(TARGET_CC)" CXX="$(TARGET_CXX)" CFLAGS="$(TARGET_CFLAGS) $(LIBS)" CXXFLAGS="$(TARGET_CXXFLAGS) $(LIBS) -nostdinc++" LDFLAGS="$(TARGET_LDFLAGS) -nodefaultlibs -luClibc++ -lc -lgcc -lgcc_s -lpthread" || touch $(PKG_BUILD_DIR)/deps/v8/build/common.gypi $(MAKE) $(PKG_JOBS) -C $(PKG_BUILD_DIR) GYP_DEFINES="$(GYP_DEFINES)" CC="$(TARGET_CC)" CXX="$(TARGET_CXX)" CFLAGS="$(TARGET_CFLAGS) $(LIBS)" CXXFLAGS="$(TARGET_CXXFLAGS) $(LIBS) -nostdinc++" LDFLAGS="$(TARGET_LDFLAGS) -nodefaultlibs -luClibc++ -lc -lgcc -lgcc_s -lpthread" endef define Package/node/install mkdir -p $(1)/usr/bin $(CP) $(PKG_BUILD_DIR)/out/Release/node $(1)/usr/bin/ ln -s /usr/bin/node $(1)/usr/bin/nodejs endef $(eval $(call BuildPackage,node))
4.保存配置文件后编译: make V=99 (參数为输出调试信息)
5.把openwrt/bin/ramips/packages下的
node_v0.10.28-2_ramips_24kec.ipk
uclibcxx_0.2.4-1_ramips_24kec.ipk
复制到路由器,先安装uclibcxx_0.2.4-1_ramips_24kec.ipk库,再安装node_v0.10.28-2_ramips_24kec.ipk,安装node的时候要耐心等待,我第一次安装的时候等了一会没有响应。以为编译失败了,终止了安装进程。因此而耗费了非常多时间。
后记:
看到恩山WIFI论坛网友soonco的帖子把编译过程中可能遇到的问题说得非常明确,当时我也走过类似的弯路。便摘录下来作为补充
http://www.right.com.cn/forum/thread-141085-1-1.html
HG255D的CPU是Ralink RT3052。mipsel的make
要是启用ssl功能就把“–without-ssl”删掉
假设是ar71xx的u请把里面的mipsel替换成mips
假设是arm的cpu请把替换
LIBS:=-I$(TOOLCHAIN_DIR)/arm-openwrt-linux/include/c++/{gcc版本}/ -I$(TOOLCHAIN_DIR)/arm-openwrt-linux/include/c++/{gcc版本}/arm-openwrt-linux-uclibcgnueabi/
和
./configure –dest-cpu=arm –dest-os=linux –without-ssl –without-snapshot –with-arm-float-abi=soft;
以此类推
无论什么版本号的openwrt版本号里面的node make文件都是出自 https://github.com/giorrrgio/nodejs-linino
(实际上我文章中提到的make文件是出自https://github.com/brimstone/nodejs-openwrt,可是也有參考过nodejs-linino)
mips的建议用attitude adjustment分支编译,不然总出错
mipsel直接用trunk就成了
特别注意:attitude adjustment的gcc版本号是4.6.3,而trunk的gcc是4.8.3
各个版本号md5值:8b905b6013b82fb7076b02a6c881f9a6 node-v0.10.18.tar.gz
ea0be82fa626a991d140444644a08001 node-v0.10.19.tar.gz
784e7d7a8e29dfec88ddb2e72a895407 node-v0.10.20.tar.gz
774bc17875c042ac42ad2d96b9c96734 node-v0.10.21.tar.gz
1f1948de2ef50a1d8e2303a6ed6c0e45 node-v0.10.22.tar.gz
90d75d6d12890cad4ec9cdfefa5f3a3e node-v0.10.23.tar.gz
186726490c9a715cb7ee2ed37ccb5eb3 node-v0.10.24.tar.gz
153bdbf77b4473df2600b8ce123ef331 node-v0.10.25.tar.gz
15e9018dadc63a2046f61eb13dfd7bd6 node-v0.10.26.tar.gz
6a087d80ca490c16afbbeaf3ebdbb946 node-v0.10.27.tar.gz
87768be7065d2120e71619948ab4bb2d node-v0.10.28.tar.gz
e14ea9f46f9beecdf4e9423fb626c70b node-v0.10.29.tar.gz
应网友要求。提供下载地址例如以下
链接: http://pan.baidu.com/s/1dDrN78H password: taet