2001-12-26 05:53:34 +01:00
|
|
|
#!/bin/sh
|
2002-01-13 21:03:03 +01:00
|
|
|
# cygmagic - Generate "magic numbers" from a structure.
|
|
|
|
#
|
|
|
|
# Copyright 2001, 2002 Red Hat, Inc.
|
|
|
|
#
|
|
|
|
# This file is part of Cygwin.
|
|
|
|
#
|
|
|
|
# This software is a copyrighted work licensed under the terms of the
|
|
|
|
# Cygwin license. Please consult the file "CYGWIN_LICENSE" for
|
|
|
|
# details.
|
|
|
|
|
2001-12-26 05:53:34 +01:00
|
|
|
file_magic=$1; shift
|
|
|
|
gcc=$1; shift
|
|
|
|
file=$1; shift
|
|
|
|
trap "rm -f /tmp/$$.magic" 0 1 2 15
|
|
|
|
cat <<EOF > $file_magic
|
|
|
|
/* autogenerated - do not edit */
|
|
|
|
#include "$file"
|
|
|
|
EOF
|
2002-08-27 06:10:54 +02:00
|
|
|
sumit() {
|
|
|
|
cksum $*
|
|
|
|
}
|
2002-01-22 04:02:00 +01:00
|
|
|
|
2001-12-26 05:53:34 +01:00
|
|
|
while [ -n "$1" ]; do
|
|
|
|
define=$1; shift
|
|
|
|
struct=$1; shift
|
2005-04-29 01:59:44 +02:00
|
|
|
sum=`$gcc -E $file | tee /tmp/1 | sed -n "/^$struct/,/^};/p" | sed -e 's/[ ]//g' -e '/^$/d' | tee /tmp/2 | sumit | tee /tmp/3 | awk '{printf "0x%xU", $1}'`
|
2001-12-26 05:53:34 +01:00
|
|
|
echo "#define $define $sum"
|
|
|
|
curr=`sed -n "s/^#[ ]*define CURR_$define[ ][ ]*\([^ ][^ ]*\)/\1/p" $file`
|
2002-01-05 00:29:58 +01:00
|
|
|
[ "$curr" != "$sum" ] && echo "*** WARNING WARNING WARNING WARNING WARNING ***
|
2001-12-26 22:35:16 +01:00
|
|
|
*** $file: magic number for $define changed old $curr != new $sum
|
2001-12-26 05:53:34 +01:00
|
|
|
*** WARNING WARNING WARNING WARNING WARNING ***" 1>&2
|
|
|
|
done >> $file_magic
|
|
|
|
exit 0
|