#
#       !!!! Do NOT edit this makefile with an editor which replace tabs by spaces !!!!    
#
##############################################################################################
# 
# On command line:
#
# make all = Create project
#
# make clean = Clean project files.
#
# To rebuild project do "make clean" and "make all".
#

##############################################################################################
# Start of default section
#

TRGT = arm-none-eabi-
CC   = $(TRGT)gcc
CP   = $(TRGT)objcopy
AS   = $(TRGT)gcc -x assembler-with-cpp
BIN  = $(CP) -O ihex 

MCU  = cortex-m3

# List all default C defines here, like -D_DEBUG=1
DDEFS = 

# List all default ASM defines here, like -D_DEBUG=1
DADEFS = 

# List all default directories to look for include files here
DINCDIR = c:\WinARM\yagarto\arm-none-eabi\include\

# List the default directory to look for the libraries here
DLIBDIR =

# List all default libraries here
DLIBS = 

#
# End of default section
##############################################################################################

##############################################################################################
# Start of user section
#

# Define project name here
PROJECT = AnaIn

# Define using Dir "out" for compilling
# This path variable must have at the end a /
#OBJDIR = ./
OBJDIR = ./out/

# Define linker script file here
LDSCRIPT_ROM = ./prj/STM32F103xC-ROM.ld

# List all user C define here, like -D_DEBUG=1
UDEFS = 

# Define ASM defines here
UADEFS = 

# List C source files here
SRC  = src/fw_update.c

SRC += src/main.c 
SRC += src/Seriell.c
SRC += src/stm32f10x_it.c
SRC += src/stm32f10x_vector.c
SRC += src/timer_task.c
SRC += src/LED.c
SRC += src/CAN.c
SRC += src/ADConvert.c

# Quell-Dateien der STM32 Bibliothek:
SRC += lib/cm3/core_cm3.c
SRC += lib/src/misc.c
SRC += lib/system_stm32f10x.c
SRC += lib/src/stm32f10x_adc.c
SRC += lib/src/stm32f10x_bkp.c
SRC += lib/src/stm32f10x_can.c
#SRC += lib/src/stm32f10x_cec.c
#SRC += lib/src/stm32f10x_crc.c
#SRC += lib/src/stm32f10x_dac.c
#SRC += lib/src/stm32f10x_dbgmcu.c
SRC += lib/src/stm32f10x_dma.c
SRC += lib/src/stm32f10x_exti.c
SRC += lib/src/stm32f10x_flash.c
#SRC += lib/src/stm32f10x_fsmc.c
SRC += lib/src/stm32f10x_gpio.c
#SRC += lib/src/stm32f10x_i2c.c
#SRC += lib/src/stm32f10x_iwdg.c
#SRC += lib/src/stm32f10x_pwr.c
SRC += lib/src/stm32f10x_rcc.c
#SRC += lib/src/stm32f10x_rtc.c
#SRC += lib/src/stm32f10x_sdio.c
#SRC += lib/src/stm32f10x_spi.c
SRC += lib/src/stm32f10x_tim.c
SRC += lib/src/stm32f10x_usart.c
#SRC += lib/src/stm32f10x_wwdg.c

# List ASM source files here
ASRC =

# List all user directories here
UINCDIR = ./inc
UINCDIR += ./lib
UINCDIR += ./lib/cm3
UINCDIR += ./lib/inc

# List the user directory to look for the libraries here
ULIBDIR =

# List all user libraries here
ULIBS = 

# Define optimisation level here
OPT = -O0

#
# End of user defines
##############################################################################################

INCDIR  = $(patsubst %,-I%,$(DINCDIR) $(UINCDIR))
LIBDIR  = $(patsubst %,-L%,$(DLIBDIR) $(ULIBDIR))
DEFS    = $(DDEFS) $(UDEFS)
ADEFS   = $(DADEFS) $(UADEFS)
OBJS    = $(addprefix $(OBJDIR), $(ASRC:.s=.o) $(SRC:.c=.o))
LIBS    = $(DLIBS) $(ULIBS)
MCFLAGS = -mcpu=$(MCU)

ASFLAGS = $(MCFLAGS) -g -gdwarf-2 -Wa,-amhls=$(addprefix $(OBJDIR), $(<:.s=.lst)) $(ADEFS)
CPFLAGS = $(MCFLAGS) $(OPT) -gdwarf-2 -mthumb -fomit-frame-pointer -Wall -Wstrict-prototypes -fverbose-asm -Wa,-ahlms=$(addprefix $(OBJDIR), $(<:.c=.lst)) $(DEFS)
LDFLAGS_ROM = $(MCFLAGS) -mthumb -nostartfiles -T$(LDSCRIPT_ROM) -Wl,-Map=$(PROJECT)_rom.map,--cref,--no-warn-mismatch $(LIBDIR)

# Generate dependency information
CPFLAGS += -MD -MP -MF .dep/$(@F).d

#
# makefile rules
#

all: start ROM
	@echo Finish.

start:
	@$(CC) --version
	@if [ -f $(PROJECT)_rom.elf ]; then echo Size before:; $(TRGT)size -A $(PROJECT)_rom.elf; fi

ROM: $(OBJS) $(PROJECT)_rom.elf $(PROJECT)_rom.hex

$(OBJDIR)%o : %c
	$(CC) -c $(CPFLAGS) -I . $(INCDIR) $< -o $@

$(OBJDIR)%o : %s
	$(AS) -c $(ASFLAGS) $< -o $@

%rom.elf: $(OBJS)
	@echo
	$(CC) $(OBJS) $(LDFLAGS_ROM) $(LIBS) -o $@

%hex: %elf
	@echo
	$(BIN) $< $@
	@if [ -f $(PROJECT)_rom.elf ]; then echo; echo Size after:; $(TRGT)size -A $(PROJECT)_rom.elf; fi

clean:
	@echo clean:
	-rm -f $(OBJS)
	-rm -f $(PROJECT)_rom.elf
	-rm -f $(PROJECT)_rom.map
	-rm -f $(PROJECT)_rom.hex
	-rm -f $(SRC:.c=.c.bak)
	-rm -f $(addprefix $(OBJDIR), $(SRC:.c=.lst))
	-rm -f $(ASRC:.s=.s.bak)
	-rm -f $(addprefix $(OBJDIR), $(ASRC:.s=.lst))
	-rm -fR .dep

# 
# Include the dependency files, should be the last of the makefile
#
-include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)

# *** EOF ***