3 # build_tools.sh - Do a build of the MIPS toolchain & glibc
5 # Copyright 2001,2003,2004 Broadcom Corporation
12 Usage: $script [-d base_dir] [-k kernel_dir] [-i install_base]
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.
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.
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.)
38 shift; echo "Error: $*"
46 echo "Internal script error ${1:-(no rc)}"
50 if [ $rc -eq 0 ]; then
53 echo "$* failed, $rc" |
tr 'a-z' 'A-Z'
60 LINUX
=${BUILD_DIR}/..
/release
/src
/linux
/linux
61 INSTALL_BASE
=$BUILD_DIR/..
/tools
/brcm
63 while getopts 'd:i:k:h' OPT
79 echo "Missing required argument for option \"$OPTARG\".\n";
83 echo "Unrecognized option - \"$OPTARG\".\n";
89 if [[ $BUILD_DIR != /* ]] ||
[[ $INSTALL_BASE != /* ]] ||
[[ ${LINUX:-/} != /* ]]; then
90 echo "Directory arguments must be absolute paths."
94 if [ "$OPTIND" -le "$#" ]; then
98 # Figure out install directory
99 INSTALL_DIR
=${INSTALL_BASE}/hndtools-mipsel-linux-3.2
.3
101 # Figure out GNU directory
103 if [ ! -d ${GNU} ]; then
104 echo "Can't find gnu (sources) in ${BUILD_DIR}"
106 if [ ! -d ${GNU} ]; then
107 echo "Nor here (in ${RUN_DIR})"
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"
118 # Enter build directory
120 checkerr $?
"Cannot cd to ${BUILD_DIR}"
122 checkerr $?
"Cannot create ${BUILD_DIR}/obj"
124 echo -n "Building gnutools: "
132 echo -n "Doing binutils: "
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: "
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)
180 INCDIR
=$INSTALL_DIR/$TARGET/include
181 CROSS
=$INSTALL_DIR/bin
/$TARGET-
183 echo -n "Coping linux includes: "
187 checkerr $?
"Cannot cd to ${LINUX}"
188 if [ ! -f .config
-o ! -f include
/linux
/version.h
]; then
189 echo "LINUX TREE IS NOT CONFIGURED"
193 # Make include directory in INSTALL_DIR and copy include files
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: "
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: "
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: "