OSDN Git Service

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