###########################################################################
#
# File :     makecom/skygcc
#
# Abstract : sky gcc 2.95.2 specific compile time options. 
#
#            See
#            o ee-gcc295 binaries
#              http://www.snsys.com/files/psx2/gcc-2.95.2-ee-1.1-bin.zip
#            o GCC homepage
#              http://www.gnu.org/software/gcc
#            o GCC compilations flags
#              http://www.gnu.org/software/gcc/onlinedocs/gcc_2.html
#
###########################################################################
#
# This file is a product of Criterion Software Ltd.
#
# This file is provided as is with no warranties of any kind and is
# provided without any obligation on Criterion Software Ltd. or Canon Inc. 
# to assist in its use or modification.
#
# Criterion Software Ltd. will not, under any circumstances, be liable for 
# any lost revenue or other damages arising from the use of this file.
#
# Copyright (c) 1999 Criterion Software Ltd.
# All Rights Reserved.
#
# RenderWare is a trademark of Canon Inc.
#
###########################################################################

# Indicate that compiler options have been included
MAKECOM=1

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 \


# by default, C optimisation is off when a C debug build is used.
ifndef COPTIMIZE
ifeq ($(CDEBUG), 1)
COPTIMIZE = 0
else
COPTIMIZE = 1
endif
endif

ifeq ($(COPTIMIZE), 1)
CFLAGS += $(C_OPT) -DNDEBUG  -Wuninitialized
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 win.
endif

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

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

CFLAGS += -DRW_USE_SPF

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

ifdef IOPPATH
CFLAGS += -DIOPPATH=$(IOPPATH)
endif

# These seem to be platform specific, not compiler specific

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

ifeq ("$(COMPILER)", "")
COMPILER=cc
endif

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

######
# included burst from sony Makefiles
######

ifeq ("$(PS2_DRIVE)", "")
SCE = /usr/local/sce/ee
else
SCE = $(PS2_DRIVE):/usr/local/sce/ee
endif

SCELIBDIR      = $(SCE)/lib
SCEINCDIR      = $(SCE)/include

ifeq ("$(SKYLCF)", "RWCMD")
LCFILE      = $(DEMODIR)/../../makecom/sky/rwapp.cmd
else  #  ("$(RWLCF)", "")
LCFILE      = $(SCELIBDIR)/app.cmd 
endif #  ("$(RWLCF)", "")

SYSLIBS     = $(SCELIBDIR)/libgraph.a \
              $(SCELIBDIR)/libdma.a

ifndef SCE_11
SYSLIBS += $(SCELIBDIR)/libpad.a
endif	

ifeq ($(RWDEBUG), 1)
ifeq ($(RWMEMDEBUG), 1)
SYSLIBS += -L$(RWLIBDIR) -lrtdbmalloc
endif # ($(RWMEMDEBUG), 1)
endif # ($(RWDEBUG), 1)
						
CWARNINGS = \
  -W \
  -Wall \
  -Wcast-qual \
  -Wchar-subscripts \
  -Wcomment \
  -Werror-implicit-function-declaration \
  -Wformat \
  -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
#  -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
#  -Wcast-align
#  -Wconversion
#  -Wfloat-equal
#  -Wpacked
#  -Wpadded
#  -Wunreachable-code
#  -Wunused-function
#  -Wunused-label
#  -Wunused-parameter
#  -Wunused-value
#  -Wunused-variable
#  -Waggregate-return
#  -Werror
#  -Wid-clash-len
#  -Wlarger-than-len
#  -fsyntax-only
#  -Wbad-function-cast
#  -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
#  -Wcast-align
#  -Wconversion
#  -Wfloat-equal
#  -Wpacked
#  -Wpadded
#  -Wunreachable-code
#  -Wunused-function
#  -Wunused-label
#  -Wunused-parameter
#  -Wunused-value
#  -Wunused-variable
#  -Waggregate-return
#  -Werror
#  -Wid-clash-len
#  -Wlarger-than-len
#  -fsyntax-only

CC        = ee-gcc295 
CPP       = $(CC)
COUT      = -o
LOUT      = -e
SOUT      = -S -o $@
CPPOPT    = -E -P
CFLAGS   += $(CWARNINGS) -fno-common -c
CFLAGS   += -Wa,-I$(DEVDIR)/$(RWTARGET)
CFLAGS   += -Wa,-al=$*.lst
CFLAGS   += -DSKY 
LD        = ee-gcc295 -Q # -Q seems to avoid temporary file race conditions
LFLAGS   = -T $(LCFILE) -g -Wl,-Map,$(TARGET).map -nostartfiles -L$(SCELIBDIR) -lm
LOUT = -o

AS        = ee-gcc295 -Q # -Q seems to avoid temporary file race conditions
AOUT      = -o
ASFLAGS   = -c -xassembler-with-cpp
ASFLAGS  += -Wa,-al=$*.lsa

DVPASM        = ee-dvp-as
DVPASFLAGS    = -I$(SRCDIR) -I$(DEVDIR)/$(RWTARGET)
DVPAOUT       = -o

RUN = dsedb -r run

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

# We do want assembler

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


# Add crtO.o to list of object files

OBJ += crt0.o

VPATH += $(SCELIBDIR)

# Define some compiler/platform specific parameters for the naming of object
# and library files

O = o
L = a
LP = lib
EXE = .elf

# Directory creation
ifndef MD
MD = mkdir -p
endif

# Patch support
ifeq ($(RWPATCH), 1)
RWLIBS +=					\
	$(RWLIBDIR)/$(LP)rppatch.$(L)			\
	$(RWLIBDIR)/$(LP)rtbezpat.$(L)
endif # ($(RWPATCH), 1)

# The following rule is required, as it is not a default

#.SUFFIXES: .c .$(O) .asm .dsm

$(OBJDIR)/%.$(O) : %.dsm
	$(DVPASM) $(DVPASFLAGS) -alhs $(DVPAOUT)$@ $^ > $(OBJDIR)/$*.lsd
CPPFLAGS += $(CFLAGS)
