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__" $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 ' $2/$file > $2/$file.sed
123 mv $2/$file.sed $2/$file
124 if cmp $file $2/$file >NUL 2>&1; then
135 # Fix first broken decl of getcwd present on some svr4 systems.
138 base=`basename $file`
139 if [ -r ${LIB}/$file ]; then
140 file_to_fix=${LIB}/$file
142 if [ -r ${INPUT}/$file ]; then
143 file_to_fix=${INPUT}/$file
148 if [ \! -z "$file_to_fix" ]; then
149 echo Checking $file_to_fix
150 sed -e 's/getcwd(char \*, int)/getcwd(char *, size_t)/' $file_to_fix > /tmp/$base
151 if cmp $file_to_fix /tmp/$base >NUL 2>&1; then \
154 echo Fixed $file_to_fix
156 cp /tmp/$base ${LIB}/$file
157 chmod a+r ${LIB}/$file
163 base=`basename $file`
164 if [ -r ${LIB}/$file ]; then
165 file_to_fix=${LIB}/$file
167 if [ -r ${INPUT}/$file ]; then
168 file_to_fix=${INPUT}/$file
173 if [ \! -z "$file_to_fix" ]; then
174 echo Checking $file_to_fix
175 sed -e 's/Format\[\]/Format\[1\]/' $file_to_fix > /tmp/$base
176 if cmp $file_to_fix /tmp/$base >NUL 2>&1; then \
179 echo Fixed $file_to_fix
181 cp /tmp/$base ${LIB}/$file
182 chmod a+r ${LIB}/$file
188 base=`basename $file`
189 if [ -r ${LIB}/$file ]; then
190 file_to_fix=${LIB}/$file
192 if [ -r ${INPUT}/$file ]; then
193 file_to_fix=${INPUT}/$file
198 if [ \! -z "$file_to_fix" ]; then
199 echo Checking $file_to_fix
201 s/^#if !defined (__cplusplus)/#if 0/
202 s/^#define DECLSPEC_IMPORT __declspec(dllimport)/#define DECLSPEC_IMPORT/
203 ' $file_to_fix > /tmp/$base
204 if cmp $file_to_fix /tmp/$base >NUL 2>&1; then \
207 echo Fixed $file_to_fix
209 cp /tmp/$base ${LIB}/$file
210 chmod a+r ${LIB}/$file
215 echo 'Removing unneeded directories:'
217 files=`find . -type d -print | sort -r`
218 for file in $files; do
219 rmdir $LIB/$file > NUL 2>&1