vsftpd ver. 2.3.4 (2011-02-15)
[tomato.git] / tools-src / build_tools.sh
blob1381f5e4693e9960123f9c0157250b8eab28c481
1 #!/bin/bash
3 # build_tools.sh - Do a build of the MIPS toolchain & glibc
5 # Copyright 2001,2003,2004 Broadcom Corporation
9 usage ()
11 cat <<EOF
12 Usage: $script [-d base_dir] [-k kernel_dir] [-i install_base]
13 -d base_dir
14 The base directory where the source will be extracted to and
15 the release will be built. If no -d option is provided,
16 the default base_dir is the current pwd.
18 -k kernel_dir
19 The base directory where a copy of the kernel sources,
20 already configured; can be found. If no -k option is
21 provided, the default kernel_dir is
22 $base_dir/../release/src/linux/linux.
24 -i install_base
25 The base directory where the resulting binaries will be
26 installed and run from. If no -i option is provided, the
27 default install_base is /opt/brcm.
29 (Note: arguments specified must be absolute paths.)
31 EOF
32 exit 1;
35 checkerr()
37 if [ $1 -ne 0 ]; then
38 shift; echo "Error: $*"
39 exit 1
43 report()
45 if [ $# -lt 2 ]; then
46 echo "Internal script error ${1:-(no rc)}"
47 exit 1
49 rc=$1; shift
50 if [ $rc -eq 0 ]; then
51 echo "$* succeeded."
52 else
53 echo "$* failed, $rc" | tr 'a-z' 'A-Z'
54 exit $rc
58 RUN_DIR=`pwd`
59 BUILD_DIR=`pwd`
60 LINUX=${BUILD_DIR}/../release/src/linux/linux
61 INSTALL_BASE=$BUILD_DIR/../tools/brcm
63 while getopts 'd:i:k:h' OPT
65 case "$OPT" in
67 BUILD_DIR=$OPTARG;
70 INSTALL_BASE=$OPTARG;
73 LINUX=$OPTARG;
76 usage;
79 echo "Missing required argument for option \"$OPTARG\".\n";
80 usage;
83 echo "Unrecognized option - \"$OPTARG\".\n";
84 usage;
86 esac
87 done
89 if [[ $BUILD_DIR != /* ]] || [[ $INSTALL_BASE != /* ]] || [[ ${LINUX:-/} != /* ]]; then
90 echo "Directory arguments must be absolute paths."
91 exit 1
94 if [ "$OPTIND" -le "$#" ]; then
95 usage;
98 # Figure out install directory
99 INSTALL_DIR=${INSTALL_BASE}/hndtools-mipsel-linux-3.2.3
101 # Figure out GNU directory
102 GNU=${BUILD_DIR}/gnu
103 if [ ! -d ${GNU} ]; then
104 echo "Can't find gnu (sources) in ${BUILD_DIR}"
105 GNU=${RUN_DIR}/gnu
106 if [ ! -d ${GNU} ]; then
107 echo "Nor here (in ${RUN_DIR})"
108 exit 1
110 echo "Using gnu in current directory (${RUN_DIR})"
113 echo "BUILD_DIR=$BUILD_DIR"
114 echo "LINUX_DIR=$LINUX"
115 echo "INSTALL_DIR=$INSTALL_DIR"
116 echo "GNU=$GNU"
118 # Enter build directory
119 cd "${BUILD_DIR}"
120 checkerr $? "Cannot cd to ${BUILD_DIR}"
121 mkdir obj
122 checkerr $? "Cannot create ${BUILD_DIR}/obj"
124 echo -n "Building gnutools: "
125 date
127 OBJ=${BUILD_DIR}/obj
128 cd ${OBJ}
130 ###############
131 # Do binutils
132 echo -n "Doing binutils: "
133 date
135 mkdir ${OBJ}/binutils && cd ${OBJ}/binutils
136 checkerr $? "Cannot cd to ${OBJ}/binutils"
138 ${GNU}/binutils/configure -v \
139 --prefix=${INSTALL_DIR} --target=mipsel-linux --with-bcm4710a0 \
140 > ${BUILD_DIR}/,binutils-config.log 2>&1
141 report $? "Configure of binutils"
143 gmake > ${BUILD_DIR}/,binutils-build.log 2>&1
144 report $? "Build of binutils"
146 gmake install > ${BUILD_DIR}/,binutils-install.log 2>&1
147 report $? "Install of binutils"
149 # Copy additional static libraries
150 cp libiberty/libiberty.a opcodes/libopcodes.a bfd/libbfd.a ${INSTALL_DIR}/lib
151 report $? "Static library copy"
153 # Make sure installed tools can now be used
154 export PATH=${INSTALL_DIR}/bin:$PATH
156 ###########################
157 # Do bootstrap gcc (xgcc)
158 echo -n "Doing xgcc: "
159 date
161 mkdir ${OBJ}/xgcc && cd ${OBJ}/xgcc
162 checkerr $? "Cannot cd to ${OBJ}/xgcc"
164 ${GNU}/gcc/configure -v \
165 --prefix=${INSTALL_DIR} --target=mipsel-linux --with-bcm4710a0 \
166 --with-newlib --disable-shared --disable-threads --enable-languages=c \
167 > ${BUILD_DIR}/,xgcc-config.log 2>& 1
168 report $? "Configure of xgcc"
170 gmake > ${BUILD_DIR}/,xgcc-build.log 2>& 1
171 report $? "Make of xgcc"
173 gmake install > ${BUILD_DIR}/,xgcc-install.log 2>&1
174 report $? "Install of xgcc"
176 #######################################
177 # Get kernel headers (to build glibc)
179 TARGET=mipsel-linux
180 INCDIR=$INSTALL_DIR/$TARGET/include
181 CROSS=$INSTALL_DIR/bin/$TARGET-
183 echo -n "Coping linux includes: "
184 date
186 cd ${LINUX}
187 checkerr $? "Cannot cd to ${LINUX}"
188 if [ ! -f .config -o ! -f include/linux/version.h ]; then
189 echo "LINUX TREE IS NOT CONFIGURED"
190 exit 1
193 # Make include directory in INSTALL_DIR and copy include files
194 mkdir -p $INCDIR
195 checkerr $? "Cannot create ${INCDIR}"
196 cd include && tar -cf - asm asm-mips linux | tar -xf - -C $INCDIR
197 report $? "Linux include directory copy"
199 #########################
200 # Do glibc (using xgcc)
201 mkdir ${OBJ}/glibc{,-install} && cd ${OBJ}/glibc
202 checkerr $? "Cannot cd to ${OBJ}/glibc"
204 echo -n "Doing glibc: "
205 date
207 CFLAGS="-O2 -g -finline-limit=10000" ${GNU}/glibc/configure \
208 --build=i686-pc-linux-gnu --host=${TARGET} --prefix= \
209 --with-headers=${INCDIR} --enable-add-ons \
210 > ${BUILD_DIR}/,glibc-config.log 2>&1
211 report $? "Configure of glibc"
213 gmake > ${BUILD_DIR}/,glibc-build.log 2>&1
214 report $? "Build of glibc"
216 # Separate install dir gives more control over what goes in
217 gmake install_root=${OBJ}/glibc-install install \
218 > ${BUILD_DIR}/,glibc-install.log 2>&1
219 report $? "Install of glibc"
221 # Now copy over include and lib, not binary
222 cd ${OBJ}/glibc-install/include && tar -cf - . | tar -xf - -C ${INCDIR}
223 report $? "Copy of glibc include"
224 cd ${OBJ}/glibc-install/lib && tar -cf - . | tar -xf - -C ${INSTALL_DIR}/${TARGET}/lib
225 report $? "Copy of glibc lib"
227 echo "Fixing up libc.so locations"
228 sed -e s%/lib/%"${INSTALL_DIR}/${TARGET}/lib/"%g \
229 < "${INSTALL_DIR}/${TARGET}/lib/libc.so" \
230 > "${INSTALL_DIR}/${TARGET}/lib/.new.libc.so"
231 report $? "Fixup of libc.so"
233 mv -f "${INSTALL_DIR}/${TARGET}/lib/.new.libc.so" \
234 "${INSTALL_DIR}/${TARGET}/lib/libc.so"
235 report $? "Replace of libc.so"
237 #######################
238 # Now do the full gcc
240 mkdir ${OBJ}/gcc && cd ${OBJ}/gcc
241 checkerr $? "Cannot cd to ${OBJ}/gcc"
243 echo -n "Doing full gcc: "
244 date
246 ${GNU}/gcc/configure -v \
247 --target=${TARGET} --prefix=${INSTALL_DIR} --with-bcm4710a0 \
248 --with-headers=${INSTALL_DIR}/${TARGET}/include --enable-languages=c,c++ \
249 > ${BUILD_DIR}/,gcc-config.log 2>&1
250 report $? "Configure of gcc"
252 gmake > ${BUILD_DIR}/,gcc-build.log 2>&1
253 report $? "Build of gcc"
255 gmake install > ${BUILD_DIR}/,gcc-install.log 2>&1
256 report $? "Install of gcc"
258 echo -n "build_tools done: "
259 date