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. 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.
40 # See README-fixinc for more information.
42 # Directory containing the original header files.
43 INPUT=${2-${INPUT-/mstools/h}}
45 # Fail if no arg to specify a directory for the output.
47 then echo fixincludes: no output directory specified
51 # Directory in which to store the results.
52 LIB=${1?"fixincludes: output directory not specified"}
54 # Make sure it exists.
55 if [ ! -d $LIB ]; then
61 # Make LIB absolute if it is relative.
62 # Don't do this if not necessary, since may screw up automounters.
67 cd $LIB; LIB=`${PWDCMD-pwd}`
71 echo 'Building fixincludes in ' ${LIB}
73 # Determine whether this filesystem has symbolic links.
74 if ln -s X $LIB/ShouldNotExist 2>NUL; then
75 rm -f $LIB/ShouldNotExist
81 echo 'Making directories:'
84 files=`ls -LR | sed -n s/:$//p`
86 files=`find . -type d -print | sed '/^.$/d'`
88 for file in $files; do
90 if [ ! -d $LIB/$file ]
95 # treetops gets an alternating list
96 # of old directories to copy
97 # and the new directories to copy to.
98 treetops="${INPUT} ${LIB}"
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:"
106 files=`find . -name '*.[hH]' -type f -print`
107 echo 'Checking header files:'
108 for file in $files; do
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
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.
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
136 # Fix first broken decl of getcwd present on some svr4 systems.
139 base=`basename $file`
140 if [ -r ${LIB}/$file ]; then
141 file_to_fix=${LIB}/$file
143 if [ -r ${INPUT}/$file ]; then
144 file_to_fix=${INPUT}/$file
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 \
155 echo Fixed $file_to_fix
157 cp /tmp/$base ${LIB}/$file
158 chmod a+r ${LIB}/$file
164 base=`basename $file`
165 if [ -r ${LIB}/$file ]; then
166 file_to_fix=${LIB}/$file
168 if [ -r ${INPUT}/$file ]; then
169 file_to_fix=${INPUT}/$file
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 \
180 echo Fixed $file_to_fix
182 cp /tmp/$base ${LIB}/$file
183 chmod a+r ${LIB}/$file
189 base=`basename $file`
190 if [ -r ${LIB}/$file ]; then
191 file_to_fix=${LIB}/$file
193 if [ -r ${INPUT}/$file ]; then
194 file_to_fix=${INPUT}/$file
199 if [ \! -z "$file_to_fix" ]; then
200 echo Checking $file_to_fix
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 \
208 echo Fixed $file_to_fix
210 cp /tmp/$base ${LIB}/$file
211 chmod a+r ${LIB}/$file
216 echo 'Removing unneeded directories:'
218 files=`find . -type d -print | sort -r`
219 for file in $files; do
220 rmdir $LIB/$file > NUL 2>&1