diff --git a/.github/workflows/ci-workflow.yml b/.github/workflows/ci-workflow.yml index e0cc32fd3..2a3c78da3 100644 --- a/.github/workflows/ci-workflow.yml +++ b/.github/workflows/ci-workflow.yml @@ -16,11 +16,11 @@ jobs: submodules: true - run: make -C apps/KhiCAS cleanall - run: make KhiCAS_rebuild - - run: ./tool/archive KhiCAS.tar KhiCAS + - run: make KhiCAS_archive - uses: actions/upload-artifact@master with: name: KhiCAS - path: KhiCAS.tar + path: apps.tar BadApple: runs-on: ubuntu-latest steps: @@ -30,11 +30,11 @@ jobs: with: submodules: true - run: make BadApple_rebuild - - run: ./tool/archive BadApple.tar BadApple + - run: make BadApple_archive - uses: actions/upload-artifact@master with: name: BadApple - path: BadApple.tar + path: apps.tar CHIP-8: runs-on: ubuntu-latest steps: @@ -44,11 +44,11 @@ jobs: with: submodules: true - run: make CHIP-8_rebuild - - run: ./tool/archive CHIP-8.tar CHIP-8 + - run: make CHIP-8_archive - uses: actions/upload-artifact@master with: name: CHIP-8 - path: CHIP-8.tar + path: apps.tar Example: runs-on: ubuntu-latest steps: @@ -58,11 +58,11 @@ jobs: with: submodules: true - run: make Example_rebuild - - run: ./tool/archive Example.tar Example + - run: make Example_archive - uses: actions/upload-artifact@master with: name: Example - path: Example.tar + path: apps.tar Example-Cpp: runs-on: ubuntu-latest steps: @@ -72,11 +72,11 @@ jobs: with: submodules: true - run: make Example-Cpp_rebuild - - run: ./tool/archive Example-Cpp.tar Example-Cpp + - run: make Example-Cpp_archive - uses: actions/upload-artifact@master with: name: Example-Cpp - path: Example-Cpp.tar + path: apps.tar HexEdit: runs-on: ubuntu-latest steps: @@ -86,11 +86,10 @@ jobs: with: submodules: true - run: make HexEdit_rebuild - - run: ./tool/archive HexEdit.tar HexEdit - uses: actions/upload-artifact@master with: name: HexEdit - path: HexEdit.tar + path: apps.tar Nofrendo: runs-on: ubuntu-latest steps: @@ -100,11 +99,10 @@ jobs: with: submodules: true - run: make Nofrendo_rebuild - - run: ./tool/archive Nofrendo.tar Nofrendo - uses: actions/upload-artifact@master with: name: Nofrendo - path: Nofrendo.tar + path: apps.tar Peanut-GB: runs-on: ubuntu-latest steps: @@ -114,11 +112,11 @@ jobs: with: submodules: true - run: make Peanut-GB_rebuild - - run: ./tool/archive Peanut-GB.tar Peanut-GB + - run: make Peanut-GB_archive - uses: actions/upload-artifact@master with: name: Peanut-GB - path: Peanut-GB.tar + path: apps.tar Periodic: runs-on: ubuntu-latest steps: @@ -128,11 +126,11 @@ jobs: with: submodules: true - run: make Periodic_rebuild - - run: ./tool/archive Periodic.tar Periodic + - run: make Periodic_archive - uses: actions/upload-artifact@master with: name: Periodic - path: Periodic.tar + path: apps.tar UnitCircle: runs-on: ubuntu-latest steps: @@ -142,11 +140,11 @@ jobs: with: submodules: true - run: make UnitCircle_rebuild - - run: ./tool/archive UnitCircle.tar UnitCircle + - run: make UnitCircle_archive - uses: actions/upload-artifact@master with: name: UnitCircle - path: UnitCircle.tar + path: apps.tar env: ACCEPT_OFFICIAL_TOS: 1 \ No newline at end of file diff --git a/Makefile b/Makefile index 36ff4e5d1..4bbfb580f 100644 --- a/Makefile +++ b/Makefile @@ -1,22 +1,28 @@ .PHONY: %_flash -%_flash: %_rebuild - ./tool/archive apps.tar $@ +%_flash: %_archive + @echo "Flashing..." @echo "Waiting for the calculator to be connected, use the bootloader to flash on Upsilon if your app is bigger than 2MB" @until dfu-util -l | grep -E "0483:a291|0483:df11" > /dev/null 2>&1; do sleep 2;done dfu-util -i 0 -a 0 -s 0x90200000 -D apps.tar +%_archive: %_build + @echo "Archiving..." + ./tool/archive.sh apps.tar $@ + +.PHONY: %_build +%_build: api/libapi.a + @echo "Building..." + ./tool/build.sh $@ + .PHONY: %_rebuild -%_rebuild: api/libapi.a +%_rebuild: %_clean api/libapi.a @echo "Rebuilding..." -# Because the Makefile can't interpret the `%` operator, we have -# to use the following command to rebuild the application. - ./tool/rebuild.sh $@ + ./tool/build.sh $@ .PHONE: %_clean %_clean: @echo "Cleaning..." rm -rf apps.tar - rm -rf api/libapi.a ./tool/clean.sh $@ api/libapi.a: diff --git a/apps/Example/main.c b/apps/Example/main.c index 5efa9a1c8..970df997a 100644 --- a/apps/Example/main.c +++ b/apps/Example/main.c @@ -7,7 +7,6 @@ #include "inc/selector.h" void extapp_main(void) { - // Wait for the key to be released before starting the application waitForKeyReleased(); // Draw a white background diff --git a/tool/archive b/tool/archive deleted file mode 100755 index b78dfecce..000000000 --- a/tool/archive +++ /dev/null @@ -1,36 +0,0 @@ -#!/usr/bin/env bash - -set -e - -LD=arm-none-eabi-ld -OBJCOPY=arm-none-eabi-objcopy - -echo "Building archive..." -echo " - ld: $LD" -echo " - objcopy: $OBJCOPY" -echo " - arguments: $@" - -OUTPUT="$1" -shift 1 -rm -f "${OUTPUT}" - -POS=0 - -while [ ! -z "$1" ]; do - # Remove the suffix from $1 - FILENAME="$(echo "$1" | sed -e 's/_flash//')" - # If filename doesn't exist, interpret it as a application name - if [ ! -f "$FILENAME" ]; then - NAME="$1" - FILENAME="apps/$FILENAME/app.elf" - fi - NAME="$(basename $(dirname "$FILENAME"))" - echo " - $FILENAME" - sed "s/\+ (0)/+ (${POS})/" apps/external.ld > temp.ld - "${LD}" "$FILENAME" -o "${NAME}_linked.elf" -Ttemp.ld - "${OBJCOPY}" -O binary "${NAME}_linked.elf" "${NAME}" - tar -rf "${OUTPUT}" "${NAME}" - POS=$(( ${POS} + (($(stat --printf="%s" "${NAME}") + 1023)/512)*512 )) - rm -f temp.ld "${NAME}" "${NAME}_linked.elf" - shift 1 -done diff --git a/tool/archive.sh b/tool/archive.sh new file mode 100755 index 000000000..aa5d7d170 --- /dev/null +++ b/tool/archive.sh @@ -0,0 +1,51 @@ +#!/usr/bin/env bash + +set -e + +LD=arm-none-eabi-ld +OBJCOPY=arm-none-eabi-objcopy + +echo "Building archive..." +echo " - ld: $LD" +echo " - objcopy: $OBJCOPY" +echo " - arguments: $*" +echo "Input files:" + +OUTPUT="$1" +shift 1 +rm -f "${OUTPUT}" + +POS=0 + +while [[ -n "$1" ]]; do + # Remove the suffix from $1 + FILENAME="$(echo "$1" | sed -e 's/_flash//')" + FILENAME="$(echo "$1" | sed -e 's/_archive//')" + # If filename doesn't exist, interpret it as a application name + if [[ -n "${FILENAME}" ]]; then + NAME="${FILENAME}" + FILENAME="apps/${FILENAME}/app.elf" + fi + echo " - ${FILENAME}" + NAME="$(basename "$(dirname "${FILENAME}")")" + sed "s/\+ (0)/+ (${POS})/" apps/external.ld > temp.ld + "${LD}" "${FILENAME}" -o "${NAME}_linked.elf" -Ttemp.ld + "${OBJCOPY}" -O binary "${NAME}_linked.elf" "${NAME}" + tar -rf "${OUTPUT}" "${NAME}" + POS=$(( POS + (($(stat --printf="%s" "${NAME}") + 1023)/512)*512 )) + rm -f temp.ld "${NAME}" "${NAME}_linked.elf" + # Add the icon if it exists to the archive (Icon is the app.icon file in the app directory) + if [[ -f "apps/${NAME}/app.icon" ]]; then + ICON="apps/${NAME}/app.icon" + echo " - ${ICON}" + # Copy temporary the icon to the current directory + cp "${ICON}" "${NAME}.icon" + # Add the icon to the archive + tar -rf "${OUTPUT}" "${NAME}.icon" + # Increase the position of the icon + POS=$(( POS + (($(stat --printf="%s" "${NAME}.icon") + 1023)/512)*512 )) + # Remove the temporary icon + rm -f "${NAME}.icon" + fi + shift 1 +done diff --git a/tool/rebuild.sh b/tool/build.sh similarity index 56% rename from tool/rebuild.sh rename to tool/build.sh index 45156e369..d41e47fad 100755 --- a/tool/rebuild.sh +++ b/tool/build.sh @@ -1,13 +1,12 @@ #!/usr/bin/sh -# Rebuild the given application with the _rebuild suffix +# Build the given application with the _(re)build suffix # $1: application to rebuild # Get the application name application="$1" # Remove the suffix application_without_suffix="$(echo "${application}" | sed -e 's/_rebuild//')" -echo "Rebuilding ${application_without_suffix}" -# Clean the application -./tool/clean.sh "${application_without_suffix}" +application_without_suffix="$(echo "${application_without_suffix}" | sed -e 's/_build//')" +echo "Building ${application_without_suffix}" # Rebuild the application make -C "apps/${application_without_suffix}" \ No newline at end of file