# $Id: makefile,v 1.01 2004/11/01 17:00:00 BorisK Exp $
#
# Copyright (C) 2004 ONTRACK s.r.o.
# 
#  Written by Boris Kralik <kralikbo@yahoo.com>, 2004.
# 

#LED : /usr/local/arm/bin/arm-elf-gcc -Tlpc2106-rom.ld -nostartfiles -Wl,-Map=led.map,--cref,-nostdlib -s -o led boot.s led.c
#arm-elf-objcopy --output-target ihex led led.hex

# Project name
PROJECT = example1

#*****************        FILES         *****************
#*** input ***       
# .c    C source; preprocess, compile, assemble
# .C    C++ source; preprocess, compile, assemble
# .cc   C++ source; preprocess, compile, assemble
# .cxx  C++ source; preprocess, compile, assemble
# .m    Objective-C source; preprocess, compile, assemble
# .i    preprocessed C; compile, assemble
# .ii   preprocessed C++; compile, assemble
# .s    Assembler source; assemble
# .S    Assembler source; preprocess, assemble
# .h    Preprocessor file; not usually named on command line                                                 
#********* output ********
# .o    Object file
# .a    Archive file

# Programs
CC 	= arm-elf-gcc
CPP = arm-elf-g++
LD	= arm-elf-ld
#CPP kompilator nejde koser 
DMP 	= arm-elf-objdump
OBJCPY 	= arm-elf-objcopy

# Target Options
# -b  machine -V version
# ARM Options 
# -mapcs-frame -mno-apcs-frame -mapcs-26 -mapcs-32 -mapcs-stack-check -mno-apcs-stack-check -mapcs-float 
# -mno-apcs-float -mapcs-reentrant -mno-apcs-reentrant -msched-prolog -mno-sched-prolog -mlittle-endian -mbig-endian 
# -mwords-little-endian -malignment-traps -mno-alignment-traps -msoft-float -mhard-float -mfpe -mthumb-interwork 
# -mno-thumb-interwork -mcpu=name -march=name -mfpe=name -mstructure-size-boundary=n -mabort-on-noreturn -mlong-calls 
# -mno-long-calls -msingle-pic-base -mno-single-pic-base -mpic-register=reg -mnop-fun-dllimport -mcirrus-fix-invalid-insns 
# -mno-cirrus-fix-invalid-insns -mpoke-function-name -mthumb -marm -mtpcs-frame -mtpcs-leaf-frame -mcaller-super-interworking 
# -mcallee-super-interworking 
TARGET = arm7tdmi
OUT_TARGET = ihex

#include 
INCLUDEFLAGS = -I
INCLUDEDIR = ./include

# Assembler Option
#-Wa,option
              
# Preprocessor flags
# -Aassertion -C -dD -dM -dN -Dmacro[=defn] -E -H -idirafter dir -include file
# -imacros file -iprefix file -iwithprefix dir -M -MD -MM -MMD -nostdinc -P
# -Umacro -undef
PREPFLAGS = -MD
#-Map=example1.map

# Optimize flags
# -fcaller-saves -fcse-follow-jumps -fcse-skip-blocks -fdelayed-branch
# -felide-constructors -fexpensive-optimizations -ffast-math -ffloat-store
# -fforce-addr -fforce-mem -finline-functions -fkeep-inline-functions
# -fmemoize-lookups -fno-default-inline -fno-defer-pop -fno-function-cse
# -fno-inline -fno-peephole -fomit-frame-pointer -frerun-cse-after-loop
# -fschedule-insns -fschedule-insns2 -fstrength-reduce -fthread-jumps -funroll-all-loops -funroll-loops -O -O2 -O3
# -funroll-all-loops -funroll-loops -O -O2 -O3         
OPTIFLAGS =  -O3

# Warnings flags
# -fsyntax-only -pedantic -pedantic-errors -w -W -Wall -Waggregate-return
# -Wcast-align -Wcast-qual -Wchar-subscript -Wcomment -Wconversion -Wenum-clash
# -Werror -Wformat -Wid-clash-len -Wimplicit -Wimplicit-int
# -Wimplicit-function-declaration -Winline -Wlong-long -Wmain
# -Wmissing-prototypes -Wmissing-declarations -Wnested-externs -Wno-import
# -Wparentheses -Wpointer-arith -Wredundant-decls -Wreturn-type -Wshadow
# -Wstrict-prototypes -Wswitch -Wtemplate-debugging -Wtraditional -Wtrigraphs
# -Wuninitialized -Wunused -Wwrite-strings
WARNFLAGS = -Wunused -Wall


# Linker Options
# -llibrary -nostartfiles -nostdlib -static -shared -symbolic -Xlinker option
# -Wl,option -u symbol -static 
LINKFLAGS =  -nostartfiles 


# Directory Options
# -Bprefix -Idir -I- -Ldir
LIBDIRS = /usr/local/arm/lib/gcc/arm-elf/lib
#Correct actual version of ARM

# ????? -T switch, what is this ? added 8.11, 14:56
TFILE = ./include/lpc229x-rom.ld
BOOT = -s boot.s

# Debuggin options
# -a -dletters -fpretend-float -g -glevel -gcoff -gxcoff -gxcoff+ -gdwarf
# -gdwarf+ -gstabs -gstabs+ -ggdb -p -pg -save-temps -print-file-name=library
# -print-libgcc-file-name -print-prog-name=program
DEBUGFLAGS = -g

#Dump options
DMPFLAGS = -S
#headers 

CFLAGS = -mcpu=$(TARGET) $(WARNFLAGS) $(OPTIFLAGS) $(COMPFLAGS) $(INCLUDEFLAGS) $(INCLUDEDIR) $(DEBUGFLAGS) -Tlpc2294-rom.ld boot.s
LFLAGS = $(LINKFLAGS) -L$(LIBDIRS)

#OUTFILE = $(addsuffix .bin, $(PROJECT))
DMPFILE = $(addsuffix .dmp, $(PROJECT))

#SYMFILE = $(addsuffix .sym, $(basename $(OUTFILE)))
#INFFILE = $(addsuffix .inf, $(basename $(OUTFILE)))

FILES = \
        ex1
OBJECTS = LokoKernel.o status.o Ramtron.o timer.o rtc.o Interrupt.o armVIC.o uart.o conv.o sysTime.o jtag.o CanTest.o CAN.o pll.o printf.o I2C.o AnalogDevices.o maxim.o ad.o MAM.o WD.o ex1_menu.o ex1.o


project: $(OBJECTS)
	@echo \************** make \( ex1.hex \) file \************** 
	@$(CC) $(PREPFLAGS) $(CFLAGS) $(LFLAGS) $(DEBUGFLAGS) $(OBJECTS) -o prj.o
	@$(OBJCPY) --output-target $(OUT_TARGET) prj.o ~/public/ex1.hex
	@cp ~/public/ex1.hex /mnt/BorisK/public

ad.o:ad.c ad.h
	@echo \************** make \( ad.o \) file \************** 
	@$(CC) $(CFLAGS) $(LFLAGS) $(DEBUGFLAGS) -c ./ad.c

AnalogDevices.o : AnalogDevices.h AnalogDevices.c 
	@echo \************** compile 'AnalogDevices'.c file \************** 
	@$(CC) $(CFLAGS) $(DEBUGFLAGS) -c AnalogDevices.h AnalogDevices.c
armVIC.o:armVIC.c armVIC.h
	@echo \************** compile armVIC.c \**********
	@$(CC) $(CFLAGS) $(DEBUGFLAGS) -c armVIC.c armVIC.h

CanTest.o:CanTest.h CanTest.c
	@echo \************** compile 'CanTest'.c file \************** 
	@$(CC) $(CFLAGS) $(DEBUGFLAGS) -c CanTest.h CanTest.c

CAN.o:	CAN.h CAN.c
	@echo \************** compile CAN.c \**********
	@$(CC) $(CFLAGS) $(DEBUGFLAGS) -c CAN.h CAN.c
conv.o : conv.h conv.o 
	@echo \************** compile 'conv'.c file \************** 
	@$(CC) $(CFLAGS) $(DEBUGFLAGS) -c conv.h conv.c

LokoKernel.o:	LokoKernel.h	LokoKernel.c
	@echo \************** compile LokoKernel.c \**********
	@$(CC) $(CFLAGS) $(DEBUGFLAGS) -c ./LokoKernel.h ./LokoKernel.c
I2C.o : I2C.c I2C.h
	@echo \************** compile 'I2C'.c file \************** 
	@$(CC) $(CFLAGS) $(DEBUGFLAGS) -c I2C.c I2C.h

printf.o:printf.c printf.h
	@echo \************** compile 'printf'.c file \************** 
	@$(CC) $(CFLAGS) $(DEBUGFLAGS) -c printf.c printf.h
pll.o : pll.c pll.h
	@echo \************** compile pll.c \************** 
	@$(CC) $(CFLAGS) $(DEBUGFLAGS) -c pll.c pll.h
Ramtron.o:Ramtron.c Ramtron.h
	@echo \************** make \( Ramtron.o \) file \************** 
	@$(CC) $(CFLAGS) $(LFLAGS) $(DEBUGFLAGS) -c ./Ramtron.c
rtc.o:	rtc.h rtc.c
	@echo \************** make \( rtc.o \) file \************** 
	@$(CC) $(CFLAGS) $(LFLAGS) $(DEBUGFLAGS) -c rtc.h rtc.c
	@$(DMP) -d -S rtc.o > rtc.s

Interrupt.o:Interrupt.c Interrupt.h
	@echo \************** compile Interrupt.c \**********
	@$(CC) $(CFLAGS) $(DEBUGFLAGS) -c Interrupt.c Interrupt.h
	@$(DMP) -d -S Interrupt.o > Interrupt.s
	
sysTime.o:sysTime.c sysTime.h
	@echo \************** compile sysTime.c \**********
	@$(CC) $(CFLAGS) $(DEBUGFLAGS) -c sysTime.c sysTime.h

status.o:status.h status.c
	@echo \************** make \( status.o \) file \************** 
	@$(CC) $(CFLAGS) $(LFLAGS) $(DEBUGFLAGS) -c ./status.h ./status.c
timer.o : timer.c timer.h
	@echo \************** compile timer.c \************** 
	@$(CC) $(CFLAGS) $(DEBUGFLAGS) -c timer.c timer.h 
	
uart.o:	uart.c uart.h
	@echo \************** compile 'uart'.c file \************** 
	@$(CC) $(CFLAGS) $(DEBUGFLAGS) -c uart.c uart.h
jtag.o :  jtag.h jtag.c
	@echo \************** compile 'jtag'.c file \************** 
	@$(CC) $(CFLAGS) $(DEBUGFLAGS) -c jtag.c
WD.o :  WD.h WD.c
	@echo \************** compile 'WD'.c file \************** 
	@$(CC) $(CFLAGS) $(LFLAGS) $(DEBUGFLAGS) -c WD.h WD.c
maxim.o:maxim.h maxim.c
	@echo \************** make \( maxim.o \) file \************** 
	@$(CC) $(CFLAGS) $(LFLAGS) $(DEBUGFLAGS) -c maxim.h maxim.c
MAM.o:	MAM.h MAM.c
	@echo \************** compile MAM.c \************** 
	@$(CC) $(CFLAGS) $(DEBUGFLAGS) -c MAM.h MAM.c

ex1_menu.o:ex1_menu.h ex1_menu.c
	@echo \************** make \( ex1_menu.o \) file \************** 
	@$(CC) $(CFLAGS) $(LFLAGS) $(DEBUGFLAGS) -c ex1_menu.h ex1_menu.c

ex1.o : ex1.h ex1.c
	@echo \************** compile 'ex1'.c file \************** 
	@$(CC) $(CFLAGS) $(LFLAGS) $(DEBUGFLAGS) -c ex1.h ex1.c
clean:
	@rm /mnt/BorisK/public/BK/ex1.hex
	rm *.o *.gch ~/public/ex1.hex
	@rm /home/borisk/public/ex1.hex

asm:	./ex1.c ./ex1.h
	@echo ASM
	@$(CC) $(PREPFLAGS) $(CFLAGS) $(LFLAGS) $(DEBUGFLAGS) -S ex1.h ex1.c
	@$(DMP) -h --disassemble ex1.o
