summaryrefslogtreecommitdiffstats
path: root/contrib/gcc/fixinc.winnt
blob: 915ac723b85e386db4665a71b9b34e8edcce2189 (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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
#! sh
#
#   fixinc.winnt  --  Install modified versions of Windows NT system include
#   files.
#
#   Based on fixinc.sco script by Ian Lance Taylor (ian@airs.com)).
#   Modifications by Douglas Rupp (drupp@cs.washington.edu)
#
# This file is part of GNU CC.
# 
# GNU CC 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.
# 
# GNU CC 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 GNU CC; see the file COPYING.  If not, write to
# the Free Software Foundation, 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.
#
#	This script munges the native include files provided with Windows NT
#	3.5 SDK systems so as to provide a reasonable namespace when
#	compiling with gcc.  The header files by default do not
#	provide many essential definitions and declarations if
#	__STDC__ is 1.  This script modifies the header files to check
#	for __STRICT_ANSI__ being defined instead.  Once munged, the
#	resulting new system include files are placed in a directory
#	that GNU C will search *before* searching the Include
#	directory.
#
#	See README-fixinc for more information.

ORIG_DIR=`pwd`

# Directory containing the original header files.
cd $2; SEDFILE=`${PWDCMD-pwd}`/fixinc-nt.sed
echo $SEDFILE
if [ ! -f $SEDFILE ]
then echo fixincludes: sed script 'fixinc-nt.sed' not found
exit 1
fi
echo 'Using sed script: ' ${SEDFILE}

cd $ORIG_DIR

INPUT=${INCLUDE}
echo 'Using the Include environment variable to find header files to fix'

# Fail if no arg to specify a directory for the output.
if [ x$1 = x ]
then echo fixincludes: no output directory specified
exit 1
fi

# Directory in which to store the results.
LIB=${1?"fixincludes: output directory not specified"}

# Make sure it exists.
if [ ! -d $LIB ]; then
  mkdir $LIB || exit 1
fi

ORIG_DIR=`pwd`

# Make LIB absolute if it is relative.
# Don't do this if not necessary, since may screw up automounters.
case $LIB in
/*)
	;;
*)
	cd $LIB; LIB=`${PWDCMD-pwd}`
	;;
esac

echo 'Building fixincludes in ' ${LIB}

# Determine whether this filesystem has symbolic links.
if ln -s X $LIB/ShouldNotExist 2>NUL; then
  rm -f $LIB/ShouldNotExist
  LINKS=true
else
  LINKS=false
fi

echo 'Making directories:'
cd ${INPUT}
if $LINKS; then
  files=`ls -LR | sed -n s/:$//p`
else
  files=`find . -type d -print | sed '/^.$/d'`
fi
for file in $files; do
  rm -rf $LIB/$file
  if [ ! -d $LIB/$file ]
  then mkdir $LIB/$file
  fi
done

# treetops gets an alternating list
# of old directories to copy
# and the new directories to copy to.
treetops="${INPUT} ${LIB}"

set - $treetops
while [ $# != 0 ]; do
  # $1 is an old directory to copy, and $2 is the new directory to copy to.
  echo "Finding header files in $1:"
  cd ${INPUT}
  cd $1
  files=`find . -name '*.[hH]' -type f -print`
  echo 'Checking header files:'
  for file in $files; do
    echo $file
    if egrep "!__STDC__" $file >NUL; then
      if [ -r $file ]; then
	cp $file $2/$file >NUL 2>&1 || echo "Can't copy $file"
	chmod +w,a+r $2/$file

# The following have been removed from the sed command below
# because it is more useful to leave these things in.
# The only reason to remove them was for -pedantic,
# which isn't much of a reason. -- rms.
#	  /^[ 	]*#[ 	]*ident/d

	sed -e '
	  s/!__STDC__/!defined (__STRICT_ANSI__)/g
	' $2/$file > $2/$file.sed
	mv $2/$file.sed $2/$file
	if cmp $file $2/$file >NUL 2>&1; then
	   rm $2/$file
	else
	   echo Fixed $file
	fi
      fi
    fi
  done
  shift; shift
done

# Fix first broken decl of getcwd present on some svr4 systems.

file=direct.h
base=`basename $file`
if [ -r ${LIB}/$file ]; then
  file_to_fix=${LIB}/$file
else
  if [ -r ${INPUT}/$file ]; then
    file_to_fix=${INPUT}/$file
  else
    file_to_fix=""
  fi
fi
if [ \! -z "$file_to_fix" ]; then
  echo Checking $file_to_fix
  sed -e 's/getcwd(char \*, int)/getcwd(char *, size_t)/' $file_to_fix > /tmp/$base
  if cmp $file_to_fix /tmp/$base >NUL 2>&1; then \
    true
  else
    echo Fixed $file_to_fix
    rm -f ${LIB}/$file
    cp /tmp/$base ${LIB}/$file
    chmod a+r ${LIB}/$file
  fi
  rm -f /tmp/$base
fi

file=rpcndr.h
base=`basename $file`
if [ -r ${LIB}/$file ]; then
  file_to_fix=${LIB}/$file
else
  if [ -r ${INPUT}/$file ]; then
    file_to_fix=${INPUT}/$file
  else
    file_to_fix=""
  fi
fi
if [ \! -z "$file_to_fix" ]; then
  echo Checking $file_to_fix
  sed -e 's/Format\[\]/Format\[1\]/' $file_to_fix > /tmp/$base
  if cmp $file_to_fix /tmp/$base >NUL 2>&1; then \
    true
  else
    echo Fixed $file_to_fix
    rm -f ${LIB}/$file
    cp /tmp/$base ${LIB}/$file
    chmod a+r ${LIB}/$file
  fi
  rm -f /tmp/$base
fi

file=winnt.h
base=`basename $file`
if [ -r ${LIB}/$file ]; then
  file_to_fix=${LIB}/$file
else
  if [ -r ${INPUT}/$file ]; then
    file_to_fix=${INPUT}/$file
  else
    file_to_fix=""
  fi
fi
if [ \! -z "$file_to_fix" ]; then
  echo Checking $file_to_fix
  sed -e '
    s/^#if !defined (__cplusplus)/#if 0/
    s/^#define DECLSPEC_IMPORT __declspec(dllimport)/#define DECLSPEC_IMPORT/
  ' $file_to_fix > /tmp/$base
  if cmp $file_to_fix /tmp/$base >NUL 2>&1; then \
    true
  else
    echo Fixed $file_to_fix
    rm -f ${LIB}/$file
    cp /tmp/$base ${LIB}/$file
    chmod a+r ${LIB}/$file
  fi
  rm -f /tmp/$base
fi

echo 'Removing unneeded directories:'
cd $LIB
files=`find . -type d -print | sort -r`
for file in $files; do
  rmdir $LIB/$file > NUL 2>&1
done

exit 0
OpenPOWER on IntegriCloud