3 # fixinc.winnt -- Install modified versions of Windows NT system include
6 # Based on fixinc.sco script by Ian Lance Taylor (ian@airs.com)).
7 # Modifications by Douglas Rupp (drupp@cs.washington.edu)
9 # This file is part of GNU CC.
11 # GNU CC is free software; you can redistribute it and/or modify
12 # it under the terms of the GNU General Public License as published by
13 # the Free Software Foundation; either version 2, or (at your option)
16 # GNU CC is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 # GNU General Public License for more details.
21 # You should have received a copy of the GNU General Public License
22 # along with GNU CC; see the file COPYING. If not, write to
23 # the Free Software Foundation, 59 Temple Place - Suite 330,
24 # Boston, MA 02111-1307, USA.
26 # This script munges the native include files provided with Windows NT
27 # 3.5 SDK systems so as to provide a reasonable namespace when
28 # compiling with gcc. The header files by default do not
29 # provide many essential definitions and declarations if
30 # __STDC__ is 1. This script modifies the header files to check
31 # for __STRICT_ANSI__ being defined instead. Once munged, the
32 # resulting new system include files are placed in a directory
33 # that GNU C will search *before* searching the Include
36 # See README-fixinc for more information.
40 # Directory containing the original header files.
41 cd $2; SEDFILE=`${PWDCMD-pwd}`/fixinc-nt.sed
44 then echo fixincludes: sed script 'fixinc-nt.sed' not found
47 echo 'Using sed script: ' ${SEDFILE}
52 echo 'Using the Include environment variable to find header files to fix'
54 # Fail if no arg to specify a directory for the output.
56 then echo fixincludes: no output directory specified
60 # Directory in which to store the results.
61 LIB=${1?"fixincludes: output directory not specified"}
63 # Make sure it exists.
64 if [ ! -d $LIB ]; then
70 # Make LIB absolute if it is relative.
71 # Don't do this if not necessary, since may screw up automounters.
76 cd $LIB; LIB=`${PWDCMD-pwd}`
80 echo 'Building fixincludes in ' ${LIB}
82 # Determine whether this filesystem has symbolic links.
83 if ln -s X $LIB/ShouldNotExist 2>NUL; then
84 rm -f $LIB/ShouldNotExist
90 echo 'Making directories:'
93 files=`ls -LR | sed -n s/:$//p`
95 files=`find . -type d -print | sed '/^.$/d'`
97 for file in $files; do
99 if [ ! -d $LIB/$file ]
100 then mkdir $LIB/$file
104 # treetops gets an alternating list
105 # of old directories to copy
106 # and the new directories to copy to.
107 treetops="${INPUT} ${LIB}"
110 while [ $# != 0 ]; do
111 # $1 is an old directory to copy, and $2 is the new directory to copy to.
112 echo "Finding header files in $1:"
115 files=`find . -name '*.[hH]' -type f -print`
116 echo 'Checking header files:'
117 for file in $files; do
119 if egrep "!__STDC__" $file >NUL; then
120 if [ -r $file ]; then
121 cp $file $2/$file >NUL 2>&1 || echo "Can't copy $file"
122 chmod +w,a+r $2/$file
124 # The following have been removed from the sed command below
125 # because it is more useful to leave these things in.
126 # The only reason to remove them was for -pedantic,
127 # which isn't much of a reason. -- rms.
131 s/!__STDC__/!defined (__STRICT_ANSI__)/g
132 ' $2/$file > $2/$file.sed
133 mv $2/$file.sed $2/$file
134 if cmp $file $2/$file >NUL 2>&1; then
145 # Fix first broken decl of getcwd present on some svr4 systems.
148 base=`basename $file`
149 if [ -r ${LIB}/$file ]; then
150 file_to_fix=${LIB}/$file
152 if [ -r ${INPUT}/$file ]; then
153 file_to_fix=${INPUT}/$file
158 if [ \! -z "$file_to_fix" ]; then
159 echo Checking $file_to_fix
160 sed -e 's/getcwd(char \*, int)/getcwd(char *, size_t)/' $file_to_fix > /tmp/$base
161 if cmp $file_to_fix /tmp/$base >NUL 2>&1; then \
164 echo Fixed $file_to_fix
166 cp /tmp/$base ${LIB}/$file
167 chmod a+r ${LIB}/$file
173 base=`basename $file`
174 if [ -r ${LIB}/$file ]; then
175 file_to_fix=${LIB}/$file
177 if [ -r ${INPUT}/$file ]; then
178 file_to_fix=${INPUT}/$file
183 if [ \! -z "$file_to_fix" ]; then
184 echo Checking $file_to_fix
185 sed -e 's/Format\[\]/Format\[1\]/' $file_to_fix > /tmp/$base
186 if cmp $file_to_fix /tmp/$base >NUL 2>&1; then \
189 echo Fixed $file_to_fix
191 cp /tmp/$base ${LIB}/$file
192 chmod a+r ${LIB}/$file
198 base=`basename $file`
199 if [ -r ${LIB}/$file ]; then
200 file_to_fix=${LIB}/$file
202 if [ -r ${INPUT}/$file ]; then
203 file_to_fix=${INPUT}/$file
208 if [ \! -z "$file_to_fix" ]; then
209 echo Checking $file_to_fix
211 s/^#if !defined (__cplusplus)/#if 0/
212 s/^#define DECLSPEC_IMPORT __declspec(dllimport)/#define DECLSPEC_IMPORT/
213 ' $file_to_fix > /tmp/$base
214 if cmp $file_to_fix /tmp/$base >NUL 2>&1; then \
217 echo Fixed $file_to_fix
219 cp /tmp/$base ${LIB}/$file
220 chmod a+r ${LIB}/$file
225 echo 'Removing unneeded directories:'
227 files=`find . -type d -print | sort -r`
228 for file in $files; do
229 rmdir $LIB/$file > NUL 2>&1