#!/bin/bash # This file is part of Jehanne. # # Copyright (C) 2017 Giacomo Tesio # # Jehanne is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, version 2 of the License. # # Jehanne is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with Jehanne. If not, see . if [ "$JEHANNE" = "" ]; then echo $0 requires the shell started by ./hacking/devshell.sh exit 1 fi export CROSS_DIR=$JEHANNE/hacking/cross export NEWLIB=$CROSS_DIR/pkgs/newlib/ export NEWLIB_SRC=$NEWLIB/src/ export NEWLIB_BUILD=$NEWLIB/build/ export NEWLIB_PREFIX=$NEWLIB/output/ export LD_PRELOAD= echo -n Building newlib. ( # Inside parentheses, and therefore a subshell . . . while [ 1 ] # Endless loop. do echo -n "." sleep 3 done ) & dotter=$! function failOnError { # $1 -> exit status on a previous command # $2 -> task description if [ $1 -ne 0 ]; then kill $dotter wait $dotter 2>/dev/null echo "ERROR $2" if [ "$TRAVIS_BUILD_DIR" != "" ]; then echo echo "CONFIG.LOG @ $NEWLIB_BUILD/config.log" echo cat $NEWLIB_BUILD/config.log cat $NEWLIB/newlib.build.log fi exit $1 fi } if [ "$NEWLIB_OPTIMIZATION" = "" ]; then NEWLIB_OPTIMIZATION=2 fi export CC=gcc export CFLAGS_FOR_TARGET="-g -gdwarf-2 -ggdb -O$NEWLIB_OPTIMIZATION -std=gnu11 -I$JEHANNE_TOOLCHAIN/cross/posix/lib/gcc/x86_64-jehanne/9.2.0/include -Lposix" ( rm -fr $NEWLIB_BUILD && rm -fr $NEWLIB_PREFIX && mkdir $NEWLIB_BUILD && mkdir $NEWLIB_PREFIX && cd $NEWLIB_BUILD && $NEWLIB_SRC/configure --enable-newlib-mb --disable-newlib-fvwrite-in-streamio --prefix=/pkgs/newlib --target=x86_64-jehanne && make all && make DESTDIR=$NEWLIB_PREFIX install && rm -fr $JEHANNE/sys/posix/newlib && rm -fr $JEHANNE/arch/amd64/lib/newlib && cp -fr $NEWLIB_PREFIX/pkgs/newlib/ $JEHANNE/pkgs/ && echo "Newlib headers installed at $JEHANNE/pkgs/newlib/" ) >> $NEWLIB/newlib.build.log 2>&1 failOnError $? "building newlib" # emultate bind for the cross compiler mkdir -p $JEHANNE/posix cp -fr $JEHANNE/pkgs/newlib/x86_64-jehanne/* $JEHANNE/posix # rename libc to libnewlibc to avoid name clash with Jehanne's libc mv $JEHANNE/posix/lib/libc.a $JEHANNE/posix/lib/libnewlibc.a kill $dotter wait $dotter 2>/dev/null echo "done" exit 0;