OSDN Git Service

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