Projet_SETI_RISC-V/riscv-gnu-toolchain/newlib/winsup/cygwin/cygmagic
2023-03-06 14:48:14 +01:00

44 lines
1.1 KiB
Bash
Executable file

#!/bin/bash
# cygmagic - Generate "magic numbers" from a structure.
#
# 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.
set -e
shopt -s -o pipefail
shopt -s inherit_errexit
file_magic=$1; shift
gcc=$1; shift
file=$1; shift
tmpfile=/tmp/$$.magic
trap "rm -f /tmp/$$.magic" 0 1 2 15
cat <<EOF > $tmpfile
/* autogenerated - do not edit */
#include "$file"
EOF
sumit() {
cksum $*
}
while [ -n "$1" ]; do
define=$1; shift
struct=$1; shift
sum=`$gcc -D__CYGMAGIC__ -E -P $file | sed -n "/^$struct/,/^};/p" | sed -e 's/[ ]//g' -e '/^$/d' | sumit | awk '{printf "0x%xU", $1}'`
echo "#define $define $sum"
curr=`sed -n "s/^#[ ]*define CURR_$define[ ][ ]*\([^ ][^ ]*\)/\1/p" $file`
[ "$curr" != "$sum" ] && echo "*** WARNING WARNING WARNING WARNING WARNING ***
*** $file: magic number for $define changed old $curr != new $sum
*** WARNING WARNING WARNING WARNING WARNING ***" 1>&2
done >> $tmpfile
mv $tmpfile $file_magic
exit 0