Skip to content

Instantly share code, notes, and snippets.

@andrewjjenkins
Last active August 10, 2021 15:32
Show Gist options
  • Save andrewjjenkins/3829d8e8486d61f49ba8 to your computer and use it in GitHub Desktop.
Save andrewjjenkins/3829d8e8486d61f49ba8 to your computer and use it in GitHub Desktop.
Cross-compile node.js for Raspberry Pi
#!/usr/bin/env bash
# Based on https://github.com/needforspeed/Nodejs-ARM-builder/blob/master/cross-compiler.sh
# but updated to use the cross-compiling tools that Raspberry Pi recommends for the kernel.
# Only works for ARMv6.
# AJJ: Released into the public domain.
set -e
PRODUCT="iojs"
PRODUCTWEB="http://iojs.org"
VERSION="1.5.1"
XCPATH="${HOME}/rpi/xc/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin"
GCCARCH="arm-linux-gnueabihf"
DEBARCH="armhf"
toolsarch=`$XCPATH/$GCCARCH-gcc -dumpmachine`
if [ "$toolsarch" != "$GCCARCH" ]; then
echo \"When asked for their arch, cross-compiling tools said, "$toolsarch", not "$GCCARCH"\"
exit 1
fi
fpm=`fpm -h`
if [ $? != 0 ]; then
echo "You need fpm. Try:"
echo " sudo apt-get install ruby-dev build-essential"
echo " sudo gem install fpm"
exit 1
fi
export PATH="$XCPATH:$PATH"
export CC="${GCCARCH}-gcc"
export CXX="${GCCARCH}-g++"
export AR="${GCCARCH}-ar"
export RANLIB="${GCCARCH}-ranlib"
export LINK="${GCCARCH}-g++"
export CCFLAGS="-march=armv6j -mfpu=vfp -mfloat-abi=hard -DUSE_EABI_HARDFLOAT"
export OPENSSL_armcap=6
export GYPFLAGS="-Darmeabi=hard -Dv8_use_arm_eabi_hardfloat=true -Dv8_can_use_vfp3_instructions=false -Dv8_can_use_vfp2_instructions=true -Darm7=0 -Darm_vfp=vfp"
export VFP3=off
export VFP2=on
PREFIX_DIR="/usr"
BUILD_DIR="${PRODUCT}-v${VERSION}"
pushd $BUILD_DIR
./configure --without-snapshot --dest-cpu=arm --dest-os=linux --prefix="${PREFIX_DIR}"
make -j8
tempdir=$(mktemp -d)
trap "rm -r $tempdir" EXIT
make install DESTDIR=$tempdir
fpm -s dir -t deb -n ${PRODUCT} -v "$VERSION" --category "web" -m "Andrew Jenkins <[email protected]>" \
--url ${PRODUCTWEB} \
--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." \
-C $tempdir -a $DEBARCH -p ../${PRODUCT}_${VERSION}-armv6_${DEBARCH}.deb ${PREFIX_DIR:1}
popd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment