#!/bin/sh
cd "$(dirname "$0")"
mkdir -p build
cd build
  if [[ ! -f arm2gas.pl || $(stat -c%s arm2gas.pl) -lt 10000 ]]; then
    curl -LO https://raw.githubusercontent.com/yxnan/arm2gas/refs/heads/main/arm2gas.pl
  fi
perl arm2gas.pl ../LR_11.s -o arm2gastemp.s -w -s 2>/dev/null
sed -e 's/MyData1, "aw", @progbits/.bss/g' \
    -e 's/MyData, "a", @progbits/.data/g' \
    -e 's/Stop\ /Stop:\ /g' \
    -e 's/_W\ \./_W:\ ./g' \
    arm2gastemp.s > LR_11.s
perl arm2gas.pl ../PZ25_6.s -o arm2gastemp.s -w -s 2>/dev/null
sed -e 's/MyData1, "aw", @progbits/.bss/g' \
    -e 's/MyData, "a", @progbits/.data/g' \
    -e 's/Stop\ /Stop:\ /g' \
    -e 's/_W\ \./_W:\ ./g' \
    -e 's/ .word/: .word/g' \
    -e 's/  :/  /g' \
    -e 's/ .space/: .space/g' \
    arm2gastemp.s > PZ25_6.s
#perl arm2gas.pl ../StartUp_1.s -o arm2gastemp.s -w -s 2>/dev/null
#sed -e 's/Stack_Mem/Stack_Mem:/g' \
#    -e 's/, @progbits//g' \
#    -e 's/ .word/: .word/g' \
#    -e 's/\([a-zA-Z0-9_]*\) \[WEAK\]/.global \1\n.weak \1/' \
#    -e 's/.weak .global/.global/g' \
##   -e 's/.global MyProg/.global MyProg\nMyProg:/g' \
#    arm2gastemp.s > StartUp_1.s
arm-none-eabi-as PZ25_6.s -o PZ25_6.o
arm-none-eabi-as LR_11.s -o LR_11.o
arm-none-eabi-ld -o PZ25_6.elf PZ25_6.o
arm-none-eabi-ld -o LR_11.elf LR_11.o
