#!/bin/bash

#That file must NOT contain any logic.

# functions defined in here: (in alphabetical order)
#    conflicts              (libgrimoire)  
#    default_build          (libgrimoire)   
#    default_post_build     (libgrimoire)   
#    default_pre_build      (libgrimoire)   
#    depends                (libdepends)
#    installed_version      (libgrimoire)   
#    message                (libmisc)      
#    mk_source_dir          (libgrimoire)   
#    on_cast                (libtriggers)   
#    on_dispel              (libtriggers)  
#    on_pre_cast            (libtriggers)   
#    on_pre_dispel          (libtriggers)   
#    optional_depends       (libdepends)
#    prepare_install        (libgrimoire)   
#    query                  (libmisc)       
#    requires               (libdepends)
#    sedit                  (libmisc)       
#    spell_installed        (libsorcery)
#    unpack                 (libgrimoire)   


# troublemakers SOURCE_CACHE, OPTS, CFLAGS, CXXFLAGS, CPPFLAGS, CC and LDFLAGS



#---------------------------------------------------------------------
## @Type API
## @param spell/service
#---------------------------------------------------------------------
function depends () {
    debug "depends - $*"
    real_depends "$@"
}


#---------------------------------------------------------------------
## @Type API
## @param spell/service
#---------------------------------------------------------------------
function optional_depends () {
    debug "optional_depends - $*"
    real_optional_depends "$@"
}


#---------------------------------------------------------------------
## @param spell
## @param default answer to dispel query
## @Type API
## If the default answer is anything other than 'y' then 'n' is assumed.
## returns the given spellname if it is installed
##
#---------------------------------------------------------------------
function conflicts () {
    debug "conflicts - $*"
    real_conflicts "$@"
}


#---------------------------------------------------------------------
## @Type API
## Creates the source directory and unpacks the source package into it.
## Used if no PRE_BUILD script is found for a spell.
##
#---------------------------------------------------------------------
function default_pre_build () {
    debug "default_pre_build - $*"
    real_default_pre_build "$@"
} 


#---------------------------------------------------------------------
## @Type API
## Used if no BUILD script is found for a spell
## Default build is:
## <pre>
##  ./configure  --build=$BUILD        \
##               --prefix=/usr         \
##               --sysconfdir=/etc     \
##               --localstatedir=/var  \
##               $OPTS                 &&
##  make                               &&
##  prepare_install                    &&
##  make    install
## </pre>
##
#---------------------------------------------------------------------
function default_build () {
    debug "default_build - $*"
    real_default_build "$@"
}


#---------------------------------------------------------------------
## @Type API
## Installs configuration files and documentation.  Stops installwatch.
## Used if no POST_BUILD script is found for a spell.
##
#---------------------------------------------------------------------
function default_post_build () {
    debug "default_post_build - $*"
    real_default_post_build "$@"
}

#---------------------------------------------------------------------
## @Type API
## @param file to unpack 
## @param md5sum
##
## Given a file, unpack runs the decompression program for that file,
## as well as untar'ing the file if appropriate and if the MD5
## matches.
## Note: zip is a special cast because it doesn't work with streams.
##
#---------------------------------------------------------------------
function unpack () {
    debug "unpack - $*"
    real_unpack "$@"
}


#---------------------------------------------------------------------
## @Type API
## Only a call to depends. Deprecated.
#---------------------------------------------------------------------
function requires () {
    debug "requires - $*"
    real_requires "$@"
}


#---------------------------------------------------------------------
## @Type API
## @param question 
## @param default answer
##
## @return 0 on yes
## @return 1 on no
##
## Asks the user a yes/no question.  First argument is the question to
## ask, second argument is the default answer.  If a timeout occurs
## before the question is answered, the given default answer is 
## applied.  Returns true or false based on the answer given.
##
#---------------------------------------------------------------------
function query () {
    debug "query - $*"
    real_query "$@"
}


#---------------------------------------------------------------------
## @Type API
## @param message to echo
## @Stdout message
## echo's the given arguments if SILENT is not set.
##
#---------------------------------------------------------------------
function message () {
    debug "message - $*"
    real_message "$@"
}


#---------------------------------------------------------------------
## @Type API
## @param sed command
## @param file
##
## First argument is a sed command.  Second argument is a file.  
## sedit performs the sed command on the file, modifiying the 
## original file.  For example, 
## <br>sedit "s/foo/bar/g" /tmp/somefile <br>
## will replace all occurances of foo with bar in /tmp/somefile.  
## This function is often used in spells to make changes to source
## files before compiling.  See the sed man page for more information.
##
#---------------------------------------------------------------------
function sedit () {
    debug "sedit - $*"
    real_sedit "$@"
}


#---------------------------------------------------------------------
## @Type API
## Prepares to install the spell.  Writes the boost lock file.  If the
## spell is installed already, the libraries are saved with
## save_libraries() and the spell is dispelled.  Usually called from
## the BUILD sript of a spell.
##
#---------------------------------------------------------------------
function prepare_install () {
    debug "prepare_install - $*"
    real_prepare_install "$@"
}


#---------------------------------------------------------------------
## @Type API
## @param directory name 
## @param [size]
## Creates a tmpfs filesystem.  By default, the size is 1GB.
## The caller may optionally supply a size argument.
## <pre>
## Example1:  Create a 2GB mount at $SOURCE_DIRECTORY
##
##    mk_source_dir  $SOURCE_DIRECTORY  2g
##
## Example2:  Create a mount at /tmp/newdir, defaults to 1GB size
##
##    mk_source_dir  /tmp/newdir
## </pre>
#---------------------------------------------------------------------
function mk_source_dir () {
    debug "mk_source_dir - $*"
    real_mk_source_dir "$@"
}


#---------------------------------------------------------------------
## @Type API
## @param spell name
##
## @return 0 if the given spell's status is "installed"
#---------------------------------------------------------------------
function spell_installed () {
    debug "spell_installed - $*"
    real_spell_installed "$@"
}


#---------------------------------------------------------------------
## @Type API
## @param spell
## Returns the current version of the given spell
##
#---------------------------------------------------------------------
function installed_version () {
    debug "installed_version - $*"
    real_installed_version "$@"
}


#---------------------------------------------------------------------
## @Type API
## @param spell that triggers
## @param action
##
## Used by spells to make adding triggerse nice.
##
#---------------------------------------------------------------------
function on_cast () {
    debug "on_cast - $*"
    real_on_cast "$@"
}



#---------------------------------------------------------------------
## @Type API
## @param spell that triggers
## @param action
##
## Used by spells to make adding triggers nice.
##
#---------------------------------------------------------------------
function on_dispel () {
    debug "on_dispel - $*"
    real_on_dispel "$@"
}


#---------------------------------------------------------------------
## @Type API
## @param spell that triggers
## @param action
##
## Used by spells to make adding triggerse nice.
##
#---------------------------------------------------------------------
function on_pre_cast () {
    debug "on_pre_cast - $*"
    real_on_pre_cast "$@"
}


#---------------------------------------------------------------------
## @Type API
## @param spell that triggers
## @param action
##
## Used by spells to make adding triggerse nice.
##
#---------------------------------------------------------------------
function on_pre_dispel () {
    debug "on_pre_dispel - $*"
    real_on_pre_dispel "$@"
}


