Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygmagic « scripts « cygwin « winsup - cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: eee4a3b734e8c2bb14614784584ecaeed6ae5f01 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/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