OSDN Git Service

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