CROSS_COMPILE:=arm-none-eabi-
CC:=$(CROSS_COMPILE)gcc
LD:=$(CROSS_COMPILE)gcc
OBJS:=startup.o main.o stm32f7_ltdc.o stm32f7_sdram.o systick.o system.o button.o cga_8x8.o palette_256_xterm.o ui.o  mpu.o timer.o led.o adc.o ft5336.o touchscreen.o task.o \
	  scr-logging.o \
	  scr-deck.o \
	  ksp-serial.o \
	  trig.o \
	stm32746g_discovery.o \
	stm32-hal/src/stm32f7xx_hal_gpio.o \
	stm32-hal/src/stm32f7xx_hal.o \
	stm32-hal/src/stm32f7xx_hal_cortex.o \
	stm32-hal/src/stm32f7xx_hal_rcc.o \
	stm32-hal/src/stm32f7xx_hal_rcc_ex.o \
	stm32-hal/src/stm32f7xx_hal_i2c.o \
	stm32-hal/src/stm32f7xx_hal_dma.o 

LSCRIPT:=target-f746.ld

OBJCOPY:=$(CROSS_COMPILE)objcopy

UMX:=unicore-mx/lib/libucmx_stm32f7.a
UMXFLAGS:=-Iunicore-mx/include/ -DSTM32F7


CFLAGS:=-mcpu=cortex-m7 -mthumb \
 -Wall -Wno-main -Wstack-usage=200 -ffreestanding -Wno-unused $(UMXFLAGS) -DSTM32F746xx -I. -Istm32-hal/include -mfpu=fpv5-d16 -mfloat-abi=hard 

#CFLAGS+=-O0 -g -ggdb3 
CFLAGS+=-O2
ASFLAGS+=-mthumb -mlittle-endian -mthumb-interwork -ggdb -ffreestanding -mcpu=cortex-m7
LDFLAGS:=-lm -T $(LSCRIPT) -Wl,-gc-sections -Wl,-Map=image.map -lm -lc -lg -specs=nano.specs -mthumb -mcpu=cortex-m7 -mfloat-abi=hard -u _printf_float -lrdimon

#all: image.bin

image.bin: image.elf
	$(OBJCOPY) -O binary $^ $@

image.elf: $(UMX) $(OBJS) $(LSCRIPT)
	$(LD) $(LDFLAGS) $(OBJS) $(UMX) -o $@

$(UMX):
	make -C unicore-mx FP_FLAGS= PREFIX=arm-frosted-eabi TARGETS=stm32/f7


	
startup.o: startup.c

main.o: main.c

clean:
	rm -f image.bin image.elf *.o image.map
	find . |grep "\.o$$" | xargs -x rm -f
