#! /bin/sh

#---------------------------------------------------------------------
#                             load-config                             
# 
# This is the opportunity for the template to modify the package
# configuration stored in fw-pkgin/config, e.g., add the template to the
# build dependencies.
# 
# The convention is that every program that wants to load fw-pkgin/config
# will go through template/$template/load-config
#---------------------------------------------------------------------

#---------------------------------------------------------------------
#                           chicken and egg                           
#---------------------------------------------------------------------

test -f "${FW_ROOT}/share/fw/sh/fw-find.sh" && fws="${FW_ROOT}/share/fw/sh/fw-find.sh"
test -f "fw/sh/fw-find.sh" && fws="fw/sh/fw-find.sh"
test -f "fw.local/sh/fw-find.sh" && fws="fw.local/sh/fw-find.sh"
test ! -z "$fws" || {
  echo "script/load-config: fatal: can't locate fw-find.sh" 1>&2
  exit 1
}

. "$fws"

#---------------------------------------------------------------------
#                              routines                               
#---------------------------------------------------------------------

fw_source "script/load-config" "sh/fw-exec.sh"
fw_source "script/load-config" "sh/parse-args.sh"
fw_source "script/load-config" "sh/validate-args.sh"

#---------------------------------------------------------------------
#                                main                                 
#---------------------------------------------------------------------

parse_args "script/load-config" "$@"

validate_args "script/load-config" "" ""

# default behavior: add the package providing the template to the build
# dependencies

fw_exec "build/automake/load-config" |                          \
perl -pe 's%FW_PACKAGE_BUILD_DEPENDS="(.*)"%FW_PACKAGE_BUILD_DEPENDS="fw-template-c, pkg-config [!darwin-i386], pkgconfig [darwin-i386], $1"%; s%, "%"%; s%#(.*)%%;'
