Skip to content

Instantly share code, notes, and snippets.

@walkerlee
Last active September 11, 2015 06:44
Show Gist options
  • Select an option

  • Save walkerlee/209d36fc84c7d29a4f74 to your computer and use it in GitHub Desktop.

Select an option

Save walkerlee/209d36fc84c7d29a4f74 to your computer and use it in GitHub Desktop.
Test cross compile nodejs with zlib and openssl via raspberry-pi toolchain
#/bin/bash
# set dir path
export TOP_DIR=${HOME}/nodejs-rpi
export SRC_DIR=${TOP_DIR}/src
export STAGING_DIR=${TOP_DIR}/staging
export ROOTFS_DIR=${TOP_DIR}/rootfs
export TOOLS_DIR=${TOP_DIR}/tools
# set environment
export PATH=$PATH:${TOOLS_DIR}/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin
export CROSS_COMPILE=arm-linux-gnueabihf-
export PKG_CONFIG_DIR=
export PKG_CONFIG_LIBDIR=${STAGING_DIR}/usr/lib/pkgconfig
export PKG_CONFIG_SYSROOT_DIR=${STAGING_DIR}
export PKG_CONFIG_ALLOW_SYSTEM_CFLAGS=1
export PKG_CONFIG_ALLOW_SYSTEM_LIBS=1
mkdir -p ${TOP_DIR} ${SRC_DIR} ${STAGING_DIR} ${ROOTFS_DIR} ${TOOLS_DIR}
# download raspberry-pi toolchain, source code
git clone --depth=1 https://github.com/raspberrypi/tools.git ${TOOLS_DIR}
git clone https://github.com/nodejs/node.git ${SRC_DIR}/node
[ -d ${SRC_DIR}/zlib-1.2.8 ] || curl http://zlib.net/zlib-1.2.8.tar.xz | tar Jxf - -C ${SRC_DIR}
[ -d ${SRC_DIR}/openssl-1.0.2d ] || curl https://www.openssl.org/source/openssl-1.0.2d.tar.gz | tar zxf - -C ${SRC_DIR}
# compile zlib
pushd ${SRC_DIR}/zlib-1.2.8
CROSS_PREFIX=${CROSS_COMPILE} ./configure --prefix=/usr
make install DESTDIR=${STAGING_DIR}
popd
# compile openssl
pushd ${SRC_DIR}/openssl-1.0.2d
./Configure linux-generic32 --prefix=/usr --libdir=lib --cross-compile-prefix=${CROSS_COMPILE} --with-zlib-include=${STAGING_DIR}/usr/include --with-zlib-lib=${STAGING_DIR}/usr/lib shared threads enable-tlsext zlib-dynamic no-idea no-mdc2 no-rc5
make install INSTALL_PREFIX=${STAGING_DIR}
popd
# compile nodejs
pushd ${SRC_DIR}/node
# apply patch to get libpath from pkg-config
sed -i -e "s/filter(None, map(str.strip, pkg_cflags.split('-L')))/map('-L{0}'.format, filter(None, map(str.strip, pkg_libpath.split('-L'))))/" configure
CC=${CROSS_COMPILE}gcc CXX=${CROSS_COMPILE}g++ ./configure --dest-cpu=arm --dest-os=linux --prefix=/usr/local/nodejs --without-snapshot --shared-openssl --shared-zlib
make install DESTDIR=${ROOTFS_DIR}
popd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment