gp24

gp24.git
git clone git://git.lenczewski.org/gp24.git
Log | Files | Refs | README | LICENSE

build.sh (2072B)


      1 #!/bin/sh
      2 
      3 TARGET="${1:-atmega2560}"
      4 
      5 # toolchain
      6 AS="clang"
      7 CC="clang"
      8 CXX="clang++"
      9 LD="ld.lld"
     10 
     11 OBJCOPY="llvm-objcopy"
     12 
     13 # toolchain flags
     14 WARNINGS="-Wall -Wextra ${WERROR:+-Werror} -Wno-unused-parameter"
     15 FLAGS="-ffreestanding -fno-builtin"
     16 
     17 # generic language flags
     18 ASFLAGS="-g3"
     19 CFLAGS="-std=c11 -O0 -g3"
     20 CXXFLAGS="-std=c++11 -O0 -g3"
     21 
     22 CPPFLAGS="-Idep"
     23 LDFLAGS="-nostdlib"
     24 
     25 # target-specific toolchain flags
     26 # --
     27 #  see: clang -target avr-none --print-supported-cpus
     28 #  see: clang -target arm-none-eabi --print-supported-cpus
     29 #  see: clang -target arm-none-eabi --print-supported-extensions
     30 #
     31 #  see: https://gcc.gnu.org/onlinedocs/gcc/AVR-Options.html
     32 #  see: https://gcc.gnu.org/onlinedocs/gcc/ARM-Options.html
     33 case $TARGET in
     34 	atmega2560) # arduino mega
     35 		TRIPLE="avr-none"
     36 		TARGET_FLAGS="-mmcu=atmega2560"
     37 		;;
     38 
     39 	stm32-m3) # stm nucleo-64
     40 		TRIPLE="arm-none-eabi"
     41 		TARGET_FLAGS="-mcpu=cortex-m3 -march=armv7-m"
     42 		;;
     43 
     44 	stm32-m4) # stm32 nucleo-144
     45 		TRIPLE="arm-none-eabi"
     46 		TARGET_FLAGS="-mcpu=cortex-m4 -march=armv7e-m+fp"
     47 		;;
     48 
     49 	*)
     50 		echo "Unsupported target: $TARGET, must be one of: "
     51 		echo "\tatmega2560 stm32-m3 stm32-m4"
     52 		exit 1
     53 		;;
     54 esac
     55 
     56 # target-specific language flags
     57 ARCH_ASFLAGS="-target $TRIPLE $TARGET_FLAGS $ASFLAGS $FLAGS"
     58 ARCH_CFLAGS="-target $TRIPLE $TARGET_FLAGS $CFLAGS $FLAGS"
     59 ARCH_CXXFLAGS="-target $TRIPLE $TARGET_FLAGS $CXXFLAGS $FLAGS"
     60 
     61 ARCH_CPPFLAGS="$CPPFLAGS"
     62 ARCH_LDFLAGS="-T $TARGET.lds $LDFLAGS"
     63 
     64 set -ex
     65 
     66 mkdir -p bin obj
     67 
     68 # build target-specific asm platform code and HAL implementation
     69 $AS $ARCH_ASFLAGS $ARCH_CPPFLAGS -o obj/plat.o -c $TARGET/plat.S -I$TARGET
     70 $CC $ARCH_CFLAGS $ARCH_CPPFLAGS -o obj/hal.o -c $TARGET/hal.c -I$TARGET
     71 
     72 # build target-independent code
     73 $CXX $ARCH_CXXFLAGS $ARCH_CPPFLAGS -o obj/gp24.o -c src/gp24.cpp
     74 
     75 # link together asm helpers, HAL, and main code
     76 $LD $ARCH_LDFLAGS --Map=bin/gp24.map --print-memory-usage \
     77 	obj/plat.o obj/hal.o obj/gp24.o -o bin/gp24.elf
     78 
     79 # prepare binary for flashing to target
     80 $OBJCOPY -S -O binary bin/gp24.elf bin/gp24.bin
     81 $OBJCOPY -S -O ihex bin/gp24.elf bin/gp24.hex