3 # Abort execution as soon as an error is encountered
4 # That way the script do not let the user think the process completed correctly
5 # and leave the opportunity to fix the problem and restart compilation where
9 # this is where this script will store downloaded files and check for already
11 dlwhere
="${CROSSBUILD_DOWNLOAD:-$PWD/crossbuild-dl}"
13 # This directory is used to extract all files and to build everything in. It
14 # must not exist before this script is invoked (as a security measure).
15 # This dir should be an absolute path
16 builddir
="${CROSSBUILD_BUILD:-$PWD/crossbuild-build}"
18 # will append the target string to the prefix dir mentioned here
19 # Note that the user running this script must be able to do make install in
20 # this given prefix directory. Also make sure that this given root dir
22 prefix
="${CROSSBUILD_PREFIX:-/usr/local}"
24 # This script needs to use GNU Make. On Linux systems, GNU Make is invoked
25 # by running the "make" command, on most BSD systems, GNU Make is invoked
26 # by running the "gmake" command. Set the "make" variable accordingly.
27 if [ -f "`which gmake 2>/dev/null`" ]; then
33 ##############################################################################
38 releasever
="or32-1.0rc1"
39 releasever_gcc
="or32-1.0rc2"
42 binutils
="binutils-$binutilsver.tar.bz2"
43 binutils_url
="http://mirrors.kernel.org/sources.redhat.com/binutils/releases"
44 binutils_patch
="binutils-$binutilsver-$releasever.patch.bz2"
45 binutils_patch_url
="ftp://ocuser:oc@opencores.org/toolchain"
48 newlib
="newlib-$newlibver.tar.gz"
49 newlib_url
="http://mirrors.kernel.org/sourceware/newlib"
50 newlib_patch
="newlib-$newlibver-$releasever.patch.bz2"
51 newlib_patch_url
="ftp://ocuser:oc@opencores.org/toolchain"
54 gcc
="gcc-$gccver.tar.bz2"
55 gcc_url
="http://mirrors.kernel.org/gnu/gcc/gcc-$gccver";
56 gcc_patch
="gcc-$gccver-$releasever_gcc.patch.bz2"
57 gcc_patch_url
="ftp://ocuser:oc@opencores.org/toolchain"
60 gdb
="gdb-$gdbver.tar.bz2"
61 gdb_url
="http://mirrors.kernel.org/gnu/gdb";
62 gdb_patch
="gdb-$gdbver-$releasever.patch.bz2"
63 gdb_patch_url
="ftp://ocuser:oc@opencores.org/toolchain"
65 # Options passed to all GNU tools during configure
66 or32configure
="--disable-checking --enable-fast-install=N/A --disable-libssp --enable-languages=c,c++ --with-or1ksim=$prefix/or1ksim --with-newlib"
69 sim
="or1ksim-$simver.tar.bz2"
70 sim_url
="ftp://ocuser:oc@opencores.org/toolchain"
73 linux
="linux-$linuxver.tar.bz2"
74 linux_url
="http://www.kernel.org/pub/linux/kernel/v2.6"
75 linux_patch
="linux-$linuxver-or32.patch.bz2"
76 linux_patch_url
="ftp://ocuser:oc@opencores.org/toolchain"
79 uclibc
="uClibc-$uclibcver.tar.bz2"
80 uclibc_url
="http://www.uclibc.org/downloads"
81 uclibc_patch
="uClibc-$uclibcver-or32.patch.bz2"
82 uclibc_patch_url
="ftp://ocuser:oc@opencores.org/toolchain"
83 uclibc_config
="extra/Configs/defconfigs/or32"
85 # These are the tools this script requires and depends upon.
86 reqtools
="gcc bzip2 make patch file makeinfo"
88 ##############################################################################
97 # echo "Checks for $file in $path" >&2
98 if test -f "$path/$file"; then
110 if test -z "$tool"; then
112 if test -n "$tool"; then
114 echo "CROSSBUILD: Downloading $2/$1 using wget"
115 $tool -O "$dlwhere/$1" "$2/$1"
119 echo "CROSSBUILD: Downloading $2/$1 using curl"
120 $tool -Lo "$dlwhere/$1" "$2/$1"
123 if [ $?
-ne 0 ] ; then
124 echo "CROSSBUILD: couldn't download the file!"
125 echo "CROSSBUILD: check your internet connection"
129 if test -z "$tool"; then
130 echo "CROSSBUILD: No downloader tool found!"
131 echo "CROSSBUILD: Please install curl or wget and re-run the script"
143 # if [ ! -d $toolname-$version ]; then
144 echo "CROSSBUILD: extracting $file"
145 if [ `file $dlwhere/$file | grep -c bzip2` -ne 0 ]; then
146 tar xjf
$dlwhere/$file
148 if [ `file $dlwhere/$file | grep -c gzip` -ne 0 ]; then
149 tar xzf
$dlwhere/$file
152 # echo "CROSSBUILD: $file already extracted"
162 # do we have a patch?
163 if test -n "$patch"; then
164 echo "CROSSBUILD: applying patch $patch"
167 (cd $builddir/$toolname-$version && bzcat
"$dlwhere/$patch" |
patch -p1)
169 # check if the patch applied cleanly
170 if [ $?
-gt 0 ]; then
171 echo "CROSSBUILD: failed to apply patch $patch"
179 download_extract_patch
() {
187 if test -f "$dlwhere/$file"; then
188 echo "CROSSBUILD: $file already downloaded"
190 getfile
"$file" "$file_url"
193 if test -n "$patch"; then
194 if test -f "$dlwhere/$patch"; then
195 echo "CROSSBUILD: $patch already downloaded"
197 getfile
"$patch" "$patch_url"
201 extract_tool
"$toolname" "$version" "$file"
203 patch_tool
"$toolname" "$version" "$patch"
214 configure_prefix
="$7"
215 configure_params
="$8"
217 download_extract_patch
"$toolname" "$version" "$file" "$file_url" "$patch" \
222 echo "CROSSBUILD: mkdir build-$toolname"
223 mkdir
-p build-
$toolname
224 echo "CROSSBUILD: cd build-$toolname"
226 echo "CROSSBUILD: $toolname/configure"
227 echo "CROSSBUILD: "..
/$toolname-$version/configure
--target=$target \
228 --prefix=$configure_prefix \
229 --with-pkgversion=$releasever-built-`date +%Y%m%d` \
230 --with-bugurl=http
://www.opencores.org
/ \
232 ..
/$toolname-$version/configure
--target=$target \
233 --prefix=$configure_prefix \
234 --with-pkgversion=$releasever-built-`date +%Y%m%d` \
235 --with-bugurl=http
://www.opencores.org
/ \
237 echo "CROSSBUILD: $toolname/make"
239 echo "CROSSBUILD: $toolname/make install"
243 # For now, just prep the GCC path, extract newlib, link in newlib and libgloss
253 download_extract_patch
"newlib" "$newlibver" "$file" "$file_url" "$patch" \
258 echo "CROSSBUILD: creating GCC source directory"
260 mkdir
-p gcc-
$prepare_gccver
262 echo "CROSSBUILD: linking newlib and libgloss into GCC source directory"
263 if [ ! -L gcc-
$prepare_gccver/newlib
]; then
264 ln -s $PWD/newlib-
$newlibver/newlib
$PWD/gcc-
$prepare_gccver/newlib
267 if [ ! -L gcc-
$prepare_gccver/libgloss
]; then
268 ln -s $PWD/newlib-
$newlibver/libgloss
$PWD/gcc-
$prepare_gccver/libgloss
270 echo "CROSSBUILD: newlib and libgloss linked into GCC source directory"
273 # Move newlib libraries and includes to own sysroot
276 mkdir
-p ${prefix}/or32-elf
/newlib
277 rm -rf ${prefix}/or32-elf
/newlib-include
279 if [ -d ${prefix}/or32-elf
/include
]
281 mv ${prefix}/or32-elf
/include \
282 ${prefix}/or32-elf
/newlib-include
285 if [ -d ${prefix}/or32-elf
/lib
]
287 afiles
=`ls -1 ${prefix}/or32-elf/lib | grep '\.a' | head -1`
289 if [ "x$afiles" != "x" ]
291 mv ${prefix}/or32-elf
/lib
/*.a
${prefix}/or32-elf
/newlib
295 if [ -f ${prefix}/or32-elf
/lib
/crt0.o
]
297 mv ${prefix}/or32-elf
/lib
/crt0.o
${prefix}/or32-elf
/newlib
301 # Download, patch kernel, install headers to $prefix/$target
302 install_linux_headers
() {
304 file_url
="$linux_url"
306 patch_url
="$linux_patch_url"
310 download_extract_patch
"$toolname" "$version" "$file" "$file_url" "$patch" \
313 cd $builddir/linux-
$linuxver
315 echo "CROSSBUILD: defconfig kernel"
316 $make ARCH
=or32 defconfig
317 echo "CROSSBUILD: installing headers to $prefix/or32-elf"
318 $make INSTALL_HDR_PATH
=$prefix/$target headers_install
323 file_url
="$uclibc_url"
324 patch="$uclibc_patch"
325 patch_url
="$uclibc_patch_url"
329 download_extract_patch
"$toolname" "$version" "$file" "$file_url" "$patch" \
335 # Substitute appropriate paths for kernel headers and install path
336 echo "CROSSBUILD: configuring .config for install path"
337 # Create a single variable with all paths expanded
338 kheaders
="KERNEL_HEADERS=\\\"$prefix\\/$target\\/include\\\""
340 sed -i -e "s|KERNEL_HEADERS.*|$kheaders|g" $uclibc_config
341 develprefix
="DEVEL_PREFIX=\\\"$prefix\\/$target\\\""
342 sed -i -e "s|DEVEL_PREFIX.*|$develprefix|g" $uclibc_config
344 echo "CROSSBUILD: defconfig uClibc"
345 $make ARCH
=or32 defconfig
346 echo "CROSSBUILD: building uClibc"
348 echo "CROSSBUILD: installing uClibc"
351 # TODO - maybe move uClibc's libc.a where GCC can find it ($prefix/$target/lib)
352 echo "CROSSBUILD: uClibc build complete"
356 ##############################################################################
359 for t
in $reqtools; do
361 if test -z "$tool"; then
362 echo "CROSSBUILD: \"$t\" is required for this script to work."
363 echo "CROSSBUILD: Please install \"$t\" and re-run the script."
368 # Verify build directory or create it
369 if test -d $builddir; then
370 if test ! -w $builddir; then
371 echo "CROSSBUILD: ERROR: No write permissions for the build directory!"
378 # Verify download directory or create it
379 if test -d "$dlwhere"; then
380 if ! test -w "$dlwhere"; then
381 echo "CROSSBUILD: $dlwhere exists, but doesn't seem to be writable for you"
386 if test $?
-ne 0; then
387 echo "CROSSBUILD: $dlwhere is missing and we failed to create it!"
390 echo "CROSSBUILD: $dlwhere has been created"
393 # Verify installation directory
394 if test ! -d $prefix; then
396 if test $?
-ne 0; then
397 echo "CROSSBUILD: $prefix is missing and we failed to create it!"
401 if test ! -w $prefix; then
402 echo "CROSSBUILD: ERROR: This script is set to install in $prefix but has no write permissions for it"
403 echo "CROSSBUILD: Please fix this and re-run this script"
407 echo "CROSSBUILD: Download dir: $dlwhere"
408 echo "CROSSBUILD: Build dir : $builddir"
409 echo "CROSSBUILD: Install dir : $prefix"
413 build_gnu_tool
"or1ksim" "$simver" "$sim" "$sim_url" "" "" "$prefix/or1ksim" "--enable-ethphy"
415 build_gnu_tool
"binutils" "$binutilsver" "$binutils" "$binutils_url" "$binutils_patch" "$binutils_patch_url" "$prefix" "$or32configure"
417 PATH
="$prefix/bin:${PATH}" # add binutils to $PATH for gcc build
419 prepare_gcc
"$gccver" "$newlib" "$newlibver" "$newlib_url" "$newlib_patch" "$newlib_patch_url"
421 build_gnu_tool
"gcc" "$gccver" "$gcc" "$gcc_url" "$gcc_patch" "$gcc_patch_url" "$prefix" "$or32configure"
425 build_gnu_tool
"gdb" "$gdbver" "$gdb" "$gdb_url" "$gdb_patch" "$gdb_patch_url" "$prefix" "$or32configure"
427 install_linux_headers
433 #echo "CROSSBUILD: Deleting build folder"
437 echo "CROSSBUILD: Done!"
439 echo "CROSSBUILD: Remove temporary build directory, $builddir, manually"
441 echo "CROSSBUILD: Now add $prefix/bin and $prefix/or1ksim/bin to your \$PATH."