#!/bin/bash

# This script uses the current directory to build newlib, installs it
# in ./install/

NEWLIB_SRC_DIR=../newlib-3.1.0

make distclean
export CCAS=arm-none-eabi-gcc

AR_FOR_TARGET=arm-none-eabi-ar AS_FOR_TARGET=arm-none-eabi-as LD_FOR_TARGET=arm-none-eabi-ld RANLIB_FOR_TARGET=arm-none-eabi-ranlib CFLAGS_FOR_TARGET="-g -Os -ffunction-sections -fdata-sections -fomit-frame-pointer -fshort-enums" CC_FOR_TARGET="clang -ffreestanding --target=arm-none-eabi -march=thumbv6m -mthumb -mcpu=cortex-m0plus" $NEWLIB_SRC_DIR/configure --prefix=$(pwd)/install --target=arm-none-eabi --disable-newlib-supplied-syscalls --enable-newlib-reent-small --disable-newlib-fvwrite-in-streamio --disable-newlib-fseek-optimization --disable-newlib-wide-orient --enable-newlib-nano-malloc --disable-newlib-unbuf-stream-opt --enable-lite-exit --enable-newlib-global-atexit --enable-newlib-nano-formatted-io --disable-nls

make clean
make -j5 all-target-newlib
make install-target-newlib
