#! /bin/sh
#
# diff-sdk -- Copyright (c) 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.
#

# This program is used for maintaining emxfixhdr
# Cf. tools/install-epocsdk-headers

ROOT=/usr/local/epocemx

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

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

test -e sdk0 && die "sdk0 exists"
test -e sdk1 && die "sdk1 exists"
mkdir sdk0 || die "cannot create sdk0"
mkdir sdk1 || die "cannot create sdk1"

s0=SDK-inc
s1=$ROOT/epocsdk/include

test -d $s0 || die "$s0: does not exist"
test -d $s1 || die "$s1: does not exist"

find $s0 -follow -type d | sed -n "s!^$s0/\(.*\)\$!\\1!p" | tr A-Z a-z |
  sed "s!^!sdk0/!" | xargs mkdir
find $s1 -follow -type d | sed -n "s!^$s1/\(.*\)\$!\\1!p" | tr A-Z a-z |
  sed "s!^!sdk1/!" | xargs mkdir

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

find $s0 -follow -type f |
  while read f ;do
    b=`echo $f|sed -n "s!$s0/!!p"`
    test -z "$b" && die "sed failed"
    test "$b" = "libc/process.h" && continue
    d=sdk0/$b
    for x in $symbian
    do
      test "$b" = "libc/$x" && d=sdk0/symbian/`echo $b|sed s!^libc/!!`
    done
    printf .
    emxfixhdr $f $d || die "emxfixhdr failed"
    touch -r $f $d || die "touch failed"
  done
echo

find $s1 -follow -type f ! -name "*~" |
  while read f ;do
    b=`echo $f|sed -n "s!$s1/!!p"`
    test -z "$b" && die "sed failed"
    d=sdk1/$b
    printf .
    emxfixhdr -n $f $d || die "emxfixhdr failed"
    touch -r $f $d || die "touch failed"
  done
echo

diff -rc sdk0 sdk1 >maint/diff-sdk.out
rm -rf sdk0 sdk1
if [ -s maint/diff-sdk.out ]
then
  echo 'There are differences, see maint/diff-sdk.out'
else
  echo 'OK'
fi
