OSDN Git Service

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