initial commit
[ETG_Helmet] / SOFTWARE / UTILS / fast-gpio / xCompile.sh
1 #!/bin/bash
2
3 # define the usage
4 usage () {
5         echo "Arguments:"
6         echo "  -buildroot <path to buildroot>"
7         echo "  -lib \"<list of additional libraries to link in compile>\""
8         echo ""
9 }
10
11 # define the path to the buildroot
12 BUILDROOT_PATH=""
13 USER_LIBS=""
14 bDebug=0
15
16
17 ###################
18 # parse arguments #
19 while [ "$1" != "" ]
20 do
21         case "$1" in
22                 # options
23                 buildroot|-buildroot|--buildroot)
24                         shift
25                         BUILDROOT_PATH="$1"
26                         shift
27                 ;;
28                 lib|-lib|--lib)
29                         shift
30                         USER_LIBS="$1"
31                         shift
32                 ;;
33                 -d|--d|debug|-debug|--debug)
34                         bDebug=1
35                         shift
36                 ;;
37                 -h|--h|help|-help|--help)
38                         usage
39                         exit
40                 ;;
41             *)
42                         echo "ERROR: Invalid Argument: $1"
43                         usage
44                         exit
45                 ;;
46         esac
47 done
48
49 # check to ensure correct arguments
50 if [ "$BUILDROOT_PATH" = "" ]
51 then
52         echo "ERROR: missing path to buildroot"
53         echo ""
54         usage
55         exit
56 fi
57
58
59 # define the toolchain and target names
60 #TOOLCHAIN_NAME="toolchain-mipsel_24kc_gcc-5.4.0_musl-1.1.16"
61 TOOLCHAIN_NAME="toolchain-mipsel_24kc_gcc-5.5.0_musl"
62 TARGET_NAME="target-mipsel_24kc_musl"
63
64 # define the relative paths
65 STAGING_DIR_RELATIVE="staging_dir"
66 TOOLCHAIN_RELATIVE="$STAGING_DIR_RELATIVE/$TOOLCHAIN_NAME"
67 TARGET_RELATIVE="$STAGING_DIR_RELATIVE/$TARGET_NAME"
68
69 # define the toolchain paths
70 TOOLCHAIN="$BUILDROOT_PATH/$TOOLCHAIN_RELATIVE"
71 TOOLCHAIN_BIN="$BUILDROOT_PATH/$TOOLCHAIN_RELATIVE/bin"
72
73 TOOLCHAIN_INCLUDE="$BUILDROOT_PATH/$TOOLCHAIN_RELATIVE/include"
74 TOOLCHAIN_LIB="$BUILDROOT_PATH/$TOOLCHAIN_RELATIVE/lib"
75 TOOLCHAIN_USR_INCLUDE="$BUILDROOT_PATH/$TOOLCHAIN_RELATIVE/usr/include"
76 TOOLCHAIN_USR_LIB="$BUILDROOT_PATH/$TOOLCHAIN_RELATIVE/usr/lib"
77
78 # define the target paths
79 TARGET="$BUILDROOT_PATH/$TARGET_RELATIVE"
80
81 TARGET_INCLUDE="$BUILDROOT_PATH/$TARGET_RELATIVE/include"
82 TARGET_LIB="$BUILDROOT_PATH/$TARGET_RELATIVE/lib"
83 TARGET_USR_INCLUDE="$BUILDROOT_PATH/$TARGET_RELATIVE/usr/include"
84 TARGET_USR_LIB="$BUILDROOT_PATH/$TARGET_RELATIVE/usr/lib"
85
86 export STAGING_DIR="BUILDROOT_PATH/$STAGING_DIR_RELATIVE"
87
88 # define the compilers and such
89 TOOLCHAIN_CC="$TOOLCHAIN_BIN/mipsel-openwrt-linux-gcc"
90 TOOLCHAIN_CXX="$TOOLCHAIN_BIN/mipsel-openwrt-linux-g++"
91 TOOLCHAIN_LD="$TOOLCHAIN_BIN/mipsel-openwrt-linux-ld"
92
93 TOOLCHAIN_AR="$TOOLCHAIN_BIN/mipsel-openwrt-linux-ar"
94 TOOLCHAIN_RANLIB="$TOOLCHAIN_BIN/mipsel-openwrt-linux-ranlib"
95
96 # define the FLAGS
97 INCLUDE_LINES="-I $TOOLCHAIN_USR_INCLUDE -I $TOOLCHAIN_INCLUDE -I $TARGET_USR_INCLUDE -I $TARGET_INCLUDE"
98 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"
99 #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"
100 TOOLCHAIN_CFLAGS="$TOOLCHAIN_CFLAGS $INCLUDE_LINES"
101
102 TOOLCHAIN_CXXFLAGS="$TOOLCHAIN_CFLAGS"
103 #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"
104 TOOLCHAIN_CXXFLAGS="$TOOLCHAIN_CXXFLAGS $INCLUDE_LINES"
105
106 TOOLCHAIN_LDFLAGS="-L$TOOLCHAIN_USR_LIB -L$TOOLCHAIN_LIB -L$TARGET_USR_LIB -L$TARGET_LIB"
107
108 # debug
109 if [ $bDebug -eq 1 ]; then
110         echo "CC=$TOOLCHAIN_CC"
111         echo "CXX=$TOOLCHAIN_CXX"
112         echo "LD=$TOOLCHAIN_LD"
113         echo "CFLAGS=$TOOLCHAIN_CFLAGS"
114         echo "LDFLAGS=$TOOLCHAIN_LDFLAGS"
115         echo "USER_LIBS=$USER_LIBS"
116         echo ""
117 fi
118
119
120 # first run make clean
121 make clean
122
123 # run the make command
124 make \
125         CC="$TOOLCHAIN_CC" \
126         CXX="$TOOLCHAIN_CXX" \
127         LD="$TOOLCHAIN_LD" \
128         CFLAGS="$TOOLCHAIN_CFLAGS" \
129         LDFLAGS="$TOOLCHAIN_LDFLAGS" \
130         LIB="$USER_LIBS"
Contact me: dev (at) shalnoff (dot) com
PGP fingerprint: A6B8 3B23 6013 F18A 0C71 198B 83D8 C64D 917A 5717