-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxCompile.sh
129 lines (107 loc) · 3.65 KB
/
xCompile.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/bin/bash
# define the usage
usage () {
echo "Arguments:"
echo " -buildroot <path to buildroot>"
echo " -lib \"<list of additional libraries to link in compile>\""
echo ""
}
# define the path to the buildroot
BUILDROOT_PATH=""
USER_LIBS=""
bDebug=0
###################
# parse arguments #
while [ "$1" != "" ]
do
case "$1" in
# options
buildroot|-buildroot|--buildroot)
shift
BUILDROOT_PATH="$1"
shift
;;
lib|-lib|--lib)
shift
USER_LIBS="$USER_LIBS -l$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 [ "$BUILDROOT_PATH" = "" ]
then
echo "ERROR: missing path to buildroot"
echo ""
usage
exit
fi
# define the toolchain and target names
TOOLCHAIN_NAME="toolchain-mipsel_24kc_gcc-5.4.0_musl"
TARGET_NAME="target-mipsel_24kc_musl"
# define the relative paths
STAGING_DIR_RELATIVE="staging_dir"
TOOLCHAIN_RELATIVE="$STAGING_DIR_RELATIVE/$TOOLCHAIN_NAME"
TARGET_RELATIVE="$STAGING_DIR_RELATIVE/$TARGET_NAME"
# define the toolchain paths
TOOLCHAIN="$BUILDROOT_PATH/$TOOLCHAIN_RELATIVE"
TOOLCHAIN_BIN="$BUILDROOT_PATH/$TOOLCHAIN_RELATIVE/bin"
TOOLCHAIN_INCLUDE="$BUILDROOT_PATH/$TOOLCHAIN_RELATIVE/include"
TOOLCHAIN_LIB="$BUILDROOT_PATH/$TOOLCHAIN_RELATIVE/lib"
TOOLCHAIN_USR_INCLUDE="$BUILDROOT_PATH/$TOOLCHAIN_RELATIVE/usr/include"
TOOLCHAIN_USR_LIB="$BUILDROOT_PATH/$TOOLCHAIN_RELATIVE/usr/lib"
# define the target paths
TARGET="$BUILDROOT_PATH/$TARGET_RELATIVE"
TARGET_INCLUDE="$BUILDROOT_PATH/$TARGET_RELATIVE/include"
TARGET_LIB="$BUILDROOT_PATH/$TARGET_RELATIVE/lib"
TARGET_USR_INCLUDE="$BUILDROOT_PATH/$TARGET_RELATIVE/usr/include"
TARGET_USR_LIB="$BUILDROOT_PATH/$TARGET_RELATIVE/usr/lib"
export STAGING_DIR="BUILDROOT_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"