#Build-Directories, PDIR will be submitted by GT.bash:
#                   PDIR=$(GT_DIR)/Build/GT2004/$(PROCSET)/DebugVersion
#directories
BDIR=$(PDIR)/bin
ODIR=$(PDIR)
PPDIR=$(ODIR)/Processes/$(PROCSET)
SDIR=$(GT_DIR)/Src/Processes/$(PROCSET)

PREFIX=/usr/local/OPEN_R_SDK

#used programms
CXX=$(PREFIX)/bin/mipsel-linux-g++
AS=$(PREFIX)/bin/mipsel-linux-as
STRIP=$(PREFIX)/bin/mipsel-linux-strip
MKBIN=$(PREFIX)/OPEN_R/bin/mkbin


WARNINGS_ON = -Wall -W -Wcast-qual -Wconversion -Wstrict-prototypes -Wmissing-prototypes -pedantic
#produce too many (useless) warnings (or errors): -Wshadow -Wredundant-decls -Weffc++ -Wwrite-strings -Wcast-align
WARNINGS_OFF = -Wno-non-virtual-dtor -Wno-switch -Wno-unused-parameter -Wno-reorder
#add -Wno-unused to avoid unused variable warnings
#add -Wno-uninitialized to avoid uninitialized variable warnings


#optimized: correct architecture, links much faster without -g
#debuggable: needs -g, output of line number only works with standard mips:3000, even -O3 does not disorganisesource code lines too much
OPTIM      = $$(if test "$(OPTIMIZATION)"x = "true"x; then echo -O3 -Wno-deprecated; else echo -g -O3 $(WARNINGS_ON) $(WARNINGS_OFF); fi)
MKBINFLAGS = $$(if test "$(OPTIMIZATION)"x = "true"x; then echo -p $(PREFIX) -A 4300 --no-warn-mismatch; else echo -p $(PREFIX); fi)
ARCH       = $$(if test "$(OPTIMIZATION)"x = "true"x; then echo -march=r4300 -mtune=r4300; fi)
ASFLAGS    = $$(if test "$(OPTIMIZATION)"x = "true"x; then echo -Wa,-W,-march=r4300,-mtune=r4300,-O; else echo -Wa,-W,-O; fi)


CXXFLAGS = $(OPTIM) $(ARCH) -DLARGE_FIELD -DAPERIOS1_3_2 $(DEBUG_DEFINITIONS) -fmessage-length=0  $(ASFLAGS)


# list of all cpp-files possibly needed for actual ProcessSet for all
# those files directories and odeps have to be built under build/$(PROCSET)
CPPS=find Representations Modules Platform/Aperios1.3.2 Processes/$(PROCSET) Tools -name '*.cpp' | sort -u -f


#some sets of include directories
CPP_INC = $(PREFIX)/OPEN_R/include/R4000 $(PREFIX)/OPEN_R/include $(PREFIX)/OPEN_R/include/stl $(GT_DIR)/Src $(PREFIX)/OPEN_R/include/mcoop
LIB_INC = 


#set of libraries
LIBS = OPENR ObjectComm mcoopstub ERA201D1 antMCOOP Internet


#some files
TMP1 = $(PDIR)/tmpfile1
DEPINC=$(PDIR)/depends.incl


all: ensuredeps objects
	@rm -rf $(SDIR)/GNUmakefile

#build all binaries, useful content will be included in $(DEPINC)
objects:
	@#that's it, we built all binaries!!!

include $(DEPINC)


#create all neccessary directories, fake all odep and bindep and include all these files
ensuredeps: $(GT_DIR)/Make/makefile
	@echo "! `date +%T` ensure existence of all directories"
	@cd $(GT_DIR)/Src && find Representations Modules Platform/Aperios1.3.2 Processes/$(PROCSET) Tools -name '*.cpp' -printf '%h\n' |sort -u -f |gawk 'BEIGN{FS="\n"}{system("mkdir -p $(ODIR)/"$$1)}'
	@echo "! generate all odeps and bindeps in depends.incl"
	@$(GT_DIR)/Bin/Depend.exe $(CXXFLAGS) -D__GNUC__ -I$(GT_DIR)/Src -B$(PDIR) -P$(PROCSET) `cat $(SDIR)/$(PROCSET).ocf |grep "^# objectmapping" |tr -d '\015' |gawk 'BEGIN{FS=" "}{print $$3"="$$4".cpp"}' |tr -s '\012' ' '` \
		|sed "s=v:/=$(REAL_GT_DIR)/="
	@make -r -f $(GT_DIR)/Make/makefile objects


.SUFFIXES: .bin .o .cpp
        
%.o:
	@echo "! compile `echo $@ |sed 's%$(ODIR)\(.*\).o%$(GT_DIR)/Src\1.cpp%'`"
	@#echo $(CXX) $(CXXFLAGS) $(CPP_INC:%=-I%) -o $@ -c `echo $@ |sed 's%$(ODIR)\(.*\).o%$(GT_DIR)/Src\1.cpp%'`
	@$(CXX) $(CXXFLAGS) $(CPP_INC:%=-I%) -o $@ -c `echo $@ |sed 's%$(ODIR)\(.*\).o%$(GT_DIR)/Src\1.cpp%'` 2>&1 \
	  |sed "s=:\([0-9][0-9]*\):[0-9]*:=(\1) :=" \
	  |sed "s=v:/=$(REAL_GT_DIR)/=" \
	  |sed "s=\(.*\):\([0-9][0-9]*\): \(.\)=   \1(\2) : error : \3=" \
	  |sed "s=.*from \(.*\):\([0-9][0-9]*\).*=   \1(\2) :=" \
	  |sed "s= error : [wW]arning= warning=" >&2

##this might be useful for finding strange compile bugs:
#$(CXX) -S $(CXXFLAGS) $(CPP_INC:%=-I%) -o $@.s -c `echo $@ |sed 's%$(ODIR)\(.*\).o%$(GT_DIR)/Src\1.cpp%'` 2>&1 \
#  |sed "s=:\([0-9][0-9]*\):[0-9]*:=(\1) :=" \
#  |sed "s=\(.*\):\([0-9][0-9]*\): \(.\)=   \1(\2) : error : \3=" \
#  |sed "s=.*from \(.*\):\([0-9][0-9]*\).*=   \1(\2) :=" \
#  |sed "s= error : warning= warning=" >&2
#if test -f $@.s; then \
#  $(AS) $(ASFLAGS) -o $@ $@.s 2>&1 |grep -v "Assembler messages" |grep -v "^Error"; \
#  rm -f $@.s; \
#else return 1; fi
##in case of failure simply exit to ensure that we do not try to link

#
# Change Log:
#
# $Log: makefile,v $
# Revision 1.8  2004/02/15 22:55:17  dueffert
# REAL_GT_DIR introduced to allow debugging and v:-subst
#
# Revision 1.7  2004/02/13 17:29:07  dueffert
# /obj removed (see newsgroup)
#
# Revision 1.6  2004/01/29 17:02:56  dueffert
# use gawk instead of awk
#
# Revision 1.5  2003/11/30 22:22:11  wachter
# added libs for direct ip communication
#
# Revision 1.4  2003/11/29 23:06:43  wachter
# added path to ant.h (openr ip-stack)
#
# Revision 1.3  2003/10/31 16:30:24  dueffert
# assembler flags restored
#
# Revision 1.2  2003/10/27 19:20:38  loetzsch
# recovered support for multiple process layouts
#
# Revision 1.1  2003/10/06 12:56:17  cvsadm
# Created GT2004 (M.J.)
#
# Revision 1.3  2003/09/26 15:30:52  juengel
# Renamed DataTypes to representations.
#
# Revision 1.2  2003/09/24 16:10:25  juengel
# removed absolute paths
#
# Revision 1.1.1.1  2003/07/02 09:40:22  cvsadm
# created new repository for the competitions in Padova from the 
# tamara CVS (Tuesday 2:00 pm)
#
# removed unused solutions
#
# Revision 1.26  2003/06/24 15:11:30  dueffert
# "DebugNoDebugDrawing" uses compiler flags for optimization now.
# This allows for stopping the times used in release version (eg ImageProcessor 20% faster).
# Unfortunately that does not work with emonlogparser. Use configuration "Debug" for that.
#
# Revision 1.25  2003/05/26 09:50:15  goehring
# An error:warning is recognized as a warning now
#
# Revision 1.24  2003/05/07 00:38:02  dueffert
# minimal speedup
#
# Revision 1.23  2003/05/05 14:59:40  dueffert
# release build without debug symbols but with architecture optimization
#
# Revision 1.22  2003/05/05 12:24:50  dueffert
# dependencies are now completely generated in c each time
#
# Revision 1.21  2003/05/03 13:05:49  roefer
# getMacAddress added
#
# Revision 1.20  2003/04/19 13:49:05  roefer
# -O3 again
#
# Revision 1.19  2003/04/16 13:54:56  loetzsch
# removed Xabsl 1 from GT2003
#
# Revision 1.18  2003/04/07 12:21:57  loetzsch
# disabled reorder warnings
#
# Revision 1.17  2003/03/14 13:46:50  dueffert
# two sets of flags: optimized and debuggable, debuggable is default
#
# Revision 1.16  2003/03/12 22:28:03  roefer
# gcc 2.95 only accepts -O2
#
# Revision 1.15  2003/03/12 11:24:45  dueffert
# produce binaries for mips:4300 instead of default mips:3000
#
# Revision 1.14  2003/03/10 18:25:28  dueffert
# output of further warnings added
#
# Revision 1.13  2003/03/10 14:16:15  dueffert
# output time
#
# Revision 1.12  2003/03/06 18:13:55  dueffert
# gimme all (useful) warnings!
#
# Revision 1.11  2003/03/03 13:31:45  dueffert
# warnings beautified
#
# Revision 1.10  2003/02/17 10:42:57  dueffert
# beautifiying
#
# Revision 1.9  2003/02/14 10:19:39  dueffert
# output of warnings beautified
#
# Revision 1.8  2003/02/12 15:42:26  dueffert
# gawk instead of awk
#
# Revision 1.7  2002/11/16 09:33:41  dueffert
# greenhills backport completed
#
# Revision 1.6  2002/11/10 18:45:42  roefer
# LARGE_FIELD defined
#
# Revision 1.5  2002/09/17 14:50:00  dueffert
# all dependencies and some comments added; cleanup
#
# Revision 1.4  2002/09/16 18:55:57  dueffert
# first GT2003-Build! Some dependencies still have to be added
#
# Revision 1.3  2002/09/12 17:10:50  dueffert
# nearly working :-)
#
# Revision 1.2  2002/09/11 17:25:23  loetzsch
# removed some left ".gcc" statements
#
# Revision 1.1  2002/09/10 15:11:38  cvsadm
# Created new project GT2003 (M.L.)
#
# Revision 1.10  2002/08/16 23:28:28  dueffert
# STRIP optional; dependency errors in VS-format
#
# Revision 1.9  2002/07/26 14:52:51  roefer
# Errors and warnings are now compatible with VisualStudio
#
# Revision 1.8  2002/07/15 12:43:31  dueffert
# gcc with -g now, *.o debuggable, FormatedOutput integrated in makefile, mkbin seems to strip debug info
#
# Revision 1.7  2002/07/14 14:03:07  roefer
# First working gcc-version
#
# Revision 1.6  2002/07/09 14:46:23  dueffert
# something for gcc port
#
# Revision 1.5  2002/07/08 15:57:32  dueffert
# gcc compiles and links now
#
# Revision 1.4  2002/07/08 10:20:18  dueffert
# further steps towards gcc
#
# Revision 1.3  2002/07/05 13:56:38  dueffert
# optimized
#
# Revision 1.2  2002/07/04 16:51:38  dueffert
# bug fixed
#
# Revision 1.1  2002/07/04 16:36:34  dueffert
# started to port to gcc
#
#
#
