OSDN Git Service

* fixinc/fixincl.c: Move declarations of 'pz_fname' and
[pf3gnuchains/gcc-fork.git] / gcc / fixinc / 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 # Copyright (C) 1995, 1996, 1997, 1998 Free Software Foundation, Inc.
10 #
11 # This file is part of GNU CC.
12
13 # GNU CC is free software; you can redistribute it and/or modify
14 # it under the terms of the GNU General Public License as published by
15 # the Free Software Foundation; either version 2, or (at your option)
16 # any later version.
17
18 # GNU CC is distributed in the hope that it will be useful,
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21 # GNU General Public License for more details.
22
23 # You should have received a copy of the GNU General Public License
24 # along with GNU CC; see the file COPYING.  If not, write to
25 # the Free Software Foundation, 59 Temple Place - Suite 330,
26 # Boston, MA 02111-1307, USA.
27 #
28 #       This script munges the native include files provided with SCO
29 #       3.2v4 systems so as to provide a reasonable namespace when
30 #       compiling with gcc.  The header files by default do not
31 #       provide many essential definitions and declarations if
32 #       __STDC__ is 1.  This script modifies the header files to check
33 #       for __STRICT_ANSI__ being defined instead.  Once munged, the
34 #       resulting new system include files are placed in a directory
35 #       that GNU C will search *before* searching the /usr/include
36 #       directory.  This script should work properly for most SCO
37 #       3.2v4 systems.  For other types of systems, you should use the
38 #       `fixincludes' or the `fixinc.svr4' script instead.
39 #
40 #       See README-fixinc for more information.
41
42 # Fail if no arg to specify a directory for the output.
43 if [ x$1 = x ]
44 then echo fixincludes: no output directory specified
45 exit 1
46 fi
47
48 # Directory in which to store the results.
49 LIB=${1?"fixincludes: output directory not specified"}
50
51 # Make sure it exists.
52 if [ ! -d $LIB ]; then
53   mkdir $LIB || exit 1
54 fi
55
56 ORIG_DIR=`${PWDCMD-pwd}`
57
58 # Make LIB absolute if it is relative.
59 # Don't do this if not necessary, since may screw up automounters.
60 case $LIB in
61 /*)
62         ;;
63 *)
64         cd $LIB; LIB=`${PWDCMD-pwd}`
65         ;;
66 esac
67
68 echo 'Building fixincludes in ' ${LIB}
69
70 # Determine whether this filesystem has symbolic links.
71 if ln -s X $LIB/ShouldNotExist 2>/dev/null; then
72   rm -f $LIB/ShouldNotExist
73   LINKS=true
74 else
75   LINKS=false
76 fi
77
78 echo 'Making directories:'
79 # Directory containing the original header files.
80 shift
81 if [ $# -eq 0 ] ; then
82   set /usr/include
83 fi
84
85 INLIST="$@"
86
87 for INPUT in ${INLIST} ; do
88 cd ${ORIG_DIR}
89 cd ${INPUT}
90
91 if $LINKS; then
92   files=`ls -LR | sed -n s/:$//p`
93 else
94   files=`find . -type d -print | sed '/^.$/d'`
95 fi
96 for file in $files; do
97   rm -rf $LIB/$file
98   if [ ! -d $LIB/$file ]
99   then mkdir $LIB/$file
100   fi
101 done
102
103 # treetops gets an alternating list
104 # of old directories to copy
105 # and the new directories to copy to.
106 treetops="${INPUT} ${LIB}"
107
108 if $LINKS; then
109   echo 'Making internal symbolic directory links'
110   for file in $files; do
111     dest=`ls -ld $file | sed -n 's/.*-> //p'`
112     if [ "$dest" ]; then    
113       cwd=`pwd`
114       # In case $dest is relative, get to $file's dir first.
115       cd ${INPUT}
116       cd `echo ./$file | sed -n 's&[^/]*$&&p'`
117       # Check that the target directory exists.
118       # Redirections changed to avoid bug in sh on Ultrix.
119       (cd $dest) > /dev/null 2>&1
120       if [ $? = 0 ]; then
121         cd $dest
122         # X gets the dir that the link actually leads to.
123         x=`pwd`
124         # If link leads back into ${INPUT},
125         # make a similar link here.
126         if expr $x : "${INPUT}/.*" > /dev/null; then
127           # Y gets the actual target dir name, relative to ${INPUT}.
128           y=`echo $x | sed -n "s&${INPUT}/&&p"`
129           echo $file '->' $y ': Making link'
130           rm -fr ${LIB}/$file > /dev/null 2>&1
131           ln -s ${LIB}/$y ${LIB}/$file > /dev/null 2>&1
132         else
133           # If the link is to outside ${INPUT},
134           # treat this directory as if it actually contained the files.
135 # This line used to have $dest instead of $x.
136 # $dest seemed to be wrong for links found in subdirectories
137 # of ${INPUT}.  Does this change break anything?
138           treetops="$treetops $x ${LIB}/$file"
139         fi
140       fi
141       cd $cwd
142     fi
143   done
144 fi
145
146 set - $treetops
147 while [ $# != 0 ]; do
148   # $1 is an old directory to copy, and $2 is the new directory to copy to.
149   echo "Finding header files in $1:"
150   cd ${INPUT}
151   cd $1
152   files=`find . -name '*.h' -type f -print`
153   echo 'Checking header files:'
154   for file in $files; do
155     if egrep '!__STDC__' $file >/dev/null; then
156       if [ -r $file ]; then
157         cp $file $2/$file >/dev/null 2>&1 || echo "Can't copy $file"
158         chmod +w $2/$file
159         chmod a+r $2/$file
160
161 # The following have been removed from the sed command below
162 # because it is more useful to leave these things in.
163 # The only reason to remove them was for -pedantic,
164 # which isn't much of a reason. -- rms.
165 #         /^[   ]*#[    ]*ident/d
166
167         sed -e '
168           s/!__STDC__/!defined (__STRICT_ANSI__)/g
169         ' $2/$file > $2/$file.sed
170         mv $2/$file.sed $2/$file
171         if cmp $file $2/$file >/dev/null 2>&1; then
172            rm $2/$file
173         else
174            echo Fixed $file
175         fi
176       fi
177     fi
178   done
179   shift; shift
180 done
181
182 # We shouldn't stay in the directory we just copied.
183 cd ${INPUT}
184
185 # Fix first broken decl of getcwd present on some svr4 systems.
186
187 file=stdlib.h
188 base=`basename $file`
189 if [ -r ${LIB}/$file ]; then
190   file_to_fix=${LIB}/$file
191 else
192   if [ -r ${INPUT}/$file ]; then
193     file_to_fix=${INPUT}/$file
194   else
195     file_to_fix=""
196   fi
197 fi
198 if [ \! -z "$file_to_fix" ]; then
199   echo Checking $file_to_fix
200   sed -e 's/getcwd(char \{0,\}\*, int)/getcwd(char *, size_t)/' $file_to_fix > /tmp/$base
201   if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
202     true
203   else
204     echo Fixed $file_to_fix
205     rm -f ${LIB}/$file
206     cp /tmp/$base ${LIB}/$file
207     chmod a+r ${LIB}/$file
208   fi
209   rm -f /tmp/$base
210 fi
211
212 # Fix second broken decl of getcwd present on some svr4 systems.  Also
213 # fix the incorrect decl of profil present on some svr4 systems.
214
215 file=unistd.h
216 base=`basename $file`
217 if [ -r ${LIB}/$file ]; then
218   file_to_fix=${LIB}/$file
219 else
220   if [ -r ${INPUT}/$file ]; then
221     file_to_fix=${INPUT}/$file
222   else
223     file_to_fix=""
224   fi
225 fi
226 if [ \! -z "$file_to_fix" ]; then
227   echo Checking $file_to_fix
228   sed -e 's/getcwd(char \*, int)/getcwd(char *, size_t)/' $file_to_fix \
229     | sed -e 's/profil(unsigned short \*, unsigned int, unsigned int, unsigned int)/profil(unsigned short *, size_t, int, unsigned)/' > /tmp/$base
230   if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
231     true
232   else
233     echo Fixed $file_to_fix
234     rm -f ${LIB}/$file
235     cp /tmp/$base ${LIB}/$file
236     chmod a+r ${LIB}/$file
237   fi
238   rm -f /tmp/$base
239 fi
240
241 # Fix third broken decl of getcwd on SCO.  Also fix incorrect decl of
242 # link.
243 file=prototypes.h
244 base=`basename $file`
245 if [ -r ${LIB}/$file ]; then
246   file_to_fix=${LIB}/$file
247 else
248   if [ -r ${INPUT}/$file ]; then
249     file_to_fix=${INPUT}/$file
250   else
251     file_to_fix=""
252   fi
253 fi
254 if [ \! -z "$file_to_fix" ]; then
255   echo Checking $file_to_fix
256   sed -e 's/getcwd(char \*, int)/getcwd(char *, size_t)/' $file_to_fix \
257     | sed -e 's/const  int      link(const char \*, char \*)/extern  int        link(const char *, const char *)/' > /tmp/$base
258   if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
259     true
260   else
261     echo Fixed $file_to_fix
262     rm -f ${LIB}/$file
263     cp /tmp/$base ${LIB}/$file
264     chmod a+r ${LIB}/$file
265   fi
266   rm -f /tmp/$base
267 fi
268
269 # Fix an error in this file: the #if says _cplusplus, not the double
270 # underscore __cplusplus that it should be
271 file=tinfo.h
272 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
273   mkdir ${LIB}/rpcsvc 2>/dev/null
274   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
275   chmod +w ${LIB}/$file 2>/dev/null
276   chmod a+r ${LIB}/$file 2>/dev/null
277 fi
278
279 if [ -r ${LIB}/$file ]; then
280   echo Fixing $file, __cplusplus macro
281   sed -e 's/[   ]_cplusplus/ __cplusplus/' ${LIB}/$file > ${LIB}/${file}.sed
282   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
283   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
284     rm ${LIB}/$file
285   fi
286 fi
287
288 # Fix prototype declaration of utime in sys/times.h.  In 3.2v4.0 the
289 # const is missing.
290 file=sys/times.h
291 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
292   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
293   chmod +w ${LIB}/$file 2>/dev/null
294   chmod a+r ${LIB}/$file 2>/dev/null
295 fi
296
297 if [ -r ${LIB}/$file ]; then
298   echo Fixing $file, utime prototype
299   sed -e 's/(const char \*, struct utimbuf \*);/(const char *, const struct utimbuf *);/' ${LIB}/$file > ${LIB}/${file}.sed
300   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
301   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
302     rm ${LIB}/$file
303   fi
304 fi
305
306 # This function is borrowed from fixinclude.svr4
307 # The OpenServer math.h defines struct exception, which conflicts with
308 # the class exception defined in the C++ file std/stdexcept.h.  We
309 # redefine it to __math_exception.  This is not a great fix, but I
310 # haven't been able to think of anything better.
311 #
312 # OpenServer's math.h declares abs as inline int abs...  Unfortunately,
313 # we blow over that one (with C++ linkage) and stick a new one in stdlib.h
314 # with C linkage.   So we eat the one out of math.h.
315 file=math.h
316 base=`basename $file`
317 if [ -r ${LIB}/$file ]; then
318   file_to_fix=${LIB}/$file
319 else
320   if [ -r ${INPUT}/$file ]; then
321     file_to_fix=${INPUT}/$file
322   else
323     file_to_fix=""
324   fi
325 fi
326 if [ \! -z "$file_to_fix" ]; then
327   echo Checking $file_to_fix
328   sed -e '/struct exception/i\
329 #ifdef __cplusplus\
330 #define exception __math_exception\
331 #endif'\
332       -e '/struct exception/a\
333 #ifdef __cplusplus\
334 #undef exception\
335 #endif' \
336       -e 's@inline int abs(int [a-z][a-z]*) {.*}@extern "C" int abs(int);@' \
337  $file_to_fix > /tmp/$base
338   if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
339     true
340   else
341     echo Fixed $file_to_fix
342     rm -f ${LIB}/$file
343     cp /tmp/$base ${LIB}/$file
344     chmod a+r ${LIB}/$file
345   fi
346   rm -f /tmp/$base
347 fi
348
349 #
350 # Also, the static functions lstat() and fchmod() in <sys/stat.h> 
351 # cause G++ grief since they're not wrapped in "if __cplusplus".   
352 # Fix that up now.
353 #
354 file=sys/stat.h
355 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
356   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
357   chmod +w ${LIB}/$file 2>/dev/null
358   chmod a+r ${LIB}/$file 2>/dev/null
359 fi
360
361 if [ -r ${LIB}/$file ]; then
362   echo Fixing $file, static definitions not C++-aware.
363   sed -e '/^static int[         ]*/i\
364 #if __cplusplus\
365 extern "C"\
366 {\
367 #endif /* __cplusplus */ \
368 ' \
369 -e '/^}$/a\
370 #if __cplusplus\
371 }\
372 #endif /* __cplusplus */ \
373 ' ${LIB}/$file > ${LIB}/${file}.sed
374   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
375   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
376     rm -f ${LIB}/$file
377   fi
378 fi
379
380 # This fix has the regex modified from the from fixinc.wrap
381 # Avoid the definition of the bool type in the following files when using
382 # g++, since it's now an official type in the C++ language.
383 for file in term.h tinfo.h
384 do
385   if [ -r $INPUT/$file ]; then
386     echo Checking $INPUT/$file
387     w='[         ]'
388     if grep "typedef$w.*char$w.*bool$w*;" $INPUT/$file >/dev/null
389     then
390       echo Fixed $file
391       rm -f $LIB/$file
392       cat <<__EOF__ >$LIB/$file
393 #ifndef _CURSES_H_WRAPPER
394 #ifdef __cplusplus
395 # define bool __curses_bool_t
396 #endif
397 #include_next <$file>
398 #ifdef __cplusplus
399 # undef bool
400 #endif
401 #define _CURSES_H_WRAPPER
402 #endif /* _CURSES_H_WRAPPER */
403 __EOF__
404       # Define _CURSES_H_WRAPPER at the end of the wrapper, not the start,
405       # so that if #include_next gets another instance of the wrapper,
406       # this will follow the #include_next chain until we arrive at
407       # the real system include file.
408       chmod a+r $LIB/$file
409     fi
410   fi
411 done
412
413 echo 'Removing unneeded directories:'
414 cd $LIB
415 files=`find . -type d -print | sort -r`
416 for file in $files; do
417   rmdir $LIB/$file > /dev/null 2>&1
418 done
419
420 if $LINKS; then
421   echo 'Making internal symbolic non-directory links'
422   cd ${INPUT}
423   files=`find . -type l -print`
424   for file in $files; do
425     dest=`ls -ld $file | sed -n 's/.*-> //p'`
426     if expr "$dest" : '[^/].*' > /dev/null; then    
427       target=${LIB}/`echo file | sed "s|[^/]*\$|$dest|"`
428       if [ -f $target ]; then
429         ln -s $dest ${LIB}/$file >/dev/null 2>&1
430       fi
431     fi
432   done
433 fi
434
435 done
436
437 if [ x${INSTALL_ASSERT_H} != x ]
438 then
439   cd ${ORIG_DIR}
440   rm -f include/assert.h
441   cp ${srcdir}/assert.h include/assert.h || exit 1
442   chmod a+r include/assert.h
443 fi
444
445 exit 0