]> sourceware.org Git - newlib-cygwin.git/blob - winsup/cygwin/cygmagic
Cygwin: Have cygmagic not create output if an error occurs
[newlib-cygwin.git] / winsup / cygwin / cygmagic
1 #!/bin/bash
2 # cygmagic - Generate "magic numbers" from a structure.
3 #
4 # This file is part of Cygwin.
5 #
6 # This software is a copyrighted work licensed under the terms of the
7 # Cygwin license. Please consult the file "CYGWIN_LICENSE" for
8 # details.
9
10 set -e
11 shopt -s -o pipefail
12 shopt -s inherit_errexit
13
14 file_magic=$1; shift
15 gcc=$1; shift
16 file=$1; shift
17
18 tmpfile=/tmp/$$.magic
19 trap "rm -f /tmp/$$.magic" 0 1 2 15
20
21 cat <<EOF > $tmpfile
22 /* autogenerated - do not edit */
23 #include "$file"
24 EOF
25
26 sumit() {
27 cksum $*
28 }
29
30 while [ -n "$1" ]; do
31 define=$1; shift
32 struct=$1; shift
33 sum=`$gcc -D__CYGMAGIC__ -E -P $file | sed -n "/^$struct/,/^};/p" | sed -e 's/[ ]//g' -e '/^$/d' | sumit | awk '{printf "0x%xU", $1}'`
34 echo "#define $define $sum"
35 curr=`sed -n "s/^#[ ]*define CURR_$define[ ][ ]*\([^ ][^ ]*\)/\1/p" $file`
36 [ "$curr" != "$sum" ] && echo "*** WARNING WARNING WARNING WARNING WARNING ***
37 *** $file: magic number for $define changed old $curr != new $sum
38 *** WARNING WARNING WARNING WARNING WARNING ***" 1>&2
39 done >> $tmpfile
40
41 mv $tmpfile $file_magic
42
43 exit 0
This page took 0.040071 seconds and 5 git commands to generate.