Skip to content

Instantly share code, notes, and snippets.

@hertzg
Last active June 17, 2021 01:54
Cross Compiling NodeJS for Raspberry PI (armv6hf)
#!/bin/bash
set -e
set -x
### IF we dont have archive url prefix
if [ -z "$_PARAMS_NODEJS_SOURCE_ARCHIVE_URL" ]; then
_PARAMS_NODEJS_SOURCE_ARCHIVE_URL=$(wget -qO- http://nodejs.org/dist/latest/ | egrep -o 'node-v[0-9\.]+.tar.gz' | tail -1);
_PARAMS_NODEJS_SOURCE_ARCHIVE_URL="http://nodejs.org/dist/latest/"$_PARAMS_NODEJS_SOURCE_ARCHIVE_URL
fi
if [ -z "$_PRAMS_RPI_TOOLS_SOURCE_ARCHIVE_URL" ]; then
_PRAMS_RPI_TOOLS_SOURCE_ARCHIVE_URL="https://github.com/raspberrypi/tools/archive/master.tar.gz"
fi;
NODEJS_SOURCE_ARCHIVE_FILENAME=$(basename $_PARAMS_NODEJS_SOURCE_ARCHIVE_URL)
NODEJS_SOURCE_DIRECTORY=${NODEJS_SOURCE_ARCHIVE_FILENAME%.tar.gz}
#Download NodeJS
echo "-> Searching for NodeJS "$NODEJS_SOURCE_ARCHIVE_FILENAME;
if [ ! -e "$PWD/$NODEJS_SOURCE_ARCHIVE_FILENAME" ]; then
echo "--> Downloading from "$_PARAMS_NODEJS_SOURCE_ARCHIVE_URL;
wget --no-check-certificate -O $NODEJS_SOURCE_ARCHIVE_FILENAME $_PARAMS_NODEJS_SOURCE_ARCHIVE_URL
echo "--> Download finished!"
fi;
echo "--> Extracting"
rm -rf $NODEJS_SOURCE_DIRECTORY
tar --overwrite -xf $NODEJS_SOURCE_ARCHIVE_FILENAME
echo "--> Linking"
ln -snf "$PWD/$NODEJS_SOURCE_DIRECTORY" "$PWD/node"
echo "-> Done!"
echo "-> Searching Raspberry Pi Toolset";
if [ ! -d "$PWD/rpi" ]; then
if [ ! -e "$PWD/rpi-tools.tar.gz" ] || [ -s "$PWD/rpi-tools.tar.gz" ]; then
echo "--> Downloading from "$_PRAMS_RPI_TOOLS_SOURCE_ARCHIVE_URL
wget --no-check-certificate -O "rpi-tools.tar.gz" $_PRAMS_RPI_TOOLS_SOURCE_ARCHIVE_URL
echo "--> Download finished"
else
echo "--> Found rpi-tools.tar.gz."
fi
echo "--> Extracting"
tar xf "rpi-tools.tar.gz"
echo "--> Linking tools-master to rpi"
ln -snf "$PWD/tools-master" "$PWD/rpi"
else
echo "-> found"
fi;
echo "-> Done!"
echo "-> Cross-Compile..."
echo "--> Setup ENV"
export PATH="$PWD/rpi/arm-bcm2708/arm-bcm2708hardfp-linux-gnueabi/bin:"$PATH
export HOST="arm-bcm2708hardfp-linux-gnueabi"
export CC="${HOST}-gcc"
export CXX="${HOST}-g++"
export AR="${HOST}-ar"
export RANLIB="${HOST}-ranlib"
export LD="${HOST}-ld"
export CPP="${HOST}-gcc -E"
export STRIP="${HOST}-strip"
export OBJCOPY="${HOST}-objcopy"
export OBJDUMP="${HOST}-objdump"
export NM="${HOST}-nm"
export AS="${HOST}-as"
"${HOST}-gcc" --version
echo "--> Waiting 5s to contiue"
pushd "$PWD/node"
sleep 5
echo "--> Clean"
make clean
echo "--> Configure"
./configure --prefix=/ --without-snapshot --dest-cpu=arm --dest-os=linux
echo "--> Build"
VERSION=${NODEJS_SOURCE_DIRECTORY##node-}
export BINARYNAME=node-${VERSION}-linux-arm-armv6j-vfp-hard
mkdir ${BINARYNAME}
make install DESTDIR=${BINARYNAME} V=1 PORTABLE=1
echo "--> Pack"
cp README.md ${BINARYNAME}
cp LICENSE ${BINARYNAME}
cp ChangeLog ${BINARYNAME}
tar -czf ${BINARYNAME}.tar.gz ${BINARYNAME}
echo "--> Cleanup"
popd
mv $PWD"/node/${BINARYNAME}.tar.gz" "./"
echo "-> Done!"
@Basti77
Copy link

Basti77 commented Jan 22, 2020

Thanks for the script.

unfortunately i get the following error and don't know what to do with it:

`cc-linaro-arm-linux-gnueabihf-raspbian-x64/bin

  • export HOST=arm-bcm2708hardfp-linux-gnueabi

  • HOST=arm-bcm2708hardfp-linux-gnueabi

  • export CC=arm-bcm2708hardfp-linux-gnueabi-gcc

  • CC=arm-bcm2708hardfp-linux-gnueabi-gcc

  • export CXX=arm-bcm2708hardfp-linux-gnueabi-g++

  • CXX=arm-bcm2708hardfp-linux-gnueabi-g++

  • export AR=arm-bcm2708hardfp-linux-gnueabi-ar

  • AR=arm-bcm2708hardfp-linux-gnueabi-ar

  • export RANLIB=arm-bcm2708hardfp-linux-gnueabi-ranlib

  • RANLIB=arm-bcm2708hardfp-linux-gnueabi-ranlib

  • export LD=arm-bcm2708hardfp-linux-gnueabi-ld

  • LD=arm-bcm2708hardfp-linux-gnueabi-ld

  • export 'CPP=arm-bcm2708hardfp-linux-gnueabi-gcc -E'

  • CPP='arm-bcm2708hardfp-linux-gnueabi-gcc -E'

  • export STRIP=arm-bcm2708hardfp-linux-gnueabi-strip

  • STRIP=arm-bcm2708hardfp-linux-gnueabi-strip

  • export OBJCOPY=arm-bcm2708hardfp-linux-gnueabi-objcopy

  • OBJCOPY=arm-bcm2708hardfp-linux-gnueabi-objcopy

  • export OBJDUMP=arm-bcm2708hardfp-linux-gnueabi-objdump

  • OBJDUMP=arm-bcm2708hardfp-linux-gnueabi-objdump

  • export NM=arm-bcm2708hardfp-linux-gnueabi-nm

  • NM=arm-bcm2708hardfp-linux-gnueabi-nm

  • export AS=arm-bcm2708hardfp-linux-gnueabi-as

  • AS=arm-bcm2708hardfp-linux-gnueabi-as

  • arm-bcm2708hardfp-linux-gnueabi-gcc --version
    arm-bcm2708hardfp-linux-gnueabi-gcc (crosstool-NG 1.15.2) 4.7.1 20120402 (prerelease)
    Copyright (C) 2012 Free Software Foundation, Inc.
    This is free software; see the source for copying conditions. There is NO
    warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

  • echo '--> Waiting 5s to contiue'
    --> Waiting 5s to contiue

  • pushd /home/klempi/node
    ~/node ~

  • sleep 5

  • echo '--> Clean'
    --> Clean

  • make clean
    /bin/sh: 1: python: not found
    make: python: Command not found
    make: python: Command not found
    make: python: Command not found
    make: python: Command not found
    make: python: Command not found
    make: python: Command not found
    make: python: Command not found
    make: python: Command not found
    make: python: Command not found
    rm -f -r out/Makefile node node_g out/Release/node
    out/Release/node.exp
    rm -f -r node_modules
    rm -f test.tap
    make testclean
    /bin/sh: 1: python: not found
    make[1]: python: Command not found
    make[1]: python: Command not found
    make[1]: python: Command not found
    make[1]: python: Command not found
    make[1]: python: Command not found
    make[1]: python: Command not found
    make[1]: python: Command not found
    make[1]: python: Command not found
    make[1]: python: Command not found
    rm -f -r test/tmp*
    rm -f -r test/.tmp*
    make test-addons-clean
    /bin/sh: 1: python: not found
    make[1]: python: Command not found
    make[1]: python: Command not found
    make[1]: python: Command not found
    make[1]: python: Command not found
    make[1]: python: Command not found
    make[1]: python: Command not found
    make[1]: python: Command not found
    make[1]: python: Command not found
    make[1]: python: Command not found
    rm -f -r test/addons/??_/
    rm -f -r test/addons/
    /build
    rm -f test/addons/.buildstamp test/addons/.docbuildstamp
    make test-js-native-api-clean
    /bin/sh: 1: python: not found
    make[2]: python: Command not found
    make[2]: python: Command not found
    make[2]: python: Command not found
    make[2]: python: Command not found
    make[2]: python: Command not found
    make[2]: python: Command not found
    make[2]: python: Command not found
    make[2]: python: Command not found
    make[2]: python: Command not found
    rm -f -r test/js-native-api//build
    rm -f test/js-native-api/.buildstamp
    make test-node-api-clean
    /bin/sh: 1: python: not found
    make[2]: python: Command not found
    make[2]: python: Command not found
    make[2]: python: Command not found
    make[2]: python: Command not found
    make[2]: python: Command not found
    make[2]: python: Command not found
    make[2]: python: Command not found
    make[2]: python: Command not found
    make[2]: python: Command not found
    rm -f -r test/node-api/
    /build
    rm -f test/node-api/.buildstamp
    make bench-addons-clean
    /bin/sh: 1: python: not found
    make[1]: python: Command not found
    make[1]: python: Command not found
    make[1]: python: Command not found
    make[1]: python: Command not found
    make[1]: python: Command not found
    make[1]: python: Command not found
    make[1]: python: Command not found
    make[1]: python: Command not found
    make[1]: python: Command not found
    rm -f -r benchmark/napi/*/build
    rm -f benchmark/napi/.buildstamp

  • echo '--> Configure'
    --> Configure

  • ./configure --prefix=/ --without-snapshot --dest-cpu=arm --dest-os=linux
    Node.js configure: Found Python 3.8.0...
    WARNING: C++ compiler (CXX=arm-bcm2708hardfp-linux-gnueabi-g++, 4.7.1) too old, need g++ 6.3.0 or clang++ 8.0.0
    WARNING: building --without-snapshot is no longer possible
    WARNING: warnings were emitted in the configure phase
    INFO: configure completed successfully

  • echo '--> Build'
    --> Build

  • VERSION=v13.7.0

  • export BINARYNAME=node-v13.7.0-linux-arm-armv6j-vfp-hard

  • BINARYNAME=node-v13.7.0-linux-arm-armv6j-vfp-hard

  • mkdir node-v13.7.0-linux-arm-armv6j-vfp-hard

  • make install DESTDIR=node-v13.7.0-linux-arm-armv6j-vfp-hard V=1 PORTABLE=1
    make -C out BUILDTYPE=Release V=1
    touch /home/klempi/node-v13.7.0/out/Release/obj.target/tools/v8_gypfiles/v8_version.stamp
    touch /home/klempi/node-v13.7.0/out/Release/obj.target/tools/v8_gypfiles/v8_headers.stamp
    arm-bcm2708hardfp-linux-gnueabi-g++ -o /home/klempi/node-v13.7.0/out/Release/obj.target/v8_libbase/deps/v8/src/base/bits.o ../deps/v8/src/base/bits.cc '-DV8_GYP_BUILD' '-DV8_TYPED_ARRAY_MAX_SIZE_IN_HEAP=64' '-D__STDC_FORMAT_MACROS' '-DOPENSSL_NO_PINSHARED' '-DOPENSSL_THREADS' '-DV8_TARGET_ARCH_ARM' '-DCAN_USE_ARMV7_INSTRUCTIONS' '-DV8_EMBEDDER_STRING="-node.28"' '-DENABLE_DISASSEMBLER' '-DV8_PROMISE_INTERNAL_FIELD_COUNT=1' '-DENABLE_MINOR_MC' '-DV8_INTL_SUPPORT' '-DV8_CONCURRENT_MARKING' '-DV8_ENABLE_LAZY_SOURCE_POSITIONS' '-DV8_EMBEDDED_BUILTINS' '-DV8_USE_SIPHASH' '-DDISABLE_UNTRUSTED_CODE_MITIGATIONS' '-DV8_WIN64_UNWINDING_INFO' '-DV8_ENABLE_REGEXP_INTERPRETER_THREADED_DISPATCH' '-DBUILDING_V8_BASE_SHARED' -I../deps/v8 -I../deps/v8/include -pthread -Wno-unused-parameter -Wno-return-type -fno-strict-aliasing -mfpu=vfp -mfloat-abi=hard -marm -O3 -fno-omit-frame-pointer -fdata-sections -ffunction-sections -O3 -fno-rtti -fno-exceptions -std=gnu++1y -MMD -MF /home/klempi/node-v13.7.0/out/Release/.deps//home/klempi/node-v13.7.0/out/Release/obj.target/v8_libbase/deps/v8/src/base/bits.o.d.raw -c
    arm-bcm2708hardfp-linux-gnueabi-g++: error: unrecognized command line option '-std=gnu++1y'
    make[1]: *** [tools/v8_gypfiles/v8_libbase.target.mk:156: /home/klempi/node-v13.7.0/out/Release/obj.target/v8_libbase/deps/v8/src/base/bits.o] Error 1
    make: *** [Makefile:101: node] Error 2
    `

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment