|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +set -exu |
| 4 | + |
| 5 | +TARGET_CPU="" |
| 6 | +OUTPUT_DIR="" |
| 7 | + |
| 8 | +while getopts "t:o:" opt |
| 9 | +do |
| 10 | + case "$opt" in |
| 11 | + t) |
| 12 | + TARGET_CPU="$OPTARG" |
| 13 | + ;; |
| 14 | + o) |
| 15 | + OUTPUT_DIR="$OPTARG" |
| 16 | + ;; |
| 17 | + ?) |
| 18 | + exit 1 |
| 19 | + ;; |
| 20 | + esac |
| 21 | +done |
| 22 | +shift "$((OPTIND - 1))" |
| 23 | + |
| 24 | +if [ -z "${TARGET_CPU}" ] || [ -z "${OUTPUT_DIR}" ] |
| 25 | +then |
| 26 | + echo "Usage: $0 -t TARGET_CPU -o OUTPUT_FILE" >&2 |
| 27 | + exit 1 |
| 28 | +fi |
| 29 | + |
| 30 | + |
| 31 | +mkdir -p "$OUTPUT_DIR" |
| 32 | +OUTPUT_DIR=$(realpath "$OUTPUT_DIR") |
| 33 | + |
| 34 | + |
| 35 | +# ENV SETUP |
| 36 | +WORKDIR="$(pwd)" |
| 37 | +SRC="${WORKDIR}/newlib" |
| 38 | +BUILD="${SRC}/arm_none_eabi_build" |
| 39 | +INSTALL="${SRC}/arm_none_eabi_install" |
| 40 | +cd "${WORKDIR}" |
| 41 | + |
| 42 | +# Get the latest fixed version |
| 43 | +git clone --depth=1 --single-branch --branch newlib-4.5.0 https://sourceware.org/git/newlib-cygwin.git "${SRC}" |
| 44 | + |
| 45 | + |
| 46 | +# Build configuration |
| 47 | +mkdir -p "${BUILD}" "${INSTALL}" |
| 48 | +cd "${BUILD}" |
| 49 | + |
| 50 | +# -march=armv8-m.main+nofp |
| 51 | + |
| 52 | +CFLAGS_FOR_TARGET="-ffunction-sections -fdata-sections -fshort-wchar -DPREFER_SIZE_OVER_SPEED -mcpu=${TARGET_CPU} -mthumb -mlittle-endian" \ |
| 53 | + ../configure \ |
| 54 | + `# Setup` \ |
| 55 | + --host=x86_64-linux-gnu `# Host` \ |
| 56 | + --target=arm-none-eabi ` # Target` \ |
| 57 | + --disable-multilib `# Building only one library` \ |
| 58 | + --prefix="${INSTALL}" `# Installation prefix` \ |
| 59 | + `# Options` \ |
| 60 | + --disable-silent-rules `# verbose build output (undo: "make V=0")` \ |
| 61 | + --disable-dependency-tracking `# speeds up one-time build` \ |
| 62 | + --enable-newlib-reent-small `# enable small reentrant struct support` \ |
| 63 | + --disable-newlib-fvwrite-in-streamio `# disable iov in streamio ` \ |
| 64 | + --disable-newlib-fseek-optimization `# disable fseek optimization` \ |
| 65 | + --disable-newlib-wide-orient `# Turn off wide orientation in streamio`\ |
| 66 | + --enable-newlib-nano-malloc `# use small-footprint nano-malloc implementation`\ |
| 67 | + --disable-newlib-unbuf-stream-opt `# disable unbuffered stream optimization in streamio` \ |
| 68 | + --enable-lite-exit `# enable light weight exit` \ |
| 69 | + --enable-newlib-global-atexit `# enable atexit data structure as global` \ |
| 70 | + --enable-newlib-nano-formatted-io `# Use small-footprint nano-formatted-IO implementation`\ |
| 71 | + --disable-newlib-supplied-syscalls `# disable newlib from supplying syscalls`\ |
| 72 | + --disable-nls `# do not use Native Language Support` \ |
| 73 | + --enable-target-optspace `# optimize for space (emits -g -Os)` |
| 74 | + |
| 75 | + |
| 76 | +# Compilation |
| 77 | +make "-j$(nproc)" |
| 78 | +make install |
| 79 | + |
| 80 | + |
| 81 | +# Copy back |
| 82 | +mkdir -p "$OUTPUT_DIR" |
| 83 | +cp "${INSTALL}/arm-none-eabi/lib/libc.a" "$OUTPUT_DIR" |
| 84 | +cp "${INSTALL}/arm-none-eabi/lib/libm.a" "$OUTPUT_DIR" |
| 85 | + |
0 commit comments