From fc283d8fc7849e742b68ffc8833ea9dc5730d469 Mon Sep 17 00:00:00 2001 From: mid-kid Date: Sun, 31 Oct 2021 16:00:32 +0100 Subject: [PATCH] Install binutils alongside agbcc Remove the need for devkitarm --- .gitignore | 3 +++ binutils/build.sh | 30 ++++++++++++++++++++++++++++++ binutils/clean.sh | 4 ++++ build.sh | 23 +++++++++++++---------- gcc/Makefile | 2 +- install.sh | 17 ++++++----------- libc/Makefile | 21 +++------------------ libgcc/Makefile | 23 ++++------------------- 8 files changed, 64 insertions(+), 59 deletions(-) create mode 100755 binutils/build.sh create mode 100755 binutils/clean.sh diff --git a/.gitignore b/.gitignore index 18dd6981..0c45b5b6 100644 --- a/.gitignore +++ b/.gitignore @@ -51,3 +51,6 @@ gcc_arm/s-peep gcc_arm/s-recog gcc_arm/tree-check.h +binutils/binutils-*.tar.xz +binutils/binutils-*/ +binutils/build/ diff --git a/binutils/build.sh b/binutils/build.sh new file mode 100755 index 00000000..6373d2a6 --- /dev/null +++ b/binutils/build.sh @@ -0,0 +1,30 @@ +#!/bin/sh +set -e + +version=2.37 +shasum=820d9724f020a3e69cb337893a0b63c2db161dadcb0e06fc11dc29eb1e84a32c +src=binutils-$version +tarball=binutils-$version.tar.xz + +checksum() { + test -f "$1" || return 1 + sha="$(sha256sum "$1" | cut -d ' ' -f 1)" + test "$sha" = "$2" || return 1 + return 0 +} + +checksum "$tarball" "$shasum" || wget -c "https://ftp.gnu.org/gnu/binutils/$tarball" +if ! checksum "$tarball" "$shasum"; then + sha256sum "$tarball" 1>&2 + echo "Checksum failed!" 1>&2 + rm -f "$tarball" +fi + +test -d "$src" || tar xf "$tarball" +mkdir -p build +cd build +"../$src/configure" \ + --prefix= \ + --target=arm-none-eabi \ + --disable-nls +MAKEINFO=false make -j "${NPROC:-$(nproc)}" diff --git a/binutils/clean.sh b/binutils/clean.sh new file mode 100755 index 00000000..ee7fd443 --- /dev/null +++ b/binutils/clean.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +rm -rf binutils-*/ +rm -rf build diff --git a/build.sh b/build.sh index 63a5d325..ffab26a0 100755 --- a/build.sh +++ b/build.sh @@ -1,23 +1,26 @@ #!/bin/sh set -e -CCOPT= -CXXOPT= -if [ ! -z "$CC" ]; then CCOPT=CC=$CC; fi -if [ ! -z "$CXX" ]; then CXXOPT=CXX=$CXX; fi +(cd binutils + ./clean.sh + ./build.sh +) make -C gcc clean -make -C gcc old $CCOPT $CXXOPT +make -C gcc old mv gcc/old_agbcc . make -C gcc clean -make -C gcc $CCOPT $CXXOPT +make -C gcc mv gcc/agbcc . # not sure if the ARM compiler is the old one or the new one (-DOLD_COMPILER) -rm -f gcc_arm/config.status gcc_arm/config.cache -cd gcc_arm && ./configure --target=arm-elf --host=i386-linux-gnu && make cc1 && cd .. +( cd gcc_arm + rm -f config.status config.cache + ./configure --target=arm-elf --host=i386-linux-gnu + make cc1 +) mv gcc_arm/cc1 agbcc_arm make -C libgcc clean -make -C libgcc $CCOPT $CXXOPT +make -C libgcc mv libgcc/libgcc.a . make -C libc clean -make -C libc $CCOPT $CXXOPT +make -C libc mv libc/libc.a . diff --git a/gcc/Makefile b/gcc/Makefile index 9756e901..dd869bac 100644 --- a/gcc/Makefile +++ b/gcc/Makefile @@ -22,7 +22,7 @@ srcdir = . VPATH = $(srcdir) -CC = gcc +CC ?= gcc BASE_CFLAGS = -g -std=gnu11 -Werror-implicit-function-declaration diff --git a/install.sh b/install.sh index 608d82df..edbcab78 100755 --- a/install.sh +++ b/install.sh @@ -1,17 +1,12 @@ #!/bin/sh set -e if [ "$1" != "" ]; then - mkdir -p $1/tools/agbcc - mkdir -p $1/tools/agbcc/bin - mkdir -p $1/tools/agbcc/include - mkdir -p $1/tools/agbcc/lib - cp agbcc $1/tools/agbcc/bin/ - cp old_agbcc $1/tools/agbcc/bin/ - cp agbcc_arm $1/tools/agbcc/bin/ - cp -R libc/include $1/tools/agbcc/ #drop include, because we don't want include/include - cp ginclude/* $1/tools/agbcc/include/ - cp libgcc.a $1/tools/agbcc/lib/ - cp libc.a $1/tools/agbcc/lib/ + dest="$(realpath "$1/tools/agbcc")" + install -Dm755 -t "$dest/bin" agbcc old_agbcc agbcc_arm + install -Dm644 -t "$dest/lib" libgcc.a libc.a + install -Dm644 -t "$dest/include" ginclude/* + cp -R libc/include "$dest/" #drop include, because we don't want include/include + make -C binutils/build DESTDIR="$dest" install else echo "Usage: install.sh PATH" fi diff --git a/libc/Makefile b/libc/Makefile index d9de489f..9a60cd05 100644 --- a/libc/Makefile +++ b/libc/Makefile @@ -1,25 +1,10 @@ -ifneq (,$(DEVKITARM)) - ifneq (,$(wildcard $(DEVKITARM)/bin)) - include $(DEVKITARM)/base_tools - DKA_EXISTS=1 - else - DKA_EXISTS=0 - endif -else -DKA_EXISTS=0 -endif - -ifneq ($(DKA_EXISTS),1) -PREFIX := arm-none-eabi- -export AR := $(PREFIX)ar -export AS := $(PREFIX)as -endif - SHELL := /bin/bash -o pipefail ASFLAGS := -mcpu=arm7tdmi -CC1 := ../old_agbcc +AR := ../binutils/build/binutils/ar +AS := ../binutils/build/gas/as-new +CC1 := ../old_agbcc CFLAGS := -O2 -fno-builtin CPPFLAGS := -I ../ginclude -I include -nostdinc -undef \ diff --git a/libgcc/Makefile b/libgcc/Makefile index 0e96527d..7701e783 100644 --- a/libgcc/Makefile +++ b/libgcc/Makefile @@ -1,21 +1,6 @@ -ifneq (,$(DEVKITARM)) - ifneq (,$(wildcard $(DEVKITARM)/bin)) - include $(DEVKITARM)/base_tools - DKA_EXISTS=1 - else - DKA_EXISTS=0 - endif -else -DKA_EXISTS=0 -endif - -ifneq ($(DKA_EXISTS),1) -PREFIX := arm-none-eabi- -export AR := $(PREFIX)ar -export AS := $(PREFIX)as -endif - -CC1 = ../old_agbcc +AR := ../binutils/build/binutils/ar +AS := ../binutils/build/gas/as-new +CC1 := ../old_agbcc libgcc.a: libgcc1.a libgcc2.a fp-bit.o dp-bit.o $(AR) -x libgcc1.a; @@ -94,4 +79,4 @@ dp-bit.c: fp-bit-base.c .PHONY: clean clean: - rm -f *.o *.a *.s *.i \ No newline at end of file + rm -f *.o *.a *.s *.i