# put your *.o targets here, make should handle the rest!


SRC=cmsis/core_cm3.c
SRC+=cmsis/core_cm3.h
SRC+=cmsis_boot/startup/startup_stm32f10x_md.c
SRC+=cmsis_boot/stm32f10x.h
SRC+=cmsis_boot/stm32f10x_conf.h
SRC+=cmsis_boot/system_stm32f10x.c
SRC+=cmsis_boot/system_stm32f10x.h
SRC+=common/src_avrcom/delay.h
SRC+=common/src_avrcom/gpio.h
SRC+=common/src_avrcom/gpio_stm32f10x.c
SRC+=common/src_avrcom/pgmspace.h
SRC+=common/src_glcd/font3x6.h
SRC+=common/src_glcd/font4x8.h
SRC+=common/src_glcd/font5x7.h
SRC+=common/src_glcd/font5x8.h
SRC+=common/src_glcd/font7x12.h
SRC+=common/src_glcd/font8x8.h
SRC+=common/src_glcd/glcd_ks0108.c
SRC+=common/src_glcd/glcd_ks0108.h
SRC+=common/src_glcd/glcd_ks0108_avr_stm32.c
SRC+=common/src_glcd/glcd_textfun.c
SRC+=common/src_glcd/glcd_textfun.h
SRC+=common/src_misc/datatypes.h
SRC+=common/src_pwm/pwm.h
SRC+=common/src_pwm/pwm_stm32.c
SRC+=ioMapping.h
SRC+=main.c
SRC+=main.h
SRC+=stdio/printf.c
SRC+=stm_lib/inc/misc.h
SRC+=stm_lib/inc/stm32f10x_adc.h
SRC+=stm_lib/inc/stm32f10x_dma.h
SRC+=stm_lib/inc/stm32f10x_gpio.h
SRC+=stm_lib/inc/stm32f10x_i2c.h
SRC+=stm_lib/inc/stm32f10x_rcc.h
SRC+=stm_lib/inc/stm32f10x_tim.h
SRC+=stm_lib/src/misc.c
SRC+=stm_lib/src/stm32f10x_adc.c
SRC+=stm_lib/src/stm32f10x_dma.c
SRC+=stm_lib/src/stm32f10x_gpio.c
SRC+=stm_lib/src/stm32f10x_i2c.c
SRC+=stm_lib/src/stm32f10x_rcc.c
SRC+=stm_lib/src/stm32f10x_tim.c
SRC+=syscalls/syscalls.c


# all the files will be generated with this name (main.elf, main.bin, main.hex, etc)

PROJ_NAME=main

# that's it, no need to change anything below this line!

###################################################

CC=arm-none-eabi-gcc
OBJCOPY=arm-none-eabi-objcopy

CFLAGS  = -g -O2 -Wall -Tstm32_flash.ld
CFLAGS += -mlittle-endian -mthumb -mcpu=cortex-m4 -mthumb-interwork
CFLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16

###################################################

vpath %.c src
vpath %.a lib

ROOT=$(shell pwd)

CFLAGS += -Iinc -Ilib -Ilib/inc
CFLAGS += -Ilib/inc/core -Ilib/inc/peripherals

#SRC += lib/startup_stm32f4xx.s # add startup file to build

OBJS = $(SRC:.c=.o)

###################################################

.PHONY: lib proj

all: lib proj

lib:
	$(MAKE) -C lib

proj:   $(PROJ_NAME).elf

$(PROJ_NAME).elf: $(SRCS)
	$(CC) $(CFLAGS) $^ -o $@ -Llib -lstm32f4
	$(OBJCOPY) -O ihex $(PROJ_NAME).elf $(PROJ_NAME).hex
	$(OBJCOPY) -O binary $(PROJ_NAME).elf $(PROJ_NAME).bin

clean:
	rm -f *.o
	rm -f $(PROJ_NAME).elf
	rm -f $(PROJ_NAME).hex
	rm -f $(PROJ_NAME).bin