Skip to content

Cross Compile Nodejs for OpenWrt

Dan edited this page Jun 12, 2018 · 6 revisions

How to cross compile Nodejs for OpenWRT

In this guide, we will explain how to compile Nodejs for any cpu-architecture supported.

We will use the OpenWRT Toolchain/RPI Toolchain. Before continuing, I recommend reading this useful guide where that tool is introduced.


## Prerequisites

Option 1: You should have downloaded and compiled the OpenWRT Toolchain according to your cpu-architecture.

Option 2: You should have downloaded the RPI Toolchain (only raspberry pi architectures)


## Cross-compiling

Firstly, We need to download node source files.

git clone https://github.com/nodejs/node

A folder named "node" will be created.

cd node

Now, we need to define some global variables. This is the most important step.

Option 1: OpenWRT Toolchain:

HOMEPATH="/home/username/openwrt/trunk"
#These depend on your arch. Look it up on your build folder.
ARCH="mips-openwrt-linux-uclibc"
TARCH="mips_34kc_gcc-4.8-linaro_uClibc-0.9.33.2"

export AR=${HOMEPATH}/staging_dir/toolchain-${TARCH}/bin/${ARCH}-ar
export CC=${HOMEPATH}/staging_dir/toolchain-${TARCH}/bin/${ARCH}-gcc
export CXX=${HOMEPATH}/staging_dir/toolchain-${TARCH}/bin/${ARCH}-g++
export LINK=${HOMEPATH}/staging_dir/toolchain-${TARCH}/bin/${ARCH}-g++
export RANLIB=${HOMEPATH}/staging_dir/toolchain-${TARCH}/bin/${ARCH}-ranlib
export STAGING_DIR=${HOMEPATH}/staging_dir
export LIBPATH=${HOMEPATH}/staging_dir/toolchain-${TARCH}/lib
export LDFLAGS='-Wl,-rpath-link '${LIBPATH}

Option 2: RPI Toolchain

export AR=tools/arm-bcm2708/gcc-linaro-arm-linux-gnuebihf-raspbian/bin/arm-linux-gnueabihf-ar
export CC =tools/arm-bcm2708/gcc-linaro-arm-linux-gnuebihf-raspbian/bin/arm-linux-gnueabihf-gcc
export CXX =tools/arm-bcm2708/gcc-linaro-arm-linux-gnuebihf-raspbian/bin/arm-linux-gnueabihf-g++
export LINK =tools/arm-bcm2708/gcc-linaro-arm-linux-gnuebihf-raspbian/bin/arm-linux-gnueabihf-g++
### Configuration file

Option 1: OpenWRT Toolchain:

./configure --without-snapshot --without-npm 

Option 2: RPI Toolchain

./configure --without-snapshot --without-npm --dest-cpu=YOUR_ARCHITECTURE --dest-os=YOUR_OPERATIVE_SYSTEM --fully-static
  • Compile
make
  • If all went fine, you will get your compiled version of nodejs in node/out/Release/node
## Testing

Copy node file to your OpenWRT device and execute

./node
console.log("Hello Netbeast World")

You will see "Hello Netbeast World" on the terminal.

You have cross compiled NodeJS successfully.

Clone this wiki locally