OSDN Git Service

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