diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml deleted file mode 100644 index 3c4388a..0000000 --- a/.github/workflows/build.yml +++ /dev/null @@ -1,23 +0,0 @@ -name: Build - -on: - push: - branches: - - '**' - -jobs: - build: - concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@main - with: - submodules: true - - name: Run build script - run: bash ./build.sh - - name: Upload artifact - uses: actions/upload-artifact@main - with: - path: ./netbsd-cross.tar.xz \ No newline at end of file diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..013bb83 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "submodules/obggcc"] + path = submodules/obggcc + url = https://github.com/AmanoTeam/obggcc diff --git a/README.md b/README.md index 8f8a00d..00a0c8e 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/build.sh b/build.sh index 8a9d45b..95cbba1 100644 --- a/build.sh +++ b/build.sh @@ -1,7 +1,6 @@ #!/bin/bash -set -e -set -u +set -eu declare -r revision="$(git rev-parse --short HEAD)" @@ -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}" @@ -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 /#include \n#include /g' "${toolchain_directory}/include/mpc.h" @@ -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 ./* @@ -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' \ @@ -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}" \ No newline at end of file diff --git a/build_all.sh b/build_all.sh new file mode 100644 index 0000000..731a294 --- /dev/null +++ b/build_all.sh @@ -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 diff --git a/submodules/obggcc b/submodules/obggcc new file mode 160000 index 0000000..dd6cd0b --- /dev/null +++ b/submodules/obggcc @@ -0,0 +1 @@ +Subproject commit dd6cd0b520a7dda33c6206e74290d6961127e972 diff --git a/tools/setup_toolchain.sh b/tools/setup_toolchain.sh new file mode 100644 index 0000000..d8076e4 --- /dev/null +++ b/tools/setup_toolchain.sh @@ -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