#============================================================================
# Setup of compiler/linker flags for debug/optimize mode
# Copyright (C)2003 by Matze Braun <matzebraun@users.sourceforge.net>
#
#    This library is free software; you can redistribute it and/or modify it
#    under the terms of the GNU Library General Public License as published by
#    the Free Software Foundation; either version 2 of the License, or (at your
#    option) any later version.
#
#    This library 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 Library General Public
#    License for more details.
#
#    You should have received a copy of the GNU Library General Public License
#    along with this library; if not, write to the Free Software Foundation,
#    Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
#============================================================================

if ! $(VARIANT)
{
  VARIANT = $(MODE) ;
}

if $(VARIANT) != "debug" && $(VARIANT) != "optimize" && $(VARIANT) != "profile"
{
  exit "Invalid modus set, please set VARIANT to debug, profile or optimize" ;
}

# Set modus related flags
CCFLAGS += $(COMPILER.CFLAGS) $(COMPILER.CFLAGS.$(VARIANT)) ;
C++FLAGS += $(COMPILER.CFLAGS) $(COMPILER.C++FLAGS)
	    $(COMPILER.CFLAGS.$(VARIANT)) $(COMPILER.C++FLAGS.$(VARIANT)) ;
LINKLIBS += $(COMPILER.LFLAGS) $(COMPILER.LFLAGS.$(VARIANT)) ;
LOCATE.OBJECTS = $(LOCATE.OBJECTS)/$(VARIANT) ;

##  SubVariant variantname
##    Specify subvariant which are placed in separate compilation directories.
SUBVARIANT ?= "" ;
SAVED_LOCATE_TARGET = "" ;
rule SubVariant
{
  if ! $(<)
  {
    SUBVARIANT = $(SUBVARIANT[2]) ;
    SUBVARIANT ?= "" ;
    LOCATE_TARGET = $(SAVED_LOCATE_TARGET[1]) ;
    SAVED_LOCATE_TARGET = $(SAVED_LOCATE_TARGET[2-]) ;
  }
  else
  {
    SUBVARIANT = $(<) $(SUBVARIANT) ;
    SAVED_LOCATE_TARGET = $(LOCATE_TARGET) $(SAVED_LOCATE_TARGET) ;
    LOCATE_TARGET = $(LOCATE_TARGET)/$(<) ;
  }
}

