OSDN Git Service

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