Skip to content

Instantly share code, notes, and snippets.

@thijstriemstra
Created August 2, 2016 13:07
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save thijstriemstra/c21631ca12d2e60f0cace5509663e3cb to your computer and use it in GitHub Desktop.
Compile static C-extension with multiple source files for PyQt
#!/bin/bash
set -e
set -o pipefail
source ../../settings.sh
export PATH=$PATH:$COMPILER_ROOT
export CC="${PLAT}gcc -pthread"
export AR="${PLAT}ar rcsv"
echo `${PLAT}gcc --version`
export CFLAGS="-I${PYTHON_ARM_DIR_HOST}/include/python3.5m -I${SYSROOT}/usr/include"
export LDFLAGS="-L${PYTHON_ARM_DIR_HOST}/lib/python3.5 -L${SYSROOT}/lib -L${SYSROOT}/usr/lib"
export HOSTPYTHON=${PYTHON_ARM_DIR_HOST}/bin/hostpython
export SRC_DIR=build/temp.linux-x86_64-3.5/source
# clean
rm -rf build
echo "Cross-compiling extension..."
$HOSTPYTHON setup.py build_ext
# build static library
echo "Creating static library..."
${AR} librpigpio.a ${SRC_DIR}/py_gpio.o ${SRC_DIR}/c_gpio.o ${SRC_DIR}/cpuinfo.o ${SRC_DIR}/event_gpio.o ${SRC_DIR}/soft_pwm.o ${SRC_DIR}/py_pwm.o ${SRC_DIR}/common.o ${SRC_DIR}/constants.o
ranlib librpigpio.a
echo "Ready."
echo
#!/bin/bash
set -e
set -o pipefail
source ../../settings.sh
# compile host python
./configure
make -j4
cp python hostpython
cp Parser/pgen Parser/hostpgen
make distclean
# compile ARM python
export PATH=$PATH:$COMPILER_ROOT
# work around: configure: error: set ac_cv_file__dev_ptmx to yes/no in your CONFIG_SITE file when cross compiling
rm -f config.site
echo ac_cv_file__dev_ptmx=no > config.site
echo ac_cv_file__dev_ptc=no >> config.site
export CONFIG_SITE=config.site
# patch Makefile for 3.5.1 (hopefully fixed in 3.5.2, see https://bugs.python.org/issue27229)
cp --verbose ../../python/Makefile.pre.in .
# configure
CC=${PLAT}gcc CXX=${PLAT}g++ AR=${PLAT}ar RANLIB=${PLAT}ranlib LD=${PLAT}ld READELF=${PLAT}readelf ./configure --host=arm-linux-gnueabihf --build=x86_64-linux-gnu --prefix=${PYTHON_ARM_DIR_HOST} --disable-ipv6
# build
make -j4
# install
make install
cp hostpython ${PYTHON_ARM_DIR_HOST}/bin/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment