歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> OpenWrt下交叉編譯Node.js(HG255D)

OpenWrt下交叉編譯Node.js(HG255D)

日期:2017/3/1 9:43:35   编辑:Linux編程

操作系統: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

按照下圖選擇對應的項目

Qtopia運行在OpenWRT上的相關說明 http://www.linuxidc.com/Linux/2013-07/87624.htm

基於Tiny210v2編譯OpenWrt http://www.linuxidc.com/Linux/2013-07/87621.htm

Node.Js入門[PDF+相關代碼] http://www.linuxidc.com/Linux/2013-06/85462.htm

Node.js入門開發指南中文版 http://www.linuxidc.com/Linux/2012-11/73363.htm

Node.js安裝與配置 http://www.linuxidc.com/Linux/2013-05/84836.htm

Ubuntu 編譯安裝Node.js http://www.linuxidc.com/Linux/2013-10/91321.htm

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

懶得自己編譯的同學,可以到我的網盤下載

http://pan.baidu.com/s/1eQ1Pkdk

拷貝到路由器,先安裝uclibcxx_0.2.4-1_ramips_24kec.ipk庫,再安裝node_v0.10.28-2_ramips_24kec.ipk,安裝node的時候要耐心等待,我第一次安裝的時候等了一會沒有響應,以為編譯失敗了,終止了安裝進程,因此而耗費了很多時間。

Node.js 的詳細介紹:請點這裡
Node.js 的下載地址:請點這裡

Copyright © Linux教程網 All Rights Reserved