diff --git a/giteapc.make b/giteapc.make index c2c8e51..8cbb896 100644 --- a/giteapc.make +++ b/giteapc.make @@ -1,25 +1,25 @@ # giteapc: version=1 PREFIX ?= $(GITEAPC_PREFIX) -VERSION_BINUTILS = 2.37 -VERSION_GCC = 11.2 +VERSION_BINUTILS := 2.37 +VERSION_GCC := 11.2 -include giteapc-config.make configure: - @ ./configure.sh --binutils $(VERSION_BINUTILS) "$(PREFIX)" - @ ./configure.sh --gcc $(VERSION_GCC) "$(PREFIX)" + @ ./scripts/binutils/configure --version=$(VERSION_BINUTILS) + @ ./scripts/gcc/configure.sh --version=$(VERSION_GCC) build: - @ ./build.sh --binutils - @ ./build.sh --gcc + @ ./scripts/binutils/build.sh + @ ./scripts/gcc/build.sh install: - @ ./install.sh --binutils "$(PREFIX)" - @ ./install.sh --gcc "$(PREFIX)" + @ ./scripts/binutils/install.sh --prefix="$(PREFIX)" + @ ./scripts/gcc/install.sh --prefix="$(PREFIX)" uninstall: - @ ./uninstall.sh --binutils "$(PREFIX)" - @ ./uninstall.sh --gcc "$(PREFIX)" + @ ./scripts/binutils/uninstall.sh --prefix="$(PREFIX)" + @ ./scripts/gcc/uninstall.sh --prefix="$(PREFIX)" .PHONY: configure build install uninstall diff --git a/scripts/binutils/build.sh b/scripts/binutils/build.sh index 80994ca..63b2ffe 100755 --- a/scripts/binutils/build.sh +++ b/scripts/binutils/build.sh @@ -47,17 +47,16 @@ TAG='' [[ ! -d ../../build/binutils/build ]] && exit 0 cd ../../build/binutils/build -# Number of processor cores -[[ $(uname) == "OpenBSD" ]] && cores=$(sysctl -n hw.ncpu) || cores=$(nproc) -# selecte make utility -[[ $(command -v gmake >/dev/null 2>&1) ]] && make_cmd=gmake || make_cmd=make +# import some utility +source ../../../scripts/utils.sh + +# build part echo "$TAG Compiling binutils (usually 5-10 minutes)..." -if [[ "$verbose" == 'false' ]]; then - source ../../../scripts/util.sh - run_quietly giteapc-build.log $make_cmd -j"$cores" -else - $make_cmd -j"$cores" -fi +$quiet $make_cmd -j"$cores" + +echo "$TAG Installing to local folder..." + +$quiet $make_cmd install-strip diff --git a/scripts/binutils/configure.sh b/scripts/binutils/configure.sh index 1f33ec3..2e281f7 100755 --- a/scripts/binutils/configure.sh +++ b/scripts/binutils/configure.sh @@ -2,7 +2,7 @@ verbose=false -no_cache=false +cache=false version='?' prefix= @@ -20,9 +20,8 @@ Usage $0 [options...] Configurations: -h, --help Display this help - --no-cache Do not keep the archive of binutils + --cache Keep the archive of binutils --verbose Display extra information during the configuration step - --prefix= Installation prefix --version= Select the binutils version. If the '?' argument is passed then all binutils version with Vhex patch availables will be printed @@ -41,7 +40,7 @@ OEF for arg; do case "$arg" in --help | -h) help;; --verbose) verbose=true;; - --no-cache) no_cache=true;; + --cache) cache=true;; --prefix=*) prefix=${arg#*=};; --version=*) version=${arg#*=};; *) @@ -77,13 +76,12 @@ fi TAG='' VERSION=$version -PREFIX="$prefix" URL="https://ftp.gnu.org/gnu/binutils/binutils-$VERSION.tar.xz" ARCHIVE="../../cache/$(basename $URL)" # Avoid rebuilds of the same version -existing_as="$PREFIX/bin/sh-elf-vhex-as" +existing_as="../../build/binutils/bin/sh-elf-vhex-as" if [[ -f "$existing_as" ]]; then existing_version=$($existing_as --version | head -n 1 | grep -Eo '[0-9.]+$') @@ -209,21 +207,16 @@ if command -v termux-setup-storage >/dev/null 2>&1; then CXXFLAGS="-D__ANDROID_API__=$(getprop ro.build.version.sdk) -g -O2" fi -# Real configuration step -if [[ "$verbose" == "true" ]]; then - ../binutils-$VERSION/configure --prefix="$PREFIX" --target=sh-elf-vhex \ - --with-multilib-list=m3,m4-nofpu --disable-nls --enable-lto -else - source ../../../scripts/util.sh - run_quietly giteapc-configure.log \ - ../binutils-$VERSION/configure --prefix="$PREFIX" --target=sh-elf-vhex \ - --with-multilib-list=m3,m4-nofpu --disable-nls --enable-lto -fi -cd .. +# check quiet mode +source ../../../scripts/utils.sh + +# Real configuration step +$quiet ../binutils-$VERSION/configure --prefix="$PREFIX" --target=sh-elf-vhex \ + --with-multilib-list=m3,m4-nofpu --disable-nls --enable-lto # cache management -if [[ "$no_cache" == 'true' ]]; then +if [[ "$cache" == 'false' ]]; then echo "$TAG Removing $ARCHIVE..." rm -f $ARCHIVE fi diff --git a/scripts/binutils/install.sh b/scripts/binutils/install.sh index ba9313b..49d1fd1 100755 --- a/scripts/binutils/install.sh +++ b/scripts/binutils/install.sh @@ -57,30 +57,7 @@ PREFIX="$prefix" # Avoid rebuilds of the same version [[ ! -d ../../build/binutils/build ]] && exit 0 -cd ../../build/binutils/build - -# add utilities - -source ../../../scripts/util.sh - - -# check gmake or make (macos support) - -if command -v gmake >/dev/null 2>&1; then - make_command=gmake -else - make_command=make -fi - -# build part - -echo "$TAG Installing to local folder..." -if [[ "$verbose" == 'true' ]]; then - $make_command install-strip -else - run_quietly giteapc-install.log $make_command install-strip -fi -cd .. +cd ../../build/binutils # Symbolic link executables to $PREFIX/bin diff --git a/scripts/binutils/uninstall.sh b/scripts/binutils/uninstall.sh index 28c7401..8fb33c5 100755 --- a/scripts/binutils/uninstall.sh +++ b/scripts/binutils/uninstall.sh @@ -46,6 +46,11 @@ esac; done TAG='' PREFIX="$prefix" +# Avoid rebuilds of the same version + +[[ ! -d ../../build/binutils ]] && exit 0 +cd ../../build/binutils + # Remove symlinks echo "$TAG Removing symlinks to binaries..." for x in bin/*; do @@ -54,4 +59,4 @@ done # Remove local files echo "$TAG Removing installed files..." -rm -rf ../../build/binutils +rm -rf ../binutils diff --git a/scripts/compile.sh b/scripts/compile.sh index eefa052..c22f808 100755 --- a/scripts/compile.sh +++ b/scripts/compile.sh @@ -2,12 +2,8 @@ echo "Compil and install binutils" cd binutils -./configure.sh --version=2.37 --prefix=/tmp \ -&& ./build.sh \ -&& ./install.sh --prefix=/tmp +./configure.sh --version=2.37 && ./build.sh && ./install.sh --prefix=/tmp echo "Compil and install GCC" cd ../gcc -./configure.sh --version=11.2.0 --prefix=/tmp \ -&& ./build.sh -#&& ./install.sh --prefix=/home/yann/CASIO/vhex-compiler/sh-elf-vhex/scripts +./configure.sh --version=11.2.0 && ./build.sh && ./install.sh --prefix=/tmp diff --git a/scripts/gcc/build.sh b/scripts/gcc/build.sh index 8a1fa89..cbb7925 100755 --- a/scripts/gcc/build.sh +++ b/scripts/gcc/build.sh @@ -56,16 +56,7 @@ esac; done TAG='' # import utility -source ../util.sh - -# Number of processor cores -[[ $(uname) == "OpenBSD" ]] && cores=$(sysctl -n hw.ncpu) || cores=$(nproc) - -# check macos make utility -[[ $(command -v gmake >/dev/null 2>&1) ]] && make_cmd=gmake || make_cmd=make - -# check quiet build -[[ "$verbose" == "true" ]] && quiet='' || quiet='run_quietly giteapc-build.log' +source ../utils.sh # OpenBSD apparently installs these in /usr/local extra_args= diff --git a/scripts/gcc/configure.sh b/scripts/gcc/configure.sh index 629bdfc..13793b0 100755 --- a/scripts/gcc/configure.sh +++ b/scripts/gcc/configure.sh @@ -1,9 +1,8 @@ #! /usr/bin/env bash verbose=false -no_cache=false +cache=false version='?' -prefix= # @@ -21,7 +20,6 @@ Configurations: -h, --help Display this help --no-cache Do not keep the archive of binutils --verbose Display extra information during the configuration step - --prefix= Installation prefix --version= Select the GCC version. If the '?' argument is passed then all binutils version with Vhex patch availables will be printed @@ -40,8 +38,7 @@ OEF for arg; do case "$arg" in --help | -h) help;; --verbose) verbose=true;; - --no-cache) no_cache=true;; - --prefix=*) prefix=${arg#*=};; + --cache) cache=true;; --version=*) version=${arg#*=};; *) echo "error: unreconized argument '$arg', giving up." >&2 @@ -74,20 +71,19 @@ fi TAG='' VERSION="$version" -PREFIX="$prefix" URL="https://ftp.gnu.org/gnu/gcc/gcc-$VERSION/gcc-$VERSION.tar.xz" ARCHIVE="../../cache/$(basename $URL)" # Avoid rebuilds of the same version -existing_gcc="$PREFIX/bin/sh-elf-vhex-gcc" +existing_gcc="../../build/gcc/bin/sh-elf-vhex-gcc" if [[ -f "$existing_gcc" ]]; then existing_version=$($existing_gcc --version | head -n 1 | grep -Eo '[0-9.]+$') if [[ $existing_version == $VERSION ]]; then echo "$TAG Version $VERSION already installed, skipping rebuild" - if [[ -e build ]]; then - rm -rf build + if [[ -e ../../build/gcc/build ]]; then + rm -rf ../../build/gcc/build fi exit 0 fi @@ -132,15 +128,15 @@ mv ./gcc-$VERSION/ ./gcc # Symlink as, ld, ar and ranlib, which gcc will not find by itself (we renamed # them from sh3eb-elf-* to sh-elf-* with --program-prefix). mkdir -p sh-elf-vhex/bin -ln -sf $PREFIX/bin/sh-elf-vhex-as sh-elf-vhex/bin/as -ln -sf $PREFIX/bin/sh-elf-vhex-ld sh-elf-vhex/bin/ld -ln -sf $PREFIX/bin/sh-elf-vhex-ar sh-elf-vhex/bin/ar -ln -sf $PREFIX/bin/sh-elf-vhex-ranlib sh-elf-vhex/bin/ranlib +ln -sf $(pwd)/../binutils/bin/sh-elf-vhex-as sh-elf-vhex/bin/as +ln -sf $(pwd)/../binutils/bin/sh-elf-vhex-ld sh-elf-vhex/bin/ld +ln -sf $(pwd)/../binutils/bin/sh-elf-vhex-ar sh-elf-vhex/bin/ar +ln -sf $(pwd)/../binutils/bin/sh-elf-vhex-ranlib sh-elf-vhex/bin/ranlib -# patch OpenLibM building error (find for sh-elf-vhex-ar) -ln -sf $PREFIX/bin/sh-elf-vhex-ar sh-elf-vhex/bin/sh-elf-vhex-ar +# patch OpenLibM building error (which search for sh-elf-vhex-ar) +ln -sf $(pwd)/../binutils/bin/sh-elf-vhex-ar sh-elf-vhex/bin/sh-elf-vhex-ar -if [[ "$no_cache" == 'true' ]]; then +if [[ "$cache" == 'false' ]]; then echo "$TAG Removing $ARCHIVE..." rm -f $ARCHIVE fi diff --git a/scripts/gcc/uninstall.sh b/scripts/gcc/uninstall.sh index 0fd10b8..f196630 100755 --- a/scripts/gcc/uninstall.sh +++ b/scripts/gcc/uninstall.sh @@ -29,6 +29,8 @@ OEF # Parse argument # +[[ $# -eq 0 ]] && help + for arg; do case "$arg" in --help | -h) help;; --verbose) verbose=true;; @@ -46,6 +48,11 @@ esac; done TAG='' PREFIX="$prefix" +# Avoid rebuilds of the same version + +[[ ! -d ../../build/gcc ]] && exit 0 +cd ../../build/gcc + # Remove symlinks echo "$TAG Removing symlinks to binaries..." for x in bin/*; do @@ -54,4 +61,5 @@ done # Remove local files echo "$TAG Removing installed files..." -rm -rf ../../build/gcc +rm -rf ../gcc +exit 0 diff --git a/scripts/util.sh b/scripts/util.sh deleted file mode 100644 index 366954d..0000000 --- a/scripts/util.sh +++ /dev/null @@ -1,9 +0,0 @@ -run_quietly() { - out="$1" - shift 1 - "$@" >$out 2>&1 - if [[ "$?" != 0 ]]; then - echo "$TAG error: build failed, please check $(pwd)/$out o(x_x)o" - exit 1 - fi -} diff --git a/scripts/utils.sh b/scripts/utils.sh new file mode 100644 index 0000000..23a4971 --- /dev/null +++ b/scripts/utils.sh @@ -0,0 +1,30 @@ + +# select the appropriate quiet primitive +quiet='run_normaly' +[[ "$verbose" == "false" ]] && quiet='run_quietly giteapc-build.log' + +# Number of processor cores +[[ $(uname) == "OpenBSD" ]] && cores=$(sysctl -n hw.ncpu) || cores=$(nproc) + +# selecte make utility +[[ $(command -v gmake >/dev/null 2>&1) ]] && make_cmd=gmake || make_cmd=make + +## functions privided + +run_normaly() { + bash -c "$@" + if [[ "$?" != 0 ]]; then + echo "$TAG error: command failed, abord" + exit 1 + fi +} + +run_quietly() { + out="$1" + shift 1 + "$@" >$out 2>&1 + if [[ "$?" != 0 ]]; then + echo "$TAG error: command failed, please check $(pwd)/$out o(x_x)o" + exit 1 + fi +}