#! /bin/sh
#
# install-epocsdk-headers -- Copyright (c) 2001-2002 Eberhard Mattes
#
# This file is part of epocemx.
#
# epocemx is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# epocemx 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with epocemx; see the file COPYING.  If not, write to the
# the Free Software Foundation, 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.
#

symbian="math.h stdio.h stdlib.h sys/ioctl.h"

usage()
{
  echo "Usage: $myname SOURCE_DIRECTORY DESTINATION_DIRECTORY"
  exit 1
}

die()
{
  echo "$*"
  exit 2
}

myname=$0
test $# = 2 || usage
test -d "$1" || die "$1: not a directory"
test -d "$2" || die "$2: not a directory"

find $1 -follow -type d | sed -n "s!^$1/\(.*\)\$!\\1!p" | tr '[A-Z]' '[a-z]' |
  sed "s!^!$2/!"| xargs mkdir -p

for x in $symbian
do
  mkdir -p $2/symbian/`dirname $x`
done

echo "Creating header files in $2"
p=
find $1 -follow -type f |
  while read f ;do
    b=`echo $f|sed -n "s!$1/!!p"|tr '[A-Z]' '[a-z]'`
    test -z "$b" && die "sed failed"
    test "$b" = "libc/process.h" && continue
    d=$2/$b
    for x in $symbian
    do
      test "$b" = "libc/$x" && d=$2/symbian/`echo $b|sed s!^libc/!!`
    done
    p=$p.
    if [ "$p" = "............" ] ;then
      printf .
      p=
    fi
    emxfixhdr $f $d || die "emxfixhdr failed"
    touch -r $f $d 2>/dev/null
  done
echo
