Skip to content

Commit

Permalink
Build all cross-compilers with OBGGCC
Browse files Browse the repository at this point in the history
  • Loading branch information
Kartatz committed May 9, 2023
1 parent e9c21fc commit 304bf94
Show file tree
Hide file tree
Showing 7 changed files with 170 additions and 49 deletions.
23 changes: 0 additions & 23 deletions .github/workflows/build.yml

This file was deleted.

3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "submodules/obggcc"]
path = submodules/obggcc
url = https://github.com/AmanoTeam/obggcc
19 changes: 17 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
# n3tbsdcr0ss
# Dakini

A GCC cross-compiler targeting NetBSD 8.0.

## Target architectures

We currently build cross-compilers targeting many NetBSD architectures. See above for more info:

* `alpha-unknown-netbsd`
* `hppa-unknown-netbsd`
* `i386-unknown-netbsdelf`
* `mips-unknown-netbsd`
* `powerpc-unknown-netbsd`
* `shle-unknown-netbsdelf`
* `sparc-unknown-netbsdelf`
* `sparc64-unknown-netbsd`
* `vax-unknown-netbsdelf`
* `x86_64-unknown-netbsd`

## Releases

You can obtain releases from the [releases](https://github.com/AmanoTeam/n3tbsdcr0ss/releases) page.
You can obtain releases from the [releases](https://github.com/AmanoTeam/Dakini/releases) page.
106 changes: 82 additions & 24 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/bin/bash

set -e
set -u
set -eu

declare -r revision="$(git rev-parse --short HEAD)"

Expand All @@ -22,7 +21,10 @@ declare -r binutils_directory='/tmp/binutils-2.40'
declare -r gcc_tarball='/tmp/gcc.tar.xz'
declare -r gcc_directory='/tmp/gcc-12.2.0'

declare -r cflags='-Os -s -DNDEBUG'
declare -r optflags='-Os'
declare -r linkflags='-Wl,-s'

source "./submodules/obggcc/toolchains/${1}.sh"

if ! [ -f "${gmp_tarball}" ]; then
wget --no-verbose 'https://ftp.gnu.org/gnu/gmp/gmp-6.2.1.tar.xz' --output-document="${gmp_tarball}"
Expand All @@ -49,50 +51,61 @@ if ! [ -f "${gcc_tarball}" ]; then
tar --directory="$(dirname "${gcc_directory}")" --extract --file="${gcc_tarball}"
fi

while read file; do
sed -i "s/-O2/${cflags}/g" "${file}"
done <<< "$(find '/tmp' -type 'f' -wholename '*configure')"

[ -d "${gcc_directory}/build" ] || mkdir "${gcc_directory}/build"

declare -r toolchain_directory="/tmp/unknown-unknown-netbsd"
declare -r toolchain_directory="/tmp/dakini"

[ -d "${gmp_directory}/build" ] || mkdir "${gmp_directory}/build"

cd "${gmp_directory}/build"
rm --force --recursive ./*

../configure \
--host="${CROSS_COMPILE_TRIPLET}" \
--prefix="${toolchain_directory}" \
--enable-shared \
--enable-static
--enable-static \
CFLAGS="${optflags}" \
CXXFLAGS="${optflags}" \
LDFLAGS="${linkflags}"

make all --jobs="$(nproc)"
make all --jobs="$(($(nproc) * 8))"
make install

[ -d "${mpfr_directory}/build" ] || mkdir "${mpfr_directory}/build"

cd "${mpfr_directory}/build"
rm --force --recursive ./*

../configure \
--host="${CROSS_COMPILE_TRIPLET}" \
--prefix="${toolchain_directory}" \
--with-gmp="${toolchain_directory}" \
--enable-shared \
--enable-static
--enable-static \
CFLAGS="${optflags}" \
CXXFLAGS="${optflags}" \
LDFLAGS="${linkflags}"

make all --jobs="$(nproc)"
make all --jobs="$(($(nproc) * 8))"
make install

[ -d "${mpc_directory}/build" ] || mkdir "${mpc_directory}/build"

cd "${mpc_directory}/build"
rm --force --recursive ./*

../configure \
--host="${CROSS_COMPILE_TRIPLET}" \
--prefix="${toolchain_directory}" \
--with-gmp="${toolchain_directory}" \
--enable-shared \
--enable-static
--enable-static \
CFLAGS="${optflags}" \
CXXFLAGS="${optflags}" \
LDFLAGS="${linkflags}"

make all --jobs="$(nproc)"
make all --jobs="$(($(nproc) * 8))"
make install

sed -i 's/#include <stdint.h>/#include <stdint.h>\n#include <stdio.h>/g' "${toolchain_directory}/include/mpc.h"
Expand Down Expand Up @@ -151,18 +164,36 @@ for target in "${targets[@]}"; do
rm --force --recursive ./*

../configure \
--host="${CROSS_COMPILE_TRIPLET}" \
--target="${triple}" \
--prefix="${toolchain_directory}" \
--enable-gold \
--enable-ld
--enable-ld \
--enable-lto \
--disable-gprofng \
--with-static-standard-libraries \
--program-prefix="${triple}-" \
CFLAGS="${optflags}" \
CXXFLAGS="${optflags}" \
LDFLAGS="${linkflags}"

make all --jobs="$(nproc)"
make all --jobs="$(($(nproc) * 8))"
make install

tar --directory="${toolchain_directory}/${triple}" --strip=2 --extract --file="${base_output}" './usr/lib' './usr/include'
tar --directory="${toolchain_directory}/${triple}" --extract --file="${base_output}" './lib'
tar --directory="${toolchain_directory}/${triple}" --strip=2 --extract --file="${comp_output}" './usr/lib' './usr/include'

cd "${toolchain_directory}/${triple}/lib"

while read filename; do
if [[ "${filename}" =~ ^lib(pthread|resolv|rt|c|m|util)\.(so|a).* || "${filename}" =~ ^.*\.o$ ]]; then
continue
fi

rm --recursive "${filename}"
done <<< "$(ls)"

cd "${gcc_directory}/build"

rm --force --recursive ./*
Expand All @@ -177,15 +208,22 @@ for target in "${targets[@]}"; do
extra_configure_flags+='--with-float=soft '
fi

declare CFLAGS_FOR_TARGET="${optflags} ${linkflags}"
declare CXXFLAGS_FOR_TARGET="${optflags} ${linkflags}"

if [ "${target}" == 'hpcsh' ]; then
CXXFLAGS_FOR_TARGET+=' -include sh3/fenv.h'
fi

../configure \
--host="${CROSS_COMPILE_TRIPLET}" \
--target="${triple}" \
--prefix="${toolchain_directory}" \
--with-linker-hash-style='sysv' \
--with-gmp="${toolchain_directory}" \
--with-mpc="${toolchain_directory}" \
--with-mpfr="${toolchain_directory}" \
--with-system-zlib \
--with-bugurl='https://github.com/AmanoTeam/n3tbsdcr0ss/issues' \
--with-bugurl='https://github.com/AmanoTeam/Dakini/issues' \
--enable-__cxa_atexit \
--enable-cet='auto' \
--enable-checking='release' \
Expand All @@ -208,17 +246,37 @@ for target in "${targets[@]}"; do
--without-headers \
--enable-ld \
--enable-gold \
--with-pic \
--with-gcc-major-version-only \
--with-pkgversion="n3tbsdcr0ss v0.1-${revision}" \
--with-pkgversion="Dakini v0.3-${revision}" \
--with-sysroot="${toolchain_directory}/${triple}" \
--with-native-system-header-dir='/include' \
${extra_configure_flags}
--disable-nls \
${extra_configure_flags} \
CFLAGS="${optflags}" \
CXXFLAGS="${optflags}" \
LDFLAGS="-Wl,-rpath-link,${OBGGCC_TOOLCHAIN}/${CROSS_COMPILE_TRIPLET}/lib ${linkflags}"

LD_LIBRARY_PATH="${toolchain_directory}/lib" PATH="${PATH}:${toolchain_directory}/bin" make CFLAGS_FOR_TARGET="${cflags}" CXXFLAGS_FOR_TARGET="${cflags}" all --jobs="$(nproc)"
LD_LIBRARY_PATH="${toolchain_directory}/lib" PATH="${PATH}:${toolchain_directory}/bin" make \
CFLAGS_FOR_TARGET="${CFLAGS_FOR_TARGET}" \
CXXFLAGS_FOR_TARGET="${CXXFLAGS_FOR_TARGET}" \
all --jobs="$(($(nproc) * 8))"
make install

cd "${toolchain_directory}/${triple}/bin"

for name in *; do
rm "${name}"
ln -s "../../bin/${triple}-${name}" "${name}"
done

rm --recursive "${toolchain_directory}/share"
rm --recursive "${toolchain_directory}/lib/gcc/${triple}/12/include-fixed"

if [ "${CROSS_COMPILE_TRIPLET}" == "${triple}" ]; then
rm "${toolchain_directory}/bin/${triple}-${triple}"*
fi

patchelf --add-rpath '$ORIGIN/../../../../lib' "${toolchain_directory}/libexec/gcc/${triple}/12/cc1"
patchelf --add-rpath '$ORIGIN/../../../../lib' "${toolchain_directory}/libexec/gcc/${triple}/12/cc1plus"
patchelf --add-rpath '$ORIGIN/../../../../lib' "${toolchain_directory}/libexec/gcc/${triple}/12/lto1"
done

tar --directory="$(dirname "${toolchain_directory}")" --create --file=- "$(basename "${toolchain_directory}")" | xz --threads=0 --compress -9 > "${toolchain_tarball}"
39 changes: 39 additions & 0 deletions build_all.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash

set -eu

declare -ra targets=(
'alpha-unknown-linux-gnu'
'x86_64-unknown-linux-gnu'
'i386-unknown-linux-gnu'
'arm-unknown-linux-gnueabi'
'arm-unknown-linux-gnueabihf'
'hppa-unknown-linux-gnu'
'aarch64-unknown-linux-gnu'
'mips-unknown-linux-gnu'
'mipsel-unknown-linux-gnu'
'powerpc-unknown-linux-gnu'
's390-unknown-linux-gnu'
's390x-unknown-linux-gnu'
'sparc-unknown-linux-gnu'
'powerpc64le-unknown-linux-gnu'
'mips64el-unknown-linux-gnuabi64'
)

declare -r tarballs_directory="${PWD}/dakini-tarballs"

[ -d "${tarballs_directory}" ] || mkdir "${tarballs_directory}"

source './tools/setup_toolchain.sh'
source './submodules/obggcc/tools/setup_toolchain.sh'

for target in "${targets[@]}"; do
bash './build.sh' "${target}"

declare tarball_filename="${tarballs_directory}/${target}.tar.xz"

tar --directory='/tmp' --create --file=- 'dakini' | xz --threads=0 --compress -9 > "${tarball_filename}"
sha256sum "${tarball_filename}" > "${tarball_filename}.sha256"

rm --recursive --force '/tmp/dakini'
done
1 change: 1 addition & 0 deletions submodules/obggcc
Submodule obggcc added at dd6cd0
28 changes: 28 additions & 0 deletions tools/setup_toolchain.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash

set -eu

declare -r DAKINI_HOME='/tmp/dakini-toolchain'

if [ -d "${DAKINI_HOME}" ]; then
PATH+=":${DAKINI_HOME}/bin"
export DAKINI_HOME \
PATH
return 0
fi

declare -r DAKINI_CROSS_TAG="$(jq --raw-output '.tag_name' <<< "$(curl --retry 10 --retry-delay 3 --silent --url 'https://api.github.com/repos/AmanoTeam/Dakini/releases/latest')")"
declare -r DAKINI_CROSS_TARBALL='/tmp/daiki.tar.xz'
declare -r DAKINI_CROSS_URL="https://github.com/AmanoTeam/Dakini/releases/download/${DAKINI_CROSS_TAG}/x86_64-unknown-linux-gnu.tar.xz"

curl --retry 10 --retry-delay 3 --silent --location --url "${DAKINI_CROSS_URL}" --output "${DAKINI_CROSS_TARBALL}"
tar --directory="$(dirname "${DAKINI_CROSS_TARBALL}")" --extract --file="${DAKINI_CROSS_TARBALL}"

rm "${DAKINI_CROSS_TARBALL}"

mv '/tmp/dakini' "${DAKINI_HOME}"

PATH+=":${DAKINI_HOME}/bin"

export DAKINI_HOME \
PATH

0 comments on commit 304bf94

Please sign in to comment.