OSDN Git Service

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