Skip to content

Instantly share code, notes, and snippets.

@mzpqnxow
Created November 25, 2018 14:39
Show Gist options
  • Select an option

  • Save mzpqnxow/630c403bc16307c65a7d0525af7c0fe3 to your computer and use it in GitHub Desktop.

Select an option

Save mzpqnxow/630c403bc16307c65a7d0525af7c0fe3 to your computer and use it in GitHub Desktop.
File to place in the root of a musl toolchain to handle some convenience functions if you don't know wtf you are doing :>
# This software is released under the terms of GPLv2 by copyright@mzpqnxow.com
# Please see LICENSE or LICENSE.md for more information on GPLv2
# This is not for you if you are not using a musl-cross-make toolchain
# This is a productivity script that should be sourced from a Bash shell
#
# It is meant to be used after making and installing a musl toolchain using
# the excellent musl-cross-make tool by Rich Felker:
#
# https://github.com/richfelker/musl-cross-make
#
# This file should be placed in /path/to/installed/toolchain/
# You should probably call it activate, but it doesn't matter
# All you need to do is source it (from anywhere) and it sets your env up for
# building software via build systems like configure or just via gcc/g++/as/ld
# commands. It helps with static linking by setting some static library paths
# also (See the XXX_STATIC variables)
#
# It makes assumptions and will try to set things up for you so you can
# conveniently build things with or without ./configure based build systems
#
CURDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
TOOLCHAIN_TARGET="$(basename $(echo $CURDIR/*-*-musl*))"
TOOLCHAIN_ROOT="$CURDIR"
# Commonly used/needed static libraries, put them in the
# environment for easy access
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="$TOOLCHAIN_ROOT/bin"
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++ \
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 PATH="$TOOLCHAIN_BIN":"$PATH"
echo "TOOLCHAIN_TARGET: $TOOLCHAIN_TARGET"
echo "TOOLCHAIN_ROOT: $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
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
@mzpqnxow
Copy link
Copy Markdown
Author

Note this doesn't work with zsh, sorry...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment