OSDN Git Service

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