From c98856b62a4fd5eca05d1d1f1185300fdee13f39 Mon Sep 17 00:00:00 2001 From: Andreas Fritiofson Date: Fri, 13 Sep 2013 23:38:30 +0200 Subject: [PATCH] contrib: Add example cross-build script Usage: export LIBUSB1_SRC=/path/to/libusb-1.0 export OPENOCD_CONFIG="--enable-..." cd /work/dir /path/to/openocd/contrib/cross-build.sh For static linking, a workaround is to export LIBUSB1_CONFIG="--enable-static --disable-shared" All the paths must not contain any spaces. Feel free to comment or update this patchset with improvements. Change-Id: Ib3b4970117f13a6140a1eddc493d324a52364519 Signed-off-by: Andreas Fritiofson Reviewed-on: http://openocd.zylin.com/1531 Tested-by: jenkins Reviewed-by: Spencer Oliver --- contrib/cross-build.sh | 104 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100755 contrib/cross-build.sh diff --git a/contrib/cross-build.sh b/contrib/cross-build.sh new file mode 100755 index 0000000000..397b7f41a9 --- /dev/null +++ b/contrib/cross-build.sh @@ -0,0 +1,104 @@ +#!/bin/sh + +# This is an example of how to do a cross-build of OpenOCD using pkg-config. +# Cross-building with pkg-config is deceptively hard and most guides and +# tutorials are incomplete or give bad advice. Some of the traps that are easy +# to fall in but handled by this script are: +# +# * Polluting search paths and flags with values from the build system. +# * Faulty pkg-config wrappers shipped with distribution packaged cross- +# toolchains. +# * Build failing because pkg-config discards some paths even though they are +# correctly listed in the .pc file. +# * Getting successfully built binaries that cannot find runtime data because +# paths refer to the build file system. +# +# This script is probably more useful as a reference than as a complete build +# tool but for some configurations it may be usable as-is. It only cross- +# builds libusb-1.0 from source, but the script can be extended to build other +# prerequisities in a similar manner. +# +# Usage: +# export LIBUSB1_SRC=/path/to/libusb-1.0 +# export OPENOCD_CONFIG="--enable-..." +# cd /work/dir +# /path/to/openocd/contrib/cross-build.sh +# +# For static linking, a workaround is to +# export LIBUSB1_CONFIG="--enable-static --disable-shared" +# +# All the paths must not contain any spaces. + +set -e -x + +WORK_DIR=$PWD + +## Source code paths, customize as necessary +: ${OPENOCD_SRC:="`dirname "$0"`/.."} +: ${LIBUSB1_SRC:=/path/to/libusb} + +OPENOCD_SRC=`readlink -m $OPENOCD_SRC` +LIBUSB1_SRC=`readlink -m $LIBUSB1_SRC` + +HOST_TRIPLET=$1 +BUILD_DIR=$WORK_DIR/$HOST_TRIPLET-build +LIBUSB1_BUILD_DIR=$BUILD_DIR/libusb1 +OPENOCD_BUILD_DIR=$BUILD_DIR/openocd + +## Root of host file tree +SYSROOT=$WORK_DIR/$HOST_TRIPLET-root + +## Install location within host file tree +: ${PREFIX=/usr} + +## OpenOCD-only install dir for packaging +PACKAGE_DIR=$WORK_DIR/openocd_`git --git-dir=$OPENOCD_SRC/.git describe`_$HOST_TRIPLET + +####### + +# Create pkg-config wrapper and make sure it's used +export PKG_CONFIG=$WORK_DIR/$HOST_TRIPLET-pkg-config + +cat > $PKG_CONFIG <