Created
October 4, 2017 17:23
-
-
Save greenbreakfast/0e1064fa4ca6a8ed9f2d5fde74666244 to your computer and use it in GitHub Desktop.
Script for cross-compiling using Omega2-Toolchain Docker Image
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# define the usage | |
usage () { | |
echo "Arguments:" | |
echo " -toolchain <path to buildroot>" | |
echo " -lib \"<list of additional libraries to link in compile>\"" | |
echo "" | |
} | |
# define the path to the buildroot | |
TOOLCHAIN_DIR_PATH="" | |
USER_LIBS="" | |
bDebug=0 | |
################### | |
# parse arguments # | |
while [ "$1" != "" ] | |
do | |
case "$1" in | |
# options | |
toolchain|-toolchain|--toolchain) | |
shift | |
TOOLCHAIN_DIR_PATH="$1" | |
shift | |
;; | |
lib|-lib|--lib) | |
shift | |
USER_LIBS="$1" | |
shift | |
;; | |
-d|--d|debug|-debug|--debug) | |
bDebug=1 | |
shift | |
;; | |
-h|--h|help|-help|--help) | |
usage | |
exit | |
;; | |
*) | |
echo "ERROR: Invalid Argument: $1" | |
usage | |
exit | |
;; | |
esac | |
done | |
# check to ensure correct arguments | |
if [ "$TOOLCHAIN_DIR_PATH" = "" ] | |
then | |
echo "ERROR: missing path to toolchain" | |
echo "" | |
usage | |
exit | |
fi | |
# define the toolchain and target names | |
TOOLCHAIN_RELATIVE="toolchain-mipsel_24kc_gcc-5.4.0_musl-1.1.16" | |
TARGET_RELATIVE="target-mipsel_24kc_musl-1.1.16" | |
# define the toolchain paths | |
TOOLCHAIN="$TOOLCHAIN_DIR_PATH/$TOOLCHAIN_RELATIVE" | |
TOOLCHAIN_BIN="$TOOLCHAIN_DIR_PATH/$TOOLCHAIN_RELATIVE/bin" | |
TOOLCHAIN_INCLUDE="$TOOLCHAIN_DIR_PATH/$TOOLCHAIN_RELATIVE/include" | |
TOOLCHAIN_LIB="$TOOLCHAIN_DIR_PATH/$TOOLCHAIN_RELATIVE/lib" | |
TOOLCHAIN_USR_INCLUDE="$TOOLCHAIN_DIR_PATH/$TOOLCHAIN_RELATIVE/usr/include" | |
TOOLCHAIN_USR_LIB="$TOOLCHAIN_DIR_PATH/$TOOLCHAIN_RELATIVE/usr/lib" | |
# define the target paths | |
TARGET="$TOOLCHAIN_DIR_PATH/$TARGET_RELATIVE" | |
TARGET_INCLUDE="$TOOLCHAIN_DIR_PATH/$TARGET_RELATIVE/include" | |
TARGET_LIB="$TOOLCHAIN_DIR_PATH/$TARGET_RELATIVE/lib" | |
TARGET_USR_INCLUDE="$TOOLCHAIN_DIR_PATH/$TARGET_RELATIVE/usr/include" | |
TARGET_USR_LIB="$TOOLCHAIN_DIR_PATH/$TARGET_RELATIVE/usr/lib" | |
#export STAGING_DIR="$TOOLCHAIN_DIR_PATH/$STAGING_DIR_RELATIVE" | |
# define the compilers and such | |
TOOLCHAIN_CC="$TOOLCHAIN_BIN/mipsel-openwrt-linux-gcc" | |
TOOLCHAIN_CXX="$TOOLCHAIN_BIN/mipsel-openwrt-linux-g++" | |
TOOLCHAIN_LD="$TOOLCHAIN_BIN/mipsel-openwrt-linux-ld" | |
TOOLCHAIN_AR="$TOOLCHAIN_BIN/mipsel-openwrt-linux-ar" | |
TOOLCHAIN_RANLIB="$TOOLCHAIN_BIN/mipsel-openwrt-linux-ranlib" | |
# define the FLAGS | |
INCLUDE_LINES="-I $TOOLCHAIN_USR_INCLUDE -I $TOOLCHAIN_INCLUDE -I $TARGET_USR_INCLUDE -I $TARGET_INCLUDE" | |
TOOLCHAIN_CFLAGS="-Os -pipe -mno-branch-likely -mips32r2 -mtune=24kc -fno-caller-saves -fno-plt -fhonour-copts -Wno-error=unused-but-set-variable -Wno-error=unused-result -msoft-float -mips16 -minterlink-mips16 -Wformat -Werror=format-security -fstack-protector -D_FORTIFY_SOURCE=1 -Wl,-z,now -Wl,-z,relro" | |
#TOOLCHAIN_CFLAGS="-Os -pipe -mno-branch-likely -mips32r2 -mtune=34kc -fno-caller-saves -fhonour-copts -Wno-error=unused-but-set-variable -Wno-error=unused-result -msoft-float -mips16 -minterlink-mips16 -fpic" | |
TOOLCHAIN_CFLAGS="$TOOLCHAIN_CFLAGS $INCLUDE_LINES" | |
TOOLCHAIN_CXXFLAGS="$TOOLCHAIN_CFLAGS" | |
#TOOLCHAIN_CXXFLAGS="-Os -pipe -mno-branch-likely -mips32r2 -mtune=34kc -fno-caller-saves -fhonour-copts -Wno-error=unused-but-set-variable -Wno-error=unused-result -msoft-float -mips16 -minterlink-mips16 -fpic" | |
TOOLCHAIN_CXXFLAGS="$TOOLCHAIN_CXXFLAGS $INCLUDE_LINES" | |
TOOLCHAIN_LDFLAGS="-L$TOOLCHAIN_USR_LIB -L$TOOLCHAIN_LIB -L$TARGET_USR_LIB -L$TARGET_LIB" | |
# debug | |
if [ $bDebug -eq 1 ]; then | |
echo "CC=$TOOLCHAIN_CC" | |
echo "CXX=$TOOLCHAIN_CXX" | |
echo "LD=$TOOLCHAIN_LD" | |
echo "CFLAGS=$TOOLCHAIN_CFLAGS" | |
echo "LDFLAGS=$TOOLCHAIN_LDFLAGS" | |
echo "USER_LIBS=$USER_LIBS" | |
echo "" | |
fi | |
# first run make clean | |
make clean | |
# run the make command | |
make \ | |
CC="$TOOLCHAIN_CC" \ | |
CXX="$TOOLCHAIN_CXX" \ | |
LD="$TOOLCHAIN_LD" \ | |
CFLAGS="$TOOLCHAIN_CFLAGS" \ | |
LDFLAGS="$TOOLCHAIN_LDFLAGS" \ | |
LIB="$USER_LIBS" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment