diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 00000000..65824f72 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +*.sh text eol=lf linguist-language=Shell +*.txt eol=lf \ No newline at end of file diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 61d7041c..89d8fe32 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -8,92 +8,139 @@ on: jobs: build: - runs-on: ${{ matrix.os }} + runs-on: ${{ matrix.runner }} strategy: fail-fast: false matrix: - os: [macos-15-intel, ubuntu-latest, macos-26] + include: + - runner: ubuntu-latest + os: linux + + - runner: macos-15-intel + os: macos + + - runner: macos-26 + os: macos steps: - - uses: actions/checkout@v6 - - - name: Install Ubuntu requirements - if: matrix.os == 'ubuntu-latest' - run: | - sudo apt-get update - sudo apt-get -y install autoconf automake bison flex gcc libelf-dev make texinfo libncurses5-dev patch python3 python-is-python3 subversion wget zlib1g-dev libtool-bin python3-dev bzip2 libgmp3-dev pkg-config - - - name: Install macOS intel requirements - if: matrix.os == 'macos-15-intel' - shell: arch -x86_64 bash -e {0} - env: - HOMEBREW_NO_AUTO_UPDATE: 1 - HOMEBREW_NO_INSTALL_CLEANUP: 1 - HOMEBREW_NO_ENV_HINTS: 1 - run: | - brew install autoconf automake openssl libelf ncurses zlib gmp wget pkg-config texinfo - - - name: Install macOS arm64 requirements - if: matrix.os == 'macos-26' - shell: bash -e {0} - env: - HOMEBREW_NO_AUTO_UPDATE: 1 - HOMEBREW_NO_INSTALL_CLEANUP: 1 - HOMEBREW_NO_ENV_HINTS: 1 - run: | - brew install autoconf automake openssl libelf ncurses zlib gmp wget pkg-config texinfo - - - name: Runs all the stages in the shell - if: matrix.os == 'ubuntu-latest' - shell: bash -e {0} - env: - BUILD_PS3TOOLCHAIN_ONLY: 1 - run: | - mkdir $PWD/ps3dev - export PS3DEV=$PWD/ps3dev - export PSL1GHT=$PS3DEV - export PATH=$PATH:$PS3DEV/bin - export PATH=$PATH:$PS3DEV/ppu/bin - export PATH=$PATH:$PS3DEV/spu/bin - ./toolchain.sh - - - name: Runs all the stages in the shell - if: matrix.os == 'macos-15-intel' - shell: arch -x86_64 bash -e {0} - env: - BUILD_PS3TOOLCHAIN_ONLY: 1 - run: | - mkdir $PWD/ps3dev - export PS3DEV=$PWD/ps3dev - export PSL1GHT=$PS3DEV - export PATH=$PATH:$PS3DEV/bin - export PATH=$PATH:$PS3DEV/ppu/bin - export PATH=$PATH:$PS3DEV/spu/bin - ./toolchain.sh - - - name: Runs all the stages in the shell - if: matrix.os == 'macos-26' - shell: bash -e {0} - env: - BUILD_PS3TOOLCHAIN_ONLY: 1 - run: | - mkdir $PWD/ps3dev - export PS3DEV=$PWD/ps3dev - export PSL1GHT=$PS3DEV - export PATH=$PATH:$PS3DEV/bin - export PATH=$PATH:$PS3DEV/ppu/bin - export PATH=$PATH:$PS3DEV/spu/bin - ./toolchain.sh - - - name: Get short SHA - id: slug - run: echo "sha8=$(echo ${GITHUB_SHA} | cut -c1-8)" >> "$GITHUB_OUTPUT" - - - name: Compress ps3dev folder - run: | - tar -zcvf ps3dev.tar.gz ps3dev - - - uses: actions/upload-artifact@v6 - with: - name: ps3dev-${{ steps.slug.outputs.sha8 }}-${{matrix.os}} - path: ps3dev.tar.gz + - uses: actions/checkout@v6 + + - name: Install Linux requirements + if: matrix.os == 'linux' + run: | + sudo apt-get update + sudo apt-get -y install \ + autoconf automake bison flex gcc libelf-dev make texinfo \ + libncurses5-dev patch python3 python-is-python3 subversion \ + wget zlib1g-dev libtool-bin python3-dev bzip2 libgmp3-dev \ + pkg-config pv libssl-dev + + # ------------------------ + # macOS dependencies + # ------------------------ + - name: Install macOS requirements + if: matrix.os == 'macos' + shell: bash + env: + HOMEBREW_NO_AUTO_UPDATE: 1 + HOMEBREW_NO_INSTALL_CLEANUP: 1 + HOMEBREW_NO_ENV_HINTS: 1 + run: | + eval "$(brew shellenv)" + brew install \ + autoconf automake openssl libelf ncurses zlib gmp wget \ + pkg-config texinfo pv + + # ------------------------ + # GLOBAL ENV SETUP + # ------------------------ + - name: Setup environment (PS3DEV + base PATH) + shell: bash + run: | + mkdir -p "$PWD/ps3dev" + mkdir -p "$PWD/build" + + echo "BUILD_PS3TOOLCHAIN_ONLY=1" >> $GITHUB_ENV + echo "NO_SAVANNAH=1" >> $GITHUB_ENV + echo "PS3DEV=$PWD/ps3dev" >> $GITHUB_ENV + echo "PSL1GHT=$PWD/ps3dev" >> $GITHUB_ENV + echo "PATH=$PATH:$PWD/ps3dev/bin:$PWD/ps3dev/ppu/bin:$PWD/ps3dev/spu/bin" >> $GITHUB_ENV + + - name: Cache downloaded archives + uses: actions/cache@v5 + with: + path: archives + key: archives-${{ hashFiles('archives/archives.txt') }} + + - name: Purge unverifiable archives + run: | + while IFS= read -r line; do + set -- $line + [ "${1:-}" = "-" ] || continue + # 3rd field is URL, 5th field (if "->") is rename + url="$3" + rename="" + [ "${4:-}" = "->" ] && rename="${5:-}" + file="${rename:-$(basename "$url")}" + rm -f "archives/$file" + done < archives/archives.txt + + # ------------------------ + # Build steps + # ------------------------ + - name: Download files + working-directory: ./build + run: ../download.sh + + - name: Build Binutils (PPU) + run: ./toolchain.sh 001 + + - name: Build GCC + Newlib (PPU) + run: ./toolchain.sh 002 + + - name: Symlinks (PPU) + run: ./toolchain.sh 004 + + - name: Build Binutils (SPU) + run: ./toolchain.sh 005 + + - name: Build GCC + Newlib (SPU) + run: ./toolchain.sh 006 + + - name: Get short SHA + id: slug + run: echo "sha8=${GITHUB_SHA::8}" >> "$GITHUB_OUTPUT" + + - name: Compress ps3dev folder + run: tar -zcvf ps3dev-${{ matrix.os }}-${{ runner.arch }}.tar.gz ps3dev + + - uses: actions/upload-artifact@v7 + with: + name: ps3dev-${{ steps.slug.outputs.sha8 }}-${{ matrix.os }}-${{ runner.arch }} + path: ps3dev-${{ matrix.os }}-${{ runner.arch }}.tar.gz + + push_release: + if: | + github.event_name == 'push' && + github.repository == 'ps3dev/ps3toolchain' + needs: build + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - name: Checkout + uses: actions/checkout@v6 + + - name: Download artifacts + uses: actions/download-artifact@v8 + with: + path: artifacts + merge-multiple: true + + - name: Create Pre-Release + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + TAG="nightly-$(date -u +%Y-%m-%d)" + gh release delete "$TAG" --yes --cleanup-tag || true + gh release create "$TAG" artifacts/*.tar.gz --target ${{ GITHUB.SHA }} -t "$TAG" --prerelease \ No newline at end of file diff --git a/.gitignore b/.gitignore index ae20c71b..90200203 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ -build/ -.idea/** +/build +/archives/* +!/archives/archives.txt +/ps3dev diff --git a/Dockerfile b/Dockerfile index 1676330d..20b88800 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,8 +12,8 @@ RUN \ apt-get -y update && \ apt-get -y install \ autoconf bison build-essential ca-certificates flex git libelf-dev\ - libgmp-dev libncurses5-dev libssl-dev libtool-bin pkg-config python-dev-is-python3 \ - texinfo wget zlib1g-dev && \ + libgmp-dev libncurses5-dev libssl-dev libtool-bin pkg-config \ + texinfo wget zlib1g-dev pv && \ apt-get -y clean autoclean autoremove && \ rm -rf /var/lib/{apt,dpkg,cache,log}/ diff --git a/README.md b/README.md index d03118e7..60260c3d 100644 --- a/README.md +++ b/README.md @@ -14,8 +14,8 @@ ## Set up your environment by installing the following software: autoconf, automake, bison, flex, gcc, libelf, make, makeinfo, - ncurses, patch, python, subversion, wget, zlib, libtool, python, - bzip2, gmp, pkg-config, g++, libssl-dev, clang + ncurses, patch, python, subversion, wget, zlib, libtool, + bzip2, gmp, pkg-config, g++, libssl-dev, clang, pv ### Linux diff --git a/archives/archives.txt b/archives/archives.txt new file mode 100644 index 00000000..7fd080d8 --- /dev/null +++ b/archives/archives.txt @@ -0,0 +1,5 @@ +6c7af8ed1c8cf9b4b9d6e6fe09a3e1d3d479fe63984ba8b9b26bf356b6313ca9 19973532 https://sourceware.org/pub/binutils/releases/binutils-2.22.tar.bz2 -> binutils-2.22.tar.bz2 +1cf7adf8ff4b5aa49041c8734bbcf1ad18cc4c94d0029aae0f4e48841088479a 62312628 https://sourceware.org/pub/gcc/releases/gcc-7.2.0/gcc-7.2.0.tar.xz -> gcc-7.2.0.tar.xz +c644b2847244278c57bec2ddda69d8fab5a7c767f3b9af69aa7aa3da823ff692 14571004 https://sourceware.org/pub/newlib/newlib-1.20.0.tar.gz -> newlib-1.20.0.tar.gz +- - https://github.com/ps3dev/psl1ght/tarball/master -> psl1ght.tar.gz +- - https://github.com/ps3dev/ps3libraries/tarball/master -> ps3libraries.tar.gz diff --git a/config/get-config-scripts.sh b/config/get-config-scripts.sh index 25d95567..73b34f86 100755 --- a/config/get-config-scripts.sh +++ b/config/get-config-scripts.sh @@ -33,5 +33,11 @@ fetch_config_file() { chmod +x "${file}" } -fetch_config_file config.guess -fetch_config_file config.sub +if [ -z "${NO_SAVANNAH}" ]; then + fetch_config_file config.guess + fetch_config_file config.sub +else + echo "NO_SAVANNAH is set, skipping Savannah downloads." + cp "${CONFIG_DIR}/config.guess" "config.guess" + cp "${CONFIG_DIR}/config.sub" "config.sub" +fi \ No newline at end of file diff --git a/depends/check-python.sh b/depends/check-python.sh deleted file mode 100755 index 90774e55..00000000 --- a/depends/check-python.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/sh -# check-python.sh by Naomi Peori (naomi@peori.ca) - -## Check for python. -( python --version || python -V ) 1>/dev/null 2>&1 || { echo "ERROR: Install python before continuing."; exit 1; } - -## Check for python-config -pyprefix=$(python-config --prefix || python3-config --prefix) -[ $? -eq 0 ] || { echo "ERROR: Install python-dev before continuing."; exit 1; } - -## Check for python header files -( ls -1d "${pyprefix}"/include/python[23].*/Python.h || ls -1d /opt/local/include/python[23].*/Python.h ) 1>/dev/null 2>&1 || [ -f "$PYINSTALLDIR/include/Python.h" ] || { echo "ERROR: Install python-dev before continuing."; exit 1; } diff --git a/download.sh b/download.sh new file mode 100755 index 00000000..7807826d --- /dev/null +++ b/download.sh @@ -0,0 +1,150 @@ +#!/usr/bin/env bash +set -euo pipefail + +cd "$(dirname "$0")" +cd archives || exit 1 + +ARCHIVE="archives.txt" +WGET="wget --tries=5 --timeout=15 --quiet --show-progress" + +# ----------------------------------------------------------------------------- +# verify_sha256 +# Returns 0 on match, 1 on mismatch or error. +# ----------------------------------------------------------------------------- +verify_sha256() { + file="$1" + expected="$2" + out=$(sha256sum "$file" 2>/dev/null) || { + echo " !! sha256sum failed: $file" >&2 + return 1 + } + set -- $out + actual="$1" + if [ "$actual" != "$expected" ]; then + echo " !! SHA256 mismatch: $file" >&2 + echo " expected: $expected" >&2 + echo " got: $actual" >&2 + return 1 + fi + return 0 +} + +# ----------------------------------------------------------------------------- +# fetch +# ----------------------------------------------------------------------------- +fetch() { + url="$1" + dest="$2" + $WGET -O "$dest" "$url" || { + echo " !! Download failed: $url" >&2 + rm -f "$dest" + return 1 + } +} + +# ----------------------------------------------------------------------------- +# download [rename] +# ----------------------------------------------------------------------------- +download() { + sha="$1" + size="$2" + url="$3" + rename="${4:-}" + file="${rename:-$(basename "$url")}" + + printf '==> %s\n' "$file" + + # If already present, verify immediately — size alone is not enough. + if [ -f "$file" ]; then + if [ "$sha" = "-" ]; then + echo " -- no checksum, skipping re-download of existing file" + return 0 + fi + if verify_sha256 "$file" "$sha"; then + echo " -- already good" + return 0 + fi + echo " -- existing file failed verification, re-downloading..." + rm -f "$file" + fi + + # First attempt + fetch "$url" "$file" + + # Verify, with one retry on mismatch + if [ "$sha" != "-" ]; then + if ! verify_sha256 "$file" "$sha"; then + echo " -- retrying download..." + rm -f "$file" + fetch "$url" "$file" + verify_sha256 "$file" "$sha" || { + rm -f "$file" + echo " !! Giving up on $file" >&2 + return 1 + } + fi + fi + + echo " -- ok" +} + +# ----------------------------------------------------------------------------- +# parse_line -> prints "sha\tsize\turl\trename" or returns 1 +# ----------------------------------------------------------------------------- +parse_line() { + line="$1" + [ -z "$line" ] && return 1 + set -- $line + [ "$#" -lt 3 ] && return 1 + sha="$1"; size="$2"; url="$3" + rename="" + shift 3 + if [ "${1:-}" = "->" ]; then + rename="${2:-}" + fi + printf '%s\t%s\t%s\t%s\n' "$sha" "$size" "$url" "$rename" +} + +# ----------------------------------------------------------------------------- +# run_all / run_one +# ----------------------------------------------------------------------------- +run_all() { + ../config/get-config-scripts.sh + while IFS= read -r line; do + [ -z "$line" ] && continue + parsed=$(parse_line "$line") || continue + IFS="$(printf '\t')" read -r sha size url rename <&2 + exit 1 + } +} + +# ----------------------------------------------------------------------------- +if [ "$#" -eq 0 ]; then + run_all +else + run_one "$1" +fi \ No newline at end of file diff --git a/scripts/001-binutils-PPU.sh b/scripts/001-binutils-PPU.sh index 86e372ff..4d54e0f8 100755 --- a/scripts/001-binutils-PPU.sh +++ b/scripts/001-binutils-PPU.sh @@ -1,24 +1,27 @@ -#!/bin/sh -e +#!/usr/bin/env bash +set -eo pipefail # binutils-PPU.sh by Naomi Peori (naomi@peori.ca) BINUTILS="binutils-2.22" +source ../utils/utils.sh if [ ! -d ${BINUTILS} ]; then ## Download the source code. - if [ ! -f ${BINUTILS}.tar.bz2 ]; then wget --continue https://ftpmirror.gnu.org/binutils/${BINUTILS}.tar.bz2; fi + ../download.sh ${BINUTILS}.tar.bz2 ## Fetch config.guess and config.sub, falling back to copies if Savannah is unavailable ../config/get-config-scripts.sh ## Unpack the source code. - tar xfvj ${BINUTILS}.tar.bz2 + echo "Unpacking ${BINUTILS}" + extract "../archives/${BINUTILS}.tar.bz2" ## Patch the source code. cat ../patches/${BINUTILS}-PS3.patch | patch -p1 -d ${BINUTILS} ## Replace config.guess and config.sub - cp config.guess config.sub ${BINUTILS} + cp ../archives/config.guess ../archives/config.sub ${BINUTILS} fi @@ -47,4 +50,5 @@ cd ${BINUTILS}/build-ppu ## Compile and install. PROCS="$(nproc --all 2>&1)" || ret=$? if [ ! -z $ret ]; then PROCS=4; fi -${MAKE:-make} -j $PROCS && ${MAKE:-make} libdir=host-libs/lib install +${MAKE:-make} -j $PROCS +${MAKE:-make} libdir=host-libs/lib MULTIOSDIR=. install diff --git a/scripts/002-gcc-newlib-PPU.sh b/scripts/002-gcc-newlib-PPU.sh index 4d173ba4..aab9aa11 100755 --- a/scripts/002-gcc-newlib-PPU.sh +++ b/scripts/002-gcc-newlib-PPU.sh @@ -1,18 +1,23 @@ -#!/bin/sh -e +#!/usr/bin/env bash +set -eo pipefail # gcc-newlib-PPU.sh by Naomi Peori (naomi@peori.ca) GCC="gcc-7.2.0" NEWLIB="newlib-1.20.0" +source ../utils/utils.sh if [ ! -d ${GCC} ]; then ## Download the source code. - if [ ! -f ${GCC}.tar.xz ]; then wget --continue https://ftpmirror.gnu.org/gnu/gcc/${GCC}/${GCC}.tar.xz; fi - if [ ! -f ${NEWLIB}.tar.gz ]; then wget --continue https://sourceware.org/pub/newlib/${NEWLIB}.tar.gz; fi + ../download.sh ${GCC}.tar.xz + ../download.sh ${NEWLIB}.tar.gz ## Unpack the source code. - rm -Rf ${GCC} && tar xfvJ ${GCC}.tar.xz - rm -Rf ${NEWLIB} && tar xfvz ${NEWLIB}.tar.gz + echo "Unpacking ${GCC}" + extract "../archives/${GCC}.tar.xz" + + echo "Unpacking ${NEWLIB}" + extract "../archives/${NEWLIB}.tar.gz" ## Patch the source code. cat ../patches/${GCC}-PS3.patch | patch -p1 -d ${GCC} @@ -70,4 +75,5 @@ CFLAGS="-Wno-int-conversion" CXXFLAGS="-Wno-int-conversion" ../configure --prefi ## Compile and install. PROCS="$(nproc --all 2>&1)" || ret=$? if [ ! -z $ret ]; then PROCS=4; fi -${MAKE:-make} -j $PROCS all && ${MAKE:-make} install +${MAKE:-make} -j $PROCS all +${MAKE:-make} MULTIOSDIR=. install diff --git a/scripts/004-symlinks-PPU.sh b/scripts/004-symlinks-PPU.sh index 582c244b..0bbcd71e 100755 --- a/scripts/004-symlinks-PPU.sh +++ b/scripts/004-symlinks-PPU.sh @@ -1,4 +1,5 @@ -#!/bin/sh -e +#!/usr/bin/env bash +set -eo pipefail # symlinks-PPU.sh by Naomi Peori (naomi@peori.ca) ## Enter the PPU directory. diff --git a/scripts/005-binutils-SPU.sh b/scripts/005-binutils-SPU.sh index 00d14a50..b2c2c218 100755 --- a/scripts/005-binutils-SPU.sh +++ b/scripts/005-binutils-SPU.sh @@ -1,24 +1,27 @@ -#!/bin/sh -e +#!/usr/bin/env bash +set -eo pipefail # binutils-SPU.sh by Naomi Peori (naomi@peori.ca) BINUTILS="binutils-2.22" +source ../utils/utils.sh if [ ! -d ${BINUTILS} ]; then ## Download the source code. - if [ ! -f ${BINUTILS}.tar.bz2 ]; then wget --continue https://ftpmirror.gnu.org/binutils/${BINUTILS}.tar.bz2; fi + ../download.sh ${BINUTILS}.tar.bz2 ## Fetch config.guess and config.sub, falling back to copies if Savannah is unavailable ../config/get-config-scripts.sh ## Unpack the source code. - tar xfvj ${BINUTILS}.tar.bz2 + echo "Unpacking ${BINUTILS}" + extract "../archives/${BINUTILS}.tar.bz2" ## Patch the source code. cat ../patches/${BINUTILS}-PS3.patch | patch -p1 -d ${BINUTILS} ## Replace config.guess and config.sub - cp config.guess config.sub ${BINUTILS} + cp ../archives/config.guess ../archives/config.sub ${BINUTILS} fi @@ -46,4 +49,5 @@ cd ${BINUTILS}/build-spu ## Compile and install. PROCS="$(nproc --all 2>&1)" || ret=$? if [ ! -z $ret ]; then PROCS=4; fi -${MAKE:-make} -j $PROCS && ${MAKE:-make} libdir=host-libs/lib install +${MAKE:-make} -j $PROCS +${MAKE:-make} libdir=host-libs/lib MULTIOSDIR=. install diff --git a/scripts/006-gcc-newlib-SPU.sh b/scripts/006-gcc-newlib-SPU.sh index 837da9af..92e3b3b1 100755 --- a/scripts/006-gcc-newlib-SPU.sh +++ b/scripts/006-gcc-newlib-SPU.sh @@ -1,18 +1,23 @@ -#!/bin/sh -e +#!/usr/bin/env bash +set -eo pipefail # gcc-newlib-SPU.sh by Naomi Peori (naomi@peori.ca) GCC="gcc-7.2.0" NEWLIB="newlib-1.20.0" +source ../utils/utils.sh if [ ! -d ${GCC} ]; then ## Download the source code. - if [ ! -f ${GCC}.tar.xz ]; then wget --continue https://ftpmirror.gnu.org/gnu/gcc/${GCC}/${GCC}.tar.xz; fi - if [ ! -f ${NEWLIB}.tar.gz ]; then wget --continue https://sourceware.org/pub/newlib/${NEWLIB}.tar.gz; fi + ../download.sh ${GCC}.tar.xz + ../download.sh ${NEWLIB}.tar.gz ## Unpack the source code. - rm -Rf ${GCC} && tar xfvJ ${GCC}.tar.xz - rm -Rf ${NEWLIB} && tar xfvz ${NEWLIB}.tar.gz + echo "Unpacking ${GCC}" + extract "../archives/${GCC}.tar.xz" + + echo "Unpacking ${NEWLIB}" + extract "../archives/${NEWLIB}.tar.gz" ## Patch the source code. cat ../patches/${GCC}-PS3.patch | patch -p1 -d ${GCC} @@ -66,4 +71,5 @@ CXXFLAGS="-Wno-int-conversion" \ ## Compile and install. PROCS="$(nproc --all 2>&1)" || ret=$? if [ ! -z $ret ]; then PROCS=4; fi -${MAKE:-make} -j $PROCS all && ${MAKE:-make} install +${MAKE:-make} -j $PROCS all +${MAKE:-make} MULTIOSDIR=. install diff --git a/scripts/008-psl1ght.sh b/scripts/008-psl1ght.sh index feea6760..c1118c95 100755 --- a/scripts/008-psl1ght.sh +++ b/scripts/008-psl1ght.sh @@ -1,4 +1,5 @@ -#!/bin/sh -e +#!/usr/bin/env bash +set -eo pipefail # psl1ght.sh by Naomi Peori (naomi@peori.ca) ## Check if we want to skip this step @@ -7,13 +8,16 @@ if [ -n "$BUILD_PS3TOOLCHAIN_ONLY" ]; then exit 0 fi +source ../utils/util.sh + ## Download the source code. -wget --no-check-certificate https://github.com/ps3dev/PSL1GHT/tarball/master -O psl1ght.tar.gz +../download.sh psl1ght.tar.gz ## Unpack the source code. -rm -Rf psl1ght && mkdir psl1ght && tar --strip-components=1 --directory=psl1ght -xvzf psl1ght.tar.gz - -## Create the build directory. +rm -Rf psl1ght +mkdir psl1ght +echo "Unpacking psl1ght" +extract ../archives/psl1ght.tar.gz --strip-components=1 --directory=psl1ght cd psl1ght ## Compile and install. diff --git a/scripts/009-ps3libraries.sh b/scripts/009-ps3libraries.sh index 4ccd9bcb..d8213d3e 100755 --- a/scripts/009-ps3libraries.sh +++ b/scripts/009-ps3libraries.sh @@ -1,4 +1,5 @@ -#!/bin/sh -e +#!/usr/bin/env bash +set -eo pipefail # ps3libraries.sh by Naomi Peori (naomi@peori.ca) ## Check if we want to skip this step @@ -7,11 +8,17 @@ if [ -n "$BUILD_PS3TOOLCHAIN_ONLY" ]; then exit 0 fi +source ../utils/util.sh + ## Download the source code. -wget --no-check-certificate https://github.com/ps3dev/ps3libraries/tarball/master -O ps3libraries.tar.gz +../download.sh ps3libraries.tar.gz ## Unpack the source code. -rm -Rf ps3libraries && mkdir ps3libraries && tar --strip-components=1 --directory=ps3libraries -xvzf ps3libraries.tar.gz && cd ps3libraries +rm -Rf ps3libraries +mkdir ps3libraries +echo "Unpacking ps3libraries" +extract ../archives/ps3libraries.tar.gz --strip-components=1 --directory=ps3libraries +cd ps3libraries ## Compile and install. ./libraries.sh diff --git a/toolchain-mingw.sh b/toolchain-mingw.sh index cf9fa4ec..b14098c5 100755 --- a/toolchain-mingw.sh +++ b/toolchain-mingw.sh @@ -1,4 +1,5 @@ -#!/bin/bash +#!/usr/bin/env bash +set -eo pipefail # toolchain-mingw.sh by Miigotu (miigotu@hotmail.com) MINGW32EXPORTS=\ diff --git a/toolchain-sudo.sh b/toolchain-sudo.sh index e4948585..3d6a1d1f 100755 --- a/toolchain-sudo.sh +++ b/toolchain-sudo.sh @@ -1,4 +1,5 @@ -#!/bin/sh +#!/usr/bin/env bash +set -eo pipefail # toolchain-sudo.sh by Naomi Peori (naomi@peori.ca) ## Enter the ps3toolchain directory. diff --git a/toolchain.sh b/toolchain.sh index 4a341ef3..a6b1dc6a 100755 --- a/toolchain.sh +++ b/toolchain.sh @@ -1,4 +1,5 @@ -#!/bin/sh +#!/usr/bin/env bash +set -eo pipefail # toolchain.sh by Naomi Peori (naomi@peori.ca) ## Enter the ps3toolchain directory. @@ -14,7 +15,14 @@ which gmake 1>/dev/null 2>&1 && export MAKE=gmake DEPEND_SCRIPTS=`ls ../depends/*.sh | sort` ## Run all the depend scripts. -for SCRIPT in $DEPEND_SCRIPTS; do "$SCRIPT" || { echo "$SCRIPT: Failed."; exit 1; } done +failed=0 +for SCRIPT in $(ls ../depends/*.sh | sort); do + "$SCRIPT" || { + echo "$SCRIPT: Failed." + failed=1 + } +done +[ "$failed" -ne 0 ] && exit "$failed" ## Fetch the build scripts. BUILD_SCRIPTS=`ls ../scripts/*.sh | sort` @@ -28,6 +36,7 @@ if [ $1 ]; then for STEP in $@; do SCRIPT="" for i in $BUILD_SCRIPTS; do + echo ">>> Running: $SCRIPT" if [ `basename $i | cut -d'-' -f1` -eq $STEP ]; then SCRIPT=$i break @@ -44,4 +53,7 @@ if [ $1 ]; then fi ## Run the build scripts. -for SCRIPT in $BUILD_SCRIPTS; do "$SCRIPT" || { echo "$SCRIPT: Failed."; exit 1; } done +for SCRIPT in $BUILD_SCRIPTS; do + echo ">>> Running: $SCRIPT" + "$SCRIPT" || { echo "$SCRIPT: Failed."; exit 1; } +done diff --git a/utils/gen-github-actions-tasks.sh b/utils/gen-github-actions-tasks.sh new file mode 100755 index 00000000..5102b3f9 --- /dev/null +++ b/utils/gen-github-actions-tasks.sh @@ -0,0 +1,24 @@ +#!/usr/bin/env bash +set -eo pipefail + +SCRIPT_DIR="../scripts" + +echo " # ------------------------" +echo " # Build steps" +echo " # ------------------------" + +for script in "$SCRIPT_DIR"/*.sh; do + filename="$(basename "$script" .sh)" + + # Remove numeric prefix and convert dashes to spaces + name="${filename#[0-9][0-9][0-9]-}" + name="${name//-/ }" + + # Capitalize first letter of each word + name="$(echo "$name" | sed -E 's/(^| )([a-z])/\1\u\2/g')" + + echo " - name: Build $name" + echo " working-directory: ./build" + echo " run: ../scripts/$(basename "$script")" + echo +done \ No newline at end of file diff --git a/utils/utils.sh b/utils/utils.sh new file mode 100755 index 00000000..ea1011a9 --- /dev/null +++ b/utils/utils.sh @@ -0,0 +1,34 @@ +#!/usr/bin/env bash +set -eo pipefail + +# Extract an archive, with pv progress if available. +# Usage: extract [extra tar args...] +extract() { + local archive="$1" + shift + + if [ ! -f "$archive" ]; then + echo "extract: not a file: $archive" >&2 + return 1 + fi + + local -a flag=() + case "$archive" in + *.tar.xz|*.txz) flag=(-J) ;; + *.tar.gz|*.tgz) flag=(-z) ;; + *.tar.bz2|*.tbz2) flag=(-j) ;; + *.tar.zst) flag=(--zstd) ;; + *.tar) flag=() ;; + *) + echo "extract: unknown archive type: $archive" >&2 + return 1 + ;; + esac + + if command -v pv >/dev/null 2>&1; then + pv -pterab "$archive" | tar "${flag[@]}" -xf - "$@" + else + echo " (pv not found, extracting without progress)" + tar "${flag[@]}" -xf "$archive" "$@" + fi +} \ No newline at end of file