OSDN Git Service

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