+/rtos
git clone https://git.julia.blue/+/rtos
caa7dc7
master
1build_dir = out 2target = $( build_dir ) /out.elf 3 4SRCS = $( wildcard src/*.c) $( wildcard lib/*.c) $( wildcard lib/usblib/*.c) 5ASM_SRCS = $( wildcard src/*.s) $( wildcard lib/*.s) 6OBJS = $( addprefix $( build_dir ) /,$( notdir $( SRCS:.c=.o))) 7OBJS += $( addprefix $( build_dir ) /,$( notdir $( ASM_SRCS:.s=.o))) 8DEPS = $( OBJS:%.o=%.d) 9 10CC = clang --target=thumbv7em-unknown-none-eabi -Wno-keyword-macro -fshort-enums 11ASSEMBLER = clang --target=thumbv7em-unknown-none-eabi 12 13ARCHFLAGS = -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mthumb -mfloat-abi=hard 14COMMONFLAGS = -ggdb3 -nodefaultlibs -nostdlib -Wall -Os 15 16CFLAGS = $( COMMONFLAGS ) $( ARCHFLAGS ) -fdata-sections -ffunction-sections 17CFLAGS += -pedantic -ffreestanding -MD -MP -std=c2x -Iinc 18 19OPENOCD = openocd -c "source [find board/ek-tm4c123gxl.cfg]" 20 21SHELL := /bin/zsh 22 23all : $( target ) 24 25$( build_dir ) /%.o: src/%.c Makefile 26$( CC ) -o $ @ $ < -c$( CFLAGS ) 27 28$( build_dir ) /%.o: lib/usblib/%.c Makefile 29$( CC ) -o $ @ $ < -c$( CFLAGS ) 30 31$( build_dir ) /%.o: lib/%.c Makefile 32$( CC ) -o $ @ $ < -c$( CFLAGS ) -D SSID_NAME='" ${ wifi_network } "' \ 33-D PASSKEY='" ${ wifi_pass } "' 34 35$( build_dir ) /%.o: lib/%.s Makefile 36$( ASSEMBLER ) -o $ @ $ < -c$( COMMONFLAGS ) $( ARCHFLAGS ) 37 38$( target ): $( OBJS ) 39$( CC ) -o $ @ $ ^ $( COMMONFLAGS ) -T misc/tm4c.ld 40 41release : 42$( CC ) src/*.c lib/*.c lib/*.s$( CFLAGS ) -O2 -T misc/tm4c.ld-o $( target ) 43 44-include$( DEPS ) 45 46timestamp = $( build_dir ) /timestamp 47$( timestamp ): $( target ) 48$( shell date '+%y%m%d%H%M%S' > $( timestamp ) ) 49$( OPENOCD ) -c "program $( target ) exit" 50 51flash : $( timestamp ) 52 53run : flash 54$( OPENOCD ) -c "init;reset;shutdown" 55 56uart : run 57screen -L /dev/ttyACM0 115200 58 59debug : flash 60arm-none-eabi-gdb $( target ) -x misc/debug.gdb 61 62debug_gui : flash 63gdbgui -g arm-none-eabi-gdb--gdb-args= "-command=misc/debug_gui.gdb" \ 64$( target ) 65 66size = $( build_dir ) /size 67$( size ): $( target ) 68llvm-nm --demangle --print-size --size-sort --no-weak --radix=d $( target ) \ 69> $( build_dir ) /sizes 70 71rom_size : $( size ) 72@ grep "^0" < $( build_dir ) /sizes| cut -f 2,4-d ' ' | \ 73numfmt --field 1--to=iec --padding -6 | sed "/^0/d" 74 75ram_size : $( size ) 76@ grep "^[^0]" < $( build_dir ) /sizes| cut -f 2,4-d ' ' | \ 77numfmt --field 1--to=iec --padding -6 | sed "/^0/d" 78 79space : $( target ) 80@ llvm-size $( target ) | tail -1 | read -r rom data bss rest \ 81&& ram =$ $(expr $$ data + $ $bss) \ 82&& echo "ROM: $ $(numfmt --to=iec $ $rom)/256K ( $ $(expr $ $rom \* 100 / 262144)%)" \ 83&& echo "RAM: $ $(numfmt --to=iec $ $ram)/32K ( $ $(expr $ $ram \* 100 / 32768)%)" 84 85disassemble : $( target ) 86arm-none-eabi-objdump $( target ) -S -C \ 87--no-show-raw-insn > $( build_dir ) /disassembly.asm 88 89clean : 90 -rm -rf $( build_dir ) 91 92$( shell mkdir -p $( build_dir ) ) 93 94.PHONY : all clean debug debug_gui run ram_size rom_size space