source: trunk/third/gcc/fixinc.svr4 @ 11288

Revision 11288, 43.0 KB checked in by ghudson, 26 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r11287, which included commits to RCS files with non-trunk default branches.
  • Property svn:executable set to *
Line 
1#! /bin/sh
2# Install modified versions of certain ANSI-incompatible
3# native System V Release 4 system include files.
4# Copyright (C) 1994, 1996, 1997 Free Software Foundation, Inc.
5# Contributed by Ron Guilmette (rfg@monkeys.com).
6#
7# This file is part of GNU CC.
8#
9# GNU CC is free software; you can redistribute it and/or modify
10# it under the terms of the GNU General Public License as published by
11# the Free Software Foundation; either version 2, or (at your option)
12# any later version.
13#
14# GNU CC is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17# GNU General Public License for more details.
18#
19# You should have received a copy of the GNU General Public License
20# along with GNU CC; see the file COPYING.  If not, write to
21# the Free Software Foundation, 59 Temple Place - Suite 330,
22# Boston, MA 02111-1307, 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 containing the original header files.
35INPUT=${2-${INPUT-/usr/include}}
36
37# Fail if no arg to specify a directory for the output.
38if [ x$1 = x ]
39then echo fixincludes: no output directory specified
40exit 1
41fi
42
43# Directory in which to store the results.
44LIB=${1?"fixincludes: output directory not specified"}
45
46# Make sure it exists.
47if [ ! -d $LIB ]; then
48  mkdir $LIB || exit 1
49fi
50
51ORIG_DIR=`pwd`
52
53# Make LIB absolute if it is relative.
54# Don't do this if not necessary, since may screw up automounters.
55case $LIB in
56/*)
57        ;;
58*)
59        LIB=$ORIG_DIR/$LIB
60        ;;
61esac
62
63echo 'Building fixincludes in ' ${LIB}
64
65# Determine whether this filesystem has symbolic links.
66if ln -s X $LIB/ShouldNotExist 2>/dev/null; then
67  rm -f $LIB/ShouldNotExist
68  LINKS=true
69else
70  LINKS=false
71fi
72
73echo 'Making directories:'
74cd ${INPUT}
75if $LINKS; then
76  files=`find . -follow -type d -print 2>/dev/null | sed '/^.$/d'`
77else
78  files=`find . -type d -print | sed '/^.$/d'`
79fi
80for file in $files; do
81  rm -rf $LIB/$file
82  if [ ! -d $LIB/$file ]
83  then mkdir $LIB/$file
84  fi
85done
86
87# treetops gets an alternating list
88# of old directories to copy
89# and the new directories to copy to.
90treetops="${INPUT} ${LIB}"
91
92if $LINKS; then
93  echo 'Making internal symbolic directory links'
94  for file in $files; do
95    dest=`ls -ld $file | sed -n 's/.*-> //p'`
96    if [ "$dest" ]; then   
97      cwd=`pwd`
98      # In case $dest is relative, get to $file's dir first.
99      cd ${INPUT}
100      cd `echo ./$file | sed -n 's&[^/]*$&&p'`
101      rwd=`pwd`
102      # Check that the target directory exists.
103      # Redirections changed to avoid bug in sh on Ultrix.
104      (cd $dest) > /dev/null 2>&1
105      if [ $? = 0 ]; then
106        cd $dest
107        # X gets the dir that the link actually leads to.
108        x=`pwd`
109        # If link leads back into ${INPUT},
110        # make a similar link here.
111        if expr "$dest" : '[^/][^/]*' >/dev/null && [ ! -h $dest ]; then
112          echo $file '->'  $dest': Making link'
113          rm -fr ${LIB}/$file > /dev/null 2>&1
114          ln -s $dest ${LIB}/$file > /dev/null 2>&1
115        elif 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          # DOTS is the relative path from ${LIB}/$file's dir back to ${LIB}.
119          dots=`echo "$file" |
120            sed -e 's@^./@@' -e 's@/./@/@g' -e 's@[^/][^/]*@..@g' -e 's@..$@@'`
121          echo $file '->' $dots$y ': Making link'
122          rm -fr ${LIB}/$file > /dev/null 2>&1
123          ln -s $dots$y ${LIB}/$file > /dev/null 2>&1
124        elif expr $x : "${rwd}/.*" > /dev/null; then
125          # Y gets the actual target dir name, relative to the directory where the link is.
126          y=`echo $x | sed -n "s&${rwd}/&&p"`
127          # DOTS is the relative path from ${LIB}/$file's dir back to ${LIB}.
128          dots=`echo "$file" |
129            sed -e 's@^./@@' -e 's@/./@/@g' -e 's@[^/][^/]*@..@g' -e 's@..$@@'`
130          echo $file '->' $dots$y ': Making link'
131          rm -fr ${LIB}/$file > /dev/null 2>&1
132          ln -s $dots$y ${LIB}/$file > /dev/null 2>&1
133        else
134          # If the link is to outside ${INPUT},
135          # treat this directory as if it actually contained the files.
136# This line used to have $dest instead of $x.
137# $dest seemed to be wrong for links found in subdirectories
138# of ${INPUT}.  Does this change break anything?
139          treetops="$treetops $x ${LIB}/$file"
140        fi
141      fi
142      cd $cwd
143    fi
144  done
145fi
146
147set - $treetops
148while [ $# != 0 ]; do
149  # $1 is an old directory to copy, and $2 is the new directory to copy to.
150  echo "Finding header files in $1:"
151  cd ${INPUT}
152  cd $1
153  files=`find . -name '*.h' -type f -print`
154  echo 'Checking header files:'
155  for file in $files; do
156      if [ -r $file ]; then
157        cp $file $2/$file >/dev/null 2>&1 || echo "Can't copy $file"
158        chmod +w $2/$file
159        chmod a+r $2/$file
160
161# The following have been removed from the sed command below
162# because it is more useful to leave these things in.
163# The only reason to remove them was for -pedantic,
164# which isn't much of a reason. -- rms.
165#         /^[   ]*#[    ]*ident/d
166
167# This code makes Solaris SCSI fail, because it changes the
168# alignment within some critical structures.  See <sys/scsi/impl/commands.h>.
169#         s/u_char\([   ][      ]*[a-zA-Z0-9_][a-zA-Z0-9_]*[    ]*:[    ]*[0-9][0-9]*\)/u_int\1/
170# Disable these also, since they probably aren't safe either.
171#         s/u_short\([  ][      ]*[a-zA-Z0-9_][a-zA-Z0-9_]*[    ]*:[    ]*[0-9][0-9]*\)/u_int\1/
172#         s/ushort\([   ][      ]*[a-zA-Z0-9_][a-zA-Z0-9_]*[    ]*:[    ]*[0-9][0-9]*\)/u_int\1/
173#         s/evcm_t\([   ][      ]*[a-zA-Z0-9_][a-zA-Z0-9_]*[    ]*:[    ]*[0-9][0-9]*\)/u_int\1/
174#         s/Pbyte\([    ][      ]*[a-zA-Z0-9_][a-zA-Z0-9_]*[    ]*:[    ]*SEQSIZ\)/unsigned int\1/
175
176# The change of u_char, etc, to u_int
177# applies to bit fields.
178        sed -e '
179          s%^\([        ]*#[    ]*else\)[       ]*/[^*].*%\1%
180          s%^\([        ]*#[    ]*else\)[       ]*[^/   ].*%\1%
181          s%^\([        ]*#[    ]*endif\)[      ]*/[^*].*%\1%
182          s%^\([        ]*#[    ]*endif\)[      ]*[^/   ].*%\1%
183          s/#lint(on)/defined(lint)/g
184          s/#lint(off)/!defined(lint)/g
185          s/#machine(\([^)]*\))/defined(__\1__)/g
186          s/#system(\([^)]*\))/defined(__\1__)/g
187          s/#cpu(\([^)]*\))/defined(__\1__)/g
188          /#[a-z]*if.*[  (]m68k/                s/\([^_]\)m68k/\1__m68k__/g
189          /#[a-z]*if.*[  (]__i386\([^_]\)/      s/__i386/__i386__/g
190          /#[a-z]*if.*[  (]i386/                s/\([^_]\)i386/\1__i386__/g
191          /#[a-z]*if.*[  (!]__i860\([^_]\)/     s/__i860/__i860__/g
192          /#[a-z]*if.*[  (!]i860/               s/\([^_]\)i860/\1__i860__/g
193          /#[a-z]*if.*[  (]sparc/       s/\([^_]\)sparc/\1__sparc__/g
194          /#[a-z]*if.*[  (]mc68000/     s/\([^_]\)mc68000/\1__mc68000__/g
195          /#[a-z]*if.*[  (]vax/         s/\([^_]\)vax/\1__vax__/g
196          /#[a-z]*if.*[  (]sun/         s/\([^_]\)\(sun[a-z0-9]*\)\([^a-z0-9_]\)/\1__\2__\3/g
197          /#[a-z]*if.*[  (]sun/         s/\([^_]\)\(sun[a-z0-9]*\)$/\1__\2__/g
198          /#[a-z]*if.*[  (]ns32000/     s/\([^_]\)ns32000/\1__ns32000__/g
199          /#[a-z]*if.*[  (]pyr/         s/\([^_]\)pyr/\1__pyr__/g
200          /#[a-z]*if.*[  (]is68k/       s/\([^_]\)is68k/\1__is68k__/g
201          s/__STDC__[   ][      ]*==[   ][      ]*0/!defined (__STRICT_ANSI__)/g
202          s/__STDC__[   ][      ]*==[   ][      ]*1/defined (__STRICT_ANSI__)/g
203          s/__STDC__[   ][      ]*!=[   ][      ]*0/defined (__STRICT_ANSI__)/g
204          s/__STDC__[   ][      ]*!=[   ][      ]*1/!defined (__STRICT_ANSI__)/g
205          s/__STDC__ - 0 == 0/!defined (__STRICT_ANSI__)/g
206          s/__STDC__ - 0 == 1/defined (__STRICT_ANSI__)/g
207          /^typedef[    ][      ]*[unsigned     ]*long[         ][      ]*[u_]*longlong_t;/s/long/long long/
208        ' $2/$file > $2/$file.sed
209        mv $2/$file.sed $2/$file
210        if cmp $file $2/$file >/dev/null 2>&1; then
211           rm $2/$file
212        else
213           echo Fixed $file
214        fi
215      fi
216  done
217  shift; shift
218done
219
220# Install the proper definition of the three standard types in header files
221# that they come from.
222for file in sys/types.h stdlib.h sys/stdtypes.h stddef.h memory.h unistd.h; do
223  if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
224    cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
225    chmod +w ${LIB}/$file 2>/dev/null
226    chmod a+r ${LIB}/$file 2>/dev/null
227  fi
228
229  if [ -r ${LIB}/$file ]; then
230    echo Fixing size_t, ptrdiff_t and wchar_t in $file
231    sed \
232      -e '/typedef[     ][      ]*[a-z_][       a-z_]*[         ]size_t/i\
233#ifndef __SIZE_TYPE__\
234#define __SIZE_TYPE__ long unsigned int\
235#endif
236' \
237      -e 's/typedef[    ][      ]*[a-z_][       a-z_]*[         ]size_t/typedef __SIZE_TYPE__ size_t/' \
238      -e '/typedef[     ][      ]*[a-z_][       a-z_]*[         ]ptrdiff_t/i\
239#ifndef __PTRDIFF_TYPE__\
240#define __PTRDIFF_TYPE__ long int\
241#endif
242' \
243      -e 's/typedef[    ][      ]*[a-z_][       a-z_]*[         ]ptrdiff_t/typedef __PTRDIFF_TYPE__ ptrdiff_t/' \
244      -e '/typedef[     ][      ]*[a-z_][       a-z_]*[         ]wchar_t/i\
245#ifndef __WCHAR_TYPE__\
246#define __WCHAR_TYPE__ int\
247#endif
248' \
249      -e 's/typedef[    ][      ]*[a-z_][       a-z_]*[         ]wchar_t/typedef __WCHAR_TYPE__ wchar_t/' \
250      ${LIB}/$file > ${LIB}/${file}.sed
251    rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
252    if cmp $file ${LIB}/$file >/dev/null 2>&1; then
253      rm ${LIB}/$file
254    fi
255  fi
256done
257
258# Fix first broken decl of getcwd present on some svr4 systems.
259
260file=stdlib.h
261base=`basename $file`
262if [ -r ${LIB}/$file ]; then
263  file_to_fix=${LIB}/$file
264else
265  if [ -r ${INPUT}/$file ]; then
266    file_to_fix=${INPUT}/$file
267  else
268    file_to_fix=""
269  fi
270fi
271if [ \! -z "$file_to_fix" ]; then
272  echo Checking $file_to_fix
273  sed -e 's/getcwd(char \*, int)/getcwd(char *, size_t)/' $file_to_fix > /tmp/$base
274  if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
275    true
276  else
277    echo Fixed $file_to_fix
278    rm -f ${LIB}/$file
279    cp /tmp/$base ${LIB}/$file
280    chmod a+r ${LIB}/$file
281  fi
282  rm -f /tmp/$base
283fi
284
285# Fix second broken decl of getcwd present on some svr4 systems.  Also
286# fix the incorrect decl of profil present on some svr4 systems.
287
288file=unistd.h
289base=`basename $file`
290if [ -r ${LIB}/$file ]; then
291  file_to_fix=${LIB}/$file
292else
293  if [ -r ${INPUT}/$file ]; then
294    file_to_fix=${INPUT}/$file
295  else
296    file_to_fix=""
297  fi
298fi
299if [ \! -z "$file_to_fix" ]; then
300  echo Checking $file_to_fix
301  sed -e 's/getcwd(char \*, int)/getcwd(char *, size_t)/' $file_to_fix \
302    | sed -e 's/profil(unsigned short \*, unsigned int, unsigned int, unsigned int)/profil(unsigned short *, size_t, int, unsigned)/' > /tmp/$base
303  if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
304    true
305  else
306    echo Fixed $file_to_fix
307    rm -f ${LIB}/$file
308    cp /tmp/$base ${LIB}/$file
309    chmod a+r ${LIB}/$file
310  fi
311  rm -f /tmp/$base
312fi
313
314# Fix the definition of NULL in <sys/param.h> so that it is conditional
315# and so that it is correct for both C and C++.
316
317file=sys/param.h
318base=`basename $file`
319if [ -r ${LIB}/$file ]; then
320  file_to_fix=${LIB}/$file
321else
322  if [ -r ${INPUT}/$file ]; then
323    file_to_fix=${INPUT}/$file
324  else
325    file_to_fix=""
326  fi
327fi
328if [ \! -z "$file_to_fix" ]; then
329  echo Checking $file_to_fix
330  cp $file_to_fix /tmp/$base
331  chmod +w /tmp/$base
332  chmod a+r /tmp/$base
333  sed -e '/^#define[    ]*NULL[         ]*0$/c\
334#ifndef NULL\
335#ifdef __cplusplus\
336#define __NULL_TYPE\
337#else /* !defined(__cplusplus) */\
338#define __NULL_TYPE (void *)\
339#endif /* !defined(__cplusplus) */\
340#define NULL (__NULL_TYPE 0)\
341#endif /* !defined(NULL) */' /tmp/$base > /tmp/$base.sed
342  if cmp $file_to_fix /tmp/$base.sed >/dev/null 2>&1; then \
343    true
344  else
345    echo Fixed $file_to_fix
346    rm -f ${LIB}/$file
347    cp /tmp/$base.sed ${LIB}/$file
348    chmod a+r ${LIB}/$file
349  fi
350  rm -f /tmp/$base /tmp/$base.sed
351fi
352
353# Likewise fix the definition of NULL in <stdio.h> so that it is conditional
354# and so that it is correct for both C and C++.
355
356file=stdio.h
357base=`basename $file`
358if [ -r ${LIB}/$file ]; then
359  file_to_fix=${LIB}/$file
360else
361  if [ -r ${INPUT}/$file ]; then
362    file_to_fix=${INPUT}/$file
363  else
364    file_to_fix=""
365  fi
366fi
367if [ \! -z "$file_to_fix" ]; then
368  echo Checking $file_to_fix
369  cp $file_to_fix /tmp/$base
370  chmod +w /tmp/$base
371  sed -e '/^#define[    ]*NULL[         ]*0$/c\
372#ifdef __cplusplus\
373#define __NULL_TYPE\
374#else /* !defined(__cplusplus) */\
375#define __NULL_TYPE (void *)\
376#endif /* !defined(__cplusplus) */\
377#define NULL (__NULL_TYPE 0)' /tmp/$base > /tmp/$base.sed
378  if cmp $file_to_fix /tmp/$base.sed >/dev/null 2>&1; then \
379    true
380  else
381    echo Fixed $file_to_fix
382    rm -f ${LIB}/$file
383    cp /tmp/$base.sed ${LIB}/$file
384    chmod a+r ${LIB}/$file
385  fi
386  rm -f /tmp/$base /tmp/$base.sed
387fi
388
389# Likewise fix the definition of NULL in <dbm.h> so that it is conditional
390# and so that it is correct for both C and C++.
391
392file=dbm.h
393base=`basename $file`
394if [ -r ${LIB}/$file ]; then
395  file_to_fix=${LIB}/$file
396else
397  if [ -r ${INPUT}/$file ]; then
398    file_to_fix=${INPUT}/$file
399  else
400    file_to_fix=""
401  fi
402fi
403if [ \! -z "$file_to_fix" ]; then
404  echo Checking $file_to_fix
405  cp $file_to_fix /tmp/$base
406  chmod +w /tmp/$base
407  sed -e '/^#define[    ]*NULL[         ]*((char \*) 0)$/c\
408#ifndef NULL\
409#ifdef __cplusplus\
410#define __NULL_TYPE\
411#else /* !defined(__cplusplus) */\
412#define __NULL_TYPE (void *)\
413#endif /* !defined(__cplusplus) */\
414#define NULL (__NULL_TYPE 0)\
415#endif /* !defined(NULL) */' /tmp/$base > /tmp/$base.sed
416  if cmp $file_to_fix /tmp/$base.sed >/dev/null 2>&1; then \
417    true
418  else
419    echo Fixed $file_to_fix
420    rm -f ${LIB}/$file
421    cp /tmp/$base.sed ${LIB}/$file
422    chmod a+r ${LIB}/$file
423  fi
424  rm -f /tmp/$base /tmp/$base.sed
425fi
426
427# Add a prototyped declaration of mmap to <sys/mman.h>.
428
429file=sys/mman.h
430base=`basename $file`
431if [ -r ${LIB}/$file ]; then
432  file_to_fix=${LIB}/$file
433else
434  if [ -r ${INPUT}/$file ]; then
435    file_to_fix=${INPUT}/$file
436  else
437    file_to_fix=""
438  fi
439fi
440if [ \! -z "$file_to_fix" ]; then
441  echo Checking $file_to_fix
442  cp $file_to_fix /tmp/$base
443  chmod +w /tmp/$base
444  sed -e '/^extern caddr_t mmap();$/c\
445#ifdef __STDC__\
446extern caddr_t mmap (caddr_t, size_t, int, int, int, off_t);\
447#else /* !defined(__STDC__) */\
448extern caddr_t mmap ();\
449#endif /* !defined(__STDC__) */' /tmp/$base > /tmp/$base.sed
450  if cmp $file_to_fix /tmp/$base.sed >/dev/null 2>&1; then \
451    true
452  else
453    echo Fixed $file_to_fix
454    rm -f ${LIB}/$file
455    cp /tmp/$base.sed ${LIB}/$file
456    chmod a+r ${LIB}/$file
457  fi
458  rm -f /tmp/$base /tmp/$base.sed
459fi
460
461# Fix declarations of `ftw' and `nftw' in <ftw.h>.  On some/most SVR4 systems
462# the file <ftw.h> contains extern declarations of these functions followed
463# by explicitly `static' definitions of these functions... and that's not
464# allowed according to ANSI C.  (Note however that on Solaris, this header
465# file glitch has been pre-fixed by Sun.  In the Solaris version of <ftw.h>
466# there are no static definitions of any function so we don't need to do
467# any of this stuff when on Solaris.
468
469file=ftw.h
470base=`basename $file`
471if [ -r ${LIB}/$file ]; then
472  file_to_fix=${LIB}/$file
473else
474  if [ -r ${INPUT}/$file ]; then
475    file_to_fix=${INPUT}/$file
476  else
477    file_to_fix=""
478  fi
479fi
480if test -z "$file_to_fix" || grep 'define       ftw' $file_to_fix > /dev/null; then
481# Either we have no <ftw.h> file at all, or else we have the pre-fixed Solaris
482# one.  Either way, we don't have to do anything.
483  true
484else
485  echo Checking $file_to_fix
486  cp $file_to_fix /tmp/$base
487  chmod +w /tmp/$base
488  sed -e '/^extern int ftw(const/i\
489#if !defined(_STYPES)\
490static\
491#else\
492extern\
493#endif
494'\
495  -e 's/extern \(int ftw(const.*\)$/\1/' \
496  -e '/^extern int nftw/i\
497#if defined(_STYPES)\
498static\
499#else\
500extern\
501#endif
502'\
503  -e 's/extern \(int nftw.*\)$/\1/' \
504  -e '/^extern int ftw(),/c\
505#if !defined(_STYPES)\
506static\
507#else\
508extern\
509#endif\
510  int ftw();\
511#if defined(_STYPES)\
512static\
513#else\
514extern\
515#endif\
516  int nftw();' /tmp/$base > /tmp/$base.sed
517  if cmp $file_to_fix /tmp/$base.sed >/dev/null 2>&1; then \
518    true
519  else
520    echo Fixed $file_to_fix
521    rm -f ${LIB}/$file
522    cp /tmp/$base.sed ${LIB}/$file
523    chmod a+r ${LIB}/$file
524  fi
525  rm -f /tmp/$base /tmp/$base.sed
526fi
527
528# Avoid the definition of the bool type in the Solaris 2.x curses.h when using
529# g++, since it's now an official type in the C++ language.
530file=curses.h
531base=`basename $file`
532if [ -r ${LIB}/$file ]; then
533  file_to_fix=${LIB}/$file
534else
535  if [ -r ${INPUT}/$file ]; then
536    file_to_fix=${INPUT}/$file
537  else
538    file_to_fix=""
539  fi
540fi
541
542if [ \! -z "$file_to_fix" ]; then
543  echo Checking $file_to_fix
544  cp $file_to_fix /tmp/$base
545  chmod +w /tmp/$base
546  sed -e 's,^typedef[   ]char[  ]bool;$,#ifndef __cplusplus\
547typedef char bool;\
548#endif /* !defined __cplusplus */,' /tmp/$base > /tmp/$base.sed
549  if cmp $file_to_fix /tmp/$base.sed >/dev/null 2>&1; then \
550    true
551  else
552    echo Fixed $file_to_fix
553    rm -f ${LIB}/$file
554    cp /tmp/$base.sed ${LIB}/$file
555    chmod a+r ${LIB}/$file
556  fi
557  rm -f /tmp/$base /tmp/$base.sed
558fi
559
560# Add a `static' declaration of `getrnge' into <regexp.h>.
561
562# Don't do this if there is already a `static void getrnge' declaration
563# present, since this would cause a redeclaration error.  Solaris 2.x has
564# such a declaration.
565
566file=regexp.h
567base=`basename $file`
568if [ -r ${LIB}/$file ]; then
569  file_to_fix=${LIB}/$file
570else
571  if [ -r ${INPUT}/$file ]; then
572    file_to_fix=${INPUT}/$file
573  else
574    file_to_fix=""
575  fi
576fi
577if [ \! -z "$file_to_fix" ]; then
578  echo Checking $file_to_fix
579  if grep "static void getrnge" $file_to_fix > /dev/null; then
580    true
581  else
582    cp $file_to_fix /tmp/$base
583    chmod +w /tmp/$base
584    sed -e '/^static int[       ]*size;/c\
585static int      size ;\
586\
587static int getrnge ();' /tmp/$base > /tmp/$base.sed
588    if cmp $file_to_fix /tmp/$base.sed >/dev/null 2>&1; then \
589      true
590    else
591      echo Fixed $file_to_fix
592      rm -f ${LIB}/$file
593      cp /tmp/$base.sed ${LIB}/$file
594      chmod a+r ${LIB}/$file
595    fi
596  fi
597  rm -f /tmp/$base /tmp/$base.sed
598fi
599
600# Disable apparent native compiler optimization cruft in SVR4.2 <string.h>
601# that is visible to any ANSI compiler using this include.  Simply
602# delete the lines that #define some string functions to internal forms.
603
604file=string.h
605base=`basename $file`
606if [ -r ${LIB}/$file ]; then
607  file_to_fix=${LIB}/$file
608else
609  if [ -r ${INPUT}/$file ]; then
610    file_to_fix=${INPUT}/$file
611  else
612    file_to_fix=""
613  fi
614fi
615if [ \! -z "$file_to_fix" ]; then
616  echo Checking $file_to_fix
617  cp $file_to_fix /tmp/$base
618  chmod +w /tmp/$base
619  sed -e '/#define.*__std_hdr_/d' /tmp/$base > /tmp/$base.sed
620  if cmp $file_to_fix /tmp/$base.sed >/dev/null 2>&1; then \
621    true
622  else
623    echo Fixed $file_to_fix
624    rm -f ${LIB}/$file
625    cp /tmp/$base.sed ${LIB}/$file
626    chmod a+r ${LIB}/$file
627  fi
628  rm -f /tmp/$base /tmp/$base.sed
629fi
630
631# Delete any #defines of `__i386' which may be present in <ieeefp.h>.  They
632# tend to conflict with the compiler's own definition of this symbol.  (We
633# will use the compiler's definition.)
634# Likewise __sparc, for Solaris, and __i860, and a few others
635# (guessing it is necessary for all of them).
636
637file=ieeefp.h
638base=`basename $file`
639if [ -r ${LIB}/$file ]; then
640  file_to_fix=${LIB}/$file
641else
642  if [ -r ${INPUT}/$file ]; then
643    file_to_fix=${INPUT}/$file
644  else
645    file_to_fix=""
646  fi
647fi
648if [ \! -z "$file_to_fix" ]; then
649  echo Checking $file_to_fix
650  cp $file_to_fix /tmp/$base
651  chmod +w /tmp/$base
652  sed -e '/#define[     ]*__i386 /d' -e '/#define[      ]*__sparc /d' \
653      -e '/#define[     ]*__i860 /d' -e '/#define[      ]*__m88k /d' \
654      -e '/#define[     ]*__mips /d' -e '/#define[      ]*__m68k /d' \
655     /tmp/$base > /tmp/$base.sed
656  if cmp $file_to_fix /tmp/$base.sed >/dev/null 2>&1; then \
657    true
658  else
659    echo Fixed $file_to_fix
660    rm -f ${LIB}/$file
661    cp /tmp/$base.sed ${LIB}/$file
662    chmod a+r ${LIB}/$file
663  fi
664  rm -f /tmp/$base /tmp/$base.sed
665fi
666
667# Add a #define of _SIGACTION_ into <sys/signal.h>.
668# Also fix types of SIG_DFL, SIG_ERR, SIG_IGN, and SIG_HOLD.
669
670file=sys/signal.h
671base=`basename $file`
672if [ -r ${LIB}/$file ]; then
673  file_to_fix=${LIB}/$file
674else
675  if [ -r ${INPUT}/$file ]; then
676    file_to_fix=${INPUT}/$file
677  else
678    file_to_fix=""
679  fi
680fi
681if [ \! -z "$file_to_fix" ]; then
682  echo Checking $file_to_fix
683  cp $file_to_fix /tmp/$base
684  chmod +w /tmp/$base
685  sed -e '/^struct sigaction {/c\
686#define _SIGACTION_\
687struct  sigaction  {' \
688  -e '1,$s/(void *(\*)())/(void (*)(int))/' /tmp/$base > /tmp/$base.sed
689  if cmp $file_to_fix /tmp/$base.sed >/dev/null 2>&1; then \
690    true
691  else
692    echo Fixed $file_to_fix
693    rm -f ${LIB}/$file
694    cp /tmp/$base.sed ${LIB}/$file
695    chmod a+r ${LIB}/$file
696  fi
697  rm -f /tmp/$base /tmp/$base.sed
698fi
699
700# Fix declarations of `makedev', `major', and `minor' in <sys/mkdev.h>.
701
702file=sys/mkdev.h
703base=`basename $file`
704if [ -r ${LIB}/$file ]; then
705  file_to_fix=${LIB}/$file
706else
707  if [ -r ${INPUT}/$file ]; then
708    file_to_fix=${INPUT}/$file
709  else
710    file_to_fix=""
711  fi
712fi
713if [ \! -z "$file_to_fix" ]; then
714  echo Checking $file_to_fix
715  cp $file_to_fix /tmp/$base
716  chmod +w /tmp/$base
717  sed -e '/^dev_t makedev(const/c\
718static dev_t makedev(const major_t, const minor_t);' \
719  -e '/^dev_t makedev()/c\
720static dev_t makedev();' \
721  -e '/^major_t major(const/c\
722static major_t major(const dev_t);' \
723  -e '/^major_t major()/c\
724static major_t major();' \
725  -e '/^minor_t minor(const/c\
726static minor_t minor(const dev_t);' \
727  -e '/^minor_t minor()/c\
728static minor_t minor();' /tmp/$base > /tmp/$base.sed
729  if cmp $file_to_fix /tmp/$base.sed >/dev/null 2>&1; then \
730    true
731  else
732    echo Fixed $file_to_fix
733    rm -f ${LIB}/$file
734    cp /tmp/$base.sed ${LIB}/$file
735    chmod a+r ${LIB}/$file
736  fi
737  rm -f /tmp/$base /tmp/$base.sed
738fi
739
740# Fix reference to NMSZ in <sys/adv.h>.
741
742file=sys/adv.h
743base=`basename $file`
744if [ -r ${LIB}/$file ]; then
745  file_to_fix=${LIB}/$file
746else
747  if [ -r ${INPUT}/$file ]; then
748    file_to_fix=${INPUT}/$file
749  else
750    file_to_fix=""
751  fi
752fi
753if [ \! -z "$file_to_fix" ]; then
754  echo Checking $file_to_fix
755  sed 's/\[NMSZ\]/\[RFS_NMSZ\]/g' $file_to_fix > /tmp/$base
756  if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
757    true
758  else
759    echo Fixed $file_to_fix
760    rm -f ${LIB}/$file
761    cp /tmp/$base ${LIB}/$file
762    chmod a+r ${LIB}/$file
763  fi
764  rm -f /tmp/$base
765fi
766
767# Fix reference to NC_NPI_RAW in <sys/netcspace.h>.  Also fix types of
768# array initializers.
769
770file=sys/netcspace.h
771base=`basename $file`
772if [ -r ${LIB}/$file ]; then
773  file_to_fix=${LIB}/$file
774else
775  if [ -r ${INPUT}/$file ]; then
776    file_to_fix=${INPUT}/$file
777  else
778    file_to_fix=""
779  fi
780fi
781if [ \! -z "$file_to_fix" ]; then
782  echo Checking $file_to_fix
783  sed 's/NC_NPI_RAW/NC_TPI_RAW/g' $file_to_fix \
784    | sed 's/NC_/(unsigned long) NC_/' > /tmp/$base
785  if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
786    true
787  else
788    echo Fixed $file_to_fix
789    rm -f ${LIB}/$file
790    cp /tmp/$base ${LIB}/$file
791    chmod a+r ${LIB}/$file
792  fi
793  rm -f /tmp/$base
794fi
795
796# Conditionalize all of <fs/rfs/rf_cache.h> on _KERNEL being defined.
797
798file=fs/rfs/rf_cache.h
799base=`basename $file`
800if [ -r ${LIB}/$file ]; then
801  file_to_fix=${LIB}/$file
802else
803  if [ -r ${INPUT}/$file ]; then
804    file_to_fix=${INPUT}/$file
805  else
806    file_to_fix=""
807  fi
808fi
809if [ \! -z "$file_to_fix" ]; then
810  echo Checking $file_to_fix
811  if grep _KERNEL $file_to_fix > /dev/null; then
812    true
813  else
814    echo '#ifdef _KERNEL' > /tmp/$base
815    cat $file_to_fix >> /tmp/$base
816    echo '#endif /* defined(_KERNEL) */' >> /tmp/$base
817    echo Fixed $file_to_fix
818    rm -f ${LIB}/$file
819    cp /tmp/$base ${LIB}/$file
820    chmod a+r ${LIB}/$file
821    rm -f /tmp/$base
822  fi
823fi
824
825# Conditionalize all of <sys/erec.h> on _KERNEL being defined.
826
827file=sys/erec.h
828base=`basename $file`
829if [ -r ${LIB}/$file ]; then
830  file_to_fix=${LIB}/$file
831else
832  if [ -r ${INPUT}/$file ]; then
833    file_to_fix=${INPUT}/$file
834  else
835    file_to_fix=""
836  fi
837fi
838if [ \! -z "$file_to_fix" ]; then
839  echo Checking $file_to_fix
840  if grep _KERNEL $file_to_fix > /dev/null; then
841    true
842  else
843    echo '#ifdef _KERNEL' > /tmp/$base
844    cat $file_to_fix >> /tmp/$base
845    echo '#endif /* defined(_KERNEL) */' >> /tmp/$base
846    echo Fixed $file_to_fix
847    rm -f ${LIB}/$file
848    cp /tmp/$base ${LIB}/$file
849    chmod a+r ${LIB}/$file
850    rm -f /tmp/$base
851  fi
852fi
853
854# Conditionalize all of <sys/err.h> on _KERNEL being defined.
855
856file=sys/err.h
857base=`basename $file`
858if [ -r ${LIB}/$file ]; then
859  file_to_fix=${LIB}/$file
860else
861  if [ -r ${INPUT}/$file ]; then
862    file_to_fix=${INPUT}/$file
863  else
864    file_to_fix=""
865  fi
866fi
867if [ \! -z "$file_to_fix" ]; then
868  echo Checking $file_to_fix
869  if grep _KERNEL $file_to_fix > /dev/null; then
870    true
871  else
872    echo '#ifdef _KERNEL' > /tmp/$base
873    cat $file_to_fix >> /tmp/$base
874    echo '#endif /* defined(_KERNEL) */' >> /tmp/$base
875    echo Fixed $file_to_fix
876    rm -f ${LIB}/$file
877    cp /tmp/$base ${LIB}/$file
878    chmod a+r ${LIB}/$file
879    rm -f /tmp/$base
880  fi
881fi
882
883# Conditionalize all of <sys/char.h> on _KERNEL being defined.
884
885file=sys/char.h
886base=`basename $file`
887if [ -r ${LIB}/$file ]; then
888  file_to_fix=${LIB}/$file
889else
890  if [ -r ${INPUT}/$file ]; then
891    file_to_fix=${INPUT}/$file
892  else
893    file_to_fix=""
894  fi
895fi
896if [ \! -z "$file_to_fix" ]; then
897  echo Checking $file_to_fix
898  if grep _KERNEL $file_to_fix > /dev/null; then
899    true
900  else
901    echo '#ifdef _KERNEL' > /tmp/$base
902    cat $file_to_fix >> /tmp/$base
903    echo '#endif /* defined(_KERNEL) */' >> /tmp/$base
904    echo Fixed $file_to_fix
905    rm -f ${LIB}/$file
906    cp /tmp/$base ${LIB}/$file
907    chmod a+r ${LIB}/$file
908    rm -f /tmp/$base
909  fi
910fi
911
912# Conditionalize all of <sys/getpages.h> on _KERNEL being defined.
913
914file=sys/getpages.h
915base=`basename $file`
916if [ -r ${LIB}/$file ]; then
917  file_to_fix=${LIB}/$file
918else
919  if [ -r ${INPUT}/$file ]; then
920    file_to_fix=${INPUT}/$file
921  else
922    file_to_fix=""
923  fi
924fi
925if [ \! -z "$file_to_fix" ]; then
926  echo Checking $file_to_fix
927  if grep _KERNEL $file_to_fix > /dev/null; then
928    true
929  else
930    echo '#ifdef _KERNEL' > /tmp/$base
931    cat $file_to_fix >> /tmp/$base
932    echo '#endif /* defined(_KERNEL) */' >> /tmp/$base
933    echo Fixed $file_to_fix
934    rm -f ${LIB}/$file
935    cp /tmp/$base ${LIB}/$file
936    chmod a+r ${LIB}/$file
937    rm -f /tmp/$base
938  fi
939fi
940
941# Conditionalize all of <sys/map.h> on _KERNEL being defined.
942
943file=sys/map.h
944base=`basename $file`
945if [ -r ${LIB}/$file ]; then
946  file_to_fix=${LIB}/$file
947else
948  if [ -r ${INPUT}/$file ]; then
949    file_to_fix=${INPUT}/$file
950  else
951    file_to_fix=""
952  fi
953fi
954if [ \! -z "$file_to_fix" ]; then
955  echo Checking $file_to_fix
956  if grep _KERNEL $file_to_fix > /dev/null; then
957    true
958  else
959    echo '#ifdef _KERNEL' > /tmp/$base
960    cat $file_to_fix >> /tmp/$base
961    echo '#endif /* defined(_KERNEL) */' >> /tmp/$base
962    echo Fixed $file_to_fix
963    rm -f ${LIB}/$file
964    cp /tmp/$base ${LIB}/$file
965    chmod a+r ${LIB}/$file
966    rm -f /tmp/$base
967  fi
968fi
969
970# Conditionalize all of <sys/cmn_err.h> on _KERNEL being defined.
971
972file=sys/cmn_err.h
973base=`basename $file`
974if [ -r ${LIB}/$file ]; then
975  file_to_fix=${LIB}/$file
976else
977  if [ -r ${INPUT}/$file ]; then
978    file_to_fix=${INPUT}/$file
979  else
980    file_to_fix=""
981  fi
982fi
983if [ \! -z "$file_to_fix" ]; then
984  echo Checking $file_to_fix
985  if grep _KERNEL $file_to_fix > /dev/null; then
986    true
987  else
988    echo '#ifdef _KERNEL' > /tmp/$base
989    cat $file_to_fix >> /tmp/$base
990    echo '#endif /* defined(_KERNEL) */' >> /tmp/$base
991    echo Fixed $file_to_fix
992    rm -f ${LIB}/$file
993    cp /tmp/$base ${LIB}/$file
994    chmod a+r ${LIB}/$file
995    rm -f /tmp/$base
996  fi
997fi
998
999# Conditionalize all of <sys/kdebugger.h> on _KERNEL being defined.
1000
1001file=sys/kdebugger.h
1002base=`basename $file`
1003if [ -r ${LIB}/$file ]; then
1004  file_to_fix=${LIB}/$file
1005else
1006  if [ -r ${INPUT}/$file ]; then
1007    file_to_fix=${INPUT}/$file
1008  else
1009    file_to_fix=""
1010  fi
1011fi
1012if [ \! -z "$file_to_fix" ]; then
1013  echo Checking $file_to_fix
1014  if grep _KERNEL $file_to_fix > /dev/null; then
1015    true
1016  else
1017    echo '#ifdef _KERNEL' > /tmp/$base
1018    cat $file_to_fix >> /tmp/$base
1019    echo '#endif /* defined(_KERNEL) */' >> /tmp/$base
1020    echo Fixed $file_to_fix
1021    rm -f ${LIB}/$file
1022    cp /tmp/$base ${LIB}/$file
1023    chmod a+r ${LIB}/$file
1024    rm -f /tmp/$base
1025  fi
1026fi
1027
1028# Conditionalize some of <netinet/in.h> on _KERNEL being defined.
1029# This has been taken out because it breaks on some versions of
1030# DYNIX/ptx, and it does not seem to do much good on any system.
1031# file=netinet/in.h
1032# base=`basename $file`
1033# if [ -r ${LIB}/$file ]; then
1034#   file_to_fix=${LIB}/$file
1035# else
1036#   if [ -r ${INPUT}/$file ]; then
1037#     file_to_fix=${INPUT}/$file
1038#   else
1039#     file_to_fix=""
1040#   fi
1041# fi
1042# if [ \! -z "$file_to_fix" ]; then
1043#   echo Checking $file_to_fix
1044#   if grep _KERNEL $file_to_fix > /dev/null; then
1045#     true
1046#   else
1047#     sed -e '/#ifdef INKERNEL/i\
1048# #ifdef _KERNEL
1049# ' \
1050#     -e '/#endif[      ]*\/\* INKERNEL \*\//a\
1051# #endif /* _KERNEL */
1052# ' \
1053#     $file_to_fix > ${LIB}/${file}.sed
1054#     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1055#     echo Fixed $file_to_fix
1056#   fi
1057# fi
1058
1059# Conditionalize some of <sys/endian.h> on __GNUC__ and __GNUG__.
1060
1061file=sys/endian.h
1062base=`basename $file`
1063if [ -r ${LIB}/$file ]; then
1064  file_to_fix=${LIB}/$file
1065else
1066  if [ -r ${INPUT}/$file ]; then
1067    file_to_fix=${INPUT}/$file
1068  else
1069    file_to_fix=""
1070  fi
1071fi
1072if [ \! -z "$file_to_fix" ]; then
1073  echo Checking $file_to_fix
1074  if grep __GNUC__ $file_to_fix > /dev/null; then
1075    true
1076  else
1077    sed -e '/#  ifdef   __STDC__/i\
1078#   if !defined (__GNUC__) && !defined (__GNUG__)
1079' \
1080    -e '/#              include <sys\/byteorder.h>/s/           /   /'\
1081    -e '/#   include    <sys\/byteorder.h>/i\
1082#   endif /* !defined (__GNUC__) && !defined (__GNUG__) */
1083'\
1084    $file_to_fix > ${LIB}/${file}.sed
1085    rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1086    echo Fixed $file_to_fix
1087  fi
1088fi
1089
1090# Commented out because tmcconne@sedona.intel.com says we don't clearly need it
1091# and the text in types.h is not erroneous.
1092## In sys/types.h, don't name the enum for booleans.
1093#
1094#file=sys/types.h
1095#base=`basename $file`
1096#if [ -r ${LIB}/$file ]; then
1097#  file_to_fix=${LIB}/$file
1098#else
1099#  if [ -r ${INPUT}/$file ]; then
1100#    file_to_fix=${INPUT}/$file
1101#  else
1102#    file_to_fix=""
1103#  fi
1104#fi
1105#if [ \! -z "$file_to_fix" ]; then
1106#  echo Checking $file_to_fix
1107#  if grep "enum boolean" $file_to_fix > /dev/null; then
1108#    sed -e 's/enum boolean/enum/' ${LIB}/$file > ${LIB}/${file}.sed
1109#    rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1110#    echo Fixed $file_to_fix
1111#  else
1112#    true
1113#  fi
1114#fi
1115
1116# Remove useless extern keyword from struct forward declarations in
1117# <sys/stream.h> and <sys/strsubr.h>
1118
1119file=sys/stream.h
1120base=`basename $file`
1121if [ -r ${LIB}/$file ]; then
1122  file_to_fix=${LIB}/$file
1123else
1124  if [ -r ${INPUT}/$file ]; then
1125    file_to_fix=${INPUT}/$file
1126  else
1127    file_to_fix=""
1128  fi
1129fi
1130if [ \! -z "$file_to_fix" ]; then
1131  echo Checking $file_to_fix
1132  sed -e '
1133    s/extern struct stdata;/struct stdata;/g
1134    s/extern struct strevent;/struct strevent;/g
1135  ' $file_to_fix > /tmp/$base
1136  if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
1137    true
1138  else
1139    echo Fixed $file_to_fix
1140    rm -f ${LIB}/$file
1141    cp /tmp/$base ${LIB}/$file
1142    chmod a+r ${LIB}/$file
1143  fi
1144  rm -f /tmp/$base
1145fi
1146
1147file=sys/strsubr.h
1148base=`basename $file`
1149if [ -r ${LIB}/$file ]; then
1150  file_to_fix=${LIB}/$file
1151else
1152  if [ -r ${INPUT}/$file ]; then
1153    file_to_fix=${INPUT}/$file
1154  else
1155    file_to_fix=""
1156  fi
1157fi
1158if [ \! -z "$file_to_fix" ]; then
1159  echo Checking $file_to_fix
1160  sed -e '
1161    s/extern struct strbuf;/struct strbuf;/g
1162    s/extern struct uio;/struct uio;/g
1163    s/extern struct thread;/struct thread;/g
1164    s/extern struct proc;/struct proc;/g
1165  ' $file_to_fix > /tmp/$base
1166  if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
1167    true
1168  else
1169    echo Fixed $file_to_fix
1170    rm -f ${LIB}/$file
1171    cp /tmp/$base ${LIB}/$file
1172    chmod a+r ${LIB}/$file
1173  fi
1174  rm -f /tmp/$base
1175fi
1176
1177# Put storage class at start of decl, to avoid warning.
1178file=rpc/types.h
1179base=`basename $file`
1180if [ -r ${LIB}/$file ]; then
1181  file_to_fix=${LIB}/$file
1182else
1183  if [ -r ${INPUT}/$file ]; then
1184    file_to_fix=${INPUT}/$file
1185  else
1186    file_to_fix=""
1187  fi
1188fi
1189if [ \! -z "$file_to_fix" ]; then
1190  echo Checking $file_to_fix
1191  sed -e '
1192    s/const extern/extern const/g
1193  ' $file_to_fix > /tmp/$base
1194  if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
1195    true
1196  else
1197    echo Fixed $file_to_fix
1198    rm -f ${LIB}/$file
1199    cp /tmp/$base ${LIB}/$file
1200    chmod a+r ${LIB}/$file
1201  fi
1202  rm -f /tmp/$base
1203fi
1204
1205# Convert functions to prototype form, and fix arg names in <sys/stat.h>.
1206
1207file=sys/stat.h
1208base=`basename $file`
1209if [ -r ${LIB}/$file ]; then
1210  file_to_fix=${LIB}/$file
1211else
1212  if [ -r ${INPUT}/$file ]; then
1213    file_to_fix=${INPUT}/$file
1214  else
1215    file_to_fix=""
1216  fi
1217fi
1218if [ \! -z "$file_to_fix" ]; then
1219  echo Checking $file_to_fix
1220  cp $file_to_fix /tmp/$base
1221  chmod +w /tmp/$base
1222  sed -e '/^stat([      ]*[^c]/{
1223N
1224N
1225s/(.*)\n/( /
1226s/;\n/, /
1227s/;$/)/
1228}' \
1229  -e '/^lstat([         ]*[^c]/{
1230N
1231N
1232s/(.*)\n/( /
1233s/;\n/, /
1234s/;$/)/
1235}' \
1236  -e '/^fstat([         ]*[^i]/{
1237N
1238N
1239s/(.*)\n/( /
1240s/;\n/, /
1241s/;$/)/
1242}' \
1243  -e '/^mknod([         ]*[^c]/{
1244N
1245N
1246N
1247s/(.*)\n/( /
1248s/;\n/, /g
1249s/;$/)/
1250}' \
1251  -e '1,$s/\([^A-Za-z]\)path\([^A-Za-z]\)/\1__path\2/g' \
1252  -e '1,$s/\([^A-Za-z]\)buf\([^A-Za-z]\)/\1__buf\2/g' \
1253  -e '1,$s/\([^A-Za-z]\)fd\([^A-Za-z]\)/\1__fd\2/g' \
1254  -e '1,$s/ret\([^u]\)/__ret\1/g' \
1255  -e '1,$s/\([^_]\)mode\([^_]\)/\1__mode\2/g' \
1256  -e '1,$s/\([^_r]\)dev\([^_]\)/\1__dev\2/g' /tmp/$base > /tmp/$base.sed
1257  if cmp $file_to_fix /tmp/$base.sed >/dev/null 2>&1; then \
1258    true
1259  else
1260    echo Fixed $file_to_fix
1261    rm -f ${LIB}/$file
1262    cp /tmp/$base.sed ${LIB}/$file
1263    chmod a+r ${LIB}/$file
1264  fi
1265  rm -f /tmp/$base /tmp/$base.sed
1266fi
1267
1268# Sony NEWSOS 5.0 does not support the complete ANSI C standard.
1269
1270if [ -x /bin/sony ]; then
1271  if /bin/sony; then
1272
1273    # Change <stdio.h> to not define __filbuf, __flsbuf, and __iob
1274
1275    file=stdio.h
1276    base=`basename $file`
1277    if [ -r ${LIB}/$file ]; then
1278      file_to_fix=${LIB}/$file
1279    else
1280      if [ -r ${INPUT}/$file ]; then
1281        file_to_fix=${INPUT}/$file
1282      else
1283        file_to_fix=""
1284      fi
1285    fi
1286    if [ \! -z "$file_to_fix" ]; then
1287      echo Checking $file_to_fix
1288      cp $file_to_fix /tmp/$base
1289      chmod +w /tmp/$base
1290      sed -e '
1291        s/__filbuf/_filbuf/g
1292        s/__flsbuf/_flsbuf/g
1293        s/__iob/_iob/g
1294      ' /tmp/$base > /tmp/$base.sed
1295      mv /tmp/$base.sed /tmp/$base
1296      if cmp $file_to_fix /tmp/$base.sed >/dev/null 2>&1; then
1297        true
1298      else
1299        echo Fixed $file_to_fix
1300        rm -f ${LIB}/$file
1301        cp /tmp/$base ${LIB}/$file
1302        chmod a+r ${LIB}/$file
1303      fi
1304      rm -f /tmp/$base
1305    fi
1306
1307    # Change <ctype.h> to not define __ctype
1308
1309    file=ctype.h
1310    base=`basename $file`
1311    if [ -r ${LIB}/$file ]; then
1312      file_to_fix=${LIB}/$file
1313    else
1314      if [ -r ${INPUT}/$file ]; then
1315        file_to_fix=${INPUT}/$file
1316      else
1317        file_to_fix=""
1318      fi
1319    fi
1320    if [ \! -z "$file_to_fix" ]; then
1321      echo Checking $file_to_fix
1322      cp $file_to_fix /tmp/$base
1323      chmod +w /tmp/$base
1324      sed -e '
1325        s/__ctype/_ctype/g
1326      ' /tmp/$base > /tmp/$base.sed
1327      mv /tmp/$base.sed /tmp/$base
1328      if cmp $file_to_fix /tmp/$base.sed >/dev/null 2>&1; then
1329        true
1330      else
1331        echo Fixed $file_to_fix
1332        rm -f ${LIB}/$file
1333        cp /tmp/$base ${LIB}/$file
1334        chmod a+r ${LIB}/$file
1335      fi
1336      rm -f /tmp/$base
1337    fi
1338  fi
1339fi
1340
1341# In limits.h, put #ifndefs around things that are supposed to be defined
1342# in float.h to avoid redefinition errors if float.h is included first.
1343# Solaris 2.1 has this problem.
1344
1345file=limits.h
1346base=`basename $file`
1347if [ -r ${LIB}/$file ]; then
1348  file_to_fix=${LIB}/$file
1349else
1350  if [ -r ${INPUT}/$file ]; then
1351    file_to_fix=${INPUT}/$file
1352  else
1353    file_to_fix=""
1354  fi
1355fi
1356if [ \! -z "$file_to_fix" ]; then
1357  echo Checking $file_to_fix
1358  sed -e '/[    ]FLT_MIN[       ]/i\
1359#ifndef FLT_MIN
1360'\
1361      -e '/[    ]FLT_MIN[       ]/a\
1362#endif
1363'\
1364      -e '/[    ]FLT_MAX[       ]/i\
1365#ifndef FLT_MAX
1366'\
1367      -e '/[    ]FLT_MAX[       ]/a\
1368#endif
1369'\
1370      -e '/[    ]FLT_DIG[       ]/i\
1371#ifndef FLT_DIG
1372'\
1373      -e '/[    ]FLT_DIG[       ]/a\
1374#endif
1375'\
1376      -e '/[    ]DBL_MIN[       ]/i\
1377#ifndef DBL_MIN
1378'\
1379      -e '/[    ]DBL_MIN[       ]/a\
1380#endif
1381'\
1382      -e '/[    ]DBL_MAX[       ]/i\
1383#ifndef DBL_MAX
1384'\
1385      -e '/[    ]DBL_MAX[       ]/a\
1386#endif
1387'\
1388      -e '/[    ]DBL_DIG[       ]/i\
1389#ifndef DBL_DIG
1390'\
1391      -e '/[    ]DBL_DIG[       ]/a\
1392#endif
1393' $file_to_fix > /tmp/$base
1394  if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
1395    true
1396  else
1397    echo Fixed $file_to_fix
1398    rm -f ${LIB}/$file
1399    cp /tmp/$base ${LIB}/$file
1400    chmod a+r ${LIB}/$file
1401  fi
1402  rm -f /tmp/$base
1403fi
1404
1405# Completely replace <sys/varargs.h> with a file that includes gcc's
1406# stdarg.h or varargs.h files as appropriate.
1407
1408file=sys/varargs.h
1409if [ -r ${INPUT}/$file ]; then
1410  echo Replacing $file
1411  cat > ${LIB}/$file << EOF
1412/* This file was generated by fixincludes.  */
1413#ifndef _SYS_VARARGS_H
1414#define _SYS_VARARGS_H
1415
1416#ifdef __STDC__
1417#include <stdarg.h>
1418#else
1419#include <varargs.h>
1420#endif
1421
1422#endif  /* _SYS_VARARGS_H */
1423EOF
1424  chmod a+r ${LIB}/$file
1425fi
1426
1427# In math.h, put #ifndefs around things that might be defined in a gcc
1428# specific math-*.h file.
1429
1430file=math.h
1431base=`basename $file`
1432if [ -r ${LIB}/$file ]; then
1433  file_to_fix=${LIB}/$file
1434else
1435  if [ -r ${INPUT}/$file ]; then
1436    file_to_fix=${INPUT}/$file
1437  else
1438    file_to_fix=""
1439  fi
1440fi
1441if [ \! -z "$file_to_fix" ]; then
1442  echo Checking $file_to_fix
1443  sed -e '/define[      ]HUGE_VAL[      ]/i\
1444#ifndef HUGE_VAL
1445'\
1446      -e '/define[      ]HUGE_VAL[      ]/a\
1447#endif
1448' $file_to_fix > /tmp/$base
1449  if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
1450    true
1451  else
1452    echo Fixed $file_to_fix
1453    rm -f ${LIB}/$file
1454    cp /tmp/$base ${LIB}/$file
1455    chmod a+r ${LIB}/$file
1456  fi
1457  rm -f /tmp/$base
1458fi
1459
1460# Solaris math.h and floatingpoint.h define __P without protection,
1461# which conflicts with the fixproto definition.  The fixproto
1462# definition and the Solaris definition are used the same way.
1463for file in math.h floatingpoint.h; do
1464  base=`basename $file`
1465  if [ -r ${LIB}/$file ]; then
1466    file_to_fix=${LIB}/$file
1467  else
1468    if [ -r ${INPUT}/$file ]; then
1469      file_to_fix=${INPUT}/$file
1470    else
1471      file_to_fix=""
1472    fi
1473  fi
1474  if [ \! -z "$file_to_fix" ]; then
1475    echo Checking $file_to_fix
1476    sed -e '/^#define[  ]*__P/i\
1477#ifndef __P
1478'\
1479        -e '/^#define[  ]*__P/a\
1480#endif
1481' $file_to_fix > /tmp/$base
1482    if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
1483      true
1484    else
1485      echo Fixed $file_to_fix
1486      rm -f ${LIB}/$file
1487      cp /tmp/$base ${LIB}/$file
1488      chmod a+r ${LIB}/$file
1489    fi
1490   rm -f /tmp/$base
1491  fi
1492done
1493
1494# The Solaris math.h defines struct exception, which conflicts with
1495# the class exception defined in the C++ file std/stdexcept.h.  We
1496# redefine it to __math_exception.  This is not a great fix, but I
1497# haven't been able to think of anything better.
1498file=math.h
1499base=`basename $file`
1500if [ -r ${LIB}/$file ]; then
1501  file_to_fix=${LIB}/$file
1502else
1503  if [ -r ${INPUT}/$file ]; then
1504    file_to_fix=${INPUT}/$file
1505  else
1506    file_to_fix=""
1507  fi
1508fi
1509if [ \! -z "$file_to_fix" ]; then
1510  echo Checking $file_to_fix
1511  sed -e '/struct exception/i\
1512#ifdef __cplusplus\
1513#define exception __math_exception\
1514#endif'\
1515      -e '/struct exception/a\
1516#ifdef __cplusplus\
1517#undef exception\
1518#endif' $file_to_fix > /tmp/$base
1519  if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
1520    true
1521  else
1522    echo Fixed $file_to_fix
1523    rm -f ${LIB}/$file
1524    cp /tmp/$base ${LIB}/$file
1525    chmod a+r ${LIB}/$file
1526  fi
1527  rm -f /tmp/$base
1528fi
1529
1530echo 'Removing unneeded directories:'
1531cd $LIB
1532files=`find . -type d -print | sort -r`
1533for file in $files; do
1534  rmdir $LIB/$file > /dev/null 2>&1
1535done
1536
1537if $LINKS; then
1538  echo 'Making internal symbolic non-directory links'
1539  cd ${INPUT}
1540  files=`find . -type l -print`
1541  for file in $files; do
1542    dest=`ls -ld $file | sed -n 's/.*-> //p'`
1543    if expr "$dest" : '[^/].*' > /dev/null; then   
1544      target=${LIB}/`echo $file | sed "s|[^/]*\$|$dest|"`
1545      if [ -f $target ]; then
1546        ln -s $dest ${LIB}/$file >/dev/null 2>&1
1547      fi
1548    fi
1549  done
1550fi
1551
1552cd ${ORIG_DIR}
1553
1554echo 'Replacing <sys/byteorder.h>'
1555if [ \! -d $LIB/sys ]; then
1556  mkdir $LIB/sys
1557fi
1558rm -f ${LIB}/sys/byteorder.h
1559cat <<'__EOF__' >${LIB}/sys/byteorder.h
1560#ifndef _SYS_BYTEORDER_H
1561#define _SYS_BYTEORDER_H
1562
1563/* Functions to convert `short' and `long' quantities from host byte order
1564   to (internet) network byte order (i.e. big-endian).
1565
1566   Written by Ron Guilmette (rfg@ncd.com).
1567
1568   This isn't actually used by GCC.  It is installed by fixinc.svr4.
1569
1570   For big-endian machines these functions are essentially no-ops.
1571
1572   For little-endian machines, we define the functions using specialized
1573   asm sequences in cases where doing so yields better code (e.g. i386).  */
1574
1575#if !defined (__GNUC__) && !defined (__GNUG__)
1576#error You lose!  This file is only useful with GNU compilers.
1577#endif
1578
1579#ifndef __BYTE_ORDER__
1580/* Byte order defines.  These are as defined on UnixWare 1.1, but with
1581   double underscores added at the front and back.  */
1582#define __LITTLE_ENDIAN__   1234
1583#define __BIG_ENDIAN__      4321
1584#define __PDP_ENDIAN__      3412
1585#endif
1586
1587#ifdef __STDC__
1588static __inline__ unsigned long htonl (unsigned long);
1589static __inline__ unsigned short htons (unsigned int);
1590static __inline__ unsigned long ntohl (unsigned long);
1591static __inline__ unsigned short ntohs (unsigned int);
1592#endif /* defined (__STDC__) */
1593
1594#if defined (__i386__)
1595
1596#ifndef __BYTE_ORDER__
1597#define __BYTE_ORDER__ __LITTLE_ENDIAN__
1598#endif
1599
1600/* Convert a host long to a network long.  */
1601
1602/* We must use a new-style function definition, so that this will also
1603   be valid for C++.  */
1604static __inline__ unsigned long
1605htonl (unsigned long __arg)
1606{
1607  register unsigned long __result;
1608
1609  __asm__ ("xchg%B0 %b0,%h0\n\
1610        ror%L0 $16,%0\n\
1611        xchg%B0 %b0,%h0" : "=q" (__result) : "0" (__arg));
1612  return __result;
1613}
1614
1615/* Convert a host short to a network short.  */
1616
1617static __inline__ unsigned short
1618htons (unsigned int __arg)
1619{
1620  register unsigned short __result;
1621
1622  __asm__ ("xchg%B0 %b0,%h0" : "=q" (__result) : "0" (__arg));
1623  return __result;
1624}
1625
1626#elif ((defined (__i860__) && !defined (__i860_big_endian__))   \
1627       || defined (__ns32k__) || defined (__vax__)              \
1628       || defined (__spur__) || defined (__arm__))
1629
1630#ifndef __BYTE_ORDER__
1631#define __BYTE_ORDER__ __LITTLE_ENDIAN__
1632#endif
1633
1634/* For other little-endian machines, using C code is just as efficient as
1635   using assembly code.  */
1636
1637/* Convert a host long to a network long.  */
1638
1639static __inline__ unsigned long
1640htonl (unsigned long __arg)
1641{
1642  register unsigned long __result;
1643
1644  __result = (__arg >> 24) & 0x000000ff;
1645  __result |= (__arg >> 8) & 0x0000ff00;
1646  __result |= (__arg << 8) & 0x00ff0000;
1647  __result |= (__arg << 24) & 0xff000000;
1648  return __result;
1649}
1650
1651/* Convert a host short to a network short.  */
1652
1653static __inline__ unsigned short
1654htons (unsigned int __arg)
1655{
1656  register unsigned short __result;
1657
1658  __result = (__arg << 8) & 0xff00;
1659  __result |= (__arg >> 8) & 0x00ff;
1660  return __result;
1661}
1662
1663#else /* must be a big-endian machine */
1664
1665#ifndef __BYTE_ORDER__
1666#define __BYTE_ORDER__ __BIG_ENDIAN__
1667#endif
1668
1669/* Convert a host long to a network long.  */
1670
1671static __inline__ unsigned long
1672htonl (unsigned long __arg)
1673{
1674  return __arg;
1675}
1676
1677/* Convert a host short to a network short.  */
1678
1679static __inline__ unsigned short
1680htons (unsigned int __arg)
1681{
1682  return __arg;
1683}
1684
1685#endif /* big-endian */
1686
1687/* Convert a network long to a host long.  */
1688
1689static __inline__ unsigned long
1690ntohl (unsigned long __arg)
1691{
1692  return htonl (__arg);
1693}
1694
1695/* Convert a network short to a host short.  */
1696
1697static __inline__ unsigned short
1698ntohs (unsigned int __arg)
1699{
1700  return htons (__arg);
1701}
1702
1703__EOF__
1704
1705if [ -r ${INPUT}/sys/byteorder.h ]; then
1706  if grep BYTE_ORDER ${INPUT}/sys/byteorder.h >/dev/null 2>/dev/null; then
1707    cat <<'__EOF__' >>${LIB}/sys/byteorder.h
1708#ifndef BYTE_ORDER
1709#define LITTLE_ENDIAN __LITTLE_ENDIAN__
1710#define BIG_ENDIAN __BIG_ENDIAN__
1711#define PDP_ENDIAN __PDP_ENDIAN__
1712#define BYTE_ORDER __BYTE_ORDER__
1713#endif
1714
1715__EOF__
1716  fi
1717fi
1718
1719cat <<'__EOF__' >>${LIB}/sys/byteorder.h
1720#endif /* !defined (_SYS_BYTEORDER_H) */
1721__EOF__
1722
1723chmod a+r ${LIB}/sys/byteorder.h
1724
1725exit 0
1726
Note: See TracBrowser for help on using the repository browser.