##########################################
# These are for gcc 2.95.3 in the sky cross env #
# See
# o ee-gcc2953 binaries
#   http://www.snsys.com/files/psx2/Temp/ps2-ee-2.95.3-v1.01.zip
# o GCC homepage
#   http://www.gnu.org/software/gcc/gcc-2.95/gcc-2.95.3.html
#   
##########################################

ifeq ($(SMALLCODE), 1)
C_OPT = -Os
else
C_OPT = -O3
endif

C_OPT += \
  -fcaller-saves \
  -fcse-follow-jumps \
  -fcse-skip-blocks \
  -fdelayed-branch \
  -fexpensive-optimizations \
  -ffast-math \
  -fgcse \
  -fmove-all-movables \
  -freduce-all-givs \
  -fregmove \
  -frerun-cse-after-loop \
  -frerun-loop-opt \
  -fschedule-insns2 \
  -fstrength-reduce \
  -fstrict-aliasing \
  -fthread-jumps \
  -funroll-loops 

#  -fdata-sections \
#  -ffunction-sections \

#  -fdelete-null-pointer-checks \
#  -foptimize-register-moves \
#  -fsingle-precision-constant \
#  -falign-functions=n \
#  -falign-jumps=n \
#  -falign-labels=n \
#  -falign-loops=n \
#  -fbranch-probabilities \
#  -fdce \
#  -ffloat-store \
#  -fforce-addr \
#  -fforce-mem \
#  -finline-functions \
#  -finline-limit=n \
#  -fkeep-inline-functions \
#  -fno-default-inline \
#  -fno-defer-pop \
#  -fno-function-cse \
#  -fno-inline \
#  -fno-math-errno \
#  -fno-peephole \
#  -fomit-frame-pointer \
#  -foptimize-sibling-calls \
#  -fschedule-insns \
#  -fssa \
#  -funroll-all-loops \

ifeq ($(COPTIMIZE), 1)
CFLAGS += $(C_OPT)
else
CFLAGS += -O0
#------------
# # gcc requires the generation of a dependency tree, and hence at least -O1,
# # to detect any use of uninitialized variables
# so build optimised then. Code generation options take priority
#------------
endif

ifeq ($(CDEBUG), 1)
CFLAGS += -g
endif

ifeq ($(PG), 1)
CFLAGS += -pg -DPG
ifeq ($(PGA), 1)
CFLAGS += -DPGA
endif
endif

ifeq ($(SCE_11), 1)
CFLAGS += -DSCE_11
endif

# These seem to be platform specific, not compiler specific

ifeq ($(NOASM), 1)
CFLAGS += -DNOASM 
endif

CFLAGS += -DRW_USE_SPF -D__FAST_MATH__

# flag that we're building a PS2 build 
CFLAGS += -DSKY
 
ifeq ("$(COMPILER)", "")
COMPILER=cc
endif

ifeq ("$(LINKER)", "")
# It should be this, but we have a rather strange idea of LINKER
LINKER=link.exe
endif

CWARNINGS =					\
  -W						\
  -Wall						\
  -Wcast-qual					\
  -Wchar-subscripts				\
  -Wcomment					\
  -Werror-implicit-function-declaration		\
  -Wformat					\
  -Wid-clash-31					\
  -Wimplicit					\
  -Wimplicit-function-declaration		\
  -Wimplicit-int				\
  -Wimport					\
  -Winline					\
  -Wlong-long					\
  -Wmain					\
  -Wmissing-noreturn				\
  -Wmultichar					\
  -Wnested-externs				\
  -Wno-import					\
  -Wparentheses					\
  -Wpointer-arith				\
  -Wreturn-type					\
  -Wsign-compare				\
  -Wswitch					\
  -Wtrigraphs					\
  -Wunknown-pragmas				\
  -Wunused					\
  -Wwrite-strings

#  -Wbad-function-cast
#  -Wpadded
#  -Wcast-align
#  -Wredundant-decls
#  -Wshadow
#  -Wtraditional
#  -Wundef
#  -pedantic
#  -Wmissing-declarations /* sce include files fire these warnings*/
#  -Wmissing-prototypes   /* sce include files fire these warnings*/
#  -Wstrict-prototypes    /* sce include files fire these warnings */
#  -w
#  -Wconversion
#  -Wfloat-equal
#  -Wpacked
#  -Wunreachable-code
#  -Wunused-function
#  -Wunused-label
#  -Wunused-parameter
#  -Wunused-value
#  -Wunused-variable
#  -Waggregate-return
#  -Werror
#  -Wlarger-than-len
#  -fsyntax-only

ifeq ($(COPTIMIZE), 1)
CWARNINGS += -Wuninitialized
endif

CC        = ee-gcc2953 # -Q seems to avoid temporary file race conditions
CPP       = $(CC)
COUT      = -o
LOUT      = -e
SOUT      = -S -o $(@F)
CPPOPT    = -E -P
CFLAGS   += $(CWARNINGS) -fno-common
CFLAGS   += -Wa,-I$(DEVDIR)/$(RWTARGET)
CFLAGS   += -Wa,-al=$(OBJDIR)/$(basename $(notdir $<)).lsc
CFLAGS   += -c

AS        = ee-gcc2953 # -Q seems to avoid temporary file race conditions
AOUT      = -o
ASFLAGS   = -c -xassembler-with-cpp
ASFLAGS  += -Wa,-al=$(OBJDIR)/$(basename $(notdir $<)).lsa

DVPASM        = ee-dvp-as
DVPAOUT       = -o

NM        = ee-nm

ifeq ($(CDEBUG), 1)
ASFLAGS     += --gstabs
DVPASMFLAGS += --gstabs
endif

# Librarian options (for append, we include the source lib again)
AR		= ee-ar -r
ARCREATEFLAGS   = $@ $^
ARAPPENDFLAGS	= -out:$@ $@

# How to run programs (no need for shell/simulator)
RUNIT		=

# We do want assembler

CFLAGS += -I/usr/local/sce/ee/include -I/usr/local/sce/gsb/include
CFLAGS += -fno-rtti -fno-exceptions
