OSDN Git Service

(X11/Xmu/Xmu.h): Fix this or X11/Xmu.h, whichever exists.
[pf3gnuchains/gcc-fork.git] / gcc / fixincludes
1 #! /bin/sh
2 # Install modified versions of certain ANSI-incompatible system header files
3 # which are fixed to work correctly with ANSI C
4 # and placed in a directory that GNU C will search.
5
6 # See README-fixinc for more information.
7
8 # Directory where gcc sources (and sometimes special include files) live.
9 # fixincludes doesn't use this, but fixinc.svr4 does, and I want to make
10 # sure somebody doesn't try to use arg3 for something incompatible. -- gumby
11 SRCDIR=${3-${SRCDIR-.}}
12
13 # Directory containing the original header files.
14 # (This was named INCLUDES, but that conflicts with a name in Makefile.in.)
15 INPUT=${2-${INPUT-/usr/include}}
16
17 # This prevents /bin/ex from failing if the current terminal type is
18 # unrecognizable.
19 TERM=unknown
20 export TERM
21
22 # Directory in which to store the results.
23 LIB=${1?"fixincludes: output directory not specified"}
24
25 # Make sure it exists.
26 if [ ! -d $LIB ]; then
27   mkdir $LIB || exit 1
28 fi
29
30 # Make LIB absolute.
31 cd $LIB; LIB=`pwd`
32
33 # Fail if no arg to specify a directory for the output.
34 if [ x$1 = x ]
35 then echo fixincludes: no output directory specified
36 exit 1
37 fi
38
39 echo 'Building fixincludes in ' ${LIB}
40
41 # Determine whether this system has symbolic links.
42 if ln -s X $LIB/ShouldNotExist 2>/dev/null; then
43   rm -f $LIB/ShouldNotExist
44   LINKS=true
45 else
46   LINKS=false
47 fi
48
49 echo 'Making directories:'
50 cd ${INPUT}
51 # Find all directories and all symlinks that point to directories.
52 # Put the list in $files.
53 # Each time we find a symlink, add it to newdirs
54 # so that we do another find within the dir the link points to.
55 # Note that $files may have duplicates in it;
56 # later parts of this file are supposed to ignore them.
57 dirs="."
58 prevdirs="."
59 while [ -n "$dirs" ]
60 do
61     newdirs=
62     for d in $prevdirs
63     do
64         if [ "$d" != . ]
65         then
66             d=$d/.
67         fi
68
69         # Find all directories under $d, relative to $d, including $d itself.
70         # Get rid of ./ at the end!
71         files="$files `find $d -type d -print | sed '/^.$/d' | sed '/\/\.$/ s|/\.$||'`"
72         $LINKS && \
73           newdirs="$newdirs `find $d -type l -exec test -d '{}' \; -print`"
74     done
75
76     dirs="$newdirs"
77     prevdirs="$newdirs"
78 done
79
80 dirs=
81 echo all directories:
82 echo $files
83
84 for file in $files; do
85   rm -rf $LIB/$file
86   if [ ! -d $LIB/$file ]
87   then mkdir $LIB/$file
88   fi
89 done
90
91 # treetops gets an alternating list
92 # of old directories to copy
93 # and the new directories to copy to.
94 treetops="${INPUT} ${LIB}"
95
96 if $LINKS; then
97   echo 'Making internal symbolic directory links'
98   for file in $files; do
99     dest=`ls -ld $file | sed -n 's/.*-> //p'`
100     if [ "$dest" ]; then    
101       cwd=`pwd`
102       # In case $dest is relative, get to $file's dir first.
103       cd ${INPUT}
104       cd `echo ./$file | sed -n 's&[^/]*$&&p'`
105       # Check that the target directory exists.
106       # Redirections changed to avoid bug in sh on Ultrix.
107       (cd $dest) > /dev/null 2>&1
108       if [ $? = 0 ]; then
109         cd $dest
110         # X gets the dir that the link actually leads to.
111         x=`pwd`
112         # If link leads back into ${INPUT},
113         # make a similar link here.
114         if expr $x : "${INPUT}/.*" > /dev/null; then
115           # Y gets the actual target dir name, relative to ${INPUT}.
116           y=`echo $x | sed -n "s&${INPUT}/&&p"`
117           echo $file '->' $y ': Making link'
118           rm -fr ${LIB}/$file > /dev/null 2>&1
119           ln -s ${LIB}/$y ${LIB}/$file > /dev/null 2>&1
120         else
121           # If the link is to outside ${INPUT},
122           # treat this directory as if it actually contained the files.
123 # This line used to have $dest instead of $x.
124 # $dest seemed to be wrong for links found in subdirectories
125 # of ${INPUT}.  Does this change break anything?
126           treetops="$treetops $x ${LIB}/$file"
127         fi
128       fi
129       cd $cwd
130     fi
131   done
132 fi
133
134 set - $treetops
135 while [ $# != 0 ]; do
136   # $1 is an old directory to copy, and $2 is the new directory to copy to.
137   echo "Finding header files in $1:"
138   cd ${INPUT}
139   cd $1
140   files=`find . -name '*.h' -type f -print`
141   echo 'Checking header files:'
142 # Note that BSD43_* are used on recent MIPS systems.
143   for file in $files; do
144 # This call to egrep is essential, since checking a file with egrep
145 # is much faster than actually trying to fix it.
146 # It is also essential that most files *not* match!
147 # Thus, matching every #endif is unacceptable.
148 # But the argument to egrep must be kept small, or many versions of egrep
149 # won't be able to handle it.
150 # rms: I removed `|#[el].*if.*[^/       ]' because it made egrep fail.
151     if egrep '[         _]_IO|CTRL|#define.NULL|#[el]*if.*([0-9]|sparc|vax|sun|pyr)' $file > /dev/null; then
152       echo Fixing $file
153       if [ -r $file ]; then
154         cp $file $2/$file >/dev/null 2>&1       \
155         || echo "Can't copy $file"
156         chmod +w $2/$file
157 # Following two lines removed.
158 #         s%^\([        ]*#[    ]*endif[        ]*\)\([^/       ].*\)$%\1/* \2 */%
159 #         s%^\([        ]*#[    ]*else[         ]*\)\([^/       ].*\)$%\1/* \2 */%
160
161         sed -e '
162                                    :loop
163           /\\$/                 N
164           /\\$/                 b loop
165           /[    ]_IO[A-Z]*[     ]*(/    s/(\(.\),/('\''\1'\'',/
166           /[    ]BSD43__IO[A-Z]*[       ]*(/    s/(\(.\),/('\''\1'\'',/
167           /#define._IO/                 s/'\''x'\''/x/g
168           /#define.BSD43__IO/           s/'\''x'\''/x/g
169           /[^A-Z]CTRL[  ]*(/            s/\([^'\'']\))/'\''\1'\'')/
170           /#define.CTRL/                s/'\''c'\''/c/g
171           /#define._CTRL/               s/'\''c'\''/c/g
172           /#define.BSD43_CTRL/          s/'\''c'\''/c/g
173           /#[a-z]*if.*[  (]m68k/        s/\([^_]\)m68k/\1__m68k__/g
174           /#[a-z]*if.*[  (]__i386/      s/__i386/__i386__/g
175           /#[a-z]*if.*[  (]i386/        s/\([^_]\)i386/\1__i386__/g
176           /#[a-z]*if.*[  (]sparc/       s/\([^_]\)sparc/\1__sparc__/g
177           /#[a-z]*if.*[  (]mc68000/     s/\([^_]\)mc68000/\1__mc68000__/g
178           /#[a-z]*if.*[  (]vax/         s/\([^_]\)vax/\1__vax__/g
179           /#[a-z]*if.*[  (]sun/         s/\([^_]\)\(sun[a-z0-9]*\)\([^a-z0-9_]\)/\1__\2__\3/g
180           /#[a-z]*if.*[  (]sun/         s/\([^_]\)\(sun[a-z0-9]*\)$/\1__\2__/g
181           /#[a-z]*if.*[  (]ns32000/     s/\([^_]\)ns32000/\1__ns32000__/g
182           /#[a-z]*if.*[  (]pyr/         s/\([^_]\)pyr/\1__pyr__/g
183           /#[a-z]*if.*[  (]is68k/       s/\([^_]\)is68k/\1__is68k__/g
184           /^#define.NULL[       ]/      i\
185                 #undef NULL
186         ' $2/$file > $2/$file.sed
187         mv $2/$file.sed $2/$file
188         if cmp $file $2/$file >/dev/null 2>&1; then
189            echo Deleting $2/$file\; no fixes were needed.
190            rm $2/$file
191         fi
192       fi
193     fi
194   done
195   shift; shift
196 done
197
198 cd ${INPUT}
199
200 # Fix one other error in this file: a mismatched quote not inside a C comment.
201 file=sundev/vuid_event.h
202 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
203   mkdir ${LIB}/sundev 2>/dev/null
204   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
205   chmod +w ${LIB}/$file 2>/dev/null
206 fi
207
208 if [ -r ${LIB}/$file ]; then
209   echo Fixing $file comment
210   ex ${LIB}/$file <<EOF
211   g/doesn't/s/doesn't/does not/
212   wq
213 EOF
214   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
215     echo Deleting ${LIB}/$file\; no fixes were needed.
216     rm ${LIB}/$file
217   fi
218 fi
219
220 # Fix this Sun file to avoid interfering with stddef.h.
221 file=sys/stdtypes.h
222 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
223   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
224   chmod +w ${LIB}/$file 2>/dev/null
225 fi
226
227 if [ -r ${LIB}/$file ]; then
228   echo Fixing $file
229   ex ${LIB}/$file <<EOF
230   /size_t.*;/
231   i
232 #ifndef _GCC_SIZE_T
233 #define _GCC_SIZE_T
234 .
235   /size_t/+1
236   i
237 #endif
238 .
239   /ptrdiff_t.*;/
240   i
241 #ifndef _GCC_PTRDIFF_T
242 #define _GCC_PTRDIFF_T
243 .
244   /ptrdiff_t/+1
245   i
246 #endif
247 .
248   /wchar_t.*;/
249   i
250 #ifndef _GCC_WCHAR_T
251 #define _GCC_WCHAR_T
252 .
253   /wchar_t/+1
254   i
255 #endif
256 .
257   wq
258 EOF
259   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
260     echo Deleting ${LIB}/$file\; no fixes were needed.
261     rm ${LIB}/$file
262   fi
263 fi
264
265 # Fix this file to avoid interfering with stddef.h.
266 file=sys/types.h
267 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
268   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
269   chmod +w ${LIB}/$file 2>/dev/null
270 fi
271
272 if [ -r ${LIB}/$file ]; then
273   echo Fixing $file
274   ex ${LIB}/$file <<EOF
275   /typedef.*size_t.*;/
276   i
277 #ifndef _GCC_SIZE_T
278 #define _GCC_SIZE_T
279 .
280   /size_t/+1
281   i
282 #endif
283 .
284   wq
285 EOF
286   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
287     echo Deleting ${LIB}/$file\; no fixes were needed.
288     rm ${LIB}/$file
289   fi
290 fi
291
292 # Fix an error in this file: a missing semi-colon at the end of the statsswtch
293 # structure definition.
294 file=rpcsvc/rstat.h
295 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
296   mkdir ${LIB}/rpcsvc 2>/dev/null
297   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
298   chmod +w ${LIB}/$file 2>/dev/null
299 fi
300
301 if [ -r ${LIB}/$file ]; then
302   echo Fixing $file, definition of statsswtch
303   ex ${LIB}/$file <<EOF
304   g/boottime$/s//&;/
305   wq
306 EOF
307   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
308     echo Deleting ${LIB}/$file\; no fixes were needed.
309     rm ${LIB}/$file
310   fi
311 fi
312
313 # Fix an error in this file: a missing semi-colon at the end of the nodeent
314 # structure definition.
315 file=netdnet/dnetdb.h
316 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
317   mkdir ${LIB}/netdnet 2>/dev/null
318   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
319   chmod +w ${LIB}/$file 2>/dev/null
320 fi
321
322 if [ -r ${LIB}/$file ]; then
323   echo Fixing $file, definition of nodeent
324   ex ${LIB}/$file <<EOF
325   g/char.*na_addr *$/s//&;/
326   wq
327 EOF
328   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
329     echo Deleting ${LIB}/$file\; no fixes were needed.
330     rm ${LIB}/$file
331   fi
332 fi
333
334 # Check for bad #ifdef line (in Ultrix 4.1)
335 file=sys/file.h
336 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
337   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
338   chmod +w ${LIB}/$file 2>/dev/null
339 fi
340
341 if [ -r ${LIB}/$file ]; then
342   echo Fixing $file, bad \#ifdef line
343   ex ${LIB}/$file <<EOF
344   g/^#ifdef KERNEL && !defined/
345   s/#ifdef KERNEL && !defined/#if defined(KERNEL) \&\& !defined/
346   wq
347 EOF
348   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
349     echo Deleting ${LIB}/$file\; no fixes were needed.
350     rm ${LIB}/$file
351   fi
352 fi
353
354 # Remove nested comments created by #endifs in a comment (Ultrix 4.1)
355 # Only needed if commenting out junk after #endif.
356 #file=signal.h
357 #if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
358 #  cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
359 #  chmod +w ${LIB}/$file 2>/dev/null
360 #fi
361 #
362 #if [ -r ${LIB}/$file ]; then
363 #  echo Fixing $file, nested comments
364 #  sed -e 's/#endif.*/#endif/' ${LIB}/$file > ${LIB}/${file}.sed
365 #  rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
366 #  if cmp $file ${LIB}/$file >/dev/null 2>&1; then
367 #    echo Deleting ${LIB}/$file\; no fixes were needed.
368 #    rm -f ${LIB}/$file
369 #  fi
370 #fi
371
372 # Check for superfluous `static' (in Ultrix 4.2)
373 file=machine/cpu.h
374 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
375   mkdir ${LIB}/machine 2>/dev/null
376   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
377   chmod +w ${LIB}/$file 2>/dev/null
378 fi
379
380 if [ -r ${LIB}/$file ]; then
381   echo Fixing $file, superfluous static
382   ex ${LIB}/$file <<EOF
383   g/^static struct tlb_pid_state/
384   s/static//
385   wq
386 EOF
387   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
388     echo Deleting ${LIB}/$file\; no fixes were needed.
389     rm ${LIB}/$file
390   else
391 # This file has an alternative name, mips/cpu.h.  Fix that name, too.
392     if cmp machine/cpu.h mips/cpu.h > /dev/null 2>& 1; then
393       mkdir ${LIB}/mips 2>&-
394       ln ${LIB}/$file ${LIB}/mips/cpu.h 
395     fi
396   fi
397 fi
398
399 # Incorrect sprintf declaration in X11/Xmu.h
400 file=X11/Xmu.h
401 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
402   mkdir ${LIB}/X11 2>/dev/null
403   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
404   chmod +w ${LIB}/$file 2>/dev/null
405 fi
406
407 if [ -r ${LIB}/$file ]; then
408   echo Fixing $file sprintf declaration
409   ex ${LIB}/$file <<EOF
410   /^extern char \*      sprintf();$/c
411 #ifndef __STDC__
412 extern char *   sprintf();
413 #endif /* !defined __STDC__ */
414 .
415   wq
416 EOF
417   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
418     echo Deleting ${LIB}/$file\; no fixes were needed.
419     rm ${LIB}/$file
420   fi
421 fi
422
423 # Incorrect sprintf declaration in X11/Xmu/Xmu.h
424 # (It's not clear whether the right file name is this or X11/Xmu.h.)
425 file=X11/Xmu/Xmu.h
426 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
427   mkdir ${LIB}/X11/Xmu 2>/dev/null
428   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
429   chmod +w ${LIB}/$file 2>/dev/null
430 fi
431
432 if [ -r ${LIB}/$file ]; then
433   echo Fixing $file sprintf declaration
434   ex ${LIB}/$file <<EOF
435   /^extern char \*      sprintf();$/c
436 #ifndef __STDC__
437 extern char *   sprintf();
438 #endif /* !defined __STDC__ */
439 .
440   wq
441 EOF
442   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
443     echo Deleting ${LIB}/$file\; no fixes were needed.
444     rm ${LIB}/$file
445   fi
446 fi
447
448 # Check for missing ';' in struct
449 file=netinet/ip.h
450 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
451   mkdir ${LIB}/netinet 2>/dev/null
452   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
453   chmod +w ${LIB}/$file 2>/dev/null
454 fi
455
456 if [ -r ${LIB}/$file ]; then
457   echo Fixing $file
458   sed -e '/^struct/,/^};/s/}$/};/' ${LIB}/$file > ${LIB}/${file}.sed
459   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
460   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
461     echo Deleting ${LIB}/$file\; no fixes were needed.
462     rm -f ${LIB}/$file
463   fi
464 fi
465
466 # Fix the CAT macro in SunOS memvar.h.
467 file=pixrect/memvar.h
468 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
469   mkdir ${LIB}/pixrect 2>/dev/null
470   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
471   chmod +w ${LIB}/$file 2>/dev/null
472 fi
473
474 if [ -r ${LIB}/$file ]; then
475   echo Fixing $file
476   sed -e '/^#define.CAT(a,b)/ i\
477 #ifdef __STDC__ \
478 #define CAT(a,b) a##b\
479 #else
480 /^#define.CAT(a,b)/ a\
481 #endif
482 ' ${LIB}/$file > ${LIB}/${file}.sed
483   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
484   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
485     echo Deleting ${LIB}/$file\; no fixes were needed.
486     rm -f ${LIB}/$file
487   fi
488 fi
489
490 # Check for yet more missing ';' in struct (in SunOS 4.0.x)
491 file=rpcsvc/rusers.h
492 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
493   mkdir ${LIB}/rpcsvc 2>/dev/null
494   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
495   chmod +w ${LIB}/$file 2>/dev/null
496 fi
497
498 if [ -r ${LIB}/$file ]; then
499   echo Fixing $file
500   sed -e '/^struct/,/^};/s/_cnt$/_cnt;/' ${LIB}/$file > ${LIB}/${file}.sed
501   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
502   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
503     echo Deleting ${LIB}/$file\; no fixes were needed.
504     rm -f ${LIB}/$file
505   fi
506 fi
507
508 # Fix return type of exit and abort in <stdlib.h> on SunOS 4.1.
509 file=stdlib.h
510 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
511   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
512   chmod +w ${LIB}/$file 2>/dev/null
513 fi
514
515 if [ -r ${LIB}/$file ]; then
516   echo Fixing $file
517   sed -e 's/int abort/void      abort/g' \
518   -e 's/int     free/void       free/g' \
519   -e 's/char \* calloc/void \*  calloc/g' \
520   -e 's/char \* malloc/void \*  malloc/g' \
521   -e 's/char \* realloc/void \* realloc/g' \
522   -e 's/int     exit/void       exit/g' ${LIB}/$file > ${LIB}/${file}.sed
523   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
524   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
525     echo Deleting ${LIB}/$file\; no fixes were needed.
526     rm -f ${LIB}/$file
527   fi
528 fi
529
530 # Fix return type of free and {c,m,re}alloc in <malloc.h> on SunOS 4.1.
531 file=malloc.h
532 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
533   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
534   chmod +w ${LIB}/$file 2>/dev/null
535 fi
536
537 if [ -r ${LIB}/$file ]; then
538   echo Fixing $file
539   sed -e 's/typedef[    ]char \*        malloc_t/typedef void \*        malloc_t/g' \
540   -e 's/int[    ][      ]*free/void     free/g' \
541   ${LIB}/$file > ${LIB}/${file}.sed
542   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
543   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
544     echo Deleting ${LIB}/$file\; no fixes were needed.
545     rm -f ${LIB}/$file
546   fi
547 fi
548
549
550 # Fix bogus comment in <locale.h> on SunOS 4.1.
551 file=locale.h
552 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
553   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
554   chmod +w ${LIB}/$file 2>/dev/null
555 fi
556
557 if [ -r ${LIB}/$file ]; then
558   echo Fixing $file
559   sed -e 's%#endif / \*%#endif /\* %g' ${LIB}/$file > ${LIB}/${file}.sed
560   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
561   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
562     echo Deleting ${LIB}/$file\; no fixes were needed.
563     rm -f ${LIB}/$file
564   fi
565 fi
566
567 # Fix bogus #ifdef in <hsfs/hsfs_spec.h> on SunOS 4.1.
568 file=hsfs/hsfs_spec.h
569 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
570   mkdir ${LIB}/hsfs 2>/dev/null
571   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
572   chmod +w ${LIB}/$file 2>/dev/null
573 fi
574
575 if [ -r ${LIB}/$file ]; then
576   echo Fixing $file
577   sed -e 's/\#ifdef __i386__ || __vax__/\#if __i386__ || __vax__/g' \
578     ${LIB}/$file > ${LIB}/${file}.sed
579   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
580   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
581     echo Deleting ${LIB}/$file\; no fixes were needed.
582     rm -f ${LIB}/$file
583   fi
584 fi
585
586 # Fix bogus #ifdef in <hsfs/hsnode.h> on SunOS 4.1.
587 file=hsfs/hsnode.h
588 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
589   mkdir ${LIB}/hsfs 2>/dev/null
590   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
591   chmod +w ${LIB}/$file 2>/dev/null
592 fi
593
594 if [ -r ${LIB}/$file ]; then
595   echo Fixing $file
596   sed -e 's/\#ifdef __i386__ || __sun4c__/\#if __i386__ || __sun4c__/g' \
597     ${LIB}/$file > ${LIB}/${file}.sed
598   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
599   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
600     echo Deleting ${LIB}/$file\; no fixes were needed.
601     rm -f ${LIB}/$file
602   fi
603 fi
604
605 # Fix bogus #ifdef in <hsfs/iso_spec.h> on SunOS 4.1.
606 file=hsfs/iso_spec.h
607 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
608   mkdir ${LIB}/hsfs 2>/dev/null
609   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
610   chmod +w ${LIB}/$file 2>/dev/null
611 fi
612
613 if [ -r ${LIB}/$file ]; then
614   echo Fixing $file
615   sed -e 's/\#ifdef __i386__ || __vax__/\#if __i386__ || __vax__/g' \
616     ${LIB}/$file > ${LIB}/${file}.sed
617   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
618   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
619     echo Deleting ${LIB}/$file\; no fixes were needed.
620     rm -f ${LIB}/$file
621   fi
622 fi
623
624 # Incorrect #include in Sony News-OS 3.2.
625 file=machine/machparam.h
626 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
627   mkdir ${LIB}/machine 2>/dev/null
628   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
629   chmod +w ${LIB}/$file 2>/dev/null
630 fi
631
632 if [ -r ${LIB}/$file ]; then
633   echo Fixing $file, incorrect \#include
634   sed -e 's@"../machine/endian.h"@<machine/endian.h>@' \
635     ${LIB}/$file > ${LIB}/${file}.sed
636   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
637   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
638     echo Deleting ${LIB}/$file\; no fixes were needed.
639     rm -f ${LIB}/$file
640   fi
641 fi
642
643 # Multiline comment after typedef on IRIX 4.0.1.
644 file=sys/types.h
645 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
646   mkdir ${LIB}/sys 2>/dev/null
647   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
648   chmod +w ${LIB}/$file 2>/dev/null
649 fi
650
651 if [ -r ${LIB}/$file ]; then
652   echo Fixing $file, comment in the middle of \#ifdef
653   sed -e 's@type of the result@type of the result */@' \
654     -e 's@of the sizeof@/* of the sizeof@' \
655     ${LIB}/$file > ${LIB}/${file}.sed
656   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
657   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
658     echo Deleting ${LIB}/$file\; no fixes were needed.
659     rm -f ${LIB}/$file
660   fi
661 fi
662
663 # Fix non-ANSI memcpy declaration that conflicts with gcc's builtin
664 # declaration on Sun OS 4.x.  We must only fix this on Sun OS 4.x, because
665 # many other systems have similar text but correct versions of the file.
666 # To ensure only Sun's is fixed, we grep for a likely unique string.
667 file=memory.h
668 if egrep '/\*   @\(#\)memory.h 1.4 88/08/19 SMI; from S5R2 1.2  \*/' $file > /dev/null; then
669   if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
670     cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
671     chmod +w ${LIB}/$file 2>/dev/null
672   fi
673   if [ -r ${LIB}/$file ]; then
674     echo Replacing $file
675     cat > ${LIB}/$file << EOF
676 /* This file was generated by fixincludes */
677 #ifndef __memory_h__
678 #define __memory_h__
679
680 #ifdef __STDC__
681 extern void *memccpy();
682 extern void *memchr();
683 extern void *memcpy();
684 extern void *memset();
685 #else
686 extern char *memccpy();
687 extern char *memchr();
688 extern char *memcpy();
689 extern char *memset();
690 #endif /* __STDC__ */
691
692 extern int memcmp();
693
694 #endif __memory_h__
695 EOF
696   fi
697 fi
698
699 # parameters not const on DECstation Ultrix V4.0.
700 file=stdio.h
701 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
702   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
703   chmod +w ${LIB}/$file 2>/dev/null
704 fi
705
706 if [ -r ${LIB}/$file ]; then
707   echo Fixing $file, non-const arg
708   sed -e 's@perror( char \*__s );@perror( const char *__s );@' \
709       -e 's@fputs( char \*__s,@fputs( const char *__s,@' \
710       -e 's@fopen( char \*__filename, char \*__type );@fopen( const char *__filename, const char *__type );@' \
711       -e 's@fwrite( void \*__ptr,@fwrite( const void *__ptr,@' \
712       -e 's@fscanf( FILE \*__stream, char \*__format,@fscanf( FILE *__stream, const char *__format,@' \
713       -e 's@scanf( char \*__format,@scanf( const char *__format,@' \
714       -e 's@sscanf( char \*__s, char \*__format,@sscanf( const char *__s, const char *__format,@' \
715     ${LIB}/$file > ${LIB}/${file}.sed
716   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
717   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
718     echo Deleting ${LIB}/$file\; no fixes were needed.
719     rm -f ${LIB}/$file
720   fi
721 fi
722
723 # parameter to atof not const on DECstation Ultrix V4.0.
724 file=math.h
725 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
726   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
727   chmod +w ${LIB}/$file 2>/dev/null
728 fi
729
730 if [ -r ${LIB}/$file ]; then
731   echo Fixing $file, non-const arg
732   sed -e 's@atof( char \*__nptr );@atof( const char *__nptr );@' \
733     ${LIB}/$file > ${LIB}/${file}.sed
734   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
735   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
736     echo Deleting ${LIB}/$file\; no fixes were needed.
737     rm -f ${LIB}/$file
738   fi
739 fi
740
741 # These two files on SunOS 4 are included by other files
742 # in the same directory, using "...".  So we must make sure they exist
743 # in the same directory as the other fixed files.
744 if [ -r ${INPUT}/multimedia/audio_errno.h ]
745 then
746   ln -s ${INPUT}/multimedia/audio_errno.h ${LIB}/multimedia 2>/dev/null
747 fi
748 if [ -r ${INPUT}/multimedia/audio_hdr.h ]
749 then
750   ln -s ${INPUT}/multimedia/audio_hdr.h ${LIB}/multimedia 2>/dev/null
751 fi
752
753 echo 'Removing unneeded directories:'
754 cd $LIB
755 files=`find . -type d -print | sort -r`
756 for file in $files; do
757   rmdir $LIB/$file > /dev/null 2>&1
758 done
759
760 if $LINKS; then
761   echo 'Making internal symbolic non-directory links'
762   cd ${INPUT}
763   files=`find . -type l -print`
764   for file in $files; do
765     dest=`ls -ld $file | sed -n 's/.*-> //p'`
766     if expr "$dest" : '[^/].*' > /dev/null; then    
767       target=${LIB}/`echo file | sed "s|[^/]*\$|$dest|"`
768       if [ -f $target ]; then
769         ln -s $dest ${LIB}/$file >/dev/null 2>&1
770       fi
771     fi
772   done
773 fi
774
775 exit 0