OSDN Git Service

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