Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Install binutils alongside agbcc #45

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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/
31 changes: 31 additions & 0 deletions binutils/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/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
MAKEINFO=false \
"../$src/configure" \
--prefix= \
--target=arm-none-eabi \
--disable-nls
make -j "${NPROC:-$(nproc)}"
4 changes: 4 additions & 0 deletions binutils/clean.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh

rm -rf binutils-*/
rm -rf build
23 changes: 13 additions & 10 deletions build.sh
Original file line number Diff line number Diff line change
@@ -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 .
2 changes: 1 addition & 1 deletion gcc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
srcdir = .
VPATH = $(srcdir)

CC = gcc
CC ?= gcc

BASE_CFLAGS = -g -std=gnu11 -Werror-implicit-function-declaration

Expand Down
32 changes: 19 additions & 13 deletions install.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
#!/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/

default_dest=/opt/agbcc

if [ $# -ge 1 ]; then
dest="$(realpath "$1")"
else
echo "Usage: install.sh PATH"
echo "INFO: Missing parameter, defaulting to installing in $default_dest" 1>&2
dest="$default_dest"
fi

# Check if we can access $dest
if [ -d "$dest" -a ! -w "$dest" ] || ! install -d "$dest" 2> /dev/null; then
echo "ERROR: Can't access directory '$dest'. Are you sure you have sufficient permissions? (hint: use 'sudo ./install.sh')" 1>&2
exit 1
fi

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
21 changes: 3 additions & 18 deletions libc/Makefile
Original file line number Diff line number Diff line change
@@ -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 \
Expand Down
23 changes: 4 additions & 19 deletions libgcc/Makefile
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -94,4 +79,4 @@ dp-bit.c: fp-bit-base.c
.PHONY: clean

clean:
rm -f *.o *.a *.s *.i
rm -f *.o *.a *.s *.i