OSDN Git Service

Change FSF address.
[pf3gnuchains/gcc-fork.git] / gcc / fixinc.winnt
1 #! sh
2 #
3 #   fixinc.winnt  --  Install modified versions of Windows NT system include
4 #   files.
5 #
6 #   Based on fixinc.sco script by Ian Lance Taylor (ian@airs.com)).
7 #   Modifications by Douglas Rupp (drupp@cs.washington.edu)
8 #
9 # This file is part of GNU CC.
10
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)
14 # any later version.
15
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.
20
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.
25 #
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.  However the most 
32 #       important modification is to change all occurrences of __stdcall
33 #       and __cdecl to __attribute__((stdcall)) and __attribute__((cdecl)),
34 #       respectively.  Once munged, the
35 #       resulting new system include files are placed in a directory
36 #       that GNU C will search *before* searching the /mstools/h
37 #       directory.  This script should work properly for an /mstools/h
38 #       directory dated 9/4/94 on the installation CDROM.
39 #
40 #       See README-fixinc for more information.
41
42 # Directory containing the original header files.
43 INPUT=${2-${INPUT-/mstools/h}}
44
45 # Fail if no arg to specify a directory for the output.
46 if [ x$1 = x ]
47 then echo fixincludes: no output directory specified
48 exit 1
49 fi
50
51 # Directory in which to store the results.
52 LIB=${1?"fixincludes: output directory not specified"}
53
54 # Make sure it exists.
55 if [ ! -d $LIB ]; then
56   mkdir $LIB || exit 1
57 fi
58
59 ORIG_DIR=`pwd`
60
61 # Make LIB absolute if it is relative.
62 # Don't do this if not necessary, since may screw up automounters.
63 case $LIB in
64 /*)
65         ;;
66 *)
67         cd $LIB; LIB=`${PWDCMD-pwd}`
68         ;;
69 esac
70
71 echo 'Building fixincludes in ' ${LIB}
72
73 # Determine whether this filesystem has symbolic links.
74 if ln -s X $LIB/ShouldNotExist 2>NUL; then
75   rm -f $LIB/ShouldNotExist
76   LINKS=true
77 else
78   LINKS=false
79 fi
80
81 echo 'Making directories:'
82 cd ${INPUT}
83 if $LINKS; then
84   files=`ls -LR | sed -n s/:$//p`
85 else
86   files=`find . -type d -print | sed '/^.$/d'`
87 fi
88 for file in $files; do
89   rm -rf $LIB/$file
90   if [ ! -d $LIB/$file ]
91   then mkdir $LIB/$file
92   fi
93 done
94
95 # treetops gets an alternating list
96 # of old directories to copy
97 # and the new directories to copy to.
98 treetops="${INPUT} ${LIB}"
99
100 set - $treetops
101 while [ $# != 0 ]; do
102   # $1 is an old directory to copy, and $2 is the new directory to copy to.
103   echo "Finding header files in $1:"
104   cd ${INPUT}
105   cd $1
106   files=`find . -name '*.[hH]' -type f -print`
107   echo 'Checking header files:'
108   for file in $files; do
109     echo $file
110     if egrep "!__STDC__" $file >NUL; then
111       if [ -r $file ]; then
112         cp $file $2/$file >NUL 2>&1 || echo "Can't copy $file"
113         chmod +w,a+r $2/$file
114
115 # The following have been removed from the sed command below
116 # because it is more useful to leave these things in.
117 # The only reason to remove them was for -pedantic,
118 # which isn't much of a reason. -- rms.
119 #         /^[   ]*#[    ]*ident/d
120
121         sed -e '
122           s/!__STDC__/!defined (__STRICT_ANSI__)/g
123         ' $2/$file > $2/$file.sed
124         mv $2/$file.sed $2/$file
125         if cmp $file $2/$file >NUL 2>&1; then
126            rm $2/$file
127         else
128            echo Fixed $file
129         fi
130       fi
131     fi
132   done
133   shift; shift
134 done
135
136 # Fix first broken decl of getcwd present on some svr4 systems.
137
138 file=direct.h
139 base=`basename $file`
140 if [ -r ${LIB}/$file ]; then
141   file_to_fix=${LIB}/$file
142 else
143   if [ -r ${INPUT}/$file ]; then
144     file_to_fix=${INPUT}/$file
145   else
146     file_to_fix=""
147   fi
148 fi
149 if [ \! -z "$file_to_fix" ]; then
150   echo Checking $file_to_fix
151   sed -e 's/getcwd(char \*, int)/getcwd(char *, size_t)/' $file_to_fix > /tmp/$base
152   if cmp $file_to_fix /tmp/$base >NUL 2>&1; then \
153     true
154   else
155     echo Fixed $file_to_fix
156     rm -f ${LIB}/$file
157     cp /tmp/$base ${LIB}/$file
158     chmod a+r ${LIB}/$file
159   fi
160   rm -f /tmp/$base
161 fi
162
163 file=rpcndr.h
164 base=`basename $file`
165 if [ -r ${LIB}/$file ]; then
166   file_to_fix=${LIB}/$file
167 else
168   if [ -r ${INPUT}/$file ]; then
169     file_to_fix=${INPUT}/$file
170   else
171     file_to_fix=""
172   fi
173 fi
174 if [ \! -z "$file_to_fix" ]; then
175   echo Checking $file_to_fix
176   sed -e 's/Format\[\]/Format\[1\]/' $file_to_fix > /tmp/$base
177   if cmp $file_to_fix /tmp/$base >NUL 2>&1; then \
178     true
179   else
180     echo Fixed $file_to_fix
181     rm -f ${LIB}/$file
182     cp /tmp/$base ${LIB}/$file
183     chmod a+r ${LIB}/$file
184   fi
185   rm -f /tmp/$base
186 fi
187
188 file=winnt.h
189 base=`basename $file`
190 if [ -r ${LIB}/$file ]; then
191   file_to_fix=${LIB}/$file
192 else
193   if [ -r ${INPUT}/$file ]; then
194     file_to_fix=${INPUT}/$file
195   else
196     file_to_fix=""
197   fi
198 fi
199 if [ \! -z "$file_to_fix" ]; then
200   echo Checking $file_to_fix
201   sed -e '
202     s/^#if !defined (__cplusplus)/#if 0/
203     s/^#define DECLSPEC_IMPORT __declspec(dllimport)/#define DECLSPEC_IMPORT/
204   ' $file_to_fix > /tmp/$base
205   if cmp $file_to_fix /tmp/$base >NUL 2>&1; then \
206     true
207   else
208     echo Fixed $file_to_fix
209     rm -f ${LIB}/$file
210     cp /tmp/$base ${LIB}/$file
211     chmod a+r ${LIB}/$file
212   fi
213   rm -f /tmp/$base
214 fi
215
216 echo 'Removing unneeded directories:'
217 cd $LIB
218 files=`find . -type d -print | sort -r`
219 for file in $files; do
220   rmdir $LIB/$file > NUL 2>&1
221 done
222
223 exit 0