# $Id: makefile,v 1.00 2005/06/09 17:51:00 BorisK Exp $
#
# Copyright (C) 2004 ONTRACK s.r.o.
# 
#  This program is free software; you can redistribute it and/or
#  modify it under the terms of the GNU General Public License
#  as published by the Free Software Foundation; either version 2
#  of the License, or (at your option) any later version.
# 
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
# 
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
#  02111-1307, USA.
# 
#  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 = PWM

#*****************        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 	= /usr/local/arm/bin/arm-elf-gcc
CPP 	= /usr/local/arm/bin/arm-elf-g++
LD	= /usr/local/arm/bin/arm-elf-ld
#CPP kompilator nejde koser 
DMP 	= /usr/local/arm/bin/arm-elf-objdump
OBJCPY 	= /usr/local/arm/bin/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/3.4.2

# ????? -T switch, what is this ? added 8.11, 14:56
TFILE = ./include/lpc229x-ram.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 = \
        PWM
OBJECTS = printf.o pll.o WD.o armVIC.o uart.o conv.o sysTime.o PWM.o I2C.o Interrupt.o jtag.o PWMEx.o
project: $(OBJECTS)
	@echo \************** make \( PWMEx.hex \) file \************** 
	@$(CC) $(PREPFLAGS) $(CFLAGS) $(LFLAGS) $(DEBUGFLAGS) $(OBJECTS) -o prj.o
	@$(OBJCPY) --output-target $(OUT_TARGET) prj.o /home/borisk/public/PWMEx.hex
	sudo cp /home/borisk/public/PWMEx.hex ~/mnt/BorisK/public
printf.o:./example1/printf.h ./example1/printf.c
	@echo \************** compile 'printf'.c file \************** 
	@$(CC) $(CFLAGS) $(DEBUGFLAGS) -c ./example1/printf.c ./example1/printf.h
pll.o : ./example1/pll.h ./example1/pll.c
	@echo \************** compile pll.c \************** 
	@$(CC) $(CFLAGS) $(DEBUGFLAGS) -c ./example1/pll.h ./example1/pll.c

WD.o : ./example1/WD.c ./example1/WD.h
	@echo \************** compile 'WD'.c file \************** 
	@$(CC) $(CFLAGS) $(DEBUGFLAGS) -c ./example1/WD.c ./example1/WD.h
armVIC.o:	./example1/armVIC.c ./example1/armVIC.h
	@echo \************** make \( armVIC.o \) file \************** 
	@$(CC) $(CFLAGS) $(LFLAGS) $(DEBUGFLAGS) -c ./example1/armVIC.c
uart.o:		./example1/uart.c ./example1/uart.h
	@echo \************** make \( uart.o \) file \************** 
	@$(CC) $(CFLAGS) $(LFLAGS) $(DEBUGFLAGS) -c ./example1/uart.c
conv.o:		./example1/conv.c ./example1/conv.h
	@echo \************** make \( conv.o \) file \************** 
	@$(CC) $(CFLAGS) $(LFLAGS) $(DEBUGFLAGS) -c ./example1/conv.c
sysTime.o:	./example1/sysTime.c ./example1/sysTime.h
	@echo \************** make \( sysTime.o \) file \************** 
	@$(CC) $(CFLAGS) $(LFLAGS) $(DEBUGFLAGS) -c ./example1/sysTime.c
PWM.o:	./example1/PWM.c ./example1/PWM.h
	@echo \************** make \( PWM.o \) file \************** 
	@$(CC) $(CFLAGS) $(LFLAGS) $(DEBUGFLAGS) -c ./example1/PWM.c
I2C.o:	./example1/I2C.c ./example1/I2C.h
	@echo \************** make \( I2C.o \) file \************** 
	@$(CC) $(CFLAGS) $(LFLAGS) $(DEBUGFLAGS) -c ./example1/I2C.c
Interrupt.o:./example1/Interrupt.c ./example1/Interrupt.h
	@echo \************** compile Interrupt.c \**********
	@$(CC) $(CFLAGS) $(DEBUGFLAGS) -c ./example1/Interrupt.c ./example1/Interrupt.h
jtag.o : ./example1/jtag.c ./example1/jtag.h
	@echo \************** compile 'jtag'.c file \************** 
	@$(CC) $(CFLAGS) $(DEBUGFLAGS) -c ./example1/jtag.c
PWMEx.o: PWMEx.c PWMEx.h
	@echo \************** make \( PWMEx.o \) file \**************
	@$(CC) $(CFLAGS) $(LFLAGS) $(DEBUGFLAGS) -c PWMEx.c
clean:
	@rm *.o ~/public/*.hex 
