2015-02-24 01:28:29 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
2016-02-12 21:49:19 +00:00
|
|
|
set -e
|
|
|
|
|
2015-02-24 01:28:29 +00:00
|
|
|
JOBS=5
|
|
|
|
TARGET=i586-elf
|
|
|
|
VERSION=2.2.0-1
|
|
|
|
MD5=94114fdc1d8391cdbc2653d89249cccf
|
2015-07-10 20:51:53 +00:00
|
|
|
PKG_NAME=newlib
|
|
|
|
SRC_DIR=${PKG_NAME}-${VERSION}
|
|
|
|
PATCH_DIR=../patches
|
|
|
|
TARBALL=${SRC_DIR}.tar.gz
|
|
|
|
DIST_SITE=ftp://sources.redhat.com/pub/newlib
|
2015-02-24 01:28:29 +00:00
|
|
|
|
|
|
|
SCRIPT_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
|
|
|
|
|
|
|
|
# This script will always run on its own basepath, no matter where you call it from.
|
|
|
|
pushd ${SCRIPT_DIR}
|
|
|
|
|
|
|
|
prepare() {
|
|
|
|
# If the source tarball doesn't exist of its md5 checksum doesn't match, download it.
|
|
|
|
if [ ! -e ./${TARBALL} ] || [ "$(md5sum ./${TARBALL} | cut -d' ' -f1)" != $MD5 ]; then
|
2015-07-10 20:51:53 +00:00
|
|
|
wget -c ${DIST_SITE}/${TARBALL}
|
2015-02-24 01:28:29 +00:00
|
|
|
fi
|
2015-07-10 20:41:24 +00:00
|
|
|
if [ ! -e ./${TARBALL} ] || [ "$(md5sum ./${TARBALL} | cut -d' ' -f1)" != $MD5 ]; then
|
|
|
|
echo "Error obtaining tarball."
|
|
|
|
exit 1
|
|
|
|
fi
|
2015-02-24 01:28:29 +00:00
|
|
|
|
|
|
|
# Clean up the previous source dir, if any.
|
2015-07-10 20:51:53 +00:00
|
|
|
if [[ -d ./${SRC_DIR} ]]; then
|
|
|
|
rm -rf ./${SRC_DIR}
|
2015-02-24 01:28:29 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Clean up the previous install dir, if any.
|
2015-11-11 17:19:17 +00:00
|
|
|
if [[ -d ./${TARGET} ]]; then
|
|
|
|
rm -rf ./${TARGET}
|
2015-02-24 01:28:29 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
tar xf ${TARBALL}
|
2015-07-10 20:51:53 +00:00
|
|
|
cd ${SRC_DIR}
|
2015-02-24 01:28:29 +00:00
|
|
|
|
2016-02-12 21:45:25 +00:00
|
|
|
for i in `ls ${PATCH_DIR}/*.patch`; do patch -p0 < ${i}; done
|
2015-02-24 01:28:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
build() {
|
|
|
|
export AR_FOR_TARGET=ar
|
|
|
|
export AS_FOR_TARGET=as
|
|
|
|
export CC_FOR_TARGET=cc
|
|
|
|
export GCC_FOR_TARGET=gcc
|
|
|
|
export CXX_FOR_TARGET=c++
|
|
|
|
export RAW_CXX_FOR_TARGET=c++
|
|
|
|
export GCJ_FOR_TARGET=gcj
|
|
|
|
export GFORTRAN_FOR_TARGET=gfortran
|
|
|
|
export GOC_FOR_TARGET=gccgo
|
|
|
|
export DLLTOOL_FOR_TARGET=dlltool
|
|
|
|
export LD_FOR_TARGET=ld
|
|
|
|
export LIPO_FOR_TARGET=lipo
|
|
|
|
export NM_FOR_TARGET=nm
|
|
|
|
export OBJDUMP_FOR_TARGET=objdump
|
|
|
|
export RANLIB_FOR_TARGET=ranlib
|
|
|
|
export READELF_FOR_TARGET=readelf
|
|
|
|
export STRIP_FOR_TARGET=strip
|
|
|
|
export WINDRES_FOR_TARGET=windres
|
|
|
|
export WINDMC_FOR_TARGET=windmc
|
|
|
|
export COMPILER_AS_FOR_TARGET=as
|
|
|
|
export COMPILER_LD_FOR_TARGET=ld
|
|
|
|
export COMPILER_NM_FOR_TARGET=nm
|
2015-07-27 02:28:31 +00:00
|
|
|
export CFLAGS_FOR_TARGET="-Os -m32 -march=i586 -mtune=i586 -fno-stack-protector -DPREFER_SIZE_OVER_SPEED -ffunction-sections -fdata-sections -fno-asynchronous-unwind-tables -fno-unwind-tables"
|
|
|
|
export CXXFLAGS_FOR_TARGET="-Os -m32 -march=i586 -mtune=i586 -fno-stack-protector -DPREFER_SIZE_OVER_SPEED -ffunction-sections -fdata-sections -fno-asynchronous-unwind-tables -fno-unwind-tables"
|
2015-02-24 01:28:29 +00:00
|
|
|
|
|
|
|
mkdir -p install
|
|
|
|
./configure --target=${TARGET} \
|
|
|
|
--prefix=`pwd`/install \
|
|
|
|
--enable-newlib-nano-formatted-io \
|
|
|
|
--enable-newlib-nano-malloc \
|
|
|
|
--enable-multithread \
|
|
|
|
--disable-newlib-fvwrite-in-streamio \
|
|
|
|
--disable-newlib-fseek-optimization \
|
|
|
|
--disable-newlib-wide-orient \
|
|
|
|
--disable-newlib-unbuf-stream-opt \
|
|
|
|
--disable-libstdcxx \
|
|
|
|
--disable-multilib \
|
|
|
|
--disable-newlib-mb \
|
|
|
|
--disable-newlib-supplied-syscalls
|
|
|
|
|
|
|
|
make -j${JOBS} all && make install
|
|
|
|
cd ..
|
2015-07-10 21:07:07 +00:00
|
|
|
|
|
|
|
echo "BUILT_LIBC = newlib" > Makefile.libc
|
2015-02-24 01:28:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
setup() {
|
2015-07-10 20:51:53 +00:00
|
|
|
cp -r ./${SRC_DIR}/install/${TARGET} .
|
2015-02-24 01:28:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
cleanup() {
|
2015-07-10 20:51:53 +00:00
|
|
|
rm -rf ./${SRC_DIR}*
|
2015-02-24 01:28:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# By default we always call prepare, build and setup.
|
2016-02-12 21:49:19 +00:00
|
|
|
prepare
|
|
|
|
build
|
|
|
|
setup
|
2015-02-24 01:28:29 +00:00
|
|
|
|
|
|
|
# But we only cleanup if -c is used.
|
|
|
|
case $1 in
|
|
|
|
-c | --cleanup)
|
|
|
|
cleanup
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
# unknown option
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
popd
|