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, 675 Mass Ave, Cambridge, MA 02139, USA.
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.
39 # See README-fixinc for more information.
41 # Directory containing the original header files.
42 INPUT=${2-${INPUT-/mstools/h}}
44 # Fail if no arg to specify a directory for the output.
46 then echo fixincludes: no output directory specified
50 # Directory in which to store the results.
51 LIB=${1?"fixincludes: output directory not specified"}
53 # Make sure it exists.
54 if [ ! -d $LIB ]; then
60 # Make LIB absolute if it is relative.
61 # Don't do this if not necessary, since may screw up automounters.
66 cd $LIB; LIB=`${PWDCMD-pwd}`
70 echo 'Building fixincludes in ' ${LIB}
72 # Determine whether this filesystem has symbolic links.
73 if ln -s X $LIB/ShouldNotExist 2>NUL; then
74 rm -f $LIB/ShouldNotExist
80 echo 'Making directories:'
83 files=`ls -LR | sed -n s/:$//p`
85 files=`find . -type d -print | sed '/^.$/d'`
87 for file in $files; do
89 if [ ! -d $LIB/$file ]
94 # treetops gets an alternating list
95 # of old directories to copy
96 # and the new directories to copy to.
97 treetops="${INPUT} ${LIB}"
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:"
105 files=`find . -name '*.[hH]' -type f -print`
106 echo 'Checking header files:'
107 for file in $files; do
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
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.
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
137 # Fix first broken decl of getcwd present on some svr4 systems.
140 base=`basename $file`
141 if [ -r ${LIB}/$file ]; then
142 file_to_fix=${LIB}/$file
144 if [ -r ${INPUT}/$file ]; then
145 file_to_fix=${INPUT}/$file
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 \
156 echo Fixed $file_to_fix
158 cp /tmp/$base ${LIB}/$file
159 chmod a+r ${LIB}/$file
165 base=`basename $file`
166 if [ -r ${LIB}/$file ]; then
167 file_to_fix=${LIB}/$file
169 if [ -r ${INPUT}/$file ]; then
170 file_to_fix=${INPUT}/$file
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 \
181 echo Fixed $file_to_fix
183 cp /tmp/$base ${LIB}/$file
184 chmod a+r ${LIB}/$file
190 base=`basename $file`
191 if [ -r ${LIB}/$file ]; then
192 file_to_fix=${LIB}/$file
194 if [ -r ${INPUT}/$file ]; then
195 file_to_fix=${INPUT}/$file
200 if [ \! -z "$file_to_fix" ]; then
201 echo Checking $file_to_fix
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 \
209 echo Fixed $file_to_fix
211 cp /tmp/$base ${LIB}/$file
212 chmod a+r ${LIB}/$file
217 echo 'Removing unneeded directories:'
219 files=`find . -type d -print | sort -r`
220 for file in $files; do
221 rmdir $LIB/$file > NUL 2>&1