User Tools

Site Tools


Sidebar

Launch of Linino.org

wiki:nodejsbuild

Foreword

All of the credit for this guide goes to Fiore Basile. I took his work as basis and perfected it since I noticed some flaws when writing the scripts for my own node toolchain.

Starting from now we'll create a working directory named CROSS_MIPS in our home folder and from there we'll perform all the build operations.

Please also keep in mind that the shell command pwd returns the current directory you're browsing at the very moment. So, we can use it to define a enviroment variable such as BASEDIR this way :

export BASEDIR=$(pwd)

we'll often use the command during this guide. In addition to this, create a directory named CROSS_MIPS in your home directory where you'll perform all the needed operations :

$ mkdir ~/CROSS_MIPS

Building the Linino toolchain under Debian or Ubuntu

1) Install the following prerequisites from shell with :

#!/bin/bash
 
sudo apt-get install python sed wget cvs subversion git-core coreutils unzip texi2html texinfo docbook-utils \
    gawk python-pysqlite2 diffstat help2man make gcc build-essential g++ desktop-file-utils chrpath \
    flex libncurses5 libncurses5-dev zlib1g-dev pkg-config gettext libxml-simple-perl guile-1.8 cmake \
    libssl-dev xsltproc fastjar mercurial pngcrush imagemagick tcl binutils bzip2 perl grep diffutils \
    openjdk-7-jdk zlib1g zlib1g-dbg zlib1g-dev zlib-bin zlibc zlib-gst ccache distcc gcc-multilib g++-multilib bin86

2) Browse into the CROSS_MIPS directory :

$ cd ~/CROSS_MIPS

3) Then checkout inside it the master branch of the linino_distro repository on github :

$ git clone https://github.com/linino/linino_distro.git -b master

then browse into the linino_distro directory and type the following commands :

$ ./script/feeds update -a
$ ./script/feeds install -a
$ make menuconfig

Once the main configuration menu appears, mark Build the OpenWrt SDK and Build the OpenWrt based Toolchain by pressing the space bar :

then select Exit and you will be asked to save your configuration :

now you're ready to begin the building from source. Just type from shell :

$ make V=s -jX

where X is the number of jobs you want to assign to the process and…….enjoy a mug of coffee :D. At the end of the process you will find the two tar.gz compressed packages in the

linino_distro/bin/ar71xx

directory of the linino_distro repository itself.

The easy way : Download the compiled Linino toolchain and the OpenWrt SDK

If you don't want your own build of the Linino SDK or toolchain, just point your browser at :

http://download.linino.org/linino-utils/

and download them. Please also note that we provide only the x86_64 binaries of the Linino SDK since we are taking for granted that you're working with a 64-bit setup on your machine.

Building the V8 Libraries for MIPS "Big Endian" Architecture

1) Browse into your ~/CROSS_MIPS folder and checkout inside it this patched v8 branch :

$ git clone https://github.com/paul99/v8m-rb.git -b dm-mipsbe-3.14

2) Create the v8 build script, I called it build_v8_mipsbe.sh

#!/bin/bash
 
export BASEDIR=$(pwd)
 
export STAGING_DIR=${BASEDIR}/linino_distro/staging_dir
 
export PREFIX=${STAGING_DIR}/toolchain-mips_r2_gcc-4.6-linaro_uClibc-0.9.33.2/bin/mips-openwrt-linux-
 
cd v8m-rb/
make dependencies
 
# MIPS cross-compile exports
export CC=${PREFIX}gcc
export CXX=${PREFIX}g++
export AR=${PREFIX}ar
export RANLIB=${PREFIX}ranlib
export LINK=${PREFIX}g++
export CPP="${PREFIX}gcc -E"
export STRIP=${PREFIX}strip
export OBJCOPY=${PREFIX}objcopy
export LD=${PREFIX}g++
export OBJDUMP=${PREFIX}objdump
export NM=${PREFIX}nm
export AS=${PREFIX}as
export PS1="[${PREFIX}] \w$ "
 
export LIBPATH=${STAGING_DIR}/toolchain-mips_r2_gcc-4.6-linaro_uClibc-0.9.33.2/lib/
 
export LDFLAGS='-Wl,-rpath-link '${LIBPATH}
 
export GYPFLAGS="-Dv8_use_mips_abi_hardfloat=false -Dv8_can_use_fpu_instructions=false"
 
# build the version for compiling node
make mips.release werror=no library=shared snapshot=off -j4

3) Make it executable and run it:

$ chmod +x build_v8_mipsbe.sh && ./build_v8_mipsbe.sh

Build Node.js for MIPS "Big Endian" Architecture

1) Now go on and download node-v0.10.25 source code. Uncompress it to ~/CROSS_MIPS :

$ tar xvf node-v0.10.25.tar.gz -c ~/CROSS_MIPS

and rename the source directory to :

$ mv node-v0.10.25/ node-v0.10.25-mips/

then create the target installation directory :

$ mkdir ~/CROSS_MIPS/nodeone && mkdir ~/CROSS_MIPS/nodeone/opt

2) Create a new script in the same folder named build_node_mipsbe.sh :

#!/bin/bash
 
cd node-v0.10.25-mips/
 
export BASEDIR=$(pwd)
export STAGING_DIR=${BASEDIR}/linino_distro/staging_dir
 
export V8SOURCE=${BASEDIR}/v8m-rb
 
export PREFIX=${STAGING_DIR}/toolchain-mips_r2_gcc-4.6-linaro_uClibc-0.9.33.2/bin/mips-openwrt-linux-
 
export LIBPATH=${STAGING_DIR}/toolchain-mips_r2_gcc-4.6-linaro_uClibc-0.9.33.2/lib/
 
# MIPS cross-compile exports
export CC=${PREFIX}gcc
export CXX=${PREFIX}g++
export AR=${PREFIX}ar
export RANLIB=${PREFIX}ranlib
export LINK=${PREFIX}g++
export CPP="${PREFIX}gcc -E"
export STRIP=${PREFIX}strip
export OBJCOPY=${PREFIX}objcopy
export LD=${PREFIX}g++
export OBJDUMP=${PREFIX}objdump
export NM=${PREFIX}nm
export AS=${PREFIX}as
export PS1="[${PREFIX}] \w$ "
export LDFLAGS='-Wl,-rpath-link '${LIBPATH}
 
export TARGET_PATH=${BASEDIR}/nodeone/opt
 
export GYPFLAGS="-Dv8_use_mips_abi_hardfloat=false -Dv8_can_use_fpu_instructions=false"
 
make clean
make distclean
 
./configure --prefix=${TARGET_PATH} --dest-cpu=mips --dest-os=linux --without-snapshot --shared-v8 --shared-v8-includes=${V8SOURCE}/include/ --shared-v8-libpath=${V8SOURCE}/out/mips.release/lib.target/ --with-mips-float-abi=soft
 
make snapshot=off -j4
 
make install

3) Make it executable and run it from your working directory (i.e. ~/CROSS_MIPS) :

$ chmod +x build_node_mipsbe.sh && ./build_node_mipsbe.sh

4) Now you have both libv8 and node and you're ready to copy them to the ONE sdcard (both are around 8mb) but before doing it, perform these last two steps :

$ cp ~/CROSS_MIPS/v8m-rb/out/mips.release/lib.target/libv8.so ~/CROSS_MIPS/nodeone/opt/lib

and :

$ cp ~/CROSS_MIPS/linino_distro/staging_dir/toolchain-mips_r2_gcc-4.6-linaro_uClibc-0.9.33.2/lib/libstdc++.so.6 ~/CROSS_MIPS/nodeone/opt/lib/

5) Copy via SSH the nodeone folder to the ONE :

$ scp -r ~/CROSS_MIPS/nodeone root@arduino.local:/mnt/sda1

6) Now login with SSH into the ONE and make some symlinks from your /mnt/sda1/nodeone/opt to the system's root directories :

ln -sf /mnt/sda1/nodeyun/opt/bin/node /usr/bin/node
ln -sf /mnt/sda1/nodeyun/opt/bin/npm /usr/bin/npm
ln -sf /mnt/sda1/nodeyun/opt/lib/libv8.so /usr/lib/libv8.so
ln -sf /mnt/sda1/nodeyun/opt/lib/libstdc++.so.6 /usr/lib/libstdc++.so.6

7) Node is now ready, try it!

root@Arduino:~# node -v
v0.10.25

8) YUN has limited memory so we strongly advise you to optimize node for it with the following CLI parameters :

node --stack_size=1024 --max_old_space_size=20 --max_new_space_size=2048 --max_executable_size=5 --gc_global --gc_interval=100

PS : The whole process has successfully been tested until Node.js v0.10.28 so far.

/var/www/wiki.linino.org/data/pages/wiki/nodejsbuild.txt · Last modified: 2014/09/22 05:35 by arturo

2014 © dog hunter llc and the Linino Community. Linino.org is a dog hunter sponsored community project. Credits