OSDN Git Service

Initial revision
[pf3gnuchains/gcc-fork.git] / gcc / fixinc.sco
1 #! /bin/sh
2 #
3 #   fixinc.sco  --  Install modified versions of SCO system include
4 #   files.
5 #
6 #   Based on fixinc.svr4 script by Ron Guilmette (rfg@ncd.com) (SCO
7 #   modifications by Ian Lance Taylor (ian@airs.com)).
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 SCO
26 #       3.2v4 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.  Once munged, the
31 #       resulting new system include files are placed in a directory
32 #       that GNU C will search *before* searching the /usr/include
33 #       directory.  This script should work properly for most SCO
34 #       3.2v4 systems.  For other types of systems, you should use the
35 #       `fixincludes' or the `fixinc.svr4' script instead.
36 #
37 #       See README-fixinc for more information.
38
39 # Directory where gcc sources (and sometimes special include files) live.
40 SRCDIR=${3-${SRCDIR-.}}
41
42 # Directory containing the original header files.
43 INPUT=${2-${INPUT-/usr/include}}
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.
62 cd $LIB; LIB=`pwd`
63
64 echo 'Building fixincludes in ' ${LIB}
65
66 # Determine whether this filesystem has symbolic links.
67 if ln -s X $LIB/ShouldNotExist 2>/dev/null; then
68   rm -f $LIB/ShouldNotExist
69   LINKS=true
70 else
71   LINKS=false
72 fi
73
74 echo 'Making directories:'
75 cd ${INPUT}
76 if $LINKS; then
77   files=`ls -LR | sed -n s/:$//p`
78 else
79   files=`find . -type d -print | sed '/^.$/d'`
80 fi
81 for file in $files; do
82   rm -rf $LIB/$file
83   if [ ! -d $LIB/$file ]
84   then mkdir $LIB/$file
85   fi
86 done
87
88 # treetops gets an alternating list
89 # of old directories to copy
90 # and the new directories to copy to.
91 treetops="${INPUT} ${LIB}"
92
93 if $LINKS; then
94   echo 'Making internal symbolic directory links'
95   for file in $files; do
96     dest=`ls -ld $file | sed -n 's/.*-> //p'`
97     if [ "$dest" ]; then    
98       cwd=`pwd`
99       # In case $dest is relative, get to $file's dir first.
100       cd ${INPUT}
101       cd `echo ./$file | sed -n 's&[^/]*$&&p'`
102       # Check that the target directory exists.
103       # Redirections changed to avoid bug in sh on Ultrix.
104       (cd $dest) > /dev/null 2>&1
105       if [ $? = 0 ]; then
106         cd $dest
107         # X gets the dir that the link actually leads to.
108         x=`pwd`
109         # If link leads back into ${INPUT},
110         # make a similar link here.
111         if expr $x : "${INPUT}/.*" > /dev/null; then
112           # Y gets the actual target dir name, relative to ${INPUT}.
113           y=`echo $x | sed -n "s&${INPUT}/&&p"`
114           echo $file '->' $y ': Making link'
115           rm -fr ${LIB}/$file > /dev/null 2>&1
116           ln -s ${LIB}/$y ${LIB}/$file > /dev/null 2>&1
117         else
118           # If the link is to outside ${INPUT},
119           # treat this directory as if it actually contained the files.
120 # This line used to have $dest instead of $x.
121 # $dest seemed to be wrong for links found in subdirectories
122 # of ${INPUT}.  Does this change break anything?
123           treetops="$treetops $x ${LIB}/$file"
124         fi
125       fi
126       cd $cwd
127     fi
128   done
129 fi
130
131 set - $treetops
132 while [ $# != 0 ]; do
133   # $1 is an old directory to copy, and $2 is the new directory to copy to.
134   echo "Finding header files in $1:"
135   cd ${INPUT}
136   cd $1
137   files=`find . -name '*.h' -type f -print`
138   echo 'Checking header files:'
139   for file in $files; do
140     if egrep '!__STDC__' $file >/dev/null; then
141       echo Fixing $file
142       if [ -r $file ]; then
143         cp $file $2/$file >/dev/null 2>&1 || echo "Can't copy $file"
144         chmod +w $2/$file
145         chmod a+r $2/$file
146
147 # The following have been removed from the sed command below
148 # because it is more useful to leave these things in.
149 # The only reason to remove them was for -pedantic,
150 # which isn't much of a reason. -- rms.
151 #         /^[   ]*#[    ]*ident/d
152
153         sed -e '
154           s/!__STDC__/!defined (__STRICT_ANSI__)/g
155         ' $2/$file > $2/$file.sed
156         mv $2/$file.sed $2/$file
157         if cmp $file $2/$file >/dev/null 2>&1; then
158            rm $2/$file
159         fi
160       fi
161     fi
162   done
163   shift; shift
164 done
165
166 # Fix first broken decl of getcwd present on some svr4 systems.
167
168 file=stdlib.h
169 base=`basename $file`
170 if [ -r ${LIB}/$file ]; then
171   file_to_fix=${LIB}/$file
172 else
173   if [ -r ${INPUT}/$file ]; then
174     file_to_fix=${INPUT}/$file
175   else
176     file_to_fix=""
177   fi
178 fi
179 if [ \! -z "$file_to_fix" ]; then
180   echo Checking $file_to_fix
181   sed -e 's/getcwd(char \{0,\}\*, int)/getcwd(char *, size_t)/' $file_to_fix > /tmp/$base
182   if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
183     true
184   else
185     echo Fixed $file_to_fix
186     rm -f ${LIB}/$file
187     cp /tmp/$base ${LIB}/$file
188     chmod a+r ${LIB}/$file
189   fi
190   rm -f /tmp/$base
191 fi
192
193 # Fix second broken decl of getcwd present on some svr4 systems.  Also
194 # fix the incorrect decl of profil present on some svr4 systems.
195
196 file=unistd.h
197 base=`basename $file`
198 if [ -r ${LIB}/$file ]; then
199   file_to_fix=${LIB}/$file
200 else
201   if [ -r ${INPUT}/$file ]; then
202     file_to_fix=${INPUT}/$file
203   else
204     file_to_fix=""
205   fi
206 fi
207 if [ \! -z "$file_to_fix" ]; then
208   echo Checking $file_to_fix
209   sed -e 's/getcwd(char \*, int)/getcwd(char *, size_t)/' $file_to_fix \
210     | sed -e 's/profil(unsigned short \*, unsigned int, unsigned int, unsigned int)/profil(unsigned short *, size_t, int, unsigned)/' > /tmp/$base
211   if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
212     true
213   else
214     echo Fixed $file_to_fix
215     rm -f ${LIB}/$file
216     cp /tmp/$base ${LIB}/$file
217     chmod a+r ${LIB}/$file
218   fi
219   rm -f /tmp/$base
220 fi
221
222 # Fix an error in this file: the #if says _cplusplus, not the double
223 # underscore __cplusplus that it should be
224 file=tinfo.h
225 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
226   mkdir ${LIB}/rpcsvc 2>/dev/null
227   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
228   chmod +w ${LIB}/$file 2>/dev/null
229   chmod a+r ${LIB}/$file 2>/dev/null
230 fi
231
232 if [ -r ${LIB}/$file ]; then
233   echo Fixing $file, __cplusplus macro
234   sed -e 's/[   ]_cplusplus/ __cplusplus/' ${LIB}/$file > ${LIB}/${file}.sed
235   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
236   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
237     rm ${LIB}/$file
238   fi
239 fi
240
241 echo 'Removing unneeded directories:'
242 cd $LIB
243 files=`find . -type d -print | sort -r`
244 for file in $files; do
245   rmdir $LIB/$file > /dev/null 2>&1
246 done
247
248 if $LINKS; then
249   echo 'Making internal symbolic non-directory links'
250   cd ${INPUT}
251   files=`find . -type l -print`
252   for file in $files; do
253     dest=`ls -ld $file | sed -n 's/.*-> //p'`
254     if expr "$dest" : '[^/].*' > /dev/null; then    
255       target=${LIB}/`echo file | sed "s|[^/]*\$|$dest|"`
256       if [ -f $target ]; then
257         ln -s $dest ${LIB}/$file >/dev/null 2>&1
258       fi
259     fi
260   done
261 fi
262
263 cd ${ORIG_DIR}
264
265 echo 'Replacing <sys/byteorder.h>'
266 rm -f ${LIB}/sys/byteorder.h
267 cp ${SRCDIR}/byteorder.h ${LIB}/sys/byteorder.h
268
269 exit 0