2017-05-04 07:37:28 +08:00
|
|
|
# This software is released under the terms of GPLv2 by copyright@mzpqnxow.com
|
|
|
|
# Please see LICENSE or LICENSE.md for more information on GPLv2
|
|
|
|
|
2017-05-15 23:36:30 +08:00
|
|
|
#
|
|
|
|
# YMMV, but this worked reliably for me. However, it ONLY worked reliably
|
|
|
|
# when using a prebuilt toolchain from the OpenWrt project. It seems to
|
|
|
|
# not work well when building your own. It's possible I just didn't use a
|
|
|
|
# suffix setting or something else that this script relies on. So just to
|
|
|
|
# reiterate: **use this only with the OpenWrt-Toolchain-xxx-yyy*.tar.bz2
|
|
|
|
# prebuilt toolchains from OpenWrt.org or all bets are off!**
|
|
|
|
#
|
|
|
|
|
2017-05-04 07:37:28 +08:00
|
|
|
#
|
|
|
|
# This is not for you unless you are using a pre-built OpenWRT toolchain
|
|
|
|
# This is a productivity script that should be sourced from a Bash shell
|
|
|
|
#
|
|
|
|
# It is meant to be used after unpacking pre-built OpenWrt toolchains, which
|
|
|
|
# are named like this:
|
|
|
|
#
|
|
|
|
# OpenWrt-Toolchain-xxx-yyy-5.3.0_musl-1.1.16.Linux-x86_64.tar.bz2
|
|
|
|
#
|
|
|
|
# A huge collection of them can be found at the following location:
|
|
|
|
#
|
|
|
|
# https://downloads.openwrt.org/snapshots/trunk/
|
|
|
|
#
|
|
|
|
# This file should be placed in /path/to/installed/toolchain/
|
|
|
|
# The file must be in the root directory of the subdirectory of the unpacked
|
|
|
|
# toolchain - NOT the directory that contains the LICENSE file, but the main
|
|
|
|
# directory under that
|
|
|
|
#
|
|
|
|
# You can name the script whatever you want, I prefer to call it 'activate'
|
|
|
|
# All you need to do is source it (from any working directory) and it will set
|
|
|
|
# your environment up for building software via build systems like configure
|
|
|
|
# as well as for manual invocation via gcc, ld, etc. It helps with static
|
|
|
|
# linking by setting some static library locations as environment variables
|
|
|
|
# as well
|
|
|
|
#
|
|
|
|
# Assumptions are made, YMMV. It works well for me when I work on weird stuff
|
|
|
|
#
|
|
|
|
|
|
|
|
CURDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
|
|
|
source "$CURDIR/info.mk"
|
|
|
|
TOOLCHAIN_TARGET="$TARGET_CROSS"
|
|
|
|
TOOLCHAIN_ROOT="$CURDIR"
|
2017-05-06 03:07:38 +08:00
|
|
|
|
|
|
|
# Commonly used/needed static libraries, put them in the
|
|
|
|
# environment for easy access
|
2017-05-04 07:37:28 +08:00
|
|
|
UTIL_STATIC=$(find $(realpath $CURDIR) -name libutil.a)
|
|
|
|
C_STATIC=$(find $(realpath $CURDIR) -name libc.a)
|
|
|
|
DL_STATIC=$(find $(realpath $CURDIR) -name libdl.a)
|
|
|
|
PTHREAD_STATIC=$(find $(realpath $CURDIR) -name libpthread.a)
|
|
|
|
STDCXX_STATIC=$(find $(realpath $CURDIR) -name libstdc++.a)
|
|
|
|
GCCEH_STATIC=$(find $(realpath $CURDIR) -name libgcc_eh.a)
|
|
|
|
TOOLCHAIN_BIN="$CURDIR/bin"
|
|
|
|
GCC_BIN=$TOOLCHAIN_BIN/$CUR${TOOLCHAIN_TARGET}-gcc
|
|
|
|
AS_BIN=$TOOLCHAIN_BIN/${TOOLCHAIN_TARGET}-as
|
|
|
|
LD_BIN=$TOOLCHAIN_BIN/${TOOLCHAIN_TARGET}-ld
|
|
|
|
GXX_BIN=$TOOLCHAIN_BIN/${TOOLCHAIN_TARGET}-g++
|
|
|
|
PATH="$TOOLCHAIN_BIN":"$PATH"
|
|
|
|
STAGING_DIR="$CURDIR"
|
|
|
|
TOOLCHAIN_TARGET=$(echo $TOOLCHAIN_TARGET | sed -e 's/-$//')
|
|
|
|
|
|
|
|
echo "--- Build environment setup ---"
|
|
|
|
echo
|
|
|
|
echo "TOOLCHAIN_TARGET: $TOOLCHAIN_TARGET"
|
|
|
|
echo "TOOLCHAIN_BIN: $TOOLCHAIN_BIN"
|
|
|
|
echo
|
|
|
|
for TOOL in gcc \
|
|
|
|
addr2line \
|
|
|
|
ar \
|
|
|
|
as \
|
|
|
|
c++ \
|
|
|
|
cpp \
|
|
|
|
g++ \
|
|
|
|
gcc \
|
|
|
|
ld \
|
|
|
|
nm \
|
|
|
|
objdump \
|
|
|
|
ranlib \
|
|
|
|
strip
|
|
|
|
do
|
|
|
|
echo " Symlinking $TOOL"
|
|
|
|
ln -sf "${TOOLCHAIN_BIN}/${TOOLCHAIN_TARGET}-${TOOL}" "${TOOLCHAIN_BIN}/${TOOL}"
|
|
|
|
done
|
|
|
|
ln -sf "${TOOLCHAIN_BIN}/${TOOLCHAIN_TARGET}-gcc" "${TOOLCHAIN_BIN}/cc"
|
|
|
|
echo
|
|
|
|
|
|
|
|
export STAGING_DIR="$TOOLCHAIN_ROOT"
|
|
|
|
|
|
|
|
PATH="$TOOLCHAIN_BIN":"$PATH"
|
|
|
|
echo "TOOLCHAIN_TARGET: $TOOLCHAIN_TARGET"
|
|
|
|
echo "TOOLCHAIN_ROOT: $TOOLCHAIN_ROOT"
|
|
|
|
echo "STAGING_DIR: $TOOLCHAIN_ROOT"
|
|
|
|
echo "TOOLCHAIN_BIN: $TOOLCHAIN_BIN"
|
|
|
|
echo
|
|
|
|
echo "GCC location: $(which gcc)"
|
|
|
|
echo "GAS location: $(which as)"
|
|
|
|
echo "GLD location: $(which ld)"
|
|
|
|
echo "G++ location: $(which g++)"
|
|
|
|
echo "CC location: $(which cc)"
|
|
|
|
|
|
|
|
echo
|
|
|
|
echo "UTIL_STATIC: $UTIL_STATIC"
|
|
|
|
echo "C_STATIC: $C_STATIC"
|
|
|
|
echo "DL_STATIC: $DL_STATIC"
|
|
|
|
echo "PTHREAD_STATIC: $PTHREAD_STATIC"
|
|
|
|
echo "STDCXX_STATIC: $STDCXX_STATIC"
|
|
|
|
echo "GCCEH_STATIC: $GCCEH_STATIC"
|
|
|
|
|
|
|
|
alias cross_configure="./configure \
|
|
|
|
--host=$TOOLCHAIN_TARGET \
|
|
|
|
--prefix=$TOOLCHAIN_ROOT"
|
|
|
|
|
|
|
|
echo
|
|
|
|
echo "Use cross_configure to invoke alias for:"
|
|
|
|
echo " $./configure --host=$TOOLCHAIN_TARGET --prefix=$TOOLCHAIN_ROOT"
|
|
|
|
echo
|
|
|
|
unset TARGET_CROSS
|
|
|
|
export UTIL_STATIC
|
|
|
|
export C_STATIC
|
|
|
|
export DL_STATIC
|
|
|
|
export PTHREAD_STATIC
|
|
|
|
export STDCXX_STATIC
|
|
|
|
export GCCEH_STATIC
|
|
|
|
export TOOLCHAIN_TARGET
|
|
|
|
export TOOLCHAIN_ROOT
|
|
|
|
export TOOLCHAIN_BIN
|
|
|
|
export STAGING_DIR
|
|
|
|
export SYSTEM_ROOT="$TOOLCHAIN_ROOT"
|
|
|
|
|