OSDN Git Service

(sys/spinlock.h): Don't copy it if it doesn't exist.
[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 # Command to run gcc.
9 GCCCMD=${4-${GCCCMD-gcc}}
10
11 # Directory where gcc sources (and sometimes special include files) live.
12 # fixincludes doesn't use this, but fixinc.svr4 does, and I want to make
13 # sure somebody doesn't try to use arg3 for something incompatible. -- gumby
14 SRCDIR=${3-${SRCDIR-.}}
15
16 # Directory containing the original header files.
17 # (This was named INCLUDES, but that conflicts with a name in Makefile.in.)
18 INPUT=${2-${INPUT-/usr/include}}
19
20 # Directory in which to store the results.
21 LIB=${1?"fixincludes: output directory not specified"}
22
23 # Define PWDCMD as a command to use to get the working dir
24 # in the form that we want.
25 PWDCMD=pwd
26 case "`pwd`" in
27 //*)
28         # On an Apollo, discard everything before `/usr'.
29         PWDCMD="eval pwd | sed -e 's,.*/usr/,/usr/,'"
30         ;;
31 esac
32
33 # Original directory.
34 ORIGDIR=`${PWDCMD}`
35
36 # Make sure it exists.
37 if [ ! -d $LIB ]; then
38   mkdir $LIB || exit 1
39 fi
40
41 # Make LIB absolute only if needed to avoid problems with the amd.
42 case $LIB in
43 /*)
44         ;;
45 *)
46         cd $LIB; LIB=`${PWDCMD}`
47         ;;
48 esac
49
50 # Make SRCDIR absolute only if needed to avoid problems with the amd.
51 cd $ORIGDIR
52 case $SRCDIR in
53 /*)
54         ;;
55 *)
56         cd $SRCDIR; SRCDIR=`${PWDCMD}`
57         ;;
58 esac
59
60 # Fail if no arg to specify a directory for the output.
61 if [ x$1 = x ]
62 then echo fixincludes: no output directory specified
63 exit 1
64 fi
65
66 echo Building fixed headers in ${LIB}
67
68 # Determine whether this system has symbolic links.
69 if ln -s X $LIB/ShouldNotExist 2>/dev/null; then
70   rm -f $LIB/ShouldNotExist
71   LINKS=true
72 elif ln -s X /tmp/ShouldNotExist 2>/dev/null; then
73   rm -f /tmp/ShouldNotExist
74   LINKS=true
75 else
76   LINKS=false
77 fi
78
79 echo Finding directories and links to directories
80 cd ${INPUT}
81 # Find all directories and all symlinks that point to directories.
82 # Put the list in $files.
83 # Each time we find a symlink, add it to newdirs
84 # so that we do another find within the dir the link points to.
85 # Note that $files may have duplicates in it;
86 # later parts of this file are supposed to ignore them.
87 dirs="."
88 levels=2
89 while [ -n "$dirs" ] && [ $levels -gt 0 ]
90 do
91     levels=`expr $levels - 1`
92     newdirs=
93     for d in $dirs
94     do
95         echo " Searching $INPUT/$d"
96         if [ "$d" != . ]
97         then
98             d=$d/.
99         fi
100
101         # Find all directories under $d, relative to $d, excluding $d itself.
102         files="$files `find $d -type d -print | \
103                        sed -e '/\/\.$/d' -e '/^\.$/d'`"
104         # Find all links to directories.
105         # Using `-exec test -d' in find fails on some systems,
106         # and trying to run test via sh fails on others,
107         # so this is the simplest alternative left.
108         # First find all the links, then test each one.
109         theselinks=
110         $LINKS && \
111           theselinks=`find $d -type l -print`
112         for d1 in $theselinks --dummy--
113         do
114             # If the link points to a directory,
115             # add that dir to $newdirs
116             if [ -d $d1 ]
117             then
118                 newdirs="$newdirs $d1"
119             fi
120         done
121     done
122
123     files="$files $newdirs"
124     dirs="$newdirs"
125 done
126
127 dirs=
128 echo "All directories (including links to directories):"
129 echo $files
130
131 for file in $files; do
132   rm -rf $LIB/$file
133   if [ ! -d $LIB/$file ]
134   then mkdir $LIB/$file
135   fi
136 done
137 mkdir $LIB/root
138
139 # treetops gets an alternating list
140 # of old directories to copy
141 # and the new directories to copy to.
142 treetops="${INPUT} ${LIB}"
143
144 if $LINKS; then
145   echo 'Making symbolic directory links'
146   for file in $files; do
147     dest=`ls -ld $file | sed -n 's/.*-> //p'`
148     if [ "$dest" ]; then    
149       cwd=`${PWDCMD}`
150       # In case $dest is relative, get to $file's dir first.
151       cd ${INPUT}
152       cd `echo ./$file | sed -n 's&[^/]*$&&p'`
153       # Check that the target directory exists.
154       # Redirections changed to avoid bug in sh on Ultrix.
155       (cd $dest) > /dev/null 2>&1
156       if [ $? = 0 ]; then
157         cd $dest
158         # X gets the dir that the link actually leads to.
159         x=`${PWDCMD}`
160         # If a link points to ., make a similar link to .
161         if [ $x = $INPUT ]; then
162           echo $file '->' . ': Making link'
163           rm -fr ${LIB}/$file > /dev/null 2>&1
164           ln -s . ${LIB}/$file > /dev/null 2>&1
165         # If link leads back into ${INPUT},
166         # make a similar link here.
167         elif expr $x : "${INPUT}/.*" > /dev/null; then
168           # Y gets the actual target dir name, relative to ${INPUT}.
169           y=`echo $x | sed -n "s&${INPUT}/&&p"`
170           # DOTS is the relative path from ${LIB}/$file's dir back to ${LIB}.
171           dots=`echo "$file" |
172                 sed -e 's@^./@@' -e 's@[^/][^/]*@..@g' -e 's@..$@@'`
173           echo $file '->' $dots$y ': Making link'
174           rm -fr ${LIB}/$file > /dev/null 2>&1
175           ln -s $dots$y ${LIB}/$file > /dev/null 2>&1
176         else
177           # If the link is to a dir $target outside ${INPUT},
178           # repoint the link at ${INPUT}/root$target
179           # and process $target into ${INPUT}/root$target
180           # treat this directory as if it actually contained the files.
181           echo $file '->' root$x ': Making link'
182           if [ -d $LIB/root$x ]
183           then true
184           else
185             dirname=root$x/
186             dirmade=.
187             cd $LIB
188             while [ x$dirname != x ]; do
189               component=`echo $dirname | sed -e 's|/.*$||'`
190               mkdir $component >/dev/null 2>&1
191               cd $component
192               dirmade=$dirmade/$component
193               dirname=`echo $dirname | sed -e 's|[^/]*/||'`
194             done
195           fi
196           # Duplicate directory structure created in ${LIB}/$file in new
197           # root area.
198           for file2 in $files; do
199             case $file2 in
200               $file/./*)
201                 dupdir=${LIB}/root$x/`echo $file2 | sed -n "s|^${file}/||p"`
202                 echo "Duplicating ${file}'s ${dupdir}"
203                 if [ -d ${dupdir} ]
204                 then true
205                 else
206                   mkdir ${dupdir}
207                 fi
208                 ;;
209               *)
210                 ;;
211             esac
212           done
213           # DOTS is the relative path from ${LIB}/$file's dir back to ${LIB}.
214           dots=`echo "$file" |
215                 sed -e 's@^./@@' -e 's@[^/][^/]*@..@g' -e 's@..$@@'`
216           rm -fr ${LIB}/$file > /dev/null 2>&1
217           ln -s ${dots}root$x ${LIB}/$file > /dev/null 2>&1
218           treetops="$treetops $x ${LIB}/root$x"
219         fi
220       fi
221       cd $cwd
222     fi
223   done
224 fi
225
226 set x $treetops
227 shift
228 while [ $# != 0 ]; do
229   # $1 is an old directory to copy, and $2 is the new directory to copy to.
230   cd ${INPUT}
231   cd $1
232 # The same dir can appear more than once in treetops.
233 # There's no need to scan it more than once.
234   if [ -f $2/DONE ]
235   then
236     files=
237   else
238     touch $2/DONE
239     echo Fixing directory $1 into $2
240 # Check .h files which are symlinks as well as those which are files.
241 # A link to a header file will not be processed by anything but this.
242     if $LINKS; then
243       files=`find . -name '*.h' \( -type f -o -type l \) -print`
244     else
245       files=`find . -name '*.h' -type f -print`
246     fi
247     echo Checking header files
248   fi
249 # Note that BSD43_* are used on recent MIPS systems.
250   for file in $files; do
251 # This call to egrep is essential, since checking a file with egrep
252 # is much faster than actually trying to fix it.
253 # It is also essential that most files *not* match!
254 # Thus, matching every #endif is unacceptable.
255 # But the argument to egrep must be kept small, or many versions of egrep
256 # won't be able to handle it.
257 #
258 # We use the pattern [!-.0-~] instead of [^/    ] to match a noncomment
259 # following #else or #endif because some buggy egreps think [^/] matches
260 # newline, and they thus think `#else ' matches `#e[ndiflse]*[  ]+[^/   ]'.
261 #
262 # We use the pattern [^a-zA-Z0-9_][_a-ce-km-z][a-z0-9] to match an identifier
263 # following #if or #elif that is not surrounded by __.  The `a-ce-km-z'
264 # in this pattern lacks `d' and `l'; this means we don't worry about
265 # identifiers starting with `d' or `l'.  This is OK, since none of the
266 # identifiers below start with `d' or `l'.  It also greatly improves
267 # performance, since many files contain lines of the form `#if ... defined ...'
268 # or `#if lint'.
269     if egrep '//|[      _]_IO|CTRL|^#define.NULL|^#e[nl][ds][ief]*[     ]+[!-.0-~]|^#[el]*if.*[^a-zA-Z0-9_][_a-ce-km-z][a-z0-9]' $file >/dev/null; then
270       if [ -r $file ]; then
271         cp $file $2/$file >/dev/null 2>&1       \
272         || echo "Can't copy $file"
273         chmod +w $2/$file
274         chmod a+r $2/$file
275         # Here is how the sed commands in braces work.
276         # (It doesn't work to put the comments inside the sed commands.)
277                 # Surround each word with spaces, to simplify matching below.
278                 # ANSIfy each pre-ANSI machine-dependent symbol
279                 # by surrounding it with __ __.
280                 # Remove the spaces that we inserted around each word.
281         sed -e '
282                                    :loop
283           /\\$/                 N
284           /\\$/                 b loop
285           s%^\([        ]*#[    ]*else\)[       ]*/[^*].*%\1%
286           s%^\([        ]*#[    ]*else\)[       ]*[^/   ].*%\1%
287           s%^\([        ]*#[    ]*endif\)[      ]*/[^*].*%\1%
288           s%^\([        ]*#[    ]*endif\)[      ]*\*[^/].*%\1%
289           s%^\([        ]*#[    ]*endif\)[      ]*[^/*  ].*%\1%
290           /\/\/[^*]/                    s|//\(.*\)$|/*\1*/|
291           /[    ]_IO[A-Z]*[     ]*(/    s/\(_IO[A-Z]*[  ]*(\)\(.\),/\1'\''\2'\'',/
292           /[    ]BSD43__IO[A-Z]*[       ]*(/    s/(\(.\),/('\''\1'\'',/
293           /#define._IO/                 s/'\''\([cgxt]\)'\''/\1/g
294           /#define.BSD43__IO/           s/'\''\([cgx]\)'\''/\1/g
295           /[^A-Z0-9_]CTRL[      ]*(/            s/\([^'\'']\))/'\''\1'\'')/
296           /[^A-Z0-9]_CTRL[      ]*(/            s/\([^'\'']\))/'\''\1'\'')/
297           /#define[     ]*[     ]CTRL/          s/'\''\([cgx]\)'\''/\1/g
298           /#define[     ]*[     ]_CTRL/         s/'\''\([cgx]\)'\''/\1/g
299           /#define.BSD43_CTRL/          s/'\''\([cgx]\)'\''/\1/g
300           /#[el]*if/{
301                 s/[a-zA-Z0-9_][a-zA-Z0-9_]*/ & /g
302
303                 s/ bsd4\([0-9]\) / __bsd4\1__ /g
304                 s/ _*i386 / __i386__ /g
305                 s/ is68k / __is68k__ /g
306                 s/ m68k / __m68k__ /g
307                 s/ mc680\([0-9]\)0 / __mc680\10__ /g
308                 s/ news\([0-9]*\) / __news\1__ /g
309                 s/ ns32000 / __ns32000__ /g
310                 s/ pyr / __pyr__ /g
311                 s/ sony_news / __sony_news__ /g
312                 s/ sparc / __sparc__ /g
313                 s/ sun\([a-z0-9]*\) / __sun\1__ /g
314                 s/ unix / __unix__ /g
315                 s/ vax / __vax__ /g
316
317                 s/ \([a-zA-Z0-9_][a-zA-Z0-9_]*\) /\1/g
318           }
319           /^#define.NULL[       ]/      i\
320                 #undef NULL
321         ' $2/$file > $2/$file.
322         mv $2/$file. $2/$file
323         if cmp $file $2/$file >/dev/null 2>&1; then
324            rm $2/$file
325         else
326            echo Fixed $file
327         fi
328       fi
329     fi
330   done
331   shift; shift
332 done
333
334 cd ${INPUT}
335
336 # Install the proper definition of size_t in header files that it comes from.
337 for file in sys/types.h stdlib.h sys/stdtypes.h; do
338   if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
339     cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
340     chmod +w ${LIB}/$file 2>/dev/null
341     chmod a+r ${LIB}/$file 2>/dev/null
342   fi
343
344   if [ -r ${LIB}/$file ]; then
345     echo Fixing $file comment
346     # Get the definition of __SIZE_TYPE__, if any.
347     # (This file must be called something.c).
348     echo "__SIZE_TYPE__" > ${LIB}/types.c
349     foo=`${GCCCMD} -E -P ${LIB}/types.c`
350     rm -f ${LIB}/types.c
351     # Default to our preferred type.
352     if [ "$foo" = __SIZE_TYPE__ ]; then foo="unsigned long int"; fi
353     sed -e "s/typedef[  a-z_]*[         ]size_t/typedef $foo size_t/" ${LIB}/$file > ${LIB}/${file}.sed
354     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
355     if cmp $file ${LIB}/$file >/dev/null 2>&1; then
356       rm ${LIB}/$file
357     fi
358   fi
359 done
360
361 # Fix one other error in this file: a mismatched quote not inside a C comment.
362 file=sundev/vuid_event.h
363 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
364   mkdir ${LIB}/sundev 2>/dev/null
365   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
366   chmod +w ${LIB}/$file 2>/dev/null
367   chmod a+r ${LIB}/$file 2>/dev/null
368 fi
369
370 if [ -r ${LIB}/$file ]; then
371   echo Fixing $file comment
372   sed -e "s/doesn't/does not/" ${LIB}/$file > ${LIB}/${file}.sed
373   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
374   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
375     rm ${LIB}/$file
376   fi
377 fi
378
379 # Fix these Sun OS files to avoid an invalid identifier in an #ifdef.
380 file=sunwindow/win_cursor.h
381 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
382 #  mkdir ${LIB}/sunwindow 2>/dev/null
383   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
384   chmod +w ${LIB}/$file 2>/dev/null
385 fi
386 if [ -r ${LIB}/$file ]; then
387   echo Fixing $file
388   sed -e "s/ecd.cursor/ecd_cursor/" ${LIB}/$file > ${LIB}/${file}.sed
389   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
390   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
391     rm ${LIB}/$file
392   fi
393 fi
394 file=sunwindow/win_lock.h
395 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
396 #  mkdir ${LIB}/sunwindow 2>/dev/null
397   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
398   chmod +w ${LIB}/$file 2>/dev/null
399 fi
400 if [ -r ${LIB}/$file ]; then
401   echo Fixing $file
402   sed -e "s/ecd.cursor/ecd_cursor/" ${LIB}/$file > ${LIB}/${file}.sed
403   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
404   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
405     rm ${LIB}/$file
406   fi
407 fi
408
409 # Fix this Sun file to avoid interfering with stddef.h.
410 file=sys/stdtypes.h
411 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
412   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
413   chmod +w ${LIB}/$file 2>/dev/null
414   chmod a+r ${LIB}/$file 2>/dev/null
415 fi
416
417 if [ -r ${LIB}/$file ]; then
418   echo Fixing $file
419 sed -e '/[       ]size_t.*;/i\
420 #ifndef _GCC_SIZE_T\
421 #define _GCC_SIZE_T' \
422     -e '/[       ]size_t.*;/a\
423 #endif' \
424     -e '/[       ]ptrdiff_t.*;/i\
425 #ifndef _GCC_PTRDIFF_T\
426 #define _GCC_PTRDIFF_T' \
427     -e '/[       ]ptrdiff_t.*;/a\
428 #endif' \
429     -e '/[       ]wchar_t.*;/i\
430 #ifndef _GCC_WCHAR_T\
431 #define _GCC_WCHAR_T' \
432     -e '/[       ]wchar_t.*;/a\
433 #endif' ${LIB}/$file > ${LIB}/${file}.sed
434   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
435   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
436     rm ${LIB}/$file
437   fi
438 fi
439
440 # Fix this file to avoid interfering with stddef.h, but don't mistakenly
441 # match e.g. ssize_t present in AIX for the ps/2.
442 file=sys/types.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
451 sed -e '/[      ]size_t.*;/i\
452 #ifndef _GCC_SIZE_T\
453 #define _GCC_SIZE_T' \
454     -e '/[      ]size_t.*;/a\
455 #endif' ${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 HP's use of ../machine/inline.h to refer to
463 # /usr/include/machine/inline.h
464 file=sys/spinlock.h
465 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
466   cp $file ${LIB}/$file
467 fi
468 if [ -r ${LIB}/$file ] ; then
469   echo Fixing $file
470   sed -e 's,"../machine/inline.h",<machine/inline.h>,' \
471     -e 's,"../machine/psl.h",<machine/psl.h>,' \
472   ${LIB}/$file > ${LIB}/${file}.sed
473   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
474   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
475     rm ${LIB}/$file
476   fi
477 fi
478
479 # Fix AIX use of "XDPS.h" to refer to <DPS/XDPS.h>
480 file=DPS/XDPSlib.h
481 if [-r $file] && [ ! -r ${LIB}/$file ] ; then
482   cp $file ${LIB}/$file
483 fi
484 if [ -r ${LIB}/$file ] ; then
485   echo Fixing $file
486   sed -e 's,"XDPS.h",<DPS/XDPS.h>,' ${LIB}/$file > ${LIB}/${file}.sed
487   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
488   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
489     rm ${LIB}/$file
490   fi
491 fi
492
493 # Fix an error in this file: the #if says _cplusplus, not the double
494 # underscore __cplusplus that it should be
495 file=tinfo.h
496 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
497   mkdir ${LIB}/rpcsvc 2>/dev/null
498   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
499   chmod +w ${LIB}/$file 2>/dev/null
500   chmod a+r ${LIB}/$file 2>/dev/null
501 fi
502
503 if [ -r ${LIB}/$file ]; then
504   echo Fixing $file, __cplusplus macro
505   sed -e 's/[   ]_cplusplus/ __cplusplus/' ${LIB}/$file > ${LIB}/${file}.sed
506   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
507   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
508     rm ${LIB}/$file
509   fi
510 fi
511
512 # Fix an error in this file: a missing semi-colon at the end of the statsswtch
513 # structure definition.
514 file=rpcsvc/rstat.h
515 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
516   mkdir ${LIB}/rpcsvc 2>/dev/null
517   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
518   chmod +w ${LIB}/$file 2>/dev/null
519   chmod a+r ${LIB}/$file 2>/dev/null
520 fi
521
522 if [ -r ${LIB}/$file ]; then
523   echo Fixing $file, definition of statsswtch
524   sed -e 's/boottime$/boottime;/' ${LIB}/$file > ${LIB}/${file}.sed
525   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
526   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
527     rm ${LIB}/$file
528   fi
529 fi
530
531 # Fix an error in this file: a missing semi-colon at the end of the nodeent
532 # structure definition.
533 file=netdnet/dnetdb.h
534 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
535   mkdir ${LIB}/netdnet 2>/dev/null
536   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
537   chmod +w ${LIB}/$file 2>/dev/null
538   chmod a+r ${LIB}/$file 2>/dev/null
539 fi
540
541 if [ -r ${LIB}/$file ]; then
542   echo Fixing $file, definition of nodeent
543   sed -e 's/char.*na_addr *$/char *na_addr;/' ${LIB}/$file > ${LIB}/${file}.sed
544   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
545   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
546     rm ${LIB}/$file
547   fi
548 fi
549
550 # Check for bad #ifdef line (in Ultrix 4.1)
551 file=sys/file.h
552 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
553   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
554   chmod +w ${LIB}/$file 2>/dev/null
555   chmod a+r ${LIB}/$file 2>/dev/null
556 fi
557
558 if [ -r ${LIB}/$file ]; then
559   echo Fixing $file, bad \#ifdef line
560   sed -e 's/#ifdef KERNEL/#if defined(KERNEL)/' ${LIB}/$file > ${LIB}/${file}.sed
561   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
562   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
563     rm ${LIB}/$file
564   fi
565 fi
566
567 # Check for superfluous `static' (in Ultrix 4.2)
568 file=machine/cpu.h
569 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
570   mkdir ${LIB}/machine 2>/dev/null
571   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
572   chmod +w ${LIB}/$file 2>/dev/null
573   chmod a+r ${LIB}/$file 2>/dev/null
574 fi
575
576 if [ -r ${LIB}/$file ]; then
577   echo Fixing $file, superfluous static
578   sed -e 's/^static struct tlb_pid_state/struct tlb_pid_state/' ${LIB}/$file > ${LIB}/${file}.sed
579   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
580   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
581     rm ${LIB}/$file
582   else
583 # This file has an alternative name, mips/cpu.h.  Fix that name, too.
584     if cmp machine/cpu.h mips/cpu.h > /dev/null 2>&1; then
585       mkdir ${LIB}/mips 2>&-
586       ln ${LIB}/$file ${LIB}/mips/cpu.h 
587     fi
588   fi
589 fi
590
591 # Incorrect sprintf declaration in X11/Xmu.h
592 file=X11/Xmu.h
593 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
594   mkdir ${LIB}/X11 2>/dev/null
595   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
596   chmod +w ${LIB}/$file 2>/dev/null
597   chmod a+r ${LIB}/$file 2>/dev/null
598 fi
599
600 if [ -r ${LIB}/$file ]; then
601   echo Fixing $file sprintf declaration
602   sed -e 's,^extern char \*     sprintf();$,#ifndef __STDC__\
603 extern char *   sprintf();\
604 #endif /* !defined __STDC__ */,' ${LIB}/$file > ${LIB}/${file}.sed
605   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
606   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
607     rm ${LIB}/$file
608   fi
609 fi
610
611 # Incorrect sprintf declaration in X11/Xmu/Xmu.h
612 # (It's not clear whether the right file name is this or X11/Xmu.h.)
613 file=X11/Xmu/Xmu.h
614 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
615   mkdir ${LIB}/X11/Xmu 2>/dev/null
616   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
617   chmod +w ${LIB}/$file 2>/dev/null
618   chmod a+r ${LIB}/$file 2>/dev/null
619 fi
620
621 if [ -r ${LIB}/$file ]; then
622   echo Fixing $file sprintf declaration
623   sed -e 's,^extern char \*     sprintf();$,#ifndef __STDC__\
624 extern char *   sprintf();\
625 #endif /* !defined __STDC__ */,' ${LIB}/$file > ${LIB}/${file}.sed
626   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
627   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
628     rm ${LIB}/$file
629   fi
630 fi
631
632 # Check for missing ';' in struct
633 file=netinet/ip.h
634 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
635   mkdir ${LIB}/netinet 2>/dev/null
636   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
637   chmod +w ${LIB}/$file 2>/dev/null
638   chmod a+r ${LIB}/$file 2>/dev/null
639 fi
640
641 if [ -r ${LIB}/$file ]; then
642   echo Fixing $file
643   sed -e '/^struct/,/^};/s/}$/};/' ${LIB}/$file > ${LIB}/${file}.sed
644   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
645   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
646     rm -f ${LIB}/$file
647   fi
648 fi
649
650 # Fix the CAT macro in SunOS memvar.h.
651 file=pixrect/memvar.h
652 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
653   mkdir ${LIB}/pixrect 2>/dev/null
654   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
655   chmod +w ${LIB}/$file 2>/dev/null
656   chmod a+r ${LIB}/$file 2>/dev/null
657 fi
658
659 if [ -r ${LIB}/$file ]; then
660   echo Fixing $file
661   sed -e '/^#define.CAT(a,b)/ i\
662 #ifdef __STDC__ \
663 #define CAT(a,b) a##b\
664 #else
665 /^#define.CAT(a,b)/ a\
666 #endif
667 ' ${LIB}/$file > ${LIB}/${file}.sed
668   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
669   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
670     rm -f ${LIB}/$file
671   fi
672 fi
673
674 # Check for yet more missing ';' in struct (in SunOS 4.0.x)
675 file=rpcsvc/rusers.h
676 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
677   mkdir ${LIB}/rpcsvc 2>/dev/null
678   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
679   chmod +w ${LIB}/$file 2>/dev/null
680   chmod a+r ${LIB}/$file 2>/dev/null
681 fi
682
683 if [ -r ${LIB}/$file ]; then
684   echo Fixing $file
685   sed -e '/^struct/,/^};/s/_cnt$/_cnt;/' ${LIB}/$file > ${LIB}/${file}.sed
686   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
687   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
688     rm -f ${LIB}/$file
689   fi
690 fi
691
692 # Fix return type of exit and abort in <stdlib.h> on SunOS 4.1.
693 # Also wrap protection around size_t for m88k-sysv3 systems.
694 file=stdlib.h
695 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
696   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
697   chmod +w ${LIB}/$file 2>/dev/null
698   chmod a+r ${LIB}/$file 2>/dev/null
699 fi
700
701 if [ -r ${LIB}/$file ]; then
702   echo Fixing $file
703   sed -e 's/int abort/void      abort/g' \
704   -e 's/int     free/void       free/g' \
705   -e 's/char \* calloc/void \*  calloc/g' \
706   -e 's/char \* malloc/void \*  malloc/g' \
707   -e 's/char \* realloc/void \* realloc/g' \
708   -e 's/int     exit/void       exit/g' \
709   -e '/typedef[         a-zA-Z_]*[      ]size_t[        ]*;/i\
710 #ifndef _GCC_SIZE_T\
711 #define _GCC_SIZE_T' \
712   -e '/typedef[         a-zA-Z_]*[      ]size_t[        ]*;/a\
713 #endif' \
714       ${LIB}/$file > ${LIB}/${file}.sed
715   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
716   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
717     rm -f ${LIB}/$file
718   fi
719 fi
720
721 # Fix return type of free and {c,m,re}alloc in <malloc.h> on SunOS 4.1.
722 file=malloc.h
723 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
724   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
725   chmod +w ${LIB}/$file 2>/dev/null
726   chmod a+r ${LIB}/$file 2>/dev/null
727 fi
728
729 if [ -r ${LIB}/$file ]; then
730   echo Fixing $file
731   sed -e 's/typedef[    ]char \*        malloc_t/typedef void \*        malloc_t/g' \
732   -e 's/int[    ][      ]*free/void     free/g' \
733   ${LIB}/$file > ${LIB}/${file}.sed
734   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
735   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
736     rm -f ${LIB}/$file
737   fi
738 fi
739
740 # Fix bogus #ifdef in <hsfs/hsfs_spec.h> on SunOS 4.1.
741 file=hsfs/hsfs_spec.h
742 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
743   mkdir ${LIB}/hsfs 2>/dev/null
744   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
745   chmod +w ${LIB}/$file 2>/dev/null
746   chmod a+r ${LIB}/$file 2>/dev/null
747 fi
748
749 if [ -r ${LIB}/$file ]; then
750   echo Fixing $file
751   sed -e 's/\#ifdef __i386__ || __vax__/\#if __i386__ || __vax__/g' \
752     ${LIB}/$file > ${LIB}/${file}.
753   rm -f ${LIB}/$file; mv ${LIB}/${file}. ${LIB}/$file
754   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
755     rm -f ${LIB}/$file
756   fi
757 fi
758
759 # Fix bogus #ifdef in <hsfs/hsnode.h> on SunOS 4.1.
760 file=hsfs/hsnode.h
761 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
762   mkdir ${LIB}/hsfs 2>/dev/null
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
768 if [ -r ${LIB}/$file ]; then
769   echo Fixing $file
770   sed -e 's/\#ifdef __i386__ || __sun4c__/\#if __i386__ || __sun4c__/g' \
771     ${LIB}/$file > ${LIB}/${file}.sed
772   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
773   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
774     rm -f ${LIB}/$file
775   fi
776 fi
777
778 # Fix bogus #ifdef in <hsfs/iso_spec.h> on SunOS 4.1.
779 file=hsfs/iso_spec.h
780 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
781   mkdir ${LIB}/hsfs 2>/dev/null
782   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
783   chmod +w ${LIB}/$file 2>/dev/null
784   chmod a+r ${LIB}/$file 2>/dev/null
785 fi
786
787 if [ -r ${LIB}/$file ]; then
788   echo Fixing $file
789   sed -e 's/\#ifdef __i386__ || __vax__/\#if __i386__ || __vax__/g' \
790     ${LIB}/$file > ${LIB}/${file}.sed
791   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
792   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
793     rm -f ${LIB}/$file
794   fi
795 fi
796
797 # Incorrect #include in Sony News-OS 3.2.
798 file=machine/machparam.h
799 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
800   mkdir ${LIB}/machine 2>/dev/null
801   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
802   chmod +w ${LIB}/$file 2>/dev/null
803   chmod a+r ${LIB}/$file 2>/dev/null
804 fi
805
806 if [ -r ${LIB}/$file ]; then
807   echo Fixing $file, incorrect \#include
808   sed -e 's@"../machine/endian.h"@<machine/endian.h>@' \
809     ${LIB}/$file > ${LIB}/${file}.
810   rm -f ${LIB}/$file; mv ${LIB}/${file}. ${LIB}/$file
811   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
812     rm -f ${LIB}/$file
813   fi
814 fi
815
816 # Multiline comment after typedef on IRIX 4.0.1.
817 file=sys/types.h
818 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
819   mkdir ${LIB}/sys 2>/dev/null
820   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
821   chmod +w ${LIB}/$file 2>/dev/null
822   chmod a+r ${LIB}/$file 2>/dev/null
823 fi
824
825 if [ -r ${LIB}/$file ]; then
826   echo Fixing $file, comment in the middle of \#ifdef
827   sed -e 's@type of the result@type of the result */@' \
828     -e 's@of the sizeof@/* of the sizeof@' \
829     ${LIB}/$file > ${LIB}/${file}.sed
830   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
831   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
832     rm -f ${LIB}/$file
833   fi
834 fi
835
836 # Turning // comments into /* */ comments trashes this IRIX 4.0.1
837 # header file, which embeds // comments inside multi-line /* */
838 # comments.  If this looks like the IRIX header file, we refix it by
839 # just throwing away the // comments.
840 file=fam.h
841 if [ -r ${LIB}/$file ]; then
842   if egrep indigo.esd ${LIB}/$file > /dev/null; then
843     echo Fixing $file, overeager sed script
844     rm ${LIB}/$file
845     sed -e 's|//.*$||g' $file > ${LIB}/$file
846     chmod +w ${LIB}/$file 2>/dev/null
847     chmod a+r ${LIB}/$file 2>/dev/null
848   fi
849 fi
850
851 # Another IRIX 4.0.1 header file contains the string "//"
852 file=elf_abi.h
853 if [ -r ${LIB}/$file ]; then
854   echo Fixing $file, overeager sed script
855   sed -e 's|"/\*"\*/|"//"|' ${LIB}/$file > ${LIB}/${file}.sed
856   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
857   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
858     rm -f ${LIB}/$file
859   fi
860 fi
861
862 # Same problem with a file from SunOS 4.1.3 : a header file containing
863 # the string "//" embedded in "/**/"
864 file=sbusdev/audiovar.h
865 if [ -r ${LIB}/$file ]; then
866   echo Fixing $file, overeager sed script
867   rm ${LIB}/$file
868   sed -e 's|//.*$||g' $file > ${LIB}/$file
869   chmod +w ${LIB}/$file 2>/dev/null
870   chmod a+r ${LIB}/$file 2>/dev/null
871 fi
872
873 # Fix non-ANSI memcpy declaration that conflicts with gcc's builtin
874 # declaration on Sun OS 4.x.  We must only fix this on Sun OS 4.x, because
875 # many other systems have similar text but correct versions of the file.
876 # To ensure only Sun's is fixed, we grep for a likely unique string.
877 file=memory.h
878 if [ -r $file ] && egrep '/\*   @\(#\)memory\.h 1\.[2-4] 8./../.. SMI; from S5R2 1\.2   \*/' $file > /dev/null; then
879   if [ ! -r ${LIB}/$file ]; then
880     cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
881     chmod +w ${LIB}/$file 2>/dev/null
882     chmod a+r ${LIB}/$file 2>/dev/null
883   fi
884   if [ -r ${LIB}/$file ]; then
885     echo Replacing $file
886     cat > ${LIB}/$file << EOF
887 /* This file was generated by fixincludes */
888 #ifndef __memory_h__
889 #define __memory_h__
890
891 #ifdef __STDC__
892 extern void *memccpy();
893 extern void *memchr();
894 extern void *memcpy();
895 extern void *memset();
896 #else
897 extern char *memccpy();
898 extern char *memchr();
899 extern char *memcpy();
900 extern char *memset();
901 #endif /* __STDC__ */
902
903 extern int memcmp();
904
905 #endif /* __memory_h__ */
906 EOF
907   fi
908 fi
909
910 # parameters not const on DECstation Ultrix V4.0.
911 file=stdio.h
912 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
913   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
914   chmod +w ${LIB}/$file 2>/dev/null
915   chmod a+r ${LIB}/$file 2>/dev/null
916 fi
917
918 if [ -r ${LIB}/$file ]; then
919   echo Fixing $file, non-const arg
920   sed -e 's@perror( char \*__s );@perror( const char *__s );@' \
921       -e 's@fputs( char \*__s,@fputs( const char *__s,@' \
922       -e 's@fopen( char \*__filename, char \*__type );@fopen( const char *__filename, const char *__type );@' \
923       -e 's@fwrite( void \*__ptr,@fwrite( const void *__ptr,@' \
924       -e 's@fscanf( FILE \*__stream, char \*__format,@fscanf( FILE *__stream, const char *__format,@' \
925       -e 's@scanf( char \*__format,@scanf( const char *__format,@' \
926       -e 's@sscanf( char \*__s, char \*__format,@sscanf( const char *__s, const char *__format,@' \
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     rm -f ${LIB}/$file
931   fi
932 fi
933
934 # parameters conflict with C++ new on rs/6000 
935 for file in stdio.h unistd.h ; do
936   if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
937     cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
938     chmod +w ${LIB}/$file 2>/dev/null
939   fi
940
941   if [ -r ${LIB}/$file ]; then
942     echo Fixing $file, parameter name conflicts
943     sed -e 's@rename(const char \*old, const char \*new)@rename(const char *_old, const char *_new)@' \
944       ${LIB}/$file > ${LIB}/${file}.sed
945     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
946     if cmp $file ${LIB}/$file >/dev/null 2>&1; then
947       rm -f ${LIB}/$file
948     fi
949   fi
950 done
951
952 # function class(double x) conflicts with C++ keyword on rs/6000 
953 file=math.h
954 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
955   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
956   chmod +w ${LIB}/$file 2>/dev/null
957   chmod a+r ${LIB}/$file 2>/dev/null
958 fi
959
960 if [ -r ${LIB}/$file ]; then
961   if grep 'class[(]' ${LIB}/$file >/dev/null; then
962     echo Fixing $file
963     sed -e '/class[(]/i\
964 #ifndef __cplusplus' \
965         -e '/class[(]/a\
966 #endif' ${LIB}/$file > ${LIB}/${file}.sed
967     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
968     if cmp $file ${LIB}/$file >/dev/null 2>&1; then
969       rm ${LIB}/$file
970     fi
971   fi
972 fi
973
974 # NeXT defines 'int wait(union wait*)', which conflicts with Posix.1.
975 file=sys/wait.h
976 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
977   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
978   chmod +w ${LIB}/$file 2>/dev/null
979 fi
980
981 if [ -r ${LIB}/$file ] \
982   && grep 'wait[(]union wait' ${LIB}/$file >/dev/null; then
983   echo Fixing $file, bad wait formal
984   sed -e 's@wait(union wait@wait(void@' ${LIB}/$file > ${LIB}/${file}.sed
985   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
986   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
987     rm -f ${LIB}/$file
988   fi
989 fi
990
991 # Don't use or define the name va_list in stdio.h.
992 # This is for ANSI and also to interoperate properly with gvarargs.h.
993 file=stdio.h
994 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
995   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
996   chmod +w ${LIB}/$file 2>/dev/null
997   chmod a+r ${LIB}/$file 2>/dev/null
998 fi
999
1000 if [ -r ${LIB}/$file ]; then
1001   echo Fixing $file, use of va_list
1002   # Arrange for stdio.h to use stdarg.h to define __gnuc_va_list
1003   (echo "#define __need___va_list"
1004    echo "#include <stdarg.h>") > ${LIB}/${file}.sed
1005   # Use __gnuc_va_list in arg types in place of va_list.
1006   # On 386BSD use __gnuc_va_list instead of _VA_LIST_. We're hoping the
1007   # trailing parentheses and semicolon save all other systems from this.
1008   # Define __va_list__ (something harmless and unused) instead of va_list.
1009   # Don't claim to have defined va_list.
1010   sed -e 's@ va_list @ __gnuc_va_list @' \
1011       -e 's@ va_list)@ __gnuc_va_list)@' \
1012       -e 's@ _VA_LIST_));@ __gnuc_va_list));@' \
1013       -e 's@ va_list@ __va_list__@' \
1014       -e 's@\*va_list@*__va_list__@' \
1015       -e 's@_NEED___VA_LIST@_NEED___Va_LIST@' \
1016       -e 's@VA_LIST@DUMMY_VA_LIST@' \
1017       -e 's@_NEED___Va_LIST@_NEED___VA_LIST@' \
1018     ${LIB}/$file >> ${LIB}/${file}.sed
1019   
1020   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1021   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1022     rm -f ${LIB}/$file
1023   fi
1024 fi
1025
1026 # Cancel out ansi_compat.h on Ultrix.  Replace it with empty file.
1027 file=ansi_compat.h
1028 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1029   if grep -s ULTRIX $file; then
1030     echo "/* This file intentionally left blank.  */" > $LIB/$file
1031   fi
1032 fi
1033
1034 # parameter to atof not const on DECstation Ultrix V4.0.
1035 # also get rid of bogus inline definitions in HP-UX 8.0
1036 file=math.h
1037 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1038   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1039   chmod +w ${LIB}/$file 2>/dev/null
1040   chmod a+r ${LIB}/$file 2>/dev/null
1041 fi
1042
1043 if [ -r ${LIB}/$file ]; then
1044   echo Fixing $file, non-const arg
1045   sed -e 's@atof( char \*__nptr );@atof( const char *__nptr );@' \
1046       -e 's@inline int abs(int d) { return (d>0)?d:-d; }@@' \
1047       -e 's@inline double abs(double d) { return fabs(d); }@@' \
1048     ${LIB}/$file > ${LIB}/${file}.sed
1049   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1050   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1051     rm -f ${LIB}/$file
1052   fi
1053 fi
1054
1055 # In limits.h, put #ifndefs around things that are supposed to be defined
1056 # in float.h to avoid redefinition errors if float.h is included first.
1057 # On HP/UX this patch does not work, because on HP/UX limits.h uses
1058 # multi line comments and the inserted #endif winds up inside the
1059 # comment.  Fortunately, HP/UX already uses #ifndefs in limits.h; if
1060 # we find a #ifndef FLT_MIN we assume that all the required #ifndefs
1061 # are there, and we do not add them ourselves.
1062 file=limits.h
1063 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1064   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1065   chmod +w ${LIB}/$file 2>/dev/null
1066   chmod a+r ${LIB}/$file 2>/dev/null
1067 fi
1068
1069 if [ -r ${LIB}/$file ]; then
1070   if egrep 'ifndef[     ]+FLT_MIN' ${LIB}/$file >/dev/null; then
1071     true
1072   else
1073     echo Fixing $file
1074     sed -e '/[  ]FLT_MIN[       ]/i\
1075 #ifndef FLT_MIN'\
1076         -e '/[  ]FLT_MIN[       ]/a\
1077 #endif'\
1078         -e '/[  ]FLT_MAX[       ]/i\
1079 #ifndef FLT_MAX'\
1080         -e '/[  ]FLT_MAX[       ]/a\
1081 #endif'\
1082         -e '/[  ]FLT_DIG[       ]/i\
1083 #ifndef FLT_DIG'\
1084         -e '/[  ]FLT_DIG[       ]/a\
1085 #endif'\
1086         -e '/[  ]DBL_MIN[       ]/i\
1087 #ifndef DBL_MIN'\
1088         -e '/[  ]DBL_MIN[       ]/a\
1089 #endif'\
1090         -e '/[  ]DBL_MAX[       ]/i\
1091 #ifndef DBL_MAX'\
1092         -e '/[  ]DBL_MAX[       ]/a\
1093 #endif'\
1094         -e '/[  ]DBL_DIG[       ]/i\
1095 #ifndef DBL_DIG'\
1096         -e '/[  ]DBL_DIG[       ]/a\
1097 #endif'\
1098       ${LIB}/$file > ${LIB}/${file}.sed
1099     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1100   fi
1101   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1102     echo Deleting ${LIB}/$file\; no fixes were needed.
1103     rm -f ${LIB}/$file
1104   fi
1105 fi
1106
1107 # In math.h, put #ifndefs around things that might be defined in a gcc
1108 # specific math-*.h file.
1109 file=math.h
1110 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1111   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1112   chmod +w ${LIB}/$file 2>/dev/null
1113   chmod a+r ${LIB}/$file 2>/dev/null
1114 fi
1115
1116 if [ -r ${LIB}/$file ]; then
1117   echo Fixing $file
1118   sed -e '/define[      ]HUGE_VAL[      ]/i\
1119 #ifndef HUGE_VAL'\
1120       -e '/define[      ]HUGE_VAL[      ]/a\
1121 #endif'\
1122     ${LIB}/$file > ${LIB}/${file}.sed
1123   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1124   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1125     echo Deleting ${LIB}/$file\; no fixes were needed.
1126     rm -f ${LIB}/$file
1127   fi
1128 fi
1129
1130 # These two files on SunOS 4 are included by other files
1131 # in the same directory, using "...".  So we must make sure they exist
1132 # in the same directory as the other fixed files.
1133 if [ -r ${INPUT}/multimedia/audio_errno.h ]
1134 then
1135   ln -s ${INPUT}/multimedia/audio_errno.h ${LIB}/multimedia 2>/dev/null
1136 fi
1137 if [ -r ${INPUT}/multimedia/audio_hdr.h ]
1138 then
1139   ln -s ${INPUT}/multimedia/audio_hdr.h ${LIB}/multimedia 2>/dev/null
1140 fi
1141
1142 # Determine if we're on Interactive Unix 2.2 or later, in which case we
1143 # need to fix some additional files.  This is the same test for ISC that
1144 # Autoconf uses.
1145 if test -d /etc/conf/kconfig.d \
1146     && grep _POSIX_VERSION /usr/include/sys/unistd.h >/dev/null 2>&1; then
1147   echo "Fixing ISC __STDC__ goof in several files..."
1148   for name in stdio.h math.h ctype.h sys/limits.h sys/fcntl.h sys/dirent.h; do
1149     echo $name
1150     if test -r ${LIB}/$name; then
1151       file=${LIB}/$name
1152     else
1153       file=${INPUT}/$name
1154     fi
1155     # On Interactive 2.2, certain traditional Unix definitions
1156     # (notably getc and putc in stdio.h) are omitted if __STDC__ is
1157     # defined, not just if _POSIX_SOURCE is defined.  This makes it
1158     # impossible to compile any nontrivial program except with -posix.
1159     sed \
1160 's/!defined(__STDC__) && !defined(_POSIX_SOURCE)/!defined(_POSIX_SOURCE)/' \
1161             < $file > ${LIB}/$name.
1162     mv ${LIB}/$name. ${LIB}/$name
1163   done
1164   
1165   echo "Fixing ISC fmod declaration"
1166   # This one's already been fixed for other things.
1167   file=${LIB}/math.h
1168   sed 's/fmod(double)/fmod(double, double)/' <$file >$file.
1169   mv $file. $file
1170   
1171   echo "Fixing nested comments in ISC <sys/limits.h>"
1172   file=sys/limits.h
1173   sed '/CHILD_MAX/s,/\* Max, Max,' < ${INPUT}/$file >${LIB}/$file.
1174   sed '/OPEN_MAX/s,/\* Max, Max,' < ${LIB}/$file. >${LIB}/$file
1175 fi
1176
1177 # These files in Sun OS 4.x use /**/ to concatenate tokens.
1178 for file in sparc/asm_linkage.h sun3/asm_linkage.h sun3x/asm_linkage.h  \
1179         sun4/asm_linkage.h sun4c/asm_linkage.h sun4m/asm_linkage.h      \
1180         sun4c/debug/asm_linkage.h sun4m/debug/asm_linkage.h;
1181 do
1182   if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1183     cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1184     chmod +w ${LIB}/$file 2>/dev/null
1185     chmod a+r ${LIB}/$file 2>/dev/null
1186   fi
1187
1188   if [ -r ${LIB}/$file ]; then
1189     sed -e 's|/\*\*/|##|g' ${LIB}/$file > ${LIB}/${file}.sed
1190     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1191     if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1192       rm -f ${LIB}/$file
1193     fi
1194   fi
1195 done
1196
1197 echo 'Removing unneeded directories:'
1198 cd $LIB
1199 files=`find . -type d -print | sort -r`
1200 for file in $files; do
1201   rmdir $LIB/$file > /dev/null 2>&1
1202 done
1203
1204 if $LINKS; then
1205   echo 'Making internal symbolic non-directory links'
1206   cd ${INPUT}
1207   files=`find . -type l -print`
1208   for file in $files; do
1209     dest=`ls -ld $file | sed -n 's/.*-> //p'`
1210     if expr "$dest" : '[^/].*' > /dev/null; then    
1211       target=${LIB}/`echo file | sed "s|[^/]*\$|$dest|"`
1212       if [ -f $target ]; then
1213         ln -s $dest ${LIB}/$file >/dev/null 2>&1
1214       fi
1215     fi
1216   done
1217 fi
1218
1219 echo 'Cleaning up DONE files.'
1220 cd $LIB
1221 find . -name DONE -exec rm -f {} ';'
1222
1223 exit 0