Skip to content

Instantly share code, notes, and snippets.

@mingwandroid
Created January 7, 2017 17:54
Show Gist options
  • Save mingwandroid/e8c5bfabd7ce33cbe19adf27abce8e32 to your computer and use it in GitHub Desktop.
Save mingwandroid/e8c5bfabd7ce33cbe19adf27abce8e32 to your computer and use it in GitHub Desktop.
#!/bin/bash
echo "activate, PATH=$PATH"
echo "activate, PWD=$PWD"
# The arguments to this are:
# 1. activation nature {activate,deactivate}
# 2. toolchain nature {build,host}
# 3. machine (should match -dumpmachine)
# 4. prefix (including the final -)
# 5+ program or environment var and value
# The format for 3+ is name{,,value}. If value is specified
# then name taken to be an environment variable, otherwise
# it is taken to be a program. In this case, which is used
# to find the full filename during activation. The original
# value is stored in environment variable CONDA_BACKUP_NAME
# For deactivation, the distinction is irrelevant as in all
# cases NAME simply gets reset to CONDA_BACKUP_NAME. It is
# a fatal error if a program is identified but not present.
function _tc_activation() {
local act_nature=$1; shift
local tc_nature=$1; shift
local tc_machine=$1; shift
local tc_prefix=$1; shift
local thing
local newval
local from
local to
local which
local pass
if [ "${act_nature}" = "activate" ]; then
from=""
to="CONDA_BACKUP_"
which=which
else
from="CONDA_BACKUP_"
to=""
which=true
fi
for pass in check apply; do
for thing in $tc_nature,$tc_machine "$@"; do
case "${thing}" in
*,*)
newval=$(echo "${thing}" | sed "s,^.*\,\(.*\),\1,")
thing=$(echo "${thing}" | sed "s,^\(.*\)\,.*,\1,")
;;
*)
newval=$(${which} ${tc_prefix}${thing} 2>/dev/null)
if [ -n "${which}" -a -z "${newval}" -a "${pass}" = "check" ]; then
echo "ERROR: This toolchain package contains no program called ${tc_prefix}${thing}"
return 1
fi
;;
esac
if [ "${pass}" = "apply" ]; then
thing=$(echo ${thing} | tr 'a-z+-' 'A-ZX_')
eval oldval="${from}\$$thing"
eval export "${to}'${thing}'=\"${oldval}\""
if [ "${thing}" = "HOST" ]; then
eval export "'${thing}=${host}'"
elif [ "${thing}" = "BUILD" ]; then
eval export "'${thing}=${build}'"
elif [ -n "${newval}" ]; then
eval export "'${thing}=${newval}'"
else
eval unset '${thing}'
fi
fi
done
done
}
env > /tmp/old-env-$$.txt
_tc_activation \
activate \
host \
arm-unknown-linux-uclibcgnueabi \
arm-unknown-linux-uclibcgnueabi- \
addr2line ar as c++ cc c++filt cpp elfedit g++ gcc c++ gcov gcov-tool gfortran gprof ld ldd nm objcopy objdump ranlib readelf size strings strip \
CFLAGS,"-test -test2 -\"test3 with spaces\"" \
CXXFLAGS,"-test -test2 -test3"
if [ $? -ne 0 ]; then
echo "Failure detected"
else
env > /tmp/new-env-$$.txt
echo "Activating '${HOST}' cross-compiler made the following environmental changes:"
diff -u0rN /tmp/old-env-$$.txt /tmp/new-env-$$.txt | tail -n +4 | grep "^-.*\|^+.*" | sort
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment