#!/bin/sh
#
# source:
#   $Source: /var/cvs/projects/debian/dpkg.common/modifydpkg,v $
#
# revision:
#   @(#) $Id: modifydpkg,v 1.6 1998/05/05 02:42:56 jplejacq Exp $
#
# copyright:
#   Copyright (C) 1998 Jean Pierre LeJacq <jplejacq@quoininc.com>
#
#   Distributed under the GNU GENERAL PUBLIC LICENSE.
#
# synopsis:
#   modifydpkg -p <DH_DOPACKAGES> -P <DH_TMPDIR>
#
# description:
#   Modification script for package files add to pristine source.
#
#   The files added to the pristine source for this debian package
#   have been parameterized to support relocation of the files.  All
#   installed file and directory locations are specified in
#   debian/scripts/substfiles.  This program reads that file and takes
#   each file in debian/src_dpkg/*.in and debian/scripts/*.in and
#   makes the substitution.
#
#   I've implemented argument parsing with the debhelper package.  The
#   sourced file, dh_lib, will define the two arguments.  Currently
#   the arguments are not used.


# main:
  set -e

  . debian/dpkg.common/substfiles 
  . debian/dpkg.scripts/substfiles


  echo "${0}: modifying debian files..."
    sed_cmd=""

    for sed_var in\
      $(grep = debian/dpkg.common/substfiles | cut -f 1 -d = | grep -v subtmp)
    do
      sed_value=$(eval echo "\${${sed_var}}")
      sed_cmd="${sed_cmd}s^@@${sed_var}@@^${sed_value}^g;"
    done

    for sed_var in\
      $(grep = debian/dpkg.scripts/substfiles | cut -f 1 -d = | grep -v subtmp)
    do
      sed_value=$(eval echo "\${${sed_var}}")
      sed_cmd="${sed_cmd}s^@@${sed_var}@@^${sed_value}^g;"
    done

    for file in $(ls ./debian/dpkg.src/*.in)
    do
      sed -e "\
        ${sed_cmd}\
      "\
      ${file} > ${file%.in}
    done

    for file in $(ls ./debian/dpkg.scripts/*.in)
    do
      sed -e "\
        ${sed_cmd}\
      "\
      ${file} > ${file%.in}

      chmod a+x ${file%.in}
    done


  exit 0
