#
# Jamrules file to build CUnit - Root Directory
# (see http://www.freetype.org/jam/index.html)
#
# Copyright (C) 2004, 2005  Jerry St.Clair
#
# 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#---------------------------------------------------------------------------

# On *nix, configure will set prefix & install locations.
# On Windows, manually edit to set prefix to the installatino root.
prefix = /usr/local ;

# Install locations - comment out to not install that class of file
INSTALL_LIB_DIR   = $(prefix)$(SLASH)lib ;
INSTALL_INC_DIR   = $(prefix)$(SLASH)include$(SLASH)CUnit ;
INSTALL_DOC_DIR   = $(prefix)$(SLASH)doc$(SLASH)CUnit ;
INSTALL_MAN_DIR   = $(prefix)$(SLASH)man ;
INSTALL_SHARE_DIR = $(prefix)$(SLASH)share$(SLASH)CUnit ;
INSTALL_EXAM_DIR  = $(prefix)$(SLASH)share$(SLASH)CUnit$(SLASH)Examples ;

# location of ncurses library for CursesTest (ignored on Windows)
SYS_LIB_DIR = /usr/lib ;

# Comment to compile with debugging & assertions enabled
NODEBUG = 1 ;

# Uncomment to perform memory tracing
#USE_MEMTRACE = -DMEMTRACE ;

# Uncomment to recognize deprecated version 1.1 function names
# and build V1.1 examples
#USE_DEPRECATED_NAMES = -DUSE_DEPRECATED_CUNIT_NAMES ;

# Comment for normal jam deletion of object files after building targets
#KEEPOBJS = true ;

#---------------------------------------------------------------------------
# Options from here on should not require routine tweaking

# Build directory - - will be qualified for compiler & build type
BUILD_DIR_ROOT = $(TOP) ;

EXAMPLES_DIR   = $(TOP)$(SLASH)Examples ;

CUNIT_HDR_DIR  = $(TOP)$(SLASH)CUnit$(SLASH)Headers ;
CUNIT_LIB_NAME = libcunit ;

if $(NODEBUG)
{
  CCFLAGS += -DNDEBUG ;               
  BUILD_SUBDIR = $(SLASH)Release ;
}
else
{
  BUILD_SUBDIR = $(SLASH)Debug ;
}

if $(NT)
{
  # variables not set properly for Windows/Win9x in Jambase 2.3
  RM = del ;
  MV = move /Y ;

  # Windows-specific defines
  CCFLAGS += -DWIN32 -D_LIB -D_MBCS -D_DELAYTEST ;
  CUNIT_WIN_DIR = $(TOP)$(SLASH)CUnit$(SLASH)Sources$(SLASH)Win ;

  if $(BCCROOT) || ( $(TOOLSET) = BORLANDC )
  {
    CCFLAGS   += -q -d -g0 -j0 ;
    CCWARN    = -w ;
    if $(NODEBUG)
    {
      CCDEBUG = -v- -O2 ;
    }
    else
    {
      CCDEBUG = -v -y -Od ;
    }
    BUILD_SUBDIR = $(BUILD_SUBDIR)$(SLASH)bcc ;
  }

  else if $(MSVCNT) || ( $(TOOLSET) = VISUALC )
  {
    CCFLAGS   += /Ze ;
    CCWARN    = /W4 ;
    if $(NODEBUG)
    {
      CCDEBUG = /O2 ;
    }
    else
    {
      CCDEBUG = /Zi /Od ;
    }
    # Libraries are in different paths depending on VC version
    LINKFLAGS += /LIBPATH:$(VISUALC)\\lib /LIBPATH:$(VISUALC)\\PlatformSDK\\lib\\ ;
    LINKLIBS = advapi32.lib
               libc.lib
               oldnames.lib
               gdi32.lib
               user32.lib
               kernel32.lib ;
    BUILD_SUBDIR = $(BUILD_SUBDIR)$(SLASH)msvc ;
  }


  else if $(MINGW) || ( $(TOOLSET) = MINGW )
  {
    # uncomment to select desired warning level and ansi-strictness
    CCWARN += -Wall ;
    CCWARN += -W ;
    CCWARN += -pedantic ;
    CCWARN += -Wshadow ;
    CCWARN += -ansi ;

    if $(NODEBUG)
    {
      CCDEBUG = -O3 ;
    }
    else
    {
      CCDEBUG = -g -O0 ;
    }
    BUILD_SUBDIR = $(BUILD_SUBDIR)$(SLASH)mingw ;
  }

  else if $(WATCOM) || ( $(TOOLSET) = WATCOM )
  {
    CCFLAGS += /fr ;
    CCWARN    = /wx ;
    if $(NODEBUG)
    {
      CCDEBUG = /ox ;
    }
    else
    {
      CCDEBUG = /od /d2 ;
    }
    BUILD_SUBDIR = $(BUILD_SUBDIR)$(SLASH)watcom ;
  }
}

else if $(OS) = LINUX
{
  # uncomment to select desired warning level and ansi-strictness
  CCWARN += -Wall ;
  CCWARN += -W ;
  CCWARN += -pedantic ;
  CCWARN += -Wshadow ;
  #CCWARN += -ansi ;

  if $(NODEBUG)
  {
    CCDEBUG = -O3 ;
  }
  else
  {
    CCDEBUG = -g -O0 ;
  }
  BUILD_SUBDIR = $(BUILD_SUBDIR)$(SLASH)linux ;
}

CCFLAGS  += $(USE_MEMTRACE) $(CCWARN) $(CCDEBUG) ;
C++FLAGS += $(CCFLAGS) ;
BUILD_DIR = $(BUILD_DIR_ROOT)$(BUILD_SUBDIR) ;

#----------------------------------------------------------------------
# CUnit-specific rules & actions
#----------------------------------------------------------------------
# If anyone can figure out a better way, good for you
# (and let me (jds) know)!  Here's the problem...
# The built-in Jam install rules all convert the grist of
# the source file to (:G=installed).  As a result, they
# seem unable to handle files having the same name in
# different directories.  If we want to install such files
# as the Jamfile's or Makefile.am's or README's, the built-ins
# can't handle it (in my hands, anyway).  As a workaround,
# we define a new rule which does not monkey with the grist
# in this way.  Duplicate file names will need to explicitly
# use grist so Jam knows the difference, but the standard
# <$(SOURCE_GRIST)> works in most cases.
#
rule DoInstallCUnitFile
{
    local i t ;

    t = $(>:D=$(<)) ;

    DEPENDS install : $(t) ;
    DEPENDS $(t) : $(>) ;
    SEARCH on $(>) = $(SEARCH_SOURCE) ;
    MakeLocate $(t) : $(<) ;

    # Arrange for jam uninstall

    Clean uninstall : $(t) ;

    for i in $(>)
    {
        Install $(i:D=$(<)) : $(i) ;
        Chmod $(i:D=$(<)) ;
    }

    if $(UNIX)
    {
        if $(OWNER) { Chown $(t) ; OWNER on $(t) = $(OWNER) ; }
        if $(GROUP) { Chgrp $(t) ; GROUP on $(t) = $(GROUP) ; }
    }
}

rule InstallCUnitBin
{
    DoInstallCUnitFile $(<) : $(>) ;
    MODE on $(>:D=$(<)) = $(EXEMODE) ;
}

rule InstallCUnitFile
{
    DoInstallCUnitFile $(<) : $(>) ;
    MODE on $(>:D=$(<)) = $(FILEMODE) ;
}
