OSDN Git Service

(stat.h): Don't depend upon specific formal
[pf3gnuchains/gcc-fork.git] / gcc / fixinc.svr4
1 #! /bin/sh
2 #
3 #   fixinc.svr4  --  Install modified versions of certain ANSI-incompatible
4 #   native System V Release 4 system include files.
5 #
6 #   Written by Ron Guilmette (rfg@ncd.com).
7 #
8 # This file is part of GNU CC.
9
10 # GNU CC is free software; you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; either version 2, or (at your option)
13 # any later version.
14
15 # GNU CC is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 # GNU General Public License for more details.
19
20 # You should have received a copy of the GNU General Public License
21 # along with GNU CC; see the file COPYING.  If not, write to
22 # the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
23 #
24 #       This script munges the native include files provided with System V
25 #       Release 4 systems so as to remove things which are violations of the
26 #       ANSI C standard.  Once munged, the resulting new system include files
27 #       are placed in a directory that GNU C will search *before* searching
28 #       the /usr/include directory. This script should work properly for most
29 #       System V Release 4 systems.  For other types of systems, you should
30 #       use the `fixincludes' script instead.
31 #
32 #       See README-fixinc for more information.
33
34 # Directory where gcc sources (and sometimes special include files) live.
35 SRCDIR=${3-${SRCDIR-.}}
36
37 # Directory containing the original header files.
38 INPUT=${2-${INPUT-/usr/include}}
39
40 # Fail if no arg to specify a directory for the output.
41 if [ x$1 = x ]
42 then echo fixincludes: no output directory specified
43 exit 1
44 fi
45
46 # Directory in which to store the results.
47 LIB=${1?"fixincludes: output directory not specified"}
48
49 # Make sure it exists.
50 if [ ! -d $LIB ]; then
51   mkdir $LIB || exit 1
52 fi
53
54 ORIG_DIR=`pwd`
55
56 # Make LIB absolute if it is relative.
57 # Don't do this if not necessary, since may screw up automounters.
58 case $LIB in
59 /*)
60         ;;
61 *)
62         cd $LIB; LIB=`${PWDCMD}`
63         ;;
64 esac
65
66 # This prevents /bin/ex from failing if the current terminal type is
67 # unrecognizable.
68 TERM=dumb
69 export TERM
70 # This prevents /bin/ex from failing if the EXINIT environment variable
71 # was set to something invalid.
72 EXINIT=""
73 export EXINIT
74
75 echo 'Building fixincludes in ' ${LIB}
76
77 # Determine whether this filesystem has symbolic links.
78 if ln -s X $LIB/ShouldNotExist 2>/dev/null; then
79   rm -f $LIB/ShouldNotExist
80   LINKS=true
81 else
82   LINKS=false
83 fi
84
85 echo 'Making directories:'
86 cd ${INPUT}
87 if $LINKS; then
88   files=`ls -LR | sed -n s/:$//p`
89 else
90   files=`find . -type d -print | sed '/^.$/d'`
91 fi
92 for file in $files; do
93   rm -rf $LIB/$file
94   if [ ! -d $LIB/$file ]
95   then mkdir $LIB/$file
96   fi
97 done
98
99 # treetops gets an alternating list
100 # of old directories to copy
101 # and the new directories to copy to.
102 treetops="${INPUT} ${LIB}"
103
104 if $LINKS; then
105   echo 'Making internal symbolic directory links'
106   for file in $files; do
107     dest=`ls -ld $file | sed -n 's/.*-> //p'`
108     if [ "$dest" ]; then    
109       cwd=`pwd`
110       # In case $dest is relative, get to $file's dir first.
111       cd ${INPUT}
112       cd `echo ./$file | sed -n 's&[^/]*$&&p'`
113       # Check that the target directory exists.
114       # Redirections changed to avoid bug in sh on Ultrix.
115       (cd $dest) > /dev/null 2>&1
116       if [ $? = 0 ]; then
117         cd $dest
118         # X gets the dir that the link actually leads to.
119         x=`pwd`
120         # If link leads back into ${INPUT},
121         # make a similar link here.
122         if expr $x : "${INPUT}/.*" > /dev/null; then
123           # Y gets the actual target dir name, relative to ${INPUT}.
124           y=`echo $x | sed -n "s&${INPUT}/&&p"`
125           echo $file '->' $y ': Making link'
126           rm -fr ${LIB}/$file > /dev/null 2>&1
127           ln -s ${LIB}/$y ${LIB}/$file > /dev/null 2>&1
128         else
129           # If the link is to outside ${INPUT},
130           # treat this directory as if it actually contained the files.
131 # This line used to have $dest instead of $x.
132 # $dest seemed to be wrong for links found in subdirectories
133 # of ${INPUT}.  Does this change break anything?
134           treetops="$treetops $x ${LIB}/$file"
135         fi
136       fi
137       cd $cwd
138     fi
139   done
140 fi
141
142 set - $treetops
143 while [ $# != 0 ]; do
144   # $1 is an old directory to copy, and $2 is the new directory to copy to.
145   echo "Finding header files in $1:"
146   cd ${INPUT}
147   cd $1
148   files=`find . -name '*.h' -type f -print`
149   echo 'Checking header files:'
150   for file in $files; do
151       echo Fixing $file
152       if [ -r $file ]; then
153         cp $file $2/$file >/dev/null 2>&1 || echo "Can't copy $file"
154         chmod +w $2/$file
155         chmod a+r $2/$file
156
157 # The following have been removed from the sed command below
158 # because it is more useful to leave these things in.
159 # The only reason to remove them was for -pedantic,
160 # which isn't much of a reason. -- rms.
161 #         /^[   ]*#[    ]*ident/d
162
163 # This code makes Solaris SCSI fail, because it changes the
164 # alignment within some critical structures.  See <sys/scsi/impl/commands.h>.
165 #         s/u_char\([   ][      ]*[a-zA-Z0-9_][a-zA-Z0-9_]*[    ]*:[    ]*[0-9][0-9]*\)/u_int\1/
166 # Disable these also, since they probably aren't safe either.
167 #         s/u_short\([  ][      ]*[a-zA-Z0-9_][a-zA-Z0-9_]*[    ]*:[    ]*[0-9][0-9]*\)/u_int\1/
168 #         s/ushort\([   ][      ]*[a-zA-Z0-9_][a-zA-Z0-9_]*[    ]*:[    ]*[0-9][0-9]*\)/u_int\1/
169 #         s/evcm_t\([   ][      ]*[a-zA-Z0-9_][a-zA-Z0-9_]*[    ]*:[    ]*[0-9][0-9]*\)/u_int\1/
170 #         s/Pbyte\([    ][      ]*[a-zA-Z0-9_][a-zA-Z0-9_]*[    ]*:[    ]*SEQSIZ\)/unsigned int\1/
171
172 # The change of u_char, etc, to u_int
173 # applies to bit fields.
174         sed -e '
175           s%^\([        ]*#[    ]*endif[        ]*\)\([^/       ].*\)$%\1/* \2 */%
176           s%^\([        ]*#[    ]*else[         ]*\)\([^/       ].*\)$%\1/* \2 */%
177           s/#lint(on)/defined(lint)/g
178           s/#lint(off)/!defined(lint)/g
179           s/#machine(\([^)]*\))/defined(__\1__)/g
180           s/#system(\([^)]*\))/defined(__\1__)/g
181           s/#cpu(\([^)]*\))/defined(__\1__)/g
182           /#[a-z]*if.*[  (]m68k/                s/\([^_]\)m68k/\1__m68k__/g
183           /#[a-z]*if.*[  (]__i386\([^_]\)/      s/__i386/__i386__/g
184           /#[a-z]*if.*[  (]i386/                s/\([^_]\)i386/\1__i386__/g
185           /#[a-z]*if.*[  (]sparc/       s/\([^_]\)sparc/\1__sparc__/g
186           /#[a-z]*if.*[  (]mc68000/     s/\([^_]\)mc68000/\1__mc68000__/g
187           /#[a-z]*if.*[  (]vax/         s/\([^_]\)vax/\1__vax__/g
188           /#[a-z]*if.*[  (]sun/         s/\([^_]\)\(sun[a-z0-9]*\)\([^a-z0-9_]\)/\1__\2__\3/g
189           /#[a-z]*if.*[  (]sun/         s/\([^_]\)\(sun[a-z0-9]*\)$/\1__\2__/g
190           /#[a-z]*if.*[  (]ns32000/     s/\([^_]\)ns32000/\1__ns32000__/g
191           /#[a-z]*if.*[  (]pyr/         s/\([^_]\)pyr/\1__pyr__/g
192           /#[a-z]*if.*[  (]is68k/       s/\([^_]\)is68k/\1__is68k__/g
193           s/__STDC__ == 0/!defined (__STRICT_ANSI__)/g
194           s/__STDC__ != 0/defined (__STRICT_ANSI__)/g
195           s/__STDC__ - 0 == 0/!defined (__STRICT_ANSI__)/g
196         ' $2/$file > $2/$file.sed
197         mv $2/$file.sed $2/$file
198         if cmp $file $2/$file >/dev/null 2>&1; then
199            rm $2/$file
200         fi
201       fi
202   done
203   shift; shift
204 done
205
206 # Fix first broken decl of getcwd present on some svr4 systems.
207
208 file=stdlib.h
209 base=`basename $file`
210 if [ -r ${LIB}/$file ]; then
211   file_to_fix=${LIB}/$file
212 else
213   if [ -r ${INPUT}/$file ]; then
214     file_to_fix=${INPUT}/$file
215   else
216     file_to_fix=""
217   fi
218 fi
219 if [ \! -z "$file_to_fix" ]; then
220   echo Checking $file_to_fix
221   sed -e 's/getcwd(char \*, int)/getcwd(char *, size_t)/' $file_to_fix > /tmp/$base
222   if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
223     true
224   else
225     echo Fixed $file_to_fix
226     rm -f ${LIB}/$file
227     cp /tmp/$base ${LIB}/$file
228     chmod a+r ${LIB}/$file
229   fi
230   rm -f /tmp/$base
231 fi
232
233 # Fix second broken decl of getcwd present on some svr4 systems.  Also
234 # fix the incorrect decl of profil present on some svr4 systems.
235
236 file=unistd.h
237 base=`basename $file`
238 if [ -r ${LIB}/$file ]; then
239   file_to_fix=${LIB}/$file
240 else
241   if [ -r ${INPUT}/$file ]; then
242     file_to_fix=${INPUT}/$file
243   else
244     file_to_fix=""
245   fi
246 fi
247 if [ \! -z "$file_to_fix" ]; then
248   echo Checking $file_to_fix
249   sed -e 's/getcwd(char \*, int)/getcwd(char *, size_t)/' $file_to_fix \
250     | sed -e 's/profil(unsigned short \*, unsigned int, unsigned int, unsigned int)/profil(unsigned short *, size_t, int, unsigned)/' > /tmp/$base
251   if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
252     true
253   else
254     echo Fixed $file_to_fix
255     rm -f ${LIB}/$file
256     cp /tmp/$base ${LIB}/$file
257     chmod a+r ${LIB}/$file
258   fi
259   rm -f /tmp/$base
260 fi
261
262 # Fix the definition of NULL in <sys/param.h> so that it is conditional
263 # and so that it is correct for both C and C++.
264
265 file=sys/param.h
266 base=`basename $file`
267 if [ -r ${LIB}/$file ]; then
268   file_to_fix=${LIB}/$file
269 else
270   if [ -r ${INPUT}/$file ]; then
271     file_to_fix=${INPUT}/$file
272   else
273     file_to_fix=""
274   fi
275 fi
276 if [ \! -z "$file_to_fix" ]; then
277   echo Checking $file_to_fix
278   cp $file_to_fix /tmp/$base
279   chmod +w /tmp/$base
280   chmod a+r /tmp/$base
281   ex /tmp/$base <<EOF
282   /^#define[    ]*NULL[         ]*0$/c
283 #ifndef NULL
284 #ifdef __cplusplus
285 #define __NULL_TYPE
286 #else /* !defined(__cplusplus) */
287 #define __NULL_TYPE (void *)
288 #endif /* !defined(__cplusplus) */
289 #define NULL (__NULL_TYPE 0)
290 #endif /* !defined(NULL) */
291 .
292   wq
293 EOF
294   if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
295     true
296   else
297     echo Fixed $file_to_fix
298     rm -f ${LIB}/$file
299     cp /tmp/$base ${LIB}/$file
300     chmod a+r ${LIB}/$file
301   fi
302   rm -f /tmp/$base
303 fi
304
305 # Likewise fix the definition of NULL in <stdio.h> so that it is conditional
306 # and so that it is correct for both C and C++.
307
308 file=stdio.h
309 base=`basename $file`
310 if [ -r ${LIB}/$file ]; then
311   file_to_fix=${LIB}/$file
312 else
313   if [ -r ${INPUT}/$file ]; then
314     file_to_fix=${INPUT}/$file
315   else
316     file_to_fix=""
317   fi
318 fi
319 if [ \! -z "$file_to_fix" ]; then
320   echo Checking $file_to_fix
321   cp $file_to_fix /tmp/$base
322   chmod +w /tmp/$base
323   ex /tmp/$base <<EOF
324   /^#define[    ]*NULL[         ]*0$/c
325 #ifdef __cplusplus
326 #define __NULL_TYPE
327 #else /* !defined(__cplusplus) */
328 #define __NULL_TYPE (void *)
329 #endif /* !defined(__cplusplus) */
330 #define NULL (__NULL_TYPE 0)
331 .
332   wq
333 EOF
334   if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
335     true
336   else
337     echo Fixed $file_to_fix
338     rm -f ${LIB}/$file
339     cp /tmp/$base ${LIB}/$file
340     chmod a+r ${LIB}/$file
341   fi
342   rm -f /tmp/$base
343 fi
344
345 # Likewise fix the definition of NULL in <dbm.h> so that it is conditional
346 # and so that it is correct for both C and C++.
347
348 file=dbm.h
349 base=`basename $file`
350 if [ -r ${LIB}/$file ]; then
351   file_to_fix=${LIB}/$file
352 else
353   if [ -r ${INPUT}/$file ]; then
354     file_to_fix=${INPUT}/$file
355   else
356     file_to_fix=""
357   fi
358 fi
359 if [ \! -z "$file_to_fix" ]; then
360   echo Checking $file_to_fix
361   cp $file_to_fix /tmp/$base
362   chmod +w /tmp/$base
363   ex /tmp/$base <<EOF
364   /^#define[    ]*NULL[         ]*((char \*) 0)$/c
365 #ifndef NULL
366 #ifdef __cplusplus
367 #define __NULL_TYPE
368 #else /* !defined(__cplusplus) */
369 #define __NULL_TYPE (void *)
370 #endif /* !defined(__cplusplus) */
371 #define NULL (__NULL_TYPE 0)
372 #endif /* !defined(NULL) */
373 .
374   wq
375 EOF
376   if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
377     true
378   else
379     echo Fixed $file_to_fix
380     rm -f ${LIB}/$file
381     cp /tmp/$base ${LIB}/$file
382     chmod a+r ${LIB}/$file
383   fi
384   rm -f /tmp/$base
385 fi
386
387 # Add a prototyped declaration of mmap to <sys/mman.h>.
388
389 file=sys/mman.h
390 base=`basename $file`
391 if [ -r ${LIB}/$file ]; then
392   file_to_fix=${LIB}/$file
393 else
394   if [ -r ${INPUT}/$file ]; then
395     file_to_fix=${INPUT}/$file
396   else
397     file_to_fix=""
398   fi
399 fi
400 if [ \! -z "$file_to_fix" ]; then
401   echo Checking $file_to_fix
402   cp $file_to_fix /tmp/$base
403   chmod +w /tmp/$base
404   ex /tmp/$base <<EOF
405   /^extern caddr_t mmap();$/c
406 #ifdef __STDC__
407 extern caddr_t mmap (caddr_t addr, size_t len, int prot, int flags,
408                      int fd, off_t off);
409 #else /* !defined(__STDC__) */
410 extern caddr_t mmap ();
411 #endif /* !defined(__STDC__) */
412 .
413   wq
414 EOF
415   if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
416     true
417   else
418     echo Fixed $file_to_fix
419     rm -f ${LIB}/$file
420     cp /tmp/$base ${LIB}/$file
421     chmod a+r ${LIB}/$file
422   fi
423   rm -f /tmp/$base
424 fi
425
426 # Fix declarations of `ftw' and `nftw' in <ftw.h>.
427
428 file=ftw.h
429 base=`basename $file`
430 if [ -r ${LIB}/$file ]; then
431   file_to_fix=${LIB}/$file
432 else
433   if [ -r ${INPUT}/$file ]; then
434     file_to_fix=${INPUT}/$file
435   else
436     file_to_fix=""
437   fi
438 fi
439 if [ \! -z "$file_to_fix" ]; then
440   echo Checking $file_to_fix
441   cp $file_to_fix /tmp/$base
442   chmod +w /tmp/$base
443   ex /tmp/$base <<EOF
444   /^extern int ftw(const/c
445 #if !defined(_STYPES)
446 static
447 #else
448 extern
449 #endif
450   int ftw(const char *, int (*)(const char *, const struct stat *, int), int);
451 .
452   /^extern int nftw/c
453 #if defined(_STYPES)
454 static
455 #else
456 extern
457 #endif
458   int nftw(const char *, int (*)(const char *, const struct stat *, int, struct FTW *),int, int);
459 .
460   /^extern int ftw(),/c
461 #if !defined(_STYPES)
462 static
463 #else
464 extern
465 #endif
466   int ftw();
467 #if defined(_STYPES)
468 static
469 #else
470 extern
471 #endif
472   int nftw();
473 .
474   wq
475 EOF
476   if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
477     true
478   else
479     echo Fixed $file_to_fix
480     rm -f ${LIB}/$file
481     cp /tmp/$base ${LIB}/$file
482     chmod a+r ${LIB}/$file
483   fi
484   rm -f /tmp/$base
485 fi
486
487 # Add a `static' declaration of `getrnge' into <regexp.h>.
488
489 # Don't do this if there is already a `static void getrnge' declaration
490 # present, since this would cause a redeclaration error.  Solaris 2.x has
491 # such a declaration.
492
493 file=regexp.h
494 base=`basename $file`
495 if [ -r ${LIB}/$file ]; then
496   file_to_fix=${LIB}/$file
497 else
498   if [ -r ${INPUT}/$file ]; then
499     file_to_fix=${INPUT}/$file
500   else
501     file_to_fix=""
502   fi
503 fi
504 if [ \! -z "$file_to_fix" ]; then
505   echo Checking $file_to_fix
506   if grep "static void getrnge" $file_to_fix > /dev/null; then
507     true
508   else
509     cp $file_to_fix /tmp/$base
510     chmod +w /tmp/$base
511     ex /tmp/$base <<EOF
512     /^static int[       ]*size;/c
513 static int      size ;
514
515 static int getrnge ();
516 .
517     wq
518 EOF
519     if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
520       true
521     else
522       echo Fixed $file_to_fix
523       rm -f ${LIB}/$file
524       cp /tmp/$base ${LIB}/$file
525       chmod a+r ${LIB}/$file
526     fi
527   fi
528   rm -f /tmp/$base
529 fi
530
531 # Disable apparent native compiler optimization cruft in SVR4.2 <string.h>
532 # that is visible to any ANSI compiler using this include.  Simply
533 # delete the lines the #define some string functions to internal forms.
534
535 file=string.h
536 base=`basename $file`
537 if [ -r ${LIB}/$file ]; then
538   file_to_fix=${LIB}/$file
539 else
540   if [ -r ${INPUT}/$file ]; then
541     file_to_fix=${INPUT}/$file
542   else
543     file_to_fix=""
544   fi
545 fi
546 if [ \! -z "$file_to_fix" ]; then
547   echo Checking $file_to_fix
548   cp $file_to_fix /tmp/$base
549   chmod +w /tmp/$base
550   ex /tmp/$base <<EOF
551   g/#define.*__std_hdr_/d
552   wq
553 EOF
554   if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
555     true
556   else
557     echo Fixed $file_to_fix
558     rm -f ${LIB}/$file
559     cp /tmp/$base ${LIB}/$file
560     chmod a+r ${LIB}/$file
561   fi
562   rm -f /tmp/$base
563 fi
564
565 # Add a #define of _SIGACTION_ into <sys/signal.h>.
566 # Also fix types of SIG_DFL, SIG_ERR, SIG_IGN, and SIG_HOLD.
567
568 file=sys/signal.h
569 base=`basename $file`
570 if [ -r ${LIB}/$file ]; then
571   file_to_fix=${LIB}/$file
572 else
573   if [ -r ${INPUT}/$file ]; then
574     file_to_fix=${INPUT}/$file
575   else
576     file_to_fix=""
577   fi
578 fi
579 if [ \! -z "$file_to_fix" ]; then
580   echo Checking $file_to_fix
581   cp $file_to_fix /tmp/$base
582   chmod +w /tmp/$base
583   ex /tmp/$base <<EOF
584   /^struct sigaction {/c
585 #define _SIGACTION_
586 struct  sigaction  {
587 .
588   1,\$s/(void *(\*)())/(void (*)(int))/
589   wq
590 EOF
591   if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
592     true
593   else
594     echo Fixed $file_to_fix
595     rm -f ${LIB}/$file
596     cp /tmp/$base ${LIB}/$file
597     chmod a+r ${LIB}/$file
598   fi
599   rm -f /tmp/$base
600 fi
601
602 # Fix declarations of `makedev', `major', and `minor' in <sys/mkdev.h>.
603
604 file=sys/mkdev.h
605 base=`basename $file`
606 if [ -r ${LIB}/$file ]; then
607   file_to_fix=${LIB}/$file
608 else
609   if [ -r ${INPUT}/$file ]; then
610     file_to_fix=${INPUT}/$file
611   else
612     file_to_fix=""
613   fi
614 fi
615 if [ \! -z "$file_to_fix" ]; then
616   echo Checking $file_to_fix
617   cp $file_to_fix /tmp/$base
618   chmod +w /tmp/$base
619   ex /tmp/$base <<EOF
620   /^dev_t makedev(const/c
621 static dev_t makedev(const major_t, const minor_t);
622 .
623   /^dev_t makedev()/c
624 static dev_t makedev();
625 .
626   /^major_t major(const/c
627 static major_t major(const dev_t);
628 .
629   /^major_t major()/c
630 static major_t major();
631 .
632   /^minor_t minor(const/c
633 static minor_t minor(const dev_t);
634 .
635   /^minor_t minor()/c
636 static minor_t minor();
637 .
638   wq
639 EOF
640   if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
641     true
642   else
643     echo Fixed $file_to_fix
644     rm -f ${LIB}/$file
645     cp /tmp/$base ${LIB}/$file
646     chmod a+r ${LIB}/$file
647   fi
648   rm -f /tmp/$base
649 fi
650
651 # Fix reference to NMSZ in <sys/adv.h>.
652
653 file=sys/adv.h
654 base=`basename $file`
655 if [ -r ${LIB}/$file ]; then
656   file_to_fix=${LIB}/$file
657 else
658   if [ -r ${INPUT}/$file ]; then
659     file_to_fix=${INPUT}/$file
660   else
661     file_to_fix=""
662   fi
663 fi
664 if [ \! -z "$file_to_fix" ]; then
665   echo Checking $file_to_fix
666   sed 's/\[NMSZ\]/\[RFS_NMSZ\]/g' $file_to_fix > /tmp/$base
667   if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
668     true
669   else
670     echo Fixed $file_to_fix
671     rm -f ${LIB}/$file
672     cp /tmp/$base ${LIB}/$file
673     chmod a+r ${LIB}/$file
674   fi
675   rm -f /tmp/$base
676 fi
677
678 # Fix reference to NC_NPI_RAW in <sys/netcspace.h>.  Also fix types of
679 # array initializers.
680
681 file=sys/netcspace.h
682 base=`basename $file`
683 if [ -r ${LIB}/$file ]; then
684   file_to_fix=${LIB}/$file
685 else
686   if [ -r ${INPUT}/$file ]; then
687     file_to_fix=${INPUT}/$file
688   else
689     file_to_fix=""
690   fi
691 fi
692 if [ \! -z "$file_to_fix" ]; then
693   echo Checking $file_to_fix
694   sed 's/NC_NPI_RAW/NC_TPI_RAW/g' $file_to_fix \
695     | sed 's/NC_/(unsigned long) NC_/' > /tmp/$base
696   if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
697     true
698   else
699     echo Fixed $file_to_fix
700     rm -f ${LIB}/$file
701     cp /tmp/$base ${LIB}/$file
702     chmod a+r ${LIB}/$file
703   fi
704   rm -f /tmp/$base
705 fi
706
707 # Conditionalize all of <fs/rfs/rf_cache.h> on _KERNEL being defined.
708
709 file=fs/rfs/rf_cache.h
710 base=`basename $file`
711 if [ -r ${LIB}/$file ]; then
712   file_to_fix=${LIB}/$file
713 else
714   if [ -r ${INPUT}/$file ]; then
715     file_to_fix=${INPUT}/$file
716   else
717     file_to_fix=""
718   fi
719 fi
720 if [ \! -z "$file_to_fix" ]; then
721   echo Checking $file_to_fix
722   if grep _KERNEL $file_to_fix > /dev/null; then
723     true
724   else
725     echo '#ifdef _KERNEL' > /tmp/$base
726     cat $file_to_fix >> /tmp/$base
727     echo '#endif /* defined(_KERNEL) */' >> /tmp/$base
728     echo Fixed $file_to_fix
729     rm -f ${LIB}/$file
730     cp /tmp/$base ${LIB}/$file
731     chmod a+r ${LIB}/$file
732     rm -f /tmp/$base
733   fi
734 fi
735
736 # Conditionalize all of <sys/erec.h> on _KERNEL being defined.
737
738 file=sys/erec.h
739 base=`basename $file`
740 if [ -r ${LIB}/$file ]; then
741   file_to_fix=${LIB}/$file
742 else
743   if [ -r ${INPUT}/$file ]; then
744     file_to_fix=${INPUT}/$file
745   else
746     file_to_fix=""
747   fi
748 fi
749 if [ \! -z "$file_to_fix" ]; then
750   echo Checking $file_to_fix
751   if grep _KERNEL $file_to_fix > /dev/null; then
752     true
753   else
754     echo '#ifdef _KERNEL' > /tmp/$base
755     cat $file_to_fix >> /tmp/$base
756     echo '#endif /* defined(_KERNEL) */' >> /tmp/$base
757     echo Fixed $file_to_fix
758     rm -f ${LIB}/$file
759     cp /tmp/$base ${LIB}/$file
760     chmod a+r ${LIB}/$file
761     rm -f /tmp/$base
762   fi
763 fi
764
765 # Conditionalize all of <sys/err.h> on _KERNEL being defined.
766
767 file=sys/err.h
768 base=`basename $file`
769 if [ -r ${LIB}/$file ]; then
770   file_to_fix=${LIB}/$file
771 else
772   if [ -r ${INPUT}/$file ]; then
773     file_to_fix=${INPUT}/$file
774   else
775     file_to_fix=""
776   fi
777 fi
778 if [ \! -z "$file_to_fix" ]; then
779   echo Checking $file_to_fix
780   if grep _KERNEL $file_to_fix > /dev/null; then
781     true
782   else
783     echo '#ifdef _KERNEL' > /tmp/$base
784     cat $file_to_fix >> /tmp/$base
785     echo '#endif /* defined(_KERNEL) */' >> /tmp/$base
786     echo Fixed $file_to_fix
787     rm -f ${LIB}/$file
788     cp /tmp/$base ${LIB}/$file
789     chmod a+r ${LIB}/$file
790     rm -f /tmp/$base
791   fi
792 fi
793
794 # Conditionalize all of <sys/char.h> on _KERNEL being defined.
795
796 file=sys/char.h
797 base=`basename $file`
798 if [ -r ${LIB}/$file ]; then
799   file_to_fix=${LIB}/$file
800 else
801   if [ -r ${INPUT}/$file ]; then
802     file_to_fix=${INPUT}/$file
803   else
804     file_to_fix=""
805   fi
806 fi
807 if [ \! -z "$file_to_fix" ]; then
808   echo Checking $file_to_fix
809   if grep _KERNEL $file_to_fix > /dev/null; then
810     true
811   else
812     echo '#ifdef _KERNEL' > /tmp/$base
813     cat $file_to_fix >> /tmp/$base
814     echo '#endif /* defined(_KERNEL) */' >> /tmp/$base
815     echo Fixed $file_to_fix
816     rm -f ${LIB}/$file
817     cp /tmp/$base ${LIB}/$file
818     chmod a+r ${LIB}/$file
819     rm -f /tmp/$base
820   fi
821 fi
822
823 # Conditionalize all of <sys/getpages.h> on _KERNEL being defined.
824
825 file=sys/getpages.h
826 base=`basename $file`
827 if [ -r ${LIB}/$file ]; then
828   file_to_fix=${LIB}/$file
829 else
830   if [ -r ${INPUT}/$file ]; then
831     file_to_fix=${INPUT}/$file
832   else
833     file_to_fix=""
834   fi
835 fi
836 if [ \! -z "$file_to_fix" ]; then
837   echo Checking $file_to_fix
838   if grep _KERNEL $file_to_fix > /dev/null; then
839     true
840   else
841     echo '#ifdef _KERNEL' > /tmp/$base
842     cat $file_to_fix >> /tmp/$base
843     echo '#endif /* defined(_KERNEL) */' >> /tmp/$base
844     echo Fixed $file_to_fix
845     rm -f ${LIB}/$file
846     cp /tmp/$base ${LIB}/$file
847     chmod a+r ${LIB}/$file
848     rm -f /tmp/$base
849   fi
850 fi
851
852 # Conditionalize all of <sys/map.h> on _KERNEL being defined.
853
854 file=sys/map.h
855 base=`basename $file`
856 if [ -r ${LIB}/$file ]; then
857   file_to_fix=${LIB}/$file
858 else
859   if [ -r ${INPUT}/$file ]; then
860     file_to_fix=${INPUT}/$file
861   else
862     file_to_fix=""
863   fi
864 fi
865 if [ \! -z "$file_to_fix" ]; then
866   echo Checking $file_to_fix
867   if grep _KERNEL $file_to_fix > /dev/null; then
868     true
869   else
870     echo '#ifdef _KERNEL' > /tmp/$base
871     cat $file_to_fix >> /tmp/$base
872     echo '#endif /* defined(_KERNEL) */' >> /tmp/$base
873     echo Fixed $file_to_fix
874     rm -f ${LIB}/$file
875     cp /tmp/$base ${LIB}/$file
876     chmod a+r ${LIB}/$file
877     rm -f /tmp/$base
878   fi
879 fi
880
881 # Conditionalize all of <sys/cmn_err.h> on _KERNEL being defined.
882
883 file=sys/cmn_err.h
884 base=`basename $file`
885 if [ -r ${LIB}/$file ]; then
886   file_to_fix=${LIB}/$file
887 else
888   if [ -r ${INPUT}/$file ]; then
889     file_to_fix=${INPUT}/$file
890   else
891     file_to_fix=""
892   fi
893 fi
894 if [ \! -z "$file_to_fix" ]; then
895   echo Checking $file_to_fix
896   if grep _KERNEL $file_to_fix > /dev/null; then
897     true
898   else
899     echo '#ifdef _KERNEL' > /tmp/$base
900     cat $file_to_fix >> /tmp/$base
901     echo '#endif /* defined(_KERNEL) */' >> /tmp/$base
902     echo Fixed $file_to_fix
903     rm -f ${LIB}/$file
904     cp /tmp/$base ${LIB}/$file
905     chmod a+r ${LIB}/$file
906     rm -f /tmp/$base
907   fi
908 fi
909
910 # Conditionalize all of <sys/kdebugger.h> on _KERNEL being defined.
911
912 file=sys/kdebugger.h
913 base=`basename $file`
914 if [ -r ${LIB}/$file ]; then
915   file_to_fix=${LIB}/$file
916 else
917   if [ -r ${INPUT}/$file ]; then
918     file_to_fix=${INPUT}/$file
919   else
920     file_to_fix=""
921   fi
922 fi
923 if [ \! -z "$file_to_fix" ]; then
924   echo Checking $file_to_fix
925   if grep _KERNEL $file_to_fix > /dev/null; then
926     true
927   else
928     echo '#ifdef _KERNEL' > /tmp/$base
929     cat $file_to_fix >> /tmp/$base
930     echo '#endif /* defined(_KERNEL) */' >> /tmp/$base
931     echo Fixed $file_to_fix
932     rm -f ${LIB}/$file
933     cp /tmp/$base ${LIB}/$file
934     chmod a+r ${LIB}/$file
935     rm -f /tmp/$base
936   fi
937 fi
938
939 # Conditionalize some of <netinet/in.h> on _KERNEL being defined.
940
941 file=netinet/in.h
942 base=`basename $file`
943 if [ -r ${LIB}/$file ]; then
944   file_to_fix=${LIB}/$file
945 else
946   if [ -r ${INPUT}/$file ]; then
947     file_to_fix=${INPUT}/$file
948   else
949     file_to_fix=""
950   fi
951 fi
952 if [ \! -z "$file_to_fix" ]; then
953   echo Checking $file_to_fix
954   if grep _KERNEL $file_to_fix > /dev/null; then
955     true
956   else
957     sed -e '/#ifdef INKERNEL/i\
958 #ifdef _KERNEL' \
959     -e '/#endif[        ]*\/\* INKERNEL \*\//a\
960 #endif /* _KERNEL */' \
961     $file_to_fix > ${LIB}/${file}.sed
962     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
963     echo Fixed $file_to_fix
964   fi
965 fi
966
967 # Conditionalize some of <sys/endian.h> on __GNUC__ and __GNUG__.
968
969 file=sys/endian.h
970 base=`basename $file`
971 if [ -r ${LIB}/$file ]; then
972   file_to_fix=${LIB}/$file
973 else
974   if [ -r ${INPUT}/$file ]; then
975     file_to_fix=${INPUT}/$file
976   else
977     file_to_fix=""
978   fi
979 fi
980 if [ \! -z "$file_to_fix" ]; then
981   echo Checking $file_to_fix
982   if grep __GNUC__ $file_to_fix > /dev/null; then
983     true
984   else
985     sed -e '/#  ifdef   __STDC__/i\
986 #   if !defined (__GNUC__) && !defined (__GNUG__)' \
987     -e '/#              include <sys\/byteorder.h>/s/           /   /'\
988     -e '/#   include    <sys\/byteorder.h>/i\
989 #   endif /* !defined (__GNUC__) && !defined (__GNUG__) */'\
990     $file_to_fix > ${LIB}/${file}.sed
991     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
992     echo Fixed $file_to_fix
993   fi
994 fi
995
996 # Commented out because tmcconne@sedona.intel.com says we don't clearly need it
997 # and the text in types.h is not erroneous.
998 ## In sys/types.h, don't name the enum for booleans.
999 #
1000 #file=sys/types.h
1001 #base=`basename $file`
1002 #if [ -r ${LIB}/$file ]; then
1003 #  file_to_fix=${LIB}/$file
1004 #else
1005 #  if [ -r ${INPUT}/$file ]; then
1006 #    file_to_fix=${INPUT}/$file
1007 #  else
1008 #    file_to_fix=""
1009 #  fi
1010 #fi
1011 #if [ \! -z "$file_to_fix" ]; then
1012 #  echo Checking $file_to_fix
1013 #  if grep "enum boolean" $file_to_fix > /dev/null; then
1014 #    sed -e 's/enum boolean/enum/' ${LIB}/$file > ${LIB}/${file}.sed
1015 #    rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1016 #    echo Fixed $file_to_fix
1017 #  else
1018 #    true
1019 #  fi
1020 #fi
1021
1022 # Remove useless extern keyword from struct forward declarations in
1023 # <sys/stream.h> and <sys/strsubr.h>
1024
1025 file=sys/stream.h
1026 base=`basename $file`
1027 if [ -r ${LIB}/$file ]; then
1028   file_to_fix=${LIB}/$file
1029 else
1030   if [ -r ${INPUT}/$file ]; then
1031     file_to_fix=${INPUT}/$file
1032   else
1033     file_to_fix=""
1034   fi
1035 fi
1036 if [ \! -z "$file_to_fix" ]; then
1037   echo Checking $file_to_fix
1038   sed -e '
1039     s/extern struct stdata;/struct stdata;/g
1040     s/extern struct strevent;/struct strevent;/g
1041   ' $file_to_fix > /tmp/$base 
1042   if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
1043     true
1044   else
1045     echo Fixed $file_to_fix
1046     rm -f ${LIB}/$file
1047     cp /tmp/$base ${LIB}/$file
1048     chmod a+r ${LIB}/$file
1049   fi
1050   rm -f /tmp/$base
1051 fi
1052
1053 file=sys/strsubr.h
1054 base=`basename $file`
1055 if [ -r ${LIB}/$file ]; then
1056   file_to_fix=${LIB}/$file
1057 else
1058   if [ -r ${INPUT}/$file ]; then
1059     file_to_fix=${INPUT}/$file
1060   else
1061     file_to_fix=""
1062   fi
1063 fi
1064 if [ \! -z "$file_to_fix" ]; then
1065   echo Checking $file_to_fix
1066   sed -e '
1067     s/extern struct strbuf;/struct strbuf;/g
1068     s/extern struct uio;/struct uio;/g
1069     s/extern struct thread;/struct thread;/g
1070     s/extern struct proc;/struct proc;/g
1071   ' $file_to_fix > /tmp/$base 
1072   if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
1073     true
1074   else
1075     echo Fixed $file_to_fix
1076     rm -f ${LIB}/$file
1077     cp /tmp/$base ${LIB}/$file
1078     chmod a+r ${LIB}/$file
1079   fi
1080   rm -f /tmp/$base
1081 fi
1082
1083 # Convert functions to prototype form, and fix arg names in <sys/stat.h>.
1084
1085 file=sys/stat.h
1086 base=`basename $file`
1087 if [ -r ${LIB}/$file ]; then
1088   file_to_fix=${LIB}/$file
1089 else
1090   if [ -r ${INPUT}/$file ]; then
1091     file_to_fix=${INPUT}/$file
1092   else
1093     file_to_fix=""
1094   fi
1095 fi
1096 if [ \! -z "$file_to_fix" ]; then
1097   echo Checking $file_to_fix
1098   cp $file_to_fix /tmp/$base
1099   chmod +w /tmp/$base
1100   ex /tmp/$base <<EOF
1101 /^stat(/
1102 s/(.*$/(/
1103 j
1104 s/;/,/
1105 j
1106 s/;/)/
1107 /^lstat(/
1108 s/(.*$/(/
1109 j
1110 s/;/,/
1111 j
1112 s/;/)/
1113 /^fstat(/
1114 s/(.*$/(/
1115 j
1116 s/;/,/
1117 j
1118 s/;/)/
1119 /^mknod(/
1120 s/(.*$/(/
1121 j
1122 s/;/,/
1123 j
1124 s/;/,/
1125 j
1126 s/;/)/
1127 1,\$s/\([^A-Za-z]\)path\([^A-Za-z]\)/\1__path\2/g
1128 1,\$s/\([^A-Za-z]\)buf\([^A-Za-z]\)/\1__buf\2/g
1129 1,\$s/\([^A-Za-z]\)fd\([^A-Za-z]\)/\1__fd\2/g
1130 1,\$s/ret\([^u]\)/__ret\1/g
1131 1,\$s/\([^_]\)mode\([^_]\)/\1__mode\2/g
1132 1,\$s/\([^_r]\)dev\([^_]\)/\1__dev\2/g
1133 wq
1134 EOF
1135   echo Fixed $file_to_fix
1136   rm -f ${LIB}/$file
1137   cp /tmp/$base ${LIB}/$file
1138   chmod a+r ${LIB}/$file
1139   rm -f /tmp/$base
1140 fi
1141
1142 # Sony NEWSOS 5.0 does not support the complete ANSI C standard.
1143
1144 if [ -x /bin/sony ]; then
1145   if /bin/sony; then
1146
1147     # Change <stdio.h> to not define __filbuf, __flsbuf, and __iob
1148
1149     file=stdio.h
1150     base=`basename $file`
1151     if [ -r ${LIB}/$file ]; then
1152       file_to_fix=${LIB}/$file
1153     else
1154       if [ -r ${INPUT}/$file ]; then
1155         file_to_fix=${INPUT}/$file
1156       else
1157         file_to_fix=""
1158       fi
1159     fi
1160     if [ \! -z "$file_to_fix" ]; then
1161       echo Checking $file_to_fix
1162       cp $file_to_fix /tmp/$base
1163       chmod +w /tmp/$base
1164       sed -e '
1165         s/__filbuf/_filbuf/g
1166         s/__flsbuf/_flsbuf/g
1167         s/__iob/_iob/g
1168       ' /tmp/$base > /tmp/$base.sed
1169       mv /tmp/$base.sed /tmp/$base
1170       if cmp $file_to_fix /tmp/$base.sed >/dev/null 2>&1; then
1171         true
1172       else
1173         echo Fixed $file_to_fix
1174         rm -f ${LIB}/$file
1175         cp /tmp/$base ${LIB}/$file
1176         chmod a+r ${LIB}/$file
1177       fi
1178       rm -f /tmp/$base
1179     fi
1180
1181     # Change <ctype.h> to not define __ctype
1182
1183     file=ctype.h
1184     base=`basename $file`
1185     if [ -r ${LIB}/$file ]; then
1186       file_to_fix=${LIB}/$file
1187     else
1188       if [ -r ${INPUT}/$file ]; then
1189         file_to_fix=${INPUT}/$file
1190       else
1191         file_to_fix=""
1192       fi
1193     fi
1194     if [ \! -z "$file_to_fix" ]; then
1195       echo Checking $file_to_fix
1196       cp $file_to_fix /tmp/$base
1197       chmod +w /tmp/$base
1198       sed -e '
1199         s/__ctype/_ctype/g
1200       ' /tmp/$base > /tmp/$base.sed
1201       mv /tmp/$base.sed /tmp/$base
1202       if cmp $file_to_fix /tmp/$base.sed >/dev/null 2>&1; then
1203         true
1204       else
1205         echo Fixed $file_to_fix
1206         rm -f ${LIB}/$file
1207         cp /tmp/$base ${LIB}/$file
1208         chmod a+r ${LIB}/$file
1209       fi
1210       rm -f /tmp/$base
1211     fi
1212   fi
1213 fi
1214
1215 # In limits.h, put #ifndefs around things that are supposed to be defined
1216 # in float.h to avoid redefinition errors if float.h is included first.
1217 # Solaris 2.1 has this problem.
1218
1219 file=limits.h
1220 base=`basename $file`
1221 if [ -r ${LIB}/$file ]; then
1222   file_to_fix=${LIB}/$file
1223 else
1224   if [ -r ${INPUT}/$file ]; then
1225     file_to_fix=${INPUT}/$file
1226   else
1227     file_to_fix=""
1228   fi
1229 fi
1230 if [ \! -z "$file_to_fix" ]; then
1231   echo Checking $file_to_fix
1232   sed -e '/[    ]FLT_MIN[       ]/i\
1233 #ifndef FLT_MIN'\
1234       -e '/[    ]FLT_MIN[       ]/a\
1235 #endif'\
1236       -e '/[    ]FLT_MAX[       ]/i\
1237 #ifndef FLT_MAX'\
1238       -e '/[    ]FLT_MAX[       ]/a\
1239 #endif'\
1240       -e '/[    ]FLT_DIG[       ]/i\
1241 #ifndef FLT_DIG'\
1242       -e '/[    ]FLT_DIG[       ]/a\
1243 #endif'\
1244       -e '/[    ]DBL_MIN[       ]/i\
1245 #ifndef DBL_MIN'\
1246       -e '/[    ]DBL_MIN[       ]/a\
1247 #endif'\
1248       -e '/[    ]DBL_MAX[       ]/i\
1249 #ifndef DBL_MAX'\
1250       -e '/[    ]DBL_MAX[       ]/a\
1251 #endif'\
1252       -e '/[    ]DBL_DIG[       ]/i\
1253 #ifndef DBL_DIG'\
1254       -e '/[    ]DBL_DIG[       ]/a\
1255 #endif' $file_to_fix > /tmp/$base
1256   if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
1257     true
1258   else
1259     echo Fixed $file_to_fix
1260     rm -f ${LIB}/$file
1261     cp /tmp/$base ${LIB}/$file
1262     chmod a+r ${LIB}/$file
1263   fi
1264   rm -f /tmp/$base
1265 fi
1266
1267 echo 'Removing unneeded directories:'
1268 cd $LIB
1269 files=`find . -type d -print | sort -r`
1270 for file in $files; do
1271   rmdir $LIB/$file > /dev/null 2>&1
1272 done
1273
1274 if $LINKS; then
1275   echo 'Making internal symbolic non-directory links'
1276   cd ${INPUT}
1277   files=`find . -type l -print`
1278   for file in $files; do
1279     dest=`ls -ld $file | sed -n 's/.*-> //p'`
1280     if expr "$dest" : '[^/].*' > /dev/null; then    
1281       target=${LIB}/`echo file | sed "s|[^/]*\$|$dest|"`
1282       if [ -f $target ]; then
1283         ln -s $dest ${LIB}/$file >/dev/null 2>&1
1284       fi
1285     fi
1286   done
1287 fi
1288
1289 cd ${ORIG_DIR}
1290
1291 echo 'Replacing <sys/byteorder.h>'
1292 rm -f ${LIB}/sys/byteorder.h
1293 cp ${SRCDIR}/byteorder.h ${LIB}/sys/byteorder.h
1294
1295 exit 0
1296