1#! /bin/sh
2# Install modified versions of certain ANSI-incompatible system header files
3# which are fixed to work correctly with ANSI C
4# and placed in a directory that GNU C will search.
5
6# See README-fixinc for more information.
7
8# Directory containing the original header files.
9# (This was named INCLUDES, but that conflicts with a name in Makefile.in.)
10if [ "x$1" = "x" ]
11then echo fixincludes: no output directory specified
12exit 1
13fi
14
15LIB=${1}
16shift
17
18# Make sure it exists.
19if [ ! -d $LIB ]; then
20  mkdir $LIB || {
21    echo fixincludes:  output dir '`'$LIB"' cannot be created"
22    exit 1
23  }
24else
25  ( \cd $LIB && touch DONE && rm DONE ) || {
26    echo fixincludes:  output dir '`'$LIB"' is an invalid directory"
27    exit 1
28  }
29fi
30
31# Define what target system we're fixing.
32#
33if test -r ./Makefile; then
34  target_canonical="`sed -n -e 's,^target[ 	]*=[ 	]*\(.*\)$,\1,p' < Makefile`"
35fi
36
37# If not from the Makefile, then try config.guess
38#
39if test -z "${target_canonical}" ; then
40  if test -x ./config.guess ; then
41    target_canonical="`config.guess`" ; fi
42  test -z "${target_canonical}" && target_canonical=unknown
43fi
44export target_canonical
45
46# # # # # # # # # # # # # # # # # # # # #
47#
48# Define PWDCMD as a command to use to get the working dir
49# in the form that we want.
50PWDCMD=pwd
51
52case "`$PWDCMD`" in
53//*)
54    # On an Apollo, discard everything before `/usr'.
55    PWDCMD="eval pwd | sed -e 's,.*/usr/,/usr/,'"
56    ;;
57esac
58
59# Original directory.
60ORIGDIR=`${PWDCMD}`
61
62# Make LIB absolute only if needed to avoid problems with the amd.
63case $LIB in
64/*)
65    ;;
66*)
67    cd $LIB; LIB=`${PWDCMD}`
68    ;;
69esac
70
71echo Fixing headers into ${LIB} for ${target_canonical} target
72
73# Determine whether this system has symbolic links.
74if ln -s X $LIB/ShouldNotExist 2>/dev/null; then
75  rm -f $LIB/ShouldNotExist
76  LINKS=true
77elif ln -s X /tmp/ShouldNotExist 2>/dev/null; then
78  rm -f /tmp/ShouldNotExist
79  LINKS=true
80else
81  LINKS=false
82fi
83
84# # # # # # # # # # # # # # # # # # # # #
85#
86#  Search each input directory for broken header files.
87#  This loop ends near the end of the file.
88#
89if test $# -eq 0
90then
91    INPUTLIST="/usr/include"
92else
93    INPUTLIST="$@"
94fi
95
96for INPUT in ${INPUTLIST} ; do
97
98cd ${ORIGDIR}
99
100cd ${INPUT} || continue
101INPUT=`${PWDCMD}`
102
103#
104# # # # # # # # # # # # # # # # # # # # #
105#
106echo Finding directories and links to directories
107
108# Find all directories and all symlinks that point to directories.
109# Put the list in $files.
110# Each time we find a symlink, add it to newdirs
111# so that we do another find within the dir the link points to.
112# Note that $files may have duplicates in it;
113# later parts of this file are supposed to ignore them.
114dirs="."
115levels=2
116while [ -n "$dirs" ] && [ $levels -gt 0 ]
117do
118    levels=`expr $levels - 1`
119    newdirs=
120    for d in $dirs
121    do
122	echo " Searching $INPUT/$d"
123
124	# Find all directories under $d, relative to $d, excluding $d itself.
125	# (The /. is needed after $d in case $d is a symlink.)
126        files="$files `find $d/. -type d -print | \
127		       sed -e '/\/\.$/d' -e 's@/./@/@g'`"
128	# Find all links to directories.
129	# Using `-exec test -d' in find fails on some systems,
130	# and trying to run test via sh fails on others,
131	# so this is the simplest alternative left.
132	# First find all the links, then test each one.
133	theselinks=
134	$LINKS && \
135	  theselinks=`find $d/. -type l -print | sed -e 's@/./@/@g'`
136	for d1 in $theselinks --dummy--
137	do
138	    # If the link points to a directory,
139	    # add that dir to $newdirs
140	    if [ -d $d1 ]
141	    then
142		files="$files $d1"
143		if [ "`ls -ld $d1 | sed -n 's/.*-> //p'`" != "." ]
144		then
145		    newdirs="$newdirs $d1"
146		fi
147	    fi
148	done
149    done
150
151    dirs="$newdirs"
152done
153
154dirs=
155echo "All directories (including links to directories):"
156echo $files
157
158for file in $files; do
159  rm -rf $LIB/$file
160  if [ ! -d $LIB/$file ]
161  then mkdir $LIB/$file
162  fi
163done
164mkdir $LIB/root
165
166# treetops gets an alternating list
167# of old directories to copy
168# and the new directories to copy to.
169treetops="${INPUT} ${LIB}"
170
171if $LINKS; then
172  echo 'Making symbolic directory links'
173  for file in $files; do
174    dest=`ls -ld $file | sed -n 's/.*-> //p'`
175    if [ "$dest" ]; then    
176      cwd=`${PWDCMD}`
177      # In case $dest is relative, get to $file's dir first.
178      cd ${INPUT}
179      cd `echo ./$file | sed -n 's&[^/]*$&&p'`
180      # Check that the target directory exists.
181      # Redirections changed to avoid bug in sh on Ultrix.
182      (cd $dest) > /dev/null 2>&1
183      if [ $? = 0 ]; then
184	cd $dest
185	# X gets the dir that the link actually leads to.
186	x=`${PWDCMD}`
187	# Canonicalize ${INPUT} now to minimize the time an
188	# automounter has to change the result of ${PWDCMD}.
189	cinput=`cd ${INPUT}; ${PWDCMD}`
190	# If a link points to ., make a similar link to .
191	if [ $x = ${cinput} ]; then
192	  echo $file '->' . ': Making link'
193	  rm -fr ${LIB}/$file > /dev/null 2>&1
194	  ln -s . ${LIB}/$file > /dev/null 2>&1
195	# If link leads back into ${INPUT},
196	# make a similar link here.
197	elif expr $x : "${cinput}/.*" > /dev/null; then
198	  # Y gets the actual target dir name, relative to ${INPUT}.
199	  y=`echo $x | sed -n "s&${cinput}/&&p"`
200	  # DOTS is the relative path from ${LIB}/$file's dir back to ${LIB}.
201	  dots=`echo "$file" |
202	    sed -e 's@^./@@' -e 's@/./@/@g' -e 's@[^/][^/]*@..@g' -e 's@..$@@'`
203	  echo $file '->' $dots$y ': Making link'
204	  rm -fr ${LIB}/$file > /dev/null 2>&1
205	  ln -s $dots$y ${LIB}/$file > /dev/null 2>&1
206	else
207	  # If the link is to a dir $target outside ${INPUT},
208	  # repoint the link at ${INPUT}/root$target
209	  # and process $target into ${INPUT}/root$target
210	  # treat this directory as if it actually contained the files.
211	  echo $file '->' root$x ': Making link'
212	  if [ -d $LIB/root$x ]
213	  then true
214	  else
215	    dirname=root$x/
216	    dirmade=.
217	    cd $LIB
218	    while [ x$dirname != x ]; do
219	      component=`echo $dirname | sed -e 's|/.*$||'`
220	      mkdir $component >/dev/null 2>&1
221	      cd $component
222	      dirmade=$dirmade/$component
223	      dirname=`echo $dirname | sed -e 's|[^/]*/||'`
224	    done
225	  fi
226	  # Duplicate directory structure created in ${LIB}/$file in new
227	  # root area.
228	  for file2 in $files; do
229	    case $file2 in
230	      $file/*)
231		dupdir=${LIB}/root$x/`echo $file2 | sed -n "s|^${file}/||p"`
232		echo "Duplicating ${file}'s ${dupdir}"
233		if [ -d ${dupdir} ]
234		then true
235		else
236		  mkdir ${dupdir}
237		fi
238		;;
239	      *)
240		;;
241	    esac
242          done
243	  # Get the path from ${LIB} to $file, accounting for symlinks.
244	  parent=`echo "$file" | sed -e 's@/[^/]*$@@'`
245	  libabs=`cd ${LIB}; ${PWDCMD}`
246	  file2=`cd ${LIB}; cd $parent; ${PWDCMD} | sed -e "s@^${libabs}@@"`
247	  # DOTS is the relative path from ${LIB}/$file's dir back to ${LIB}.
248	  dots=`echo "$file2" | sed -e 's@/[^/]*@../@g'`
249	  rm -fr ${LIB}/$file > /dev/null 2>&1
250	  ln -s ${dots}root$x ${LIB}/$file > /dev/null 2>&1
251	  treetops="$treetops $x ${LIB}/root$x"
252	fi
253      fi
254      cd $cwd
255    fi
256  done
257fi
258
259required=
260set x $treetops
261shift
262while [ $# != 0 ]; do
263  # $1 is an old directory to copy, and $2 is the new directory to copy to.
264  cd ${INPUT}
265  cd $1
266# The same dir can appear more than once in treetops.
267# There's no need to scan it more than once.
268  if [ -f $2/DONE ]
269  then
270    files=
271  else
272    touch $2/DONE
273    echo Fixing directory $1 into $2
274# Check .h files which are symlinks as well as those which are files.
275# A link to a header file will not be processed by anything but this.
276    if $LINKS; then
277      files=`find . -name '*.h' \( -type f -o -type l \) -print`
278    else
279      files=`find . -name '*.h' -type f -print`
280    fi
281    echo Checking header files
282  fi
283# Note that BSD43_* are used on recent MIPS systems.
284  for file in $files; do
285# This call to egrep is essential, since checking a file with egrep
286# is much faster than actually trying to fix it.
287# It is also essential that most files *not* match!
288# Thus, matching every #endif is unacceptable.
289# But the argument to egrep must be kept small, or many versions of egrep
290# won't be able to handle it.
291#
292# We use the pattern [!-.0-z{|}~] instead of [^/ 	] to match a noncomment
293# following #else or #endif because some buggy egreps think [^/] matches
294# newline, and they thus think `#else ' matches `#e[ndiflse]*[ 	]+[^/ 	]'.
295# [!-.0-~] does not work properly on AIX 4.1.
296#
297# We use the pattern [^a-zA-Z0-9_][_a-ce-km-z][a-z0-9] to match an identifier
298# following #if or #elif that is not surrounded by __.  The `a-ce-km-z'
299# in this pattern lacks `d' and `l'; this means we don't worry about
300# identifiers starting with `d' or `l'.  This is OK, since none of the
301# identifiers below start with `d' or `l'.  It also greatly improves
302# performance, since many files contain lines of the form `#if ... defined ...'
303# or `#if lint'.
304    if egrep '//|[ 	_]_IO|CTRL|^#define.NULL|^#e[nl][ds][ief]*[ 	]+[!-.0-z\{\|\}\~]|^#[el]*if.*[^a-zA-Z0-9_][_a-ce-km-zA-Z][a-zA-Z0-9]' $file >/dev/null; then
305      if [ -r $file ]; then
306	cp $file $2/$file >/dev/null 2>&1	\
307	|| echo "Can't copy $file"
308	chmod +w $2/$file
309	chmod a+r $2/$file
310	# The fixinc_eol stuff is to work around a bug in the sed
311	# program on HP/UX 10.20.
312	# Here is how the sed commands in braces work.
313	# (It doesn't work to put the comments inside the sed commands.)
314		# Surround each word with spaces, to simplify matching below.
315		# ANSIfy each pre-ANSI machine-dependent symbol
316		# by surrounding it with __ __.
317		# Remove the spaces that we inserted around each word.
318	sed -e '
319				   :loop
320	  /\\$/			N
321 	  s/\\$/\\*fixinc_eol*/
322	  /\\$/			b loop
323	  s/\\\*fixinc_eol\*/\\/g
324	  s%^\([ 	]*#[ 	]*else\)[ 	]*/[^*].*%\1%
325	  s%^\([ 	]*#[ 	]*else\)[ 	]*[^/ 	].*%\1%
326	  s%^\([ 	]*#[ 	]*endif\)[ 	]*/[^*].*%\1%
327	  s%^\([ 	]*#[ 	]*endif\)[ 	]*\*[^/].*%\1%
328	  s%^\([ 	]*#[ 	]*endif\)[ 	]*[^/* 	].*%\1%
329	  /\/\/[^*]/			s|//\(.*\)$|/*\1*/|
330	  /^[ 	]*\/\/[ 	]*/s///
331	  /[ 	]_IO[A-Z]*[ 	]*(/	s/\(_IO[A-Z]*[ 	]*(\)\(.\),/\1'\''\2'\'',/
332	  /[ 	]BSD43__IO[A-Z]*[ 	]*(/	s/(\(.\),/('\''\1'\'',/
333	  /#[ 	]*define[ 	]*[ 	]_IO/			s/'\''\([cgxtf]\)'\''/\1/g
334	  /#[ 	]*define[ 	]*[ 	]BSD43__IO/		s/'\''\([cgx]\)'\''/\1/g
335	  /#[ 	]*define[ 	]*[ 	]DESIOC/		s/'\''\([cdgx]\)'\''/\1/g
336	  /[^A-Z0-9_]CTRL[ 	]*(/		s/\([^'\'']\))/'\''\1'\'')/
337	  /[^A-Z0-9]_CTRL[ 	]*(/		s/\([^'\'']\))/'\''\1'\'')/
338	  /#[ 	]*define[ 	]*[ 	]CTRL/		s/'\''\([cgx]\)'\''/\1/g
339	  /#[ 	]*define[ 	]*[ 	]_CTRL/		s/'\''\([cgx]\)'\''/\1/g
340	  /#[ 	]*define.BSD43_CTRL/		s/'\''\([cgx]\)'\''/\1/g
341	  /#[ 	]*define[ 	]*[ 	][_]*ISCTRL/		s/'\''\([cgx]\)'\''/\1/g
342	  /#[	 ]*[el]*if/{
343		s/[a-zA-Z0-9_][a-zA-Z0-9_]*/ & /g
344
345		s/ bsd4\([0-9]\) / __bsd4\1__ /g
346		s/ _*host_mips / __host_mips__ /g
347		s/ _*i386 / __i386__ /g
348		s/ M32 / __M32__ /g
349		s/ is68k / __is68k__ /g
350		s/ m68k / __m68k__ /g
351		s/ mc680\([0-9]\)0 / __mc680\10__ /g
352		s/ m88k / __m88k__ /g
353		s/ _*mips / __mips__ /g
354		s/ news\([0-9]*\) / __news\1__ /g
355		s/ ns32000 / __ns32000__ /g
356		s/ pdp11 / __pdp11__ /g
357		s/ pyr / __pyr__ /g
358		s/ sel / __sel__ /g
359		s/ sony_news / __sony_news__ /g
360		s/ sparc / __sparc__ /g
361		s/ sun\([a-z0-9]*\) / __sun\1__ /g
362		s/ tahoe / __tahoe__ /g
363		s/ tower\([_0-9]*\) / __tower\1__ /g
364		s/ u370 / __u370__ /g
365		s/ u3b\([0-9]*\) / __u3b\1__ /g
366		s/ unix / __unix__ /g
367		s/ vax / __vax__ /g
368		s/ _*MIPSE\([LB]\) / __MIPSE\1__ /g
369		s/ _*\([Rr][34]\)000 / __\1000__ /g
370		s/ _*SYSTYPE_\([A-Z0-9]*\) / __SYSTYPE_\1__ /g
371
372		s/ \([a-zA-Z0-9_][a-zA-Z0-9_]*\) /\1/g
373	  }
374	  /^#define.NULL[ 	]/	i\
375		#undef NULL
376	' $2/$file > $2/$file.
377	mv $2/$file. $2/$file
378	if cmp $file $2/$file >/dev/null 2>&1 \
379	    || egrep 'This file is part of the GNU C Library' $2/$file >/dev/null 2>&1; then
380	   rm $2/$file
381	else
382	   echo Fixed $file
383	   # Find any include directives that use "file".
384	   for include in `egrep '^[ 	]*#[ 	]*include[ 	]*"[^/]' $2/$file | sed -e 's/^[ 	]*#[ 	]*include[ 	]*"\([^"]*\)".*$/\1/'`; do
385	      dir=`echo $file | sed -e s'|/[^/]*$||'`
386	      required="$required $1 $dir/$include $2/$dir/$include"
387	   done
388	fi
389      fi
390    fi
391  done
392  shift; shift
393done
394
395cd ${INPUT}
396
397# Install the proper definition of the three standard types in header files
398# that they come from.
399for file in sys/types.h stdlib.h sys/stdtypes.h stddef.h memory.h unistd.h; do
400  if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
401    cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
402    chmod +w ${LIB}/$file 2>/dev/null
403    chmod a+r ${LIB}/$file 2>/dev/null
404  fi
405
406  if [ -r ${LIB}/$file ]; then
407    echo Fixing size_t, ptrdiff_t and wchar_t in $file
408    sed \
409      -e '/^[ 	]*\*[ 	]*typedef unsigned int size_t;/N'	\
410      -e 's/^\([ 	]*\*[ 	]*typedef unsigned int size_t;\n[ 	]*\*\/\)/\1\
411#ifndef __SIZE_TYPE__\
412#define __SIZE_TYPE__ long unsigned int\
413#endif\
414typedef __SIZE_TYPE__ size_t;\
415/'	\
416      -e '/typedef[ 	][ 	]*[a-z_][ 	a-z_]*[ 	]size_t/i\
417#ifndef __SIZE_TYPE__\
418#define __SIZE_TYPE__ long unsigned int\
419#endif
420' \
421      -e 's/typedef[ 	][ 	]*[a-z_][ 	a-z_]*[ 	]size_t/typedef __SIZE_TYPE__ size_t/' \
422      -e '/typedef[ 	][ 	]*[a-z_][ 	a-z_]*[ 	]ptrdiff_t/i\
423#ifndef __PTRDIFF_TYPE__\
424#define __PTRDIFF_TYPE__ long int\
425#endif
426' \
427      -e 's/typedef[ 	][ 	]*[a-z_][ 	a-z_]*[ 	]ptrdiff_t/typedef __PTRDIFF_TYPE__ ptrdiff_t/' \
428      -e '/typedef[ 	][ 	]*[a-z_][ 	a-z_]*[ 	]wchar_t/i\
429#ifndef __WCHAR_TYPE__\
430#define __WCHAR_TYPE__ int\
431#endif\
432#ifndef __cplusplus
433' \
434      -e '/typedef[ 	][ 	]*[a-z_][ 	a-z_]*[ 	]wchar_t/a\
435#endif
436' \
437      -e 's/typedef[ 	][ 	]*[a-z_][ 	a-z_]*[ 	]wchar_t/typedef __WCHAR_TYPE__ wchar_t/' \
438      ${LIB}/$file > ${LIB}/${file}.sed
439    rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
440    if cmp $file ${LIB}/$file >/dev/null 2>&1; then
441      rm ${LIB}/$file
442    else
443      # Find any include directives that use "file".
444      for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
445        dir=`echo $file | sed -e s'|/[^/]*$||'`
446        required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
447      done
448    fi
449  fi
450done
451
452# Fix #defines under Alpha OSF/1:
453# The following files contain '#pragma extern_prefix "_FOO"' followed by
454# a '#define something(x,y,z) _FOOsomething(x,y,z)'.  The intent of these
455# statements is to reduce namespace pollution.  While these macros work
456# properly in most cases, they don't allow you to take a pointer to the
457# "something" being modified.  To get around this limitation, change these
458# statements to be of the form '#define something _FOOsomething'.
459for file in libgen.h dirent.h ftw.h grp.h ndbm.h pthread.h pwd.h signal.h standards.h stdlib.h string.h stropts.h time.h unistd.h
460do
461  if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
462    cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
463    chmod +w ${LIB}/$file 2>/dev/null
464    chmod a+r ${LIB}/$file 2>/dev/null
465  fi
466
467  if [ -r ${LIB}/$file ]; then
468    echo Fixing $file extern_prefix
469    sed -e 's/^[ 	]*#[ 	]*define[ 	]*\([^(]*\)\(([^)]*)\)[ 	]*\(_.\)\1\2[ 	]*$/#define \1 \3\1/' ${LIB}/$file > ${LIB}/${file}.sed
470    rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
471    if cmp $file ${LIB}/$file >/dev/null 2>&1; then
472      rm ${LIB}/$file
473    else
474      # Find any include directives that use "file".
475      for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
476	dir=`echo $file | sed -e s'|/[^/]*$||'`
477	required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
478      done
479    fi
480  fi
481done
482 
483# Fix one other error in this file: a mismatched quote not inside a C comment.
484file=sundev/vuid_event.h
485if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
486  mkdir ${LIB}/sundev 2>/dev/null
487  cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
488  chmod +w ${LIB}/$file 2>/dev/null
489  chmod a+r ${LIB}/$file 2>/dev/null
490fi
491
492if [ -r ${LIB}/$file ]; then
493  echo Fixing $file comment
494  sed -e "s/doesn't/does not/" ${LIB}/$file > ${LIB}/${file}.sed
495  rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
496  if cmp $file ${LIB}/$file >/dev/null 2>&1; then
497    rm ${LIB}/$file
498  else
499    # Find any include directives that use "file".
500    for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
501      dir=`echo $file | sed -e s'|/[^/]*$||'`
502      required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
503    done
504  fi
505fi
506
507# Fix these Sun OS files to avoid an invalid identifier in an #ifdef.
508file=sunwindow/win_cursor.h
509if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
510#  mkdir ${LIB}/sunwindow 2>/dev/null
511  cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
512  chmod +w ${LIB}/$file 2>/dev/null
513fi
514if [ -r ${LIB}/$file ]; then
515  echo Fixing $file
516  sed -e "s/ecd.cursor/ecd_cursor/" ${LIB}/$file > ${LIB}/${file}.sed
517  rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
518  if cmp $file ${LIB}/$file >/dev/null 2>&1; then
519    rm ${LIB}/$file
520  else
521    # Find any include directives that use "file".
522    for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
523      dir=`echo $file | sed -e s'|/[^/]*$||'`
524      required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
525    done
526  fi
527fi
528file=sunwindow/win_lock.h
529if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
530#  mkdir ${LIB}/sunwindow 2>/dev/null
531  cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
532  chmod +w ${LIB}/$file 2>/dev/null
533fi
534if [ -r ${LIB}/$file ]; then
535  echo Fixing $file
536  sed -e "s/ecd.cursor/ecd_cursor/" ${LIB}/$file > ${LIB}/${file}.sed
537  rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
538  if cmp $file ${LIB}/$file >/dev/null 2>&1; then
539    rm ${LIB}/$file
540  else
541    # Find any include directives that use "file".
542    for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
543      dir=`echo $file | sed -e s'|/[^/]*$||'`
544      required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
545    done
546  fi
547fi
548
549# Fix this Sun file to avoid interfering with stddef.h.
550file=sys/stdtypes.h
551if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
552  cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
553  chmod +w ${LIB}/$file 2>/dev/null
554  chmod a+r ${LIB}/$file 2>/dev/null
555fi
556
557if [ -r ${LIB}/$file ]; then
558  echo Fixing $file
559sed -e '/[	 ]size_t.*;/i\
560#ifndef _GCC_SIZE_T\
561#define _GCC_SIZE_T
562' \
563    -e '/[	 ]size_t.*;/a\
564#endif
565' \
566    -e '/[	 ]ptrdiff_t.*;/i\
567#ifndef _GCC_PTRDIFF_T\
568#define _GCC_PTRDIFF_T
569' \
570    -e '/[	 ]ptrdiff_t.*;/a\
571#endif
572' \
573    -e '/[	 ]wchar_t.*;/i\
574#ifndef _GCC_WCHAR_T\
575#define _GCC_WCHAR_T
576' \
577    -e '/[	 ]wchar_t.*;/a\
578#endif
579' ${LIB}/$file > ${LIB}/${file}.sed
580  rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
581  if cmp $file ${LIB}/$file >/dev/null 2>&1; then
582    rm ${LIB}/$file
583  else
584    # Find any include directives that use "file".
585    for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
586      dir=`echo $file | sed -e s'|/[^/]*$||'`
587      required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
588    done
589  fi
590fi
591
592# Fix this ARM/RISCiX file to avoid interfering with the use of __wchar_t
593# in cc1plus.
594file=stdlib.h
595if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
596  cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
597  chmod +w ${LIB}/$file 2>/dev/null
598  chmod a+r ${LIB}/$file 2>/dev/null
599fi
600
601if [ -r ${LIB}/$file ]; then
602  echo Fixing $file
603  sed -e "s/\(#[ 	]*ifndef[ 	]*\)__wchar_t/\1_GCC_WCHAR_T/" \
604      -e "s/\(#[ 	]*define[ 	]*\)__wchar_t/\1_GCC_WCHAR_T/" \
605     ${LIB}/$file > ${LIB}/${file}.sed
606  rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
607  if cmp $file ${LIB}/$file >/dev/null 2>&1; then
608    rm ${LIB}/$file
609  else
610    # Find any include directives that use "file".
611    for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
612      dir=`echo $file | sed -e s'|/[^/]*$||'`
613      required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
614    done
615  fi
616fi
617
618# Fix this ARM/RISCiX file where ___type is a Compiler hint that is specific to
619# the Norcroft compiler.
620file=X11/Intrinsic.h
621if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
622  cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
623  chmod +w ${LIB}/$file 2>/dev/null
624  chmod a+r ${LIB}/$file 2>/dev/null
625fi
626
627if [ -r ${LIB}/$file ]; then
628  echo Fixing $file
629  sed -e "s/___type p_type/p_type/" \
630     ${LIB}/$file > ${LIB}/${file}.sed
631  rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
632  if cmp $file ${LIB}/$file >/dev/null 2>&1; then
633    rm ${LIB}/$file
634  else
635    # Find any include directives that use "file".
636    for include in `egrep '^[         ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
637      dir=`echo $file | sed -e s'|/[^/]*$||'`
638      required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
639    done
640  fi
641fi
642
643# Fix this file to avoid interfering with stddef.h, but don't mistakenly
644# match ssize_t present in AIX for the ps/2, or typedefs which use (but do not
645# set) size_t.
646file=sys/types.h
647if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
648  cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
649  chmod +w ${LIB}/$file 2>/dev/null
650  chmod a+r ${LIB}/$file 2>/dev/null
651fi
652
653if [ -r ${LIB}/$file ]; then
654  echo Fixing $file
655sed -e '/typedef[ 	][ 	]*[A-Za-z_][ 	A-Za-z_]*[ 	]size_t/i\
656#ifndef _GCC_SIZE_T\
657#define _GCC_SIZE_T
658' \
659    -e '/typedef[ 	][ 	]*[A-Za-z_][ 	A-Za-z_]*[ 	]size_t/a\
660#endif
661' ${LIB}/$file > ${LIB}/${file}.sed
662  rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
663  if cmp $file ${LIB}/$file >/dev/null 2>&1; then
664    rm ${LIB}/$file
665  else
666    # Find any include directives that use "file".
667    for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
668      dir=`echo $file | sed -e s'|/[^/]*$||'`
669      required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
670    done
671  fi
672fi
673
674# Fix HP's use of ../machine/inline.h to refer to
675# /usr/include/machine/inline.h
676file=sys/spinlock.h
677if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
678  cp $file ${LIB}/$file
679fi
680if [ -r ${LIB}/$file ] ; then
681  echo Fixing $file
682  sed -e 's,"../machine/inline.h",<machine/inline.h>,' \
683    -e 's,"../machine/psl.h",<machine/psl.h>,' \
684  ${LIB}/$file > ${LIB}/${file}.sed
685  rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
686  if cmp $file ${LIB}/$file >/dev/null 2>&1; then
687    rm ${LIB}/$file
688  else
689    # Find any include directives that use "file".
690    for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
691      dir=`echo $file | sed -e s'|/[^/]*$||'`
692      required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
693    done
694  fi
695fi
696
697# Fix an error in this file: the #if says _cplusplus, not the double
698# underscore __cplusplus that it should be
699file=tinfo.h
700if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
701  mkdir ${LIB}/rpcsvc 2>/dev/null
702  cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
703  chmod +w ${LIB}/$file 2>/dev/null
704  chmod a+r ${LIB}/$file 2>/dev/null
705fi
706
707if [ -r ${LIB}/$file ]; then
708  echo Fixing $file, __cplusplus macro
709  sed -e 's/[ 	]_cplusplus/ __cplusplus/' ${LIB}/$file > ${LIB}/${file}.sed
710  rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
711  if cmp $file ${LIB}/$file >/dev/null 2>&1; then
712    rm ${LIB}/$file
713  else
714    # Find any include directives that use "file".
715    for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
716      dir=`echo $file | sed -e s'|/[^/]*$||'`
717      required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
718    done
719  fi
720fi
721
722# Fix an error in this file: a missing semi-colon at the end of the statsswtch
723# structure definition.
724file=rpcsvc/rstat.h
725if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
726  mkdir ${LIB}/rpcsvc 2>/dev/null
727  cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
728  chmod +w ${LIB}/$file 2>/dev/null
729  chmod a+r ${LIB}/$file 2>/dev/null
730fi
731
732if [ -r ${LIB}/$file ]; then
733  echo Fixing $file, definition of statsswtch
734  sed -e 's/boottime$/boottime;/' ${LIB}/$file > ${LIB}/${file}.sed
735  rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
736  if cmp $file ${LIB}/$file >/dev/null 2>&1; then
737    rm ${LIB}/$file
738  else
739    # Find any include directives that use "file".
740    for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
741      dir=`echo $file | sed -e s'|/[^/]*$||'`
742      required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
743    done
744  fi
745fi
746
747# Fix an error in this file: a missing semi-colon at the end of the nodeent
748# structure definition.
749file=netdnet/dnetdb.h
750if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
751  mkdir ${LIB}/netdnet 2>/dev/null
752  cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
753  chmod +w ${LIB}/$file 2>/dev/null
754  chmod a+r ${LIB}/$file 2>/dev/null
755fi
756
757if [ -r ${LIB}/$file ]; then
758  echo Fixing $file, definition of nodeent
759  sed -e 's/char.*na_addr *$/char *na_addr;/' ${LIB}/$file > ${LIB}/${file}.sed
760  rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
761  if cmp $file ${LIB}/$file >/dev/null 2>&1; then
762    rm ${LIB}/$file
763  else
764    # Find any include directives that use "file".
765    for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
766      dir=`echo $file | sed -e s'|/[^/]*$||'`
767      required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
768    done
769  fi
770fi
771
772# Check for bad #ifdef line (in Ultrix 4.1)
773file=sys/file.h
774if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
775  cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
776  chmod +w ${LIB}/$file 2>/dev/null
777  chmod a+r ${LIB}/$file 2>/dev/null
778fi
779
780if [ -r ${LIB}/$file ]; then
781  echo Fixing $file, bad \#ifdef line
782  sed -e 's/#ifdef KERNEL/#if defined(KERNEL)/' ${LIB}/$file > ${LIB}/${file}.sed
783  rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
784  if cmp $file ${LIB}/$file >/dev/null 2>&1; then
785    rm ${LIB}/$file
786  else
787    # Find any include directives that use "file".
788    for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
789      dir=`echo $file | sed -e s'|/[^/]*$||'`
790      required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
791    done
792  fi
793fi
794
795# Check for (...) in C++ code in HP/UX sys/file.h.
796file=sys/file.h
797if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
798  cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
799  chmod +w ${LIB}/$file 2>/dev/null
800  chmod a+r ${LIB}/$file 2>/dev/null
801fi
802
803if [ -r ${LIB}/$file ]; then
804  if egrep HPUX_SOURCE ${LIB}/$file > /dev/null; then
805    echo Fixing $file, use of '(...)'
806    sed -e 's/(\.\.\.)/(struct file * ...)/' ${LIB}/$file > ${LIB}/${file}.sed
807    rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
808    if cmp $file ${LIB}/$file >/dev/null 2>&1; then
809      rm ${LIB}/$file
810    else
811      # Find any include directives that use "file".
812      for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
813	dir=`echo $file | sed -e s'|/[^/]*$||'`
814	required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
815      done
816    fi
817  fi
818fi
819
820# Check for superfluous `static' (in Ultrix 4.2)
821# On Ultrix 4.3, includes of other files (r3_cpu.h,r4_cpu.h) is broken.
822file=machine/cpu.h
823if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
824  mkdir ${LIB}/machine 2>/dev/null
825  cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
826  chmod +w ${LIB}/$file 2>/dev/null
827  chmod a+r ${LIB}/$file 2>/dev/null
828fi
829
830if [ -r ${LIB}/$file ]; then
831  echo Fixing $file, superfluous static and broken includes of other files.
832  sed -e 's/^static struct tlb_pid_state/struct tlb_pid_state/' \
833      -e 's/^#include "r3_cpu\.h"$/#include <machine\/r3_cpu\.h>/' \
834      -e 's/^#include "r4_cpu\.h"$/#include <machine\/r4_cpu\.h>/' \
835      ${LIB}/$file > ${LIB}/${file}.sed
836  rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
837  if cmp $file ${LIB}/$file >/dev/null 2>&1; then
838    rm ${LIB}/$file
839  else
840    # Find any include directives that use "file".
841    for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
842      dir=`echo $file | sed -e s'|/[^/]*$||'`
843      required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
844    done
845# This file has an alternative name, mips/cpu.h.  Fix that name, too.
846    if cmp machine/cpu.h mips/cpu.h > /dev/null 2>&1; then
847      mkdir ${LIB}/mips 2>&-
848# Don't remove the file first, they may be the same file!
849      ln ${LIB}/$file ${LIB}/mips/cpu.h > /dev/null 2>&1
850    fi
851  fi
852fi
853
854# Incorrect sprintf declaration in X11/Xmu.h
855file=X11/Xmu.h
856if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
857  mkdir ${LIB}/X11 2>/dev/null
858  cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
859  chmod +w ${LIB}/$file 2>/dev/null
860  chmod a+r ${LIB}/$file 2>/dev/null
861fi
862
863if [ -r ${LIB}/$file ]; then
864  echo Fixing $file sprintf declaration
865  sed -e 's,^extern char \*	sprintf();$,#ifndef __STDC__\
866extern char *	sprintf();\
867#endif /* !defined __STDC__ */,' ${LIB}/$file > ${LIB}/${file}.sed
868  rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
869  if cmp $file ${LIB}/$file >/dev/null 2>&1; then
870    rm ${LIB}/$file
871  else
872    # Find any include directives that use "file".
873    for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
874      dir=`echo $file | sed -e s'|/[^/]*$||'`
875      required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
876    done
877  fi
878fi
879
880# Incorrect sprintf declaration in X11/Xmu/Xmu.h
881# (It's not clear whether the right file name is this or X11/Xmu.h.)
882file=X11/Xmu/Xmu.h
883if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
884  mkdir ${LIB}/X11/Xmu 2>/dev/null
885  cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
886  chmod +w ${LIB}/$file 2>/dev/null
887  chmod a+r ${LIB}/$file 2>/dev/null
888fi
889
890if [ -r ${LIB}/$file ]; then
891  echo Fixing $file sprintf declaration
892  sed -e 's,^extern char \*	sprintf();$,#ifndef __STDC__\
893extern char *	sprintf();\
894#endif /* !defined __STDC__ */,' ${LIB}/$file > ${LIB}/${file}.sed
895  rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
896  if cmp $file ${LIB}/$file >/dev/null 2>&1; then
897    rm ${LIB}/$file
898  else
899    # Find any include directives that use "file".
900    for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
901      dir=`echo $file | sed -e s'|/[^/]*$||'`
902      required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
903    done
904  fi
905fi
906
907# Check for missing ';' in struct
908file=netinet/ip.h
909if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
910  mkdir ${LIB}/netinet 2>/dev/null
911  cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
912  chmod +w ${LIB}/$file 2>/dev/null
913  chmod a+r ${LIB}/$file 2>/dev/null
914fi
915
916if [ -r ${LIB}/$file ]; then
917  echo Fixing $file
918  sed -e '/^struct/,/^};/s/}$/};/' ${LIB}/$file > ${LIB}/${file}.sed
919  rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
920  if cmp $file ${LIB}/$file >/dev/null 2>&1; then
921    rm -f ${LIB}/$file
922  else
923    # Find any include directives that use "file".
924    for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
925      dir=`echo $file | sed -e s'|/[^/]*$||'`
926      required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
927    done
928  fi
929fi
930
931# Fix the CAT macro in SunOS memvar.h.
932file=pixrect/memvar.h
933if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
934  mkdir ${LIB}/pixrect 2>/dev/null
935  cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
936  chmod +w ${LIB}/$file 2>/dev/null
937  chmod a+r ${LIB}/$file 2>/dev/null
938fi
939
940if [ -r ${LIB}/$file ]; then
941  echo Fixing $file
942  sed -e '/^#define.CAT(a,b)/ i\
943#ifdef __STDC__ \
944#define CAT(a,b) a##b\
945#else
946/^#define.CAT(a,b)/ a\
947#endif
948' ${LIB}/$file > ${LIB}/${file}.sed
949  rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
950  if cmp $file ${LIB}/$file >/dev/null 2>&1; then
951    rm -f ${LIB}/$file
952  else
953    # Find any include directives that use "file".
954    for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
955      dir=`echo $file | sed -e s'|/[^/]*$||'`
956      required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
957    done
958  fi
959fi
960
961# Check for yet more missing ';' in struct (in SunOS 4.0.x)
962file=rpcsvc/rusers.h
963if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
964  mkdir ${LIB}/rpcsvc 2>/dev/null
965  cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
966  chmod +w ${LIB}/$file 2>/dev/null
967  chmod a+r ${LIB}/$file 2>/dev/null
968fi
969
970if [ -r ${LIB}/$file ]; then
971  echo Fixing $file
972  sed -e '/^struct/,/^};/s/_cnt$/_cnt;/' ${LIB}/$file > ${LIB}/${file}.sed
973  rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
974  if cmp $file ${LIB}/$file >/dev/null 2>&1; then
975    rm -f ${LIB}/$file
976  else
977    # Find any include directives that use "file".
978    for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
979      dir=`echo $file | sed -e s'|/[^/]*$||'`
980      required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
981    done
982  fi
983fi
984
985# Fix return type of exit and abort in <stdlib.h> on SunOS 4.1.
986# Also wrap protection around size_t for m88k-sysv3 systems.
987file=stdlib.h
988if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
989  cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
990  chmod +w ${LIB}/$file 2>/dev/null
991  chmod a+r ${LIB}/$file 2>/dev/null
992fi
993
994if [ -r ${LIB}/$file ]; then
995  echo Fixing $file
996  if grep _GCC_SIZE_T ${LIB}/$file >/dev/null
997  then size_t_pattern='<<< do not double-wrap the size_t typedef >>>'
998  else size_t_pattern='typedef[ 	a-zA-Z_]*[ 	]size_t[ 	]*;'
999  fi
1000  sed -e 's/int	abort/void	abort/g' \
1001  -e 's/int	free/void	free/g' \
1002  -e 's/char[ 	]*\*[ 	]*calloc/void \*	calloc/g' \
1003  -e 's/char[ 	]*\*[ 	]*malloc/void \*	malloc/g' \
1004  -e 's/char[ 	]*\*[ 	]*realloc/void \*	realloc/g' \
1005  -e 's/char[ 	]*\*[ 	]*bsearch/void \*	bsearch/g' \
1006  -e 's/int[ 	][ 	]*exit/void	exit/g' \
1007  -e "/$size_t_pattern/"'i\
1008#ifndef _GCC_SIZE_T\
1009#define _GCC_SIZE_T
1010' \
1011  -e "/$size_t_pattern/"'a\
1012#endif
1013' \
1014      ${LIB}/$file > ${LIB}/${file}.sed
1015  rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1016  if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1017    rm -f ${LIB}/$file
1018  else
1019    # Find any include directives that use "file".
1020    for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1021      dir=`echo $file | sed -e s'|/[^/]*$||'`
1022      required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1023    done
1024  fi
1025fi
1026
1027# Fix return type of free and {c,m,re}alloc in <malloc.h> on SunOS 4.1.
1028# Also fix return type of {m,re}alloc in <malloc.h> on sysV68
1029file=malloc.h
1030if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1031  cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1032  chmod +w ${LIB}/$file 2>/dev/null
1033  chmod a+r ${LIB}/$file 2>/dev/null
1034fi
1035
1036if [ -r ${LIB}/$file ]; then
1037  echo Fixing $file
1038  sed -e 's/typedef[ 	]char \*	malloc_t/typedef void \*	malloc_t/g' \
1039  -e 's/int[ 	][ 	]*free/void	free/g' \
1040  -e 's/char\([ 	]*\*[ 	]*malloc\)/void\1/g' \
1041  -e 's/char\([ 	]*\*[ 	]*realloc\)/void\1/g' \
1042  ${LIB}/$file > ${LIB}/${file}.sed
1043  rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1044  if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1045    rm -f ${LIB}/$file
1046  else
1047    # Find any include directives that use "file".
1048    for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1049      dir=`echo $file | sed -e s'|/[^/]*$||'`
1050      required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1051    done
1052  fi
1053fi
1054
1055# Fix bogus #ifdef in <hsfs/hsfs_spec.h> on SunOS 4.1.
1056file=hsfs/hsfs_spec.h
1057if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1058  mkdir ${LIB}/hsfs 2>/dev/null
1059  cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1060  chmod +w ${LIB}/$file 2>/dev/null
1061  chmod a+r ${LIB}/$file 2>/dev/null
1062fi
1063
1064if [ -r ${LIB}/$file ]; then
1065  echo Fixing $file
1066  sed -e 's/\#ifdef __i386__ || __vax__/\#if __i386__ || __vax__/g' \
1067    ${LIB}/$file > ${LIB}/${file}.
1068  rm -f ${LIB}/$file; mv ${LIB}/${file}. ${LIB}/$file
1069  if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1070    rm -f ${LIB}/$file
1071  else
1072    # Find any include directives that use "file".
1073    for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1074      dir=`echo $file | sed -e s'|/[^/]*$||'`
1075      required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1076    done
1077  fi
1078fi
1079
1080# Fix bogus #ifdef in <hsfs/hsnode.h> on SunOS 4.1.
1081file=hsfs/hsnode.h
1082if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1083  mkdir ${LIB}/hsfs 2>/dev/null
1084  cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1085  chmod +w ${LIB}/$file 2>/dev/null
1086  chmod a+r ${LIB}/$file 2>/dev/null
1087fi
1088
1089if [ -r ${LIB}/$file ]; then
1090  echo Fixing $file
1091  sed -e 's/\#ifdef __i386__ || __sun4c__/\#if __i386__ || __sun4c__/g' \
1092    ${LIB}/$file > ${LIB}/${file}.sed
1093  rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1094  if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1095    rm -f ${LIB}/$file
1096  else
1097    # Find any include directives that use "file".
1098    for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1099      dir=`echo $file | sed -e s'|/[^/]*$||'`
1100      required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1101    done
1102  fi
1103fi
1104
1105# Fix bogus #ifdef in <hsfs/iso_spec.h> on SunOS 4.1.
1106file=hsfs/iso_spec.h
1107if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1108  mkdir ${LIB}/hsfs 2>/dev/null
1109  cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1110  chmod +w ${LIB}/$file 2>/dev/null
1111  chmod a+r ${LIB}/$file 2>/dev/null
1112fi
1113
1114if [ -r ${LIB}/$file ]; then
1115  echo Fixing $file
1116  sed -e 's/\#ifdef __i386__ || __vax__/\#if __i386__ || __vax__/g' \
1117    ${LIB}/$file > ${LIB}/${file}.sed
1118  rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1119  if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1120    rm -f ${LIB}/$file
1121  else
1122    # Find any include directives that use "file".
1123    for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1124      dir=`echo $file | sed -e s'|/[^/]*$||'`
1125      required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1126    done
1127  fi
1128fi
1129
1130# Incorrect #include in Sony News-OS 3.2.
1131file=machine/machparam.h
1132if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1133  mkdir ${LIB}/machine 2>/dev/null
1134  cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1135  chmod +w ${LIB}/$file 2>/dev/null
1136  chmod a+r ${LIB}/$file 2>/dev/null
1137fi
1138
1139if [ -r ${LIB}/$file ]; then
1140  echo Fixing $file, incorrect \#include
1141  sed -e 's@"../machine/endian.h"@<machine/endian.h>@' \
1142    ${LIB}/$file > ${LIB}/${file}.
1143  rm -f ${LIB}/$file; mv ${LIB}/${file}. ${LIB}/$file
1144  if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1145    rm -f ${LIB}/$file
1146  else
1147    # Find any include directives that use "file".
1148    for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1149      dir=`echo $file | sed -e s'|/[^/]*$||'`
1150      required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1151    done
1152  fi
1153fi
1154
1155# Multiline comment after typedef on IRIX 4.0.1.
1156file=sys/types.h
1157if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1158  mkdir ${LIB}/sys 2>/dev/null
1159  cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1160  chmod +w ${LIB}/$file 2>/dev/null
1161  chmod a+r ${LIB}/$file 2>/dev/null
1162fi
1163
1164if [ -r ${LIB}/$file ]; then
1165  echo Fixing $file, comment in the middle of \#ifdef
1166  sed -e 's@type of the result@type of the result */@' \
1167    -e 's@of the sizeof@/* of the sizeof@' \
1168    ${LIB}/$file > ${LIB}/${file}.sed
1169  rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1170  if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1171    rm -f ${LIB}/$file
1172  else
1173    # Find any include directives that use "file".
1174    for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1175      dir=`echo $file | sed -e s'|/[^/]*$||'`
1176      required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1177    done
1178  fi
1179fi
1180
1181# Turning // comments into /* */ comments trashes this IRIX 4.0.1
1182# header file, which embeds // comments inside multi-line /* */
1183# comments.  If this looks like the IRIX header file, we refix it by
1184# just throwing away the // comments.
1185file=fam.h
1186if [ -r ${LIB}/$file ]; then
1187  if egrep indigo.esd ${LIB}/$file > /dev/null; then
1188    echo Fixing $file, overeager sed script
1189    rm ${LIB}/$file
1190    sed -e 's|//.*$||g' $file > ${LIB}/$file
1191    chmod +w ${LIB}/$file 2>/dev/null
1192    chmod a+r ${LIB}/$file 2>/dev/null
1193  fi
1194fi
1195
1196# There is a similar problem with the VxWorks drv/netif/if_med.h file.
1197file=drv/netif/if_med.h
1198if [ -r ${LIB}/$file ]; then
1199  if egrep 'Wind River' ${LIB}/$file > /dev/null; then
1200    echo Fixing $file, overeager sed script
1201    rm ${LIB}/$file
1202    sed -e 's|//.*$||g' $file > ${LIB}/$file
1203    chmod +w ${LIB}/$file 2>/dev/null
1204    chmod a+r ${LIB}/$file 2>/dev/null
1205  fi
1206fi
1207
1208# And also with the HP-UX 10 and HP-UX 11 sys/pci.h file
1209file=sys/pci.h
1210if [ -r ${LIB}/$file ]; then
1211  if egrep 'System Private Structures' ${LIB}/$file > /dev/null; then
1212    echo Fixing $file, overeager sed script
1213    rm ${LIB}/$file
1214    sed -e 's|//.*$||g' $file > ${LIB}/$file
1215    chmod +w ${LIB}/$file 2>/dev/null
1216    chmod a+r ${LIB}/$file 2>/dev/null
1217  fi
1218fi
1219
1220# And also with a few more HP-UX 11 headers which are only broken
1221# after they are "fixed".
1222file=sys/ki_iface.h
1223if [ -r ${LIB}/$file ]; then
1224  if egrep 'These definitions are for HP Internal developers' ${LIB}/$file > /dev/null; then
1225    echo Fixing $file, overeager sed script
1226    rm ${LIB}/$file
1227  fi
1228fi
1229
1230file=sys/ki.h
1231if [ -r ${LIB}/$file ]; then
1232  if egrep '11.00 HP-UX LP64' ${LIB}/$file > /dev/null; then
1233    echo Fixing $file, overeager sed script
1234    rm ${LIB}/$file
1235  fi
1236fi
1237
1238file=sys/ki_calls.h
1239if [ -r ${LIB}/$file ]; then
1240  if egrep 'KI_MAX_PROCS is an arbitrary number' ${LIB}/$file > /dev/null; then
1241    echo Fixing $file, overeager sed script
1242    rm ${LIB}/$file
1243  fi
1244fi
1245
1246file=sys/ki_defs.h
1247if [ -r ${LIB}/$file ] ; then
1248  if egrep 'Kernel Instrumentation Definitions' ${LIB}/$file > /dev/null; then
1249    echo Fixing $file, overeager sed script
1250    rm ${LIB}/$file
1251  fi
1252fi
1253
1254file=sys/time.h
1255if [ -r ${LIB}/$file ] ; then
1256  if egrep 'For CASPEC, look in' ${LIB}/$file > /dev/null; then
1257    echo Fixing $file, overeager sed script
1258    rm ${LIB}/$file
1259  fi
1260fi
1261
1262# Some IRIX header files contains the string "//"
1263for file in elf_abi.h elf.h; do
1264  if [ -r ${LIB}/$file ]; then
1265    echo Fixing $file, overeager sed script
1266    sed -e 's|"/\*"\*/|"//"|' ${LIB}/$file > ${LIB}/${file}.sed
1267    rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1268    if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1269      rm -f ${LIB}/$file
1270  else
1271    # Find any include directives that use "file".
1272    for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1273      dir=`echo $file | sed -e s'|/[^/]*$||'`
1274      required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1275    done
1276    fi
1277  fi
1278done
1279
1280# IRIX 4.0.5 <rpc/auth.h> uses struct sockaddr in prototype without
1281# previous definition.
1282file=rpc/auth.h
1283if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1284  mkdir ${LIB}/rpc 2>/dev/null
1285  cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1286  chmod +w ${LIB}/$file 2>/dev/null
1287  chmod a+r ${LIB}/$file 2>/dev/null
1288fi
1289
1290if [ -r ${LIB}/$file ]; then
1291  echo Fixing $file, undefined type
1292  sed -e '/authdes_create.*struct sockaddr/i\
1293struct sockaddr;
1294' \
1295    ${LIB}/$file > ${LIB}/$file.sed
1296  rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1297  if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1298    rm -f ${LIB}/$file
1299  else
1300    # Find any include directives that use "file".
1301    for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1302      dir=`echo $file | sed -e s'|/[^/]*$||'`
1303      required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1304    done
1305  fi
1306fi
1307
1308# IRIX 4.0.5 <rpc/xdr.h> uses struct __file_s in prototype without previous
1309# definition.
1310file=rpc/xdr.h
1311if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1312  mkdir ${LIB}/rpc 2>/dev/null
1313  cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1314  chmod +w ${LIB}/$file 2>/dev/null
1315  chmod a+r ${LIB}/$file 2>/dev/null
1316fi
1317
1318if [ -r ${LIB}/$file ]; then
1319  echo Fixing $file, undefined type
1320  sed -e '/xdrstdio_create.*struct __file_s/i\
1321struct __file_s;
1322' \
1323    ${LIB}/$file > ${LIB}/$file.sed
1324  rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1325  if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1326    rm -f ${LIB}/$file
1327  else
1328    # Find any include directives that use "file".
1329    for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1330      dir=`echo $file | sed -e s'|/[^/]*$||'`
1331      required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1332    done
1333  fi
1334fi
1335
1336# Same problem with a file from SunOS 4.1.3 : a header file containing
1337# the string "//" embedded in "/**/"
1338file=sbusdev/audiovar.h
1339if [ -r ${LIB}/$file ]; then
1340  echo Fixing $file, overeager sed script
1341  rm ${LIB}/$file
1342  sed -e 's|//.*$||g' $file > ${LIB}/$file
1343  chmod +w ${LIB}/$file 2>/dev/null
1344  chmod a+r ${LIB}/$file 2>/dev/null
1345fi
1346
1347# Fix non-ANSI memcpy declaration that conflicts with gcc's builtin
1348# declaration on Sun OS 4.x.  We must only fix this on Sun OS 4.x, because
1349# many other systems have similar text but correct versions of the file.
1350# To ensure only Sun's is fixed, we grep for a likely unique string.
1351# Fix also on sysV68 R3V7.1 (head/memory.h\t50.1\t )
1352file=memory.h
1353if [ -r $file ] && egrep '/\*	@\(#\)(head/memory.h	50.1	 |memory\.h 1\.[2-4] 8./../.. SMI; from S5R2 1\.2	)\*/' $file > /dev/null; then
1354  if [ ! -r ${LIB}/$file ]; then
1355    cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1356    chmod +w ${LIB}/$file 2>/dev/null
1357    chmod a+r ${LIB}/$file 2>/dev/null
1358  fi
1359  if [ -r ${LIB}/$file ]; then
1360    echo Replacing $file
1361    cat > ${LIB}/$file << EOF
1362/* This file was generated by fixincludes */
1363#ifndef __memory_h__
1364#define __memory_h__
1365
1366#ifdef __STDC__
1367extern void *memccpy();
1368extern void *memchr();
1369extern void *memcpy();
1370extern void *memset();
1371#else
1372extern char *memccpy();
1373extern char *memchr();
1374extern char *memcpy();
1375extern char *memset();
1376#endif /* __STDC__ */
1377
1378extern int memcmp();
1379
1380#endif /* __memory_h__ */
1381EOF
1382  fi
1383fi
1384
1385# Fix return type of fread and fwrite on sysV68
1386file=stdio.h
1387if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1388  cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1389  chmod +w ${LIB}/$file 2>/dev/null
1390  chmod a+r ${LIB}/$file 2>/dev/null
1391fi
1392
1393if [ -r ${LIB}/$file ]; then
1394  echo Fixing $file, fread and fwrite return type
1395  sed -e 's/^\(extern int	fclose(), fflush()\), \(fread(), fwrite()\)\(.*\)$/extern unsigned int	\2;\
1396\1\3/' \
1397    ${LIB}/$file > ${LIB}/${file}.sed
1398  rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1399  if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1400    rm -f ${LIB}/$file
1401  else
1402    # Find any include directives that use "file".
1403    for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1404      dir=`echo $file | sed -e s'|/[^/]*$||'`
1405      required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1406    done
1407  fi
1408fi
1409
1410# parameters not const on DECstation Ultrix V4.0 and OSF/1.
1411file=stdio.h
1412if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1413  cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1414  chmod +w ${LIB}/$file 2>/dev/null
1415  chmod a+r ${LIB}/$file 2>/dev/null
1416fi
1417
1418if [ -r ${LIB}/$file ]; then
1419  echo Fixing $file, non-const arg
1420  sed -e 's@perror( char \*__s );@perror( const char *__s );@' \
1421      -e 's@fputs( char \*__s,@fputs( const char *__s,@' \
1422      -e 's@fopen( char \*__filename, char \*__type );@fopen( const char *__filename, const char *__type );@' \
1423      -e 's@fwrite( void \*__ptr,@fwrite( const void *__ptr,@' \
1424      -e 's@fscanf( FILE \*__stream, char \*__format,@fscanf( FILE *__stream, const char *__format,@' \
1425      -e 's@scanf( char \*__format,@scanf( const char *__format,@' \
1426      -e 's@sscanf( char \*__s, char \*__format,@sscanf( const char *__s, const char *__format,@' \
1427      -e 's@popen(char \*, char \*);@popen(const char *, const char *);@' \
1428      -e 's@tempnam(char\*,char\*);@tempnam(const char*,const char*);@' \
1429    ${LIB}/$file > ${LIB}/${file}.sed
1430  rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1431  if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1432    rm -f ${LIB}/$file
1433  else
1434    # Find any include directives that use "file".
1435    for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1436      dir=`echo $file | sed -e s'|/[^/]*$||'`
1437      required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1438    done
1439  fi
1440fi
1441
1442# parameters conflict with C++ new on rs/6000 
1443for file in stdio.h unistd.h ; do
1444  if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1445    cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1446    chmod +w ${LIB}/$file 2>/dev/null
1447  fi
1448
1449  if [ -r ${LIB}/$file ]; then
1450    echo Fixing $file, parameter name conflicts
1451    sed -e 's@rename(const char \*old, const char \*new)@rename(const char *_old, const char *_new)@' \
1452      ${LIB}/$file > ${LIB}/${file}.sed
1453    rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1454    if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1455      rm -f ${LIB}/$file
1456    else
1457      # Find any include directives that use "file".
1458      for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1459        dir=`echo $file | sed -e s'|/[^/]*$||'`
1460        required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1461      done
1462    fi
1463  fi
1464done
1465
1466# function class(double x) conflicts with C++ keyword on rs/6000 
1467file=math.h
1468if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1469  cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1470  chmod +w ${LIB}/$file 2>/dev/null
1471  chmod a+r ${LIB}/$file 2>/dev/null
1472fi
1473
1474if [ -r ${LIB}/$file ]; then
1475  if grep '[^a-zA-Z_]class[(]' ${LIB}/$file >/dev/null; then
1476    echo Fixing $file
1477    sed -e '/class[(]/i\
1478#ifndef __cplusplus
1479' \
1480        -e '/class[(]/a\
1481#endif
1482' ${LIB}/$file > ${LIB}/${file}.sed
1483    rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1484    if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1485      rm ${LIB}/$file
1486    else
1487      # Find any include directives that use "file".
1488      for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1489        dir=`echo $file | sed -e s'|/[^/]*$||'`
1490        required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1491      done
1492    fi
1493  fi
1494fi
1495
1496# Wrong fchmod prototype on RS/6000.
1497file=sys/stat.h
1498if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1499  mkdir ${LIB}/sys 2>/dev/null
1500  cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1501  chmod +w ${LIB}/$file 2>/dev/null
1502  chmod a+r ${LIB}/$file 2>/dev/null
1503fi
1504
1505if [ -r ${LIB}/$file ]; then
1506  echo Fixing $file, fchmod prototype
1507  sed -e 's/fchmod(char \*/fchmod(int/' \
1508    ${LIB}/$file > ${LIB}/$file.sed
1509  rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1510  if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1511    rm -f ${LIB}/$file
1512  else
1513    # Find any include directives that use "file".
1514    for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1515      dir=`echo $file | sed -e s'|/[^/]*$||'`
1516      required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1517    done
1518  fi
1519fi
1520
1521# There are several name conflicts with C++ reserved words in X11
1522# header files.  These are fixed in some versions, so don't do the
1523# fixes if we find __cplusplus in the file.  These were found on the
1524# RS/6000.
1525
1526# class in X11/ShellP.h
1527file=X11/ShellP.h
1528if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1529  mkdir ${LIB}/sys 2>/dev/null
1530  cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1531  chmod +w ${LIB}/$file 2>/dev/null
1532  chmod a+r ${LIB}/$file 2>/dev/null
1533fi
1534
1535if [ -r ${LIB}/$file ]; then
1536  if grep __cplusplus ${LIB}/$file >/dev/null 2>/dev/null; then
1537    true;
1538  else
1539    echo Fixing $file, field class
1540    sed -e '/char [*]class;/i\
1541#ifdef __cplusplus\
1542	char *c_class;\
1543#else
1544' \
1545        -e '/char [*]class;/a\
1546#endif
1547' ${LIB}/$file > ${LIB}/${file}.sed
1548    rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1549  fi
1550  if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1551    rm -f ${LIB}/$file
1552  else
1553    # Find any include directives that use "file".
1554    for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1555      dir=`echo $file | sed -e s'|/[^/]*$||'`
1556      required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1557    done
1558  fi
1559fi
1560# new in Xm/Traversal.h
1561file=Xm/Traversal.h
1562if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1563  mkdir ${LIB}/sys 2>/dev/null
1564  cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1565  chmod +w ${LIB}/$file 2>/dev/null
1566  chmod a+r ${LIB}/$file 2>/dev/null
1567fi
1568
1569if [ -r ${LIB}/$file ]; then
1570  if grep __cplusplus ${LIB}/$file >/dev/null 2>/dev/null; then
1571    true;
1572  else
1573    echo Fixing $file, uses of new
1574    sed -e '/Widget	old, new;/i\
1575#ifdef __cplusplus\
1576	Widget	old, c_new;\
1577#else
1578' \
1579        -e '/Widget	old, new;/a\
1580#endif
1581' \
1582	-e 's/Widget new,/Widget c_new,/g' ${LIB}/$file > ${LIB}/${file}.sed
1583    rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1584  fi
1585  if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1586    rm -f ${LIB}/$file
1587  else
1588    # Find any include directives that use "file".
1589    for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1590      dir=`echo $file | sed -e s'|/[^/]*$||'`
1591      required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1592    done
1593  fi
1594fi
1595# class in Xm/BaseClassI.h
1596file=Xm/BaseClassI.h
1597if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1598  mkdir ${LIB}/sys 2>/dev/null
1599  cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1600  chmod +w ${LIB}/$file 2>/dev/null
1601  chmod a+r ${LIB}/$file 2>/dev/null
1602fi
1603
1604if [ -r ${LIB}/$file ]; then
1605  if grep __cplusplus ${LIB}/$file >/dev/null 2>/dev/null; then
1606    true;
1607  else
1608    echo Fixing $file, prototype parameter name
1609    sed -e 's/ class[)]/ c_class)/g' ${LIB}/$file > ${LIB}/${file}.sed
1610    rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1611  fi
1612  if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1613    rm -f ${LIB}/$file
1614  else
1615    # Find any include directives that use "file".
1616    for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1617      dir=`echo $file | sed -e s'|/[^/]*$||'`
1618      required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1619    done
1620  fi
1621fi
1622
1623# NeXT 3.2 adds const prefix to some math functions. These conflict
1624# with the built-in functions.
1625file=ansi/math.h
1626if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1627  cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1628  chmod +w ${LIB}/$file 2>/dev/null
1629fi
1630if [ -r ${LIB}/$file ]; then
1631  echo Fixing $file
1632  sed -e '/^extern.*double.*__const__.*sqrt(/s/__const__//' \
1633      -e '/^extern.*double.*__const__.*fabs(/s/__const__//' \
1634      -e '/^extern.*double.*__const__.*cos(/s/__const__//' \
1635      -e '/^extern.*double.*__const__.*hypot(/s/__const__//' \
1636      -e '/^extern.*double.*__const__.*sin(/s/__const__//' ${LIB}/$file > ${LIB}/${file}.sed
1637  rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1638  if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1639    rm -f ${LIB}/$file
1640  else
1641    # Find any include directives that use "file".
1642    for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1643      dir=`echo $file | sed -e s'|/[^/]*$||'`
1644      required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1645    done
1646  fi
1647fi
1648
1649# NeXT 3.2 uses the word "template" as a parameter for some 
1650# functions. GCC reports an invalid use of a reserved key word
1651# with the built-in functions. NeXT 3.2 includes the keyword
1652# volatile in the prototype for abort(). This conflicts with
1653# the built-in definition.
1654file=bsd/libc.h
1655if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1656  cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1657  chmod +w ${LIB}/$file 2>/dev/null
1658fi
1659if [ -r ${LIB}/$file ]; then
1660  echo Fixing $file
1661  sed -e '/\(.*template\)/s/template//' \
1662      -e '/extern.*volatile.*void.*abort/s/volatile//' ${LIB}/$file > ${LIB}/${file}.sed
1663  rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1664  if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1665    rm -f ${LIB}/$file
1666  else
1667    # Find any include directives that use "file".
1668    for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1669      dir=`echo $file | sed -e s'|/[^/]*$||'`
1670      required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1671    done
1672  fi
1673fi
1674
1675# NeXT 3.2 includes the keyword volatile in the abort() and 
1676# exit() function prototypes. That conflicts with the 
1677# built-in functions.
1678file=ansi/stdlib.h
1679if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1680  cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1681  chmod +w ${LIB}/$file 2>/dev/null
1682fi
1683if [ -r ${LIB}/$file ]; then
1684  echo Fixing $file
1685  sed -e '/extern.*volatile.*void.*exit/s/volatile//' \
1686      -e '/extern.*volatile.*void.*abort/s/volatile//' ${LIB}/$file > ${LIB}/${file}.sed
1687  rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1688  if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1689    rm -f ${LIB}/$file
1690  else
1691    # Find any include directives that use "file".
1692    for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1693      dir=`echo $file | sed -e s'|/[^/]*$||'`
1694      required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1695    done
1696  fi
1697fi
1698
1699# sys/utsname.h on Ultrix V4.[35] puts the declaration of uname before the
1700# definition of struct utsname, so the prototype (added by fixproto) causes
1701# havoc.
1702file=sys/utsname.h
1703if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1704  cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1705  chmod +w ${LIB}/$file 2>/dev/null
1706fi
1707
1708if [ -r ${LIB}/$file ] \
1709  && grep 'ULTRIX' ${LIB}/$file >/dev/null; then
1710  echo Fixing $file, uname declaration
1711  sed -e '/^[ 	]*extern[ 	]*int[ 	]*uname();$/i\
1712struct utsname;
1713'\
1714    ${LIB}/$file > ${LIB}/${file}.sed
1715  rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1716  if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1717    rm -f ${LIB}/$file
1718  else
1719    # Find any include directives that use "file".
1720    for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1721      dir=`echo $file | sed -e s'|/[^/]*$||'`
1722      required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1723    done
1724  fi
1725fi
1726
1727# sys/wait.h on AIX 3.2.5 puts the declaration of wait3 before the definition
1728# of struct rusage, so the prototype (added by fixproto) causes havoc.
1729file=sys/wait.h
1730if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1731  cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1732  chmod +w ${LIB}/$file 2>/dev/null
1733fi
1734
1735if [ -r ${LIB}/$file ] \
1736  && grep 'bos325,' ${LIB}/$file >/dev/null; then
1737  echo Fixing $file, wait3 declaration
1738  sed -e '/^extern pid_t wait3();$/i\
1739struct rusage;
1740'\
1741    ${LIB}/$file > ${LIB}/${file}.sed
1742  rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1743  if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1744    rm -f ${LIB}/$file
1745  else
1746    # Find any include directives that use "file".
1747    for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1748      dir=`echo $file | sed -e s'|/[^/]*$||'`
1749      required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1750    done
1751  fi
1752fi
1753
1754# NeXT 2.0 defines 'int wait(union wait*)', which conflicts with Posix.1.
1755# Note that version 3 of the NeXT system has wait.h in a different directory,
1756# so that this code won't do anything.  But wait.h in version 3 has a
1757# conditional, so it doesn't need this fix.  So everything is okay.
1758file=sys/wait.h
1759if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1760  cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1761  chmod +w ${LIB}/$file 2>/dev/null
1762fi
1763
1764if [ -r ${LIB}/$file ] \
1765  && grep 'wait[(]union wait' ${LIB}/$file >/dev/null; then
1766  echo Fixing $file, bad wait formal
1767  sed -e 's@wait(union wait@wait(void@' ${LIB}/$file > ${LIB}/${file}.sed
1768  rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1769  if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1770    rm -f ${LIB}/$file
1771  else
1772    # Find any include directives that use "file".
1773    for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1774      dir=`echo $file | sed -e s'|/[^/]*$||'`
1775      required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1776    done
1777  fi
1778fi
1779
1780# Don't use or define the name va_list in stdio.h.
1781# This is for ANSI and also to interoperate properly with gcc's varargs.h.
1782file=stdio.h
1783if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1784  cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1785  chmod +w ${LIB}/$file 2>/dev/null
1786  chmod a+r ${LIB}/$file 2>/dev/null
1787fi
1788
1789if [ -r ${LIB}/$file ]; then
1790  echo Fixing $file, use of va_list
1791  # Arrange for stdio.h to use stdarg.h to define __gnuc_va_list
1792  if egrep "__need___va_list" ${LIB}/$file >/dev/null 2>&1; then
1793    touch ${LIB}/${file}.sed
1794  else
1795    (echo "#define __need___va_list"
1796     echo "#include <stdarg.h>") > ${LIB}/${file}.sed
1797  fi
1798  # Use __gnuc_va_list in arg types in place of va_list.
1799  # On 386BSD use __gnuc_va_list instead of _VA_LIST_. We're hoping the
1800  # trailing parentheses and semicolon save all other systems from this.
1801  # Define __va_list__ (something harmless and unused) instead of va_list.
1802  # Don't claim to have defined va_list.
1803  sed -e 's@ va_list @ __gnuc_va_list @' \
1804      -e 's@ va_list)@ __gnuc_va_list)@' \
1805      -e 's@ _BSD_VA_LIST_));@ __gnuc_va_list));@' \
1806      -e 's@ _VA_LIST_));@ __gnuc_va_list));@' \
1807      -e 's@ va_list@ __va_list__@' \
1808      -e 's@\*va_list@*__va_list__@' \
1809      -e 's@ __va_list)@ __gnuc_va_list)@' \
1810      -e 's@GNUC_VA_LIST@GNUC_Va_LIST@' \
1811      -e 's@_NEED___VA_LIST@_NEED___Va_LIST@' \
1812      -e 's@VA_LIST@DUMMY_VA_LIST@' \
1813      -e 's@_Va_LIST@_VA_LIST@' \
1814    ${LIB}/$file >> ${LIB}/${file}.sed
1815  
1816  rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1817  if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1818    rm -f ${LIB}/$file
1819  else
1820    # Find any include directives that use "file".
1821    for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1822      dir=`echo $file | sed -e s'|/[^/]*$||'`
1823      required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1824    done
1825  fi
1826fi
1827
1828# Cancel out ansi_compat.h on Ultrix.  Replace it with empty file.
1829file=ansi_compat.h
1830if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1831  if grep -s ULTRIX $file; then
1832    echo "/* This file intentionally left blank.  */" > $LIB/$file
1833  fi
1834fi
1835
1836# parameter to atof not const on DECstation Ultrix V4.0 and NEWS-OS 4.2R.
1837# also get rid of bogus inline definitions in HP-UX 8.0
1838file=math.h
1839if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1840  cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1841  chmod +w ${LIB}/$file 2>/dev/null
1842  chmod a+r ${LIB}/$file 2>/dev/null
1843fi
1844
1845if [ -r ${LIB}/$file ]; then
1846  echo Fixing $file, non-const arg
1847  sed -e 's@atof(\([ 	]*char[ 	]*\*[^)]*\))@atof(const \1)@' \
1848      -e 's@inline int abs(int [a-z][a-z]*) {.*}@extern "C" int abs(int);@' \
1849      -e 's@inline double abs(double [a-z][a-z]*) {.*}@@' \
1850      -e 's@inline int sqr(int [a-z][a-z]*) {.*}@@' \
1851      -e 's@inline double sqr(double [a-z][a-z]*) {.*}@@' \
1852    ${LIB}/$file > ${LIB}/${file}.sed
1853  rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1854  if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1855    rm -f ${LIB}/$file
1856  else
1857    # Find any include directives that use "file".
1858    for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1859      dir=`echo $file | sed -e s'|/[^/]*$||'`
1860      required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1861    done
1862  fi
1863fi
1864
1865# fix bogus recursive stdlib.h in NEWS-OS 4.0C
1866file=stdlib.h
1867if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1868  cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1869  chmod +w ${LIB}/$file 2>/dev/null
1870  chmod a+r ${LIB}/$file 2>/dev/null
1871fi
1872
1873if [ -r ${LIB}/$file ]; then
1874  echo Fixing $file, recursive inclusion
1875  sed -e '/^#include <stdlib.h>/i\
1876#if 0
1877' \
1878      -e '/^#include <stdlib.h>/a\
1879#endif
1880' \
1881    ${LIB}/$file > ${LIB}/${file}.sed
1882  rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1883  if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1884    rm -f ${LIB}/$file
1885  else
1886    # Find any include directives that use "file".
1887    for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1888      dir=`echo $file | sed -e s'|/[^/]*$||'`
1889      required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1890    done
1891  fi
1892fi
1893
1894# Avoid nested comments on Ultrix 4.3.
1895file=rpc/svc.h
1896if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1897  mkdir ${LIB}/rpc 2>/dev/null
1898  cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1899  chmod +w ${LIB}/$file 2>/dev/null
1900  chmod a+r ${LIB}/$file 2>/dev/null
1901fi
1902
1903if [ -r ${LIB}/$file ]; then
1904  echo Fixing $file, nested comment
1905  sed -e 's@^\( \*	int protocol;  \)/\*@\1*/ /*@' \
1906    ${LIB}/$file > ${LIB}/$file.sed
1907  rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1908  if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1909    rm -f ${LIB}/$file
1910  else
1911    # Find any include directives that use "file".
1912    for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1913      dir=`echo $file | sed -e s'|/[^/]*$||'`
1914      required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1915    done
1916  fi
1917fi
1918
1919# This file in RISC/os uses /**/ to concatenate two tokens.
1920file=bsd43/bsd43_.h
1921if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1922  cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1923  chmod +w ${LIB}/$file 2>/dev/null
1924  chmod a+r ${LIB}/$file 2>/dev/null
1925fi
1926if [ -r ${LIB}/$file ]; then
1927  sed -e 's|/\*\*/|##|' ${LIB}/$file > ${LIB}/${file}.sed
1928  rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1929  if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1930    rm -f ${LIB}/$file
1931  else
1932    # Find any include directives that use "file".
1933    for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1934      dir=`echo $file | sed -e s'|/[^/]*$||'`
1935      required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1936    done
1937  fi
1938fi
1939
1940file=rpc/rpc.h
1941if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1942  mkdir ${LIB}/rpc 2>/dev/null
1943  cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1944  chmod +w ${LIB}/$file 2>/dev/null
1945  chmod a+r ${LIB}/$file 2>/dev/null
1946fi
1947
1948if [ -r ${LIB}/$file ]; then
1949  echo Fixing $file, nested comment
1950  sed -e 's@^\(/\*.*rpc/auth_des.h>.*\)/\*@\1*/ /*@' \
1951    ${LIB}/$file > ${LIB}/$file.sed
1952  rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1953  if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1954    rm -f ${LIB}/$file
1955  else
1956    # Find any include directives that use "file".
1957    for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1958      dir=`echo $file | sed -e s'|/[^/]*$||'`
1959      required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1960    done
1961  fi
1962fi
1963
1964# rpc/types.h on OSF1/2.0 is not C++ ready, even though NO_IMPLICIT_EXTERN_C
1965# is defined for the alpha.  The problem is the declaration of malloc.
1966file=rpc/types.h
1967if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1968  mkdir ${LIB}/rpc 2>/dev/null
1969  cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1970  chmod +w ${LIB}/$file 2>/dev/null
1971  chmod a+r ${LIB}/$file 2>/dev/null
1972fi
1973if [ -r ${LIB}/$file ]; then
1974  if egrep '"C"' ${LIB}/$file >/dev/null 2>&1; then
1975    true
1976  else
1977    echo Fixing $file
1978    echo '#ifdef __cplusplus
1979extern "C" {
1980#endif' > ${LIB}/${file}.sed
1981    cat ${LIB}/${file} >> ${LIB}/${file}.sed
1982    echo '#ifdef __cplusplus
1983}
1984#endif' >> ${LIB}/${file}.sed 
1985    rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1986    if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1987      rm -f ${LIB}/$file
1988    else
1989      # Find any include directives that use "file".
1990      for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1991        dir=`echo $file | sed -e s'|/[^/]*$||'`
1992        required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1993      done
1994    fi
1995  fi
1996fi
1997
1998# In limits.h, put #ifndefs around things that are supposed to be defined
1999# in float.h to avoid redefinition errors if float.h is included first.
2000# On HP/UX this patch does not work, because on HP/UX limits.h uses
2001# multi line comments and the inserted #endif winds up inside the
2002# comment.  Fortunately, HP/UX already uses #ifndefs in limits.h; if
2003# we find a #ifndef FLT_MIN we assume that all the required #ifndefs
2004# are there, and we do not add them ourselves.
2005# Also fix a nested comment problem in sys/limits.h on Motorola sysV68 R3V7.1
2006for file in limits.h sys/limits.h; do
2007  if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
2008    mkdir ${LIB}/sys 2>/dev/null
2009    cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
2010    chmod +w ${LIB}/$file 2>/dev/null
2011    chmod a+r ${LIB}/$file 2>/dev/null
2012  fi
2013
2014  if [ -r ${LIB}/$file ]; then
2015    if egrep 'ifndef[ 	]+FLT_MIN' ${LIB}/$file >/dev/null; then
2016      true
2017    else
2018      echo Fixing $file
2019      sed -e '/[ 	]FLT_MIN[ 	]/i\
2020#ifndef FLT_MIN
2021'\
2022	  -e '/[ 	]FLT_MIN[ 	]/a\
2023#endif
2024'\
2025	  -e '/[ 	]FLT_MAX[ 	]/i\
2026#ifndef FLT_MAX
2027'\
2028	  -e '/[ 	]FLT_MAX[ 	]/a\
2029#endif
2030'\
2031	  -e '/[ 	]FLT_DIG[ 	]/i\
2032#ifndef FLT_DIG
2033'\
2034	  -e '/[ 	]FLT_DIG[ 	]/a\
2035#endif
2036'\
2037	  -e '/[ 	]DBL_MIN[ 	]/i\
2038#ifndef DBL_MIN
2039'\
2040	  -e '/[ 	]DBL_MIN[ 	]/a\
2041#endif
2042'\
2043	  -e '/[ 	]DBL_MAX[ 	]/i\
2044#ifndef DBL_MAX
2045'\
2046	  -e '/[ 	]DBL_MAX[ 	]/a\
2047#endif
2048'\
2049	  -e '/[ 	]DBL_DIG[ 	]/i\
2050#ifndef DBL_DIG
2051'\
2052	  -e '/[ 	]DBL_DIG[ 	]/a\
2053#endif
2054'\
2055	  -e '/^\(\/\*#define	HUGE_VAL	3\.[0-9e+]* *\)\/\*/s//\1/'\
2056	${LIB}/$file > ${LIB}/${file}.sed
2057      rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
2058    fi
2059    if cmp $file ${LIB}/$file >/dev/null 2>&1; then
2060      echo Deleting ${LIB}/$file\; no fixes were needed.
2061      rm -f ${LIB}/$file
2062    else
2063      # Find any include directives that use "file".
2064      for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
2065        dir=`echo $file | sed -e s'|/[^/]*$||'`
2066        required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
2067      done
2068    fi
2069  fi
2070done
2071
2072# In math.h, put #ifndefs around things that might be defined in a gcc
2073# specific math-*.h file.
2074file=math.h
2075if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
2076  cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
2077  chmod +w ${LIB}/$file 2>/dev/null
2078  chmod a+r ${LIB}/$file 2>/dev/null
2079fi
2080
2081if [ -r ${LIB}/$file ]; then
2082  echo Fixing $file
2083  sed -e '/define[ 	]HUGE_VAL[ 	]/i\
2084#ifndef HUGE_VAL
2085'\
2086      -e '/define[ 	]HUGE_VAL[ 	]/a\
2087#endif
2088'\
2089    ${LIB}/$file > ${LIB}/${file}.sed
2090  rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
2091
2092  # In addition, copy the definition of DBL_MAX from float.h
2093  # if math.h requires one.  The Lynx math.h requires it.
2094  if egrep '#define[ 	]*HUGE_VAL[ 	]+DBL_MAX' $file >/dev/null 2>&1; then
2095    if egrep '#define[ 	]+DBL_MAX[ 	]+' $file >/dev/null 2>&1; then
2096      true;
2097    else
2098      dbl_max_def=`egrep 'define[ 	]+DBL_MAX[ 	]+.*' float.h 2>/dev/null`
2099      if [ "$dbl_max_def" != "" ]; then
2100        dbl_max_def=`echo $dbl_max_def | sed 's/.*define[ 	]*DBL_MAX[ 	]*//'`
2101        sed -e "/define[ 	]HUGE_VAL[ 	]DBL_MAX/s/DBL_MAX/$dbl_max_def/" \
2102          ${LIB}/$file > ${LIB}/${file}.sed
2103	rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
2104      fi
2105    fi
2106  fi
2107
2108  if cmp $file ${LIB}/$file >/dev/null 2>&1; then
2109    echo Deleting ${LIB}/$file\; no fixes were needed.
2110    rm -f ${LIB}/$file
2111  else
2112    # Find any include directives that use "file".
2113    for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
2114      dir=`echo $file | sed -e s'|/[^/]*$||'`
2115      required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
2116    done
2117  fi
2118fi
2119
2120# Remove erroneous parentheses in sym.h on Alpha OSF/1.
2121file=sym.h
2122if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
2123  cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
2124  chmod +w ${LIB}/$file 2>/dev/null
2125  chmod a+r ${LIB}/$file 2>/dev/null
2126fi
2127
2128if [ -r ${LIB}/$file ]; then
2129  echo Fixing $file
2130  sed -e 's/#ifndef(__mips64)/#ifndef __mips64/' \
2131    ${LIB}/$file > ${LIB}/${file}.sed
2132  rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
2133  if cmp $file ${LIB}/$file >/dev/null 2>&1; then
2134    rm -f ${LIB}/$file
2135  else
2136    # Find any include directives that use "file".
2137    for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
2138      dir=`echo $file | sed -e s'|/[^/]*$||'`
2139      required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
2140    done
2141  fi
2142fi
2143
2144# Fix return value of mem{ccpy,chr,cpy,set} and str{len,spn,cspn}
2145# in string.h on sysV68
2146# Correct the return type for strlen in string.h on Lynx.
2147# Correct the argument type for ffs in string.h on Alpha OSF/1 V2.0.
2148# Add missing const for strdup on OSF/1 V3.0.
2149# On sysV88 layout is slightly different.
2150file=string.h
2151if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
2152  cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
2153  chmod +w ${LIB}/$file 2>/dev/null
2154  chmod a+r ${LIB}/$file 2>/dev/null
2155fi
2156
2157if [ -r ${LIB}/$file ]; then
2158  echo Fixing $file, mem{ccpy,chr,cpy,set} and str{len,spn,cspn} return value
2159  sed -e 's/extern[ 	]*int[ 	]*strlen();/extern unsigned int strlen();/' \
2160      -e 's/extern[ 	]*int[ 	]*ffs[ 	]*(long);/extern int ffs(int);/' \
2161      -e 's/strdup(char \*s1);/strdup(const char *s1);/' \
2162      -e '/^extern char$/N' \
2163      -e 's/^extern char\(\n	\*memccpy(),\)$/extern void\1/'\
2164      -e '/^	strncmp(),$/N'\
2165      -e 's/^\(	strncmp()\),\n\(	strlen(),\)$/\1;\
2166extern unsigned int\
2167\2/'\
2168      -e '/^extern int$/N'\
2169      -e 's/^extern int\(\n	strlen(),\)/extern size_t\1/' \
2170    ${LIB}/$file > ${LIB}/${file}.sed
2171  rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
2172  if cmp $file ${LIB}/$file >/dev/null 2>&1; then
2173    rm -f ${LIB}/$file
2174  else
2175    # Find any include directives that use "file".
2176    for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
2177      dir=`echo $file | sed -e s'|/[^/]*$||'`
2178      required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
2179    done
2180  fi
2181fi
2182
2183# Correct the return type for strlen in strings.h in SunOS 4.
2184file=strings.h
2185if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
2186  cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
2187  chmod +w ${LIB}/$file 2>/dev/null
2188  chmod a+r ${LIB}/$file 2>/dev/null
2189fi
2190
2191if [ -r ${LIB}/$file ]; then
2192  echo Fixing $file
2193  sed -e 's/int[ 	]*strlen();/__SIZE_TYPE__ strlen();/' \
2194    ${LIB}/$file > ${LIB}/${file}.sed
2195  rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
2196  if cmp $file ${LIB}/$file >/dev/null 2>&1; then
2197    rm -f ${LIB}/$file
2198  else
2199    # Find any include directives that use "file".
2200    for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
2201      dir=`echo $file | sed -e s'|/[^/]*$||'`
2202      required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
2203    done
2204  fi
2205fi
2206
2207# Delete the '#define void int' line from curses.h on Lynx
2208file=curses.h
2209if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
2210  cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
2211  chmod +w ${LIB}/$file 2>/dev/null
2212  chmod a+r ${LIB}/$file 2>/dev/null
2213fi
2214
2215if [ -r ${LIB}/$file ]; then
2216  echo Fixing $file
2217  sed -e '/#[ 	]*define[ 	][ 	]*void[ 	]int/d' \
2218     ${LIB}/$file > ${LIB}/${file}.sed
2219  rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
2220  if cmp $file ${LIB}/$file >/dev/null 2>&1; then
2221    rm -f ${LIB}/$file
2222  else
2223    # Find any include directives that use "file".
2224    for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
2225      dir=`echo $file | sed -e s'|/[^/]*$||'`
2226      required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
2227    done
2228  fi
2229fi
2230
2231# Fix `typedef struct term;' on hppa1.1-hp-hpux9.
2232file=curses.h
2233if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
2234  cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
2235  chmod +w ${LIB}/$file 2>/dev/null
2236  chmod a+r ${LIB}/$file 2>/dev/null
2237fi
2238
2239if [ -r ${LIB}/$file ]; then
2240  echo Fixing $file
2241  sed -e 's/^[ 	]*typedef[ 	][ 	]*\(struct[ 	][ 	]*term[ 	]*;[ 	]*\)$/\1/' \
2242     ${LIB}/$file > ${LIB}/${file}.sed
2243  rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
2244  if cmp $file ${LIB}/$file >/dev/null 2>&1; then
2245    rm -f ${LIB}/$file
2246  else
2247    # Find any include directives that use "file".
2248    for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
2249      dir=`echo $file | sed -e s'|/[^/]*$||'`
2250      required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
2251    done
2252  fi
2253fi
2254
2255# For C++, avoid any typedef or macro definition of bool, and use the
2256# built in type instead.  HP/UX 10.20, at least, also has it
2257# in curses_colr/curses.h.
2258for file in curses.h curses_colr/curses.h ; do
2259  if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
2260    cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
2261    chmod +w ${LIB}/$file 2>/dev/null
2262    chmod a+r ${LIB}/$file 2>/dev/null
2263  fi
2264  if [ -r ${LIB}/$file ] && egrep bool ${LIB}/$file >/dev/null 2>&1; then
2265    echo Fixing $file, typedef or macro for bool is invalid in C++
2266    sed -e '/^#[ 	]*define[ 	][ 	]*bool[ 	][ 	]*char[ 	]*$/i\
2267#ifndef __cplusplus
2268'\
2269	-e '/^#[ 	]*define[ 	][ 	]*bool[ 	][ 	]*char[ 	]*$/a\
2270#endif
2271'\
2272	-e '/^typedef[ 	][ 	]*char[ 	][ 	]*bool[ 	]*;/i\
2273#ifndef __cplusplus
2274'\
2275	-e '/^typedef[ 	][ 	]*char[ 	][ 	]*bool[ 	]*;/a\
2276#endif
2277'\
2278	${LIB}/$file > ${LIB}/${file}.sed
2279    rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
2280    if cmp $file ${LIB}/$file >/dev/null 2>&1; then
2281      rm -f ${LIB}/$file
2282    else
2283      # Find any include directives that use "file".
2284      for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
2285        dir=`echo $file | sed -e s'|/[^/]*$||'`
2286        required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
2287      done
2288    fi
2289  fi
2290done
2291
2292# Fix incorrect S_IF* definitions on m88k-sysv3.
2293file=sys/stat.h
2294if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
2295  cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
2296  chmod +w ${LIB}/$file 2>/dev/null
2297  chmod a+r ${LIB}/$file 2>/dev/null
2298fi
2299
2300if [ -r ${LIB}/$file ]; then
2301  echo Fixing $file
2302  sed -e 's/^\(#define[ 	]*S_IS[A-Z]*(m)\)[ 	]*(m[ 	]*&[ 	]*\(S_IF[A-Z][A-Z][A-Z][A-Z]*\)[ 	]*)/\1 (((m)\&S_IFMT)==\2)/' \
2303      -e 's/^\(#define[ 	]*S_IS[A-Z]*(m)\)[ 	]*(m[ 	]*&[ 	]*\(0[0-9]*\)[ 	]*)/\1 (((m)\&S_IFMT)==\2)/' \
2304    ${LIB}/$file > ${LIB}/${file}.sed
2305  rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
2306  if cmp $file ${LIB}/$file >/dev/null 2>&1; then
2307    rm -f ${LIB}/$file
2308  else
2309    # Find any include directives that use "file".
2310    for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
2311      dir=`echo $file | sed -e s'|/[^/]*$||'`
2312      required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
2313    done
2314  fi
2315fi
2316
2317# Fix nested comments in Motorola's <limits.h> and <sys/limits.h>
2318for file in limits.h sys/limits.h; do
2319  if [ $target_canonical = m88k-motorola-sysv3 -o \
2320       $target_canonical = m68k-motorola-sysv ]; then
2321
2322    if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
2323      cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
2324      chmod +w ${LIB}/$file 2>/dev/null
2325      chmod a+r ${LIB}/$file 2>/dev/null
2326    fi
2327
2328    if [ -r ${LIB}/$file ]; then
2329      echo "Fixing nested comments in Motorola's $file"
2330      sed \
2331        -e 's@^\(#undef[ 	][ 	]*PIPE_BUF[ 	]*/\* max # bytes atomic in write to a\)$@\1 */@' \
2332        -e 's@\(/\*#define	HUGE_VAL	3.40282346638528860e+38 \)\(/\*error value returned by Math lib\*/\)$@\1*/ \2@'	\
2333  	  < ${LIB}/$file > ${LIB}/${file}.sed
2334      rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
2335      if cmp $file ${LIB}/$file >/dev/null 2>&1; then
2336        rm -f ${LIB}/$file
2337      fi
2338    fi
2339  fi
2340done
2341
2342# Fix getopt declarations in stdio.h and stdlib.h on Alpha OSF/1 and AIX.
2343for file in stdio.h stdlib.h; do
2344  if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
2345    cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
2346    chmod +w ${LIB}/$file 2>/dev/null
2347    chmod a+r ${LIB}/$file 2>/dev/null
2348  fi
2349
2350  if [ -r ${LIB}/$file ]; then
2351    echo Fixing $file, getopt declaration
2352    sed -e 's/getopt(int, char \*\[\],[ ]*char \*)/getopt(int, char *const[], const char *)/' \
2353      ${LIB}/$file > ${LIB}/${file}.sed
2354    rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
2355    if cmp $file ${LIB}/$file >/dev/null 2>&1; then
2356      rm -f ${LIB}/$file
2357    else
2358      # Find any include directives that use "file".
2359      for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
2360        dir=`echo $file | sed -e s'|/[^/]*$||'`
2361        required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
2362      done
2363    fi
2364  fi
2365done
2366
2367# Fix __page_size* declarations in pthread.h AIX 4.1.[34].
2368# The original ones fail if uninitialized externs are not common.
2369# This is the default for all ANSI standard C++ compilers.
2370for file in pthread.h; do
2371  if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
2372    cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
2373    chmod +w ${LIB}/$file 2>/dev/null
2374    chmod a+r ${LIB}/$file 2>/dev/null
2375  fi
2376
2377  if [ -r ${LIB}/$file ]; then
2378    echo Fixing $file, __page_size* declarations
2379    sed -e 's/^int __page_size/extern int __page_size/' \
2380      ${LIB}/$file > ${LIB}/${file}.sed
2381    rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
2382    if cmp $file ${LIB}/$file >/dev/null 2>&1; then
2383      rm -f ${LIB}/$file
2384    else
2385      # Find any include directives that use "file".
2386      for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
2387        dir=`echo $file | sed -e s'|/[^/]*$||'`
2388        required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
2389      done
2390    fi
2391  fi
2392done
2393
2394# Determine if we're on Interactive Unix 2.2 or later, in which case we
2395# need to fix some additional files.  This is the same test for ISC that
2396# Autoconf uses.
2397if test -d /etc/conf/kconfig.d \
2398    && grep _POSIX_VERSION /usr/include/sys/unistd.h >/dev/null 2>&1; then
2399  echo "Fixing ISC __STDC__ goof in several files..."
2400  for name in stdio.h math.h ctype.h sys/limits.h sys/fcntl.h sys/dirent.h; do
2401    echo $name
2402    if test -r ${LIB}/$name; then
2403      file=${LIB}/$name
2404    else
2405      file=${INPUT}/$name
2406    fi
2407    # On Interactive 2.2, certain traditional Unix definitions
2408    # (notably getc and putc in stdio.h) are omitted if __STDC__ is
2409    # defined, not just if _POSIX_SOURCE is defined.  This makes it
2410    # impossible to compile any nontrivial program except with -posix.
2411    sed \
2412's/!defined(__STDC__) && !defined(_POSIX_SOURCE)/!defined(_POSIX_SOURCE)/' \
2413	    < $file > ${LIB}/$name.
2414    mv ${LIB}/$name. ${LIB}/$name
2415  done
2416  
2417  echo "Fixing ISC fmod declaration"
2418  # This one's already been fixed for other things.
2419  file=${LIB}/math.h
2420  sed 's/fmod(double)/fmod(double, double)/' <$file >$file.
2421  mv $file. $file
2422  
2423  echo "Fixing nested comments in ISC <sys/limits.h>"
2424  file=sys/limits.h
2425  sed '/CHILD_MAX/s,/\* Max, Max,' < ${INPUT}/$file >${LIB}/$file.
2426  sed '/OPEN_MAX/s,/\* Max, Max,' < ${LIB}/$file. >${LIB}/$file
2427fi
2428
2429# These files in Sun OS 4.x use /**/ to concatenate tokens.
2430for file in sparc/asm_linkage.h sun3/asm_linkage.h sun3x/asm_linkage.h	\
2431	sun4/asm_linkage.h sun4c/asm_linkage.h sun4m/asm_linkage.h	\
2432	sun4c/debug/asm_linkage.h sun4m/debug/asm_linkage.h;
2433do
2434  if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
2435    cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
2436    chmod +w ${LIB}/$file 2>/dev/null
2437    chmod a+r ${LIB}/$file 2>/dev/null
2438  fi
2439
2440  if [ -r ${LIB}/$file ]; then
2441    sed -e 's|/\*\*/|##|g' ${LIB}/$file > ${LIB}/${file}.sed
2442    rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
2443    if cmp $file ${LIB}/$file >/dev/null 2>&1; then
2444      rm -f ${LIB}/$file
2445    else
2446      # Find any include directives that use "file".
2447      for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
2448        dir=`echo $file | sed -e s'|/[^/]*$||'`
2449        required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
2450      done
2451    fi
2452  fi
2453done
2454
2455# These files in ARM/RISCiX use /**/ to concatenate tokens.
2456for file in arm/as_support.h arm/mc_type.h arm/xcb.h dev/chardefmac.h \
2457	dev/ps_irq.h dev/screen.h dev/scsi.h sys/tty.h Xm.acorn/XmP.h
2458do
2459  if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
2460    cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
2461    chmod +w ${LIB}/$file 2>/dev/null
2462    chmod a+r ${LIB}/$file 2>/dev/null
2463  fi
2464
2465  if [ -r ${LIB}/$file ]; then
2466    sed -e 's|/\*\*/|##|g' ${LIB}/$file > ${LIB}/${file}.sed
2467    rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
2468    if cmp $file ${LIB}/$file >/dev/null 2>&1; then
2469      rm -f ${LIB}/$file
2470  else
2471    # Find any include directives that use "file".
2472    for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
2473      dir=`echo $file | sed -e s'|/[^/]*$||'`
2474      required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
2475    done
2476    fi
2477  fi
2478done
2479
2480# libm.a on m88k-motorola-sysv3 contains a stupid optimization for function
2481# hypot(), which returns the second argument without even looking at its value
2482# if the other is 0.0
2483# Another drawback is that fix-header doesn't fix fabs' prototype, and I have
2484#  no idea why.
2485file=math.h
2486if [ $target_canonical = m88k-motorola-sysv3 ]; then
2487  if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
2488    cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
2489    chmod +w ${LIB}/$file 2>/dev/null
2490    chmod a+r ${LIB}/$file 2>/dev/null
2491  fi
2492
2493  if [ -r ${LIB}/$file ]; then
2494    echo Fixing $file, fabs/hypot definition
2495    sed \
2496      -e 's/extern double floor(), ceil(), fmod(), fabs();/extern double floor(), ceil(), fmod(), fabs _PARAMS((double));/' \
2497      -e '/^extern double hypot();$/a\
2498\/* Workaround a stupid Motorola optimization if one\
2499   of x or y is 0.0 and the other is negative!  *\/\
2500#ifdef __STDC__\
2501static __inline__ double fake_hypot (double x, double y)\
2502#else\
2503static __inline__ double fake_hypot (x, y)\
2504	double x, y;\
2505#endif\
2506{\
2507	return fabs (hypot (x, y));\
2508}\
2509#define hypot	fake_hypot
2510' \
2511      ${LIB}/$file > ${LIB}/${file}.sed
2512    rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
2513    if cmp $file ${LIB}/$file >/dev/null 2>&1; then
2514      rm -f ${LIB}/$file
2515    fi
2516  fi
2517fi
2518
2519# math.h on SunOS 4 puts the declaration of matherr before the definition
2520# of struct exception, so the prototype (added by fixproto) causes havoc.
2521file=math.h
2522if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
2523  cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
2524  chmod +w ${LIB}/$file 2>/dev/null
2525  chmod a+r ${LIB}/$file 2>/dev/null
2526fi
2527
2528if [ -r ${LIB}/$file ]; then
2529  echo Fixing $file, matherr declaration
2530  sed -e '/^struct exception/,$b' \
2531      -e '/matherr/i\
2532struct exception;
2533'\
2534    ${LIB}/$file > ${LIB}/${file}.sed
2535  rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
2536  if cmp $file ${LIB}/$file >/dev/null 2>&1; then
2537    rm -f ${LIB}/$file
2538  else
2539    # Find any include directives that use "file".
2540    for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
2541      dir=`echo $file | sed -e s'|/[^/]*$||'`
2542      required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
2543    done
2544  fi
2545fi
2546
2547# sys/mman.h on HP/UX is not C++ ready, even though
2548# NO_IMPLICIT_EXTERN_C is defined on HP/UX.
2549for file in sys/mman.h; do
2550  if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
2551    cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
2552    chmod +w ${LIB}/$file 2>/dev/null
2553    chmod a+r ${LIB}/$file 2>/dev/null
2554  fi
2555
2556  if [ -r ${LIB}/$file ]; then
2557    if egrep '"C"' ${LIB}/$file >/dev/null 2>&1 \
2558       || egrep '__BEGIN_DECLS' ${LIB}/$file >/dev/null 2>&1; then
2559      true
2560    else
2561      echo Fixing $file
2562      echo '#ifdef __cplusplus
2563extern "C" {
2564#endif' > ${LIB}/${file}.sed
2565      cat ${LIB}/${file} >> ${LIB}/${file}.sed
2566      echo '#ifdef __cplusplus
2567}
2568#endif' >> ${LIB}/${file}.sed 
2569      rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
2570    fi
2571    if cmp $file ${LIB}/$file >/dev/null 2>&1; then
2572      rm -f ${LIB}/$file
2573    else
2574      # Find any include directives that use "file".
2575      for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
2576	dir=`echo $file | sed -e s'|/[^/]*$||'`
2577	required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
2578      done
2579    fi
2580  fi
2581done
2582
2583# Fix return value of sbrk in unistd.h on Alpha OSF/1 V2.0
2584file=unistd.h
2585if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
2586  cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
2587  chmod +w ${LIB}/$file 2>/dev/null
2588  chmod a+r ${LIB}/$file 2>/dev/null
2589fi
2590
2591if [ -r ${LIB}/$file ]; then
2592  echo Fixing $file, sbrk declaration
2593  sed -e 's/char\([ 	]*\*[	 ]*sbrk[ 	]*(\)/void\1/' \
2594    ${LIB}/$file > ${LIB}/${file}.sed
2595  rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
2596  if cmp $file ${LIB}/$file >/dev/null 2>&1; then
2597    rm -f ${LIB}/$file
2598  else
2599    # Find any include directives that use "file".
2600    for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
2601      dir=`echo $file | sed -e s'|/[^/]*$||'`
2602      required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
2603    done
2604  fi
2605fi
2606
2607# Fix <c_asm.h> on Digital UNIX V4.0:
2608# It contains a prototype for a DEC C internal asm() function, clashing with
2609# gcc's asm keyword.  So protect this with __DECC.
2610file=c_asm.h
2611if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
2612  cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
2613  chmod +w ${LIB}/$file 2>/dev/null
2614  chmod a+r ${LIB}/$file 2>/dev/null
2615fi
2616
2617if [ -r ${LIB}/$file ]; then
2618  echo Fixing $file
2619  sed -e '/^[ 	]*float[ 	]*fasm/i\
2620#ifdef __DECC
2621' \
2622      -e '/^[ 	]*#[ 	]*pragma[ 	]*intrinsic([ 	]*dasm/a\
2623#endif
2624' ${LIB}/$file > ${LIB}/${file}.sed
2625  rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
2626  if cmp $file ${LIB}/$file >/dev/null 2>&1; then
2627    rm ${LIB}/$file
2628  else
2629    # Find any include directives that use "file".
2630    for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
2631      dir=`echo $file | sed -e s'|/[^/]*$||'`
2632      required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
2633    done
2634  fi
2635fi
2636
2637# This file on SunOS 4 has a very large macro.  When the sed loop
2638# tries pull it in, it overflows the pattern space size of the SunOS
2639# sed (GNU sed does not have this problem).  Since the file does not
2640# require fixing, we remove it from the fixed directory.
2641file=sundev/ipi_error.h
2642if [ -r ${LIB}/$file ]; then
2643  echo "Removing incorrect fix to SunOS <sundev/ipi_error.h>"
2644  rm -f ${LIB}/$file
2645fi
2646
2647# Put cpp wrappers around these include files to avoid redeclaration
2648# errors during multiple inclusion on m88k-tektronix-sysv3.
2649for file in time.h sys/time.h ; do
2650  if egrep '#ifndef' $file >/dev/null 2>&1; then
2651    true
2652  else
2653    if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
2654      cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
2655      chmod +w ${LIB}/$file 2>/dev/null
2656    fi
2657    if [ -r ${LIB}/$file ]; then
2658      echo Fixing $file, to protect against multiple inclusion.
2659      cpp_wrapper=`echo $file | sed -e 's,\.,_,g' -e 's,/,_,g'`
2660      (echo "#ifndef __GCC_GOT_${cpp_wrapper}_"
2661      echo "#define __GCC_GOT_${cpp_wrapper}_"
2662      cat ${LIB}/${file}
2663      echo '#endif /* !_GCC_GOT_'${cpp_wrapper}_' */')  > ${LIB}/${file}.new
2664      rm -f ${LIB}/$file; mv ${LIB}/${file}.new ${LIB}/$file
2665    fi
2666  fi
2667done
2668
2669# Fix fcntl prototype in fcntl.h on LynxOS.
2670file=fcntl.h
2671if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
2672  cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
2673  chmod +w ${LIB}/$file 2>/dev/null
2674  chmod a+r ${LIB}/$file 2>/dev/null
2675fi
2676
2677if [ -r ${LIB}/$file ]; then
2678  echo Fixing $file, fcntl declaration
2679  sed -e 's/\(fcntl.*(int, int, \)int)/\1...)/' \
2680    ${LIB}/$file > ${LIB}/${file}.sed
2681  rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
2682  if cmp $file ${LIB}/$file >/dev/null 2>&1; then
2683    rm -f ${LIB}/$file
2684  else
2685    # Find any include directives that use "file".
2686    for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
2687      dir=`echo $file | sed -e s'|/[^/]*$||'`
2688      required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
2689    done
2690  fi
2691fi
2692
2693# Fix definitions of macros used by va-i960.h in VxWorks header file.
2694file=arch/i960/archI960.h
2695if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
2696  cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
2697  chmod +w ${LIB}/$file 2>/dev/null
2698  chmod a+r ${LIB}/$file 2>/dev/null
2699fi
2700
2701if [ -r ${LIB}/$file ]; then
2702  echo Fixing $file
2703  sed -e 's/__vsiz/__vxvsiz/' -e 's/__vali/__vxvali/' \
2704      -e s'/__vpad/__vxvpad/' -e 's/__alignof__/__vxalignof__/' \
2705    ${LIB}/$file > ${LIB}/${file}.sed
2706  rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
2707  if cmp $file ${LIB}/$file >/dev/null 2>&1; then
2708    rm -f ${LIB}/$file
2709  else
2710    # Find any include directives that use "file".
2711    for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
2712      dir=`echo $file | sed -e s'|/[^/]*$||'`
2713      required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
2714    done
2715  fi
2716fi
2717
2718# Make VxWorks header which is almost gcc ready fully gcc ready.
2719file=types/vxTypesBase.h
2720if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
2721  cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
2722  chmod +w ${LIB}/$file 2>/dev/null
2723  chmod a+r ${LIB}/$file 2>/dev/null
2724fi
2725
2726if [ -r ${LIB}/$file ]; then
2727  echo Fixing $file
2728  sed -e 's/#ifdef __GNUC_TYPEOF_FEATURE_BROKEN_USE_DEFAULT_UNTIL_FIXED__/#if 1/' \
2729      -e '/[ 	]size_t/i\
2730#ifndef _GCC_SIZE_T\
2731#define _GCC_SIZE_T
2732' \
2733      -e '/[ 	]size_t/a\
2734#endif
2735' \
2736      -e '/[ 	]ptrdiff_t/i\
2737#ifndef _GCC_PTRDIFF_T\
2738#define _GCC_PTRDIFF_T
2739' \
2740      -e '/[ 	]ptrdiff_t/a\
2741#endif
2742' \
2743      -e '/[ 	]wchar_t/i\
2744#ifndef _GCC_WCHAR_T\
2745#define _GCC_WCHAR_T
2746' \
2747      -e '/[ 	]wchar_t/a\
2748#endif
2749' \
2750    ${LIB}/$file > ${LIB}/${file}.sed
2751  rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
2752  if cmp $file ${LIB}/$file >/dev/null 2>&1; then
2753    rm -f ${LIB}/$file
2754  else
2755    # Find any include directives that use "file".
2756    for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
2757      dir=`echo $file | sed -e s'|/[^/]*$||'`
2758      required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
2759    done
2760  fi
2761fi
2762
2763# Fix VxWorks <sys/stat.h> to not require including <vxWorks.h>.
2764file=sys/stat.h
2765if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
2766  mkdir ${LIB}/sys 2>/dev/null
2767  cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
2768  chmod +w ${LIB}/$file 2>/dev/null
2769  chmod a+r ${LIB}/$file 2>/dev/null
2770fi
2771
2772if [ -r ${LIB}/$file ]; then
2773  if egrep '#include' ${LIB}/$file >/dev/null 2>&1; then
2774    :
2775  else
2776    if egrep 'ULONG' ${LIB}/$file >/dev/null 2>&1 \
2777       && [ -r types/vxTypesOld.h ]; then
2778      echo Fixing $file
2779      sed -e '/#define[ 	][ 	]*__INCstath/a\
2780#include <types/vxTypesOld.h>
2781' \
2782    ${LIB}/$file > ${LIB}/${file}.sed
2783      rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
2784    fi
2785  fi
2786  if cmp $file ${LIB}/$file >/dev/null 2>&1; then
2787    rm -f ${LIB}/$file
2788  else
2789    # Find any include directives that use "file".
2790    for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
2791      dir=`echo $file | sed -e s'|/[^/]*$||'`
2792      required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
2793    done
2794  fi
2795fi
2796
2797# Fix VxWorks <time.h> to not require including <vxTypes.h>.
2798file=time.h
2799if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
2800  mkdir ${LIB}/sys 2>/dev/null
2801  cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
2802  chmod +w ${LIB}/$file 2>/dev/null
2803  chmod a+r ${LIB}/$file 2>/dev/null
2804fi
2805
2806if [ -r ${LIB}/$file ]; then
2807  if egrep 'uint_t[ 	][ 	]*_clocks_per_sec' ${LIB}/$file >/dev/null 2>&1; then
2808    echo Fixing $file
2809    sed -e 's/uint_t/unsigned int/' ${LIB}/$file > ${LIB}/${file}.sed
2810    rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
2811  fi
2812  if cmp $file ${LIB}/$file >/dev/null 2>&1; then
2813    rm -f ${LIB}/$file
2814  else
2815    # Find any include directives that use "file".
2816    for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
2817      dir=`echo $file | sed -e s'|/[^/]*$||'`
2818      required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
2819    done
2820  fi
2821fi
2822    
2823# Fix hpux10.20 <sys/time.h> to avoid invalid forward decl
2824file=sys/time.h
2825if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
2826  mkdir ${LIB}/sys 2>/dev/null
2827  cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
2828  chmod +w ${LIB}/$file 2>/dev/null
2829  chmod a+r ${LIB}/$file 2>/dev/null
2830fi
2831
2832if [ -r ${LIB}/$file ]; then
2833  if egrep '^extern struct sigevent;' ${LIB}/$file >/dev/null 2>&1; then
2834    echo Fixing $file
2835    sed -e 's/^extern struct sigevent;/struct sigevent;/' ${LIB}/$file > ${LIB}/${file}.sed
2836    rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
2837  fi
2838  if cmp $file ${LIB}/$file >/dev/null 2>&1; then
2839    rm -f ${LIB}/$file
2840  else
2841    # Find any include directives that use "file".
2842    for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
2843      dir=`echo $file | sed -e s'|/[^/]*$||'`
2844      required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
2845    done
2846  fi
2847fi
2848    
2849# Another bad dependency in VxWorks 5.2 <time.h>.
2850file=time.h
2851if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
2852  mkdir ${LIB}/sys 2>/dev/null
2853  cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
2854  chmod +w ${LIB}/$file 2>/dev/null
2855  chmod a+r ${LIB}/$file 2>/dev/null
2856fi
2857
2858if [ -r ${LIB}/$file ]; then
2859  if egrep VOIDFUNCPTR ${LIB}/$file >/dev/null 2>&1; then
2860    if [ -r vxWorks.h ]; then
2861      echo Fixing $file
2862      sed -e '/VOIDFUNCPTR/i\
2863#ifndef __gcc_VOIDFUNCPTR_defined\
2864#ifdef __cplusplus\
2865typedef void (*__gcc_VOIDFUNCPTR) (...);\
2866#else\
2867typedef void (*__gcc_VOIDFUNCPTR) ();\
2868#endif\
2869#define __gcc_VOIDFUNCPTR_defined\
2870#endif
2871' \
2872	  -e 's/VOIDFUNCPTR/__gcc_VOIDFUNCPTR/g' \
2873	${LIB}/$file > ${LIB}/${file}.sed
2874      rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
2875    fi
2876  fi
2877  if cmp $file ${LIB}/$file >/dev/null 2>&1; then
2878    rm -f ${LIB}/$file
2879  else
2880    # Find any include directives that use "file".
2881    for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
2882      dir=`echo $file | sed -e s'|/[^/]*$||'`
2883      required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
2884    done
2885  fi
2886fi
2887    
2888# This file in A/UX 3.0.x/3.1.x contains an __asm directive for c89; gcc
2889# doesn't understand it.
2890file=sys/param.h
2891if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
2892  cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
2893  chmod +w ${LIB}/$file 2>/dev/null
2894  chmod a+r ${LIB}/$file 2>/dev/null
2895fi
2896
2897if [ -r ${LIB}/$file ]; then
2898  echo "Fixing __asm directive in sys/param.h"
2899  sed -e 's|#ifndef NOINLINE|#if !defined(NOINLINE) \&\& !defined(__GNUC__)|' \
2900    ${LIB}/$file > ${LIB}/${file}.sed
2901  rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
2902  if cmp $file ${LIB}/$file >/dev/null 2>&1; then
2903    rm -f ${LIB}/$file
2904  else
2905    # Find any include directives that use "file".
2906    for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
2907      dir=`echo $file | sed -e s'|/[^/]*$||'`
2908      required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
2909    done
2910  fi
2911fi
2912
2913# signal.h on SunOS defines signal using (), which causes trouble when
2914# compiling with g++ -pedantic.
2915for file in signal.h sys/signal.h; do
2916  if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
2917    cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
2918    chmod +w ${LIB}/$file 2>/dev/null
2919    chmod a+r ${LIB}/$file 2>/dev/null
2920  fi
2921
2922  if [ -r ${LIB}/$file ]; then
2923    echo "Checking for bad C++ prototype in $file"
2924    sed -e '/^void	(\*signal())();$/i\
2925  #ifdef __cplusplus\
2926  void	(*signal(...))(...);\
2927  #else
2928  ' \
2929	-e '/^void	(\*signal())();$/a\
2930  #endif
2931  ' \
2932      ${LIB}/$file > ${LIB}/${file}.sed
2933    rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
2934    if cmp $file ${LIB}/$file >/dev/null 2>&1; then
2935      rm -f ${LIB}/$file
2936    else
2937      # Find any include directives that use "file".
2938      for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
2939	dir=`echo $file | sed -e s'|/[^/]*$||'`
2940	required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
2941      done
2942    fi
2943  fi
2944done
2945
2946# sys/signal.h on some versions of AIX uses volatile in the typedef of
2947# sig_atomic_t, which causes gcc to generate a warning about duplicate
2948# volatile when a sig_atomic_t variable is declared volatile, as
2949# required by ANSI C.
2950file=sys/signal.h
2951if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
2952  cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
2953  chmod +w ${LIB}/$file 2>/dev/null
2954  chmod a+r ${LIB}/$file 2>/dev/null
2955fi
2956
2957if [ -r ${LIB}/$file ]; then
2958  echo "Checking for duplicate volatile in sys/signal.h"
2959  sed -e 's/typedef volatile int sig_atomic_t/typedef int sig_atomic_t/' \
2960    ${LIB}/$file > ${LIB}/${file}.sed
2961  rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
2962  if cmp $file ${LIB}/$file >/dev/null 2>&1; then
2963    rm -f ${LIB}/$file
2964  else
2965    # Find any include directives that use "file".
2966    for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
2967      dir=`echo $file | sed -e s'|/[^/]*$||'`
2968      required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
2969    done
2970  fi
2971fi
2972
2973# Some math.h files define struct exception, which conflicts with
2974# the class exception defined in the C++ file std/stdexcept.h.  We
2975# redefine it to __math_exception.  This is not a great fix, but I
2976# haven't been able to think of anything better.
2977file=math.h
2978if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
2979  cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
2980  chmod +w ${LIB}/$file 2>/dev/null
2981  chmod a+r ${LIB}/$file 2>/dev/null
2982fi
2983
2984if [ -r ${LIB}/$file ]; then
2985  echo Fixing $file, exception
2986  sed -e '/struct exception/i\
2987#ifdef __cplusplus\
2988#define exception __math_exception\
2989#endif
2990'\
2991      -e '/struct exception/a\
2992#ifdef __cplusplus\
2993#undef exception\
2994#endif
2995' ${LIB}/$file > ${LIB}/${file}.sed
2996  rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
2997  if egrep 'matherr()' ${LIB}/$file >/dev/null 2>&1; then
2998    sed -e '/matherr/i\
2999#ifdef __cplusplus\
3000#define exception __math_exception\
3001#endif
3002'\
3003        -e '/matherr/a\
3004#ifdef __cplusplus\
3005#undef exception\
3006#endif
3007' ${LIB}/$file > ${LIB}/${file}.sed
3008    rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
3009  fi
3010  if cmp $file ${LIB}/$file >/dev/null 2>&1; then
3011    rm -f ${LIB}/$file
3012  else
3013    # Find any include directives that use "file".
3014    for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
3015      dir=`echo $file | sed -e s'|/[^/]*$||'`
3016      required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
3017    done
3018  fi
3019fi
3020
3021# rpc/auth.h on SunOS needs prototypes for its AUTH->auth_ops function pointers
3022# Similarly for 
3023#   rpc/clnt.h CLIENT->clnt_ops
3024#   rpc/svc.h SVCXPRT->xp_ops
3025#   rpc/xdr.h XDR->xdr_ops
3026for file in rpc/auth.h rpc/clnt.h rpc/svc.h rpc/xdr.h; do
3027  # each file has a different name to replace, so if you add a file to
3028  # that list please update the following case statement.
3029  case "$file" in
3030    rpc/auth.h)
3031      prefix="ah_"
3032      ;;
3033    rpc/clnt.h)
3034      prefix="cl_"
3035      ;;
3036    rpc/svc.h)
3037      prefix="xp_"
3038      ;;
3039    rpc/xdr.h)
3040      prefix="x_"
3041      ;;
3042    *)
3043      # Oh Oh, we shouldn't be here
3044      exit 1;
3045      ;;
3046  esac
3047
3048  if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
3049    cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
3050    chmod +w ${LIB}/$file 2>/dev/null
3051    chmod a+r ${LIB}/$file 2>/dev/null
3052  fi
3053
3054  if [ -r ${LIB}/$file ]; then
3055    echo "Checking for needed C++ prototype in $file"
3056    sed -e 's/^\(.*\)\*\('$prefix'.*\)();\(.*\)/\
3057#ifdef __cplusplus\
3058\1*\2(...);\3\
3059#else\
3060\1*\2();\3\
3061#endif/g' \
3062     $LIB/$file > ${LIB}/${file}.sed
3063
3064    rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
3065    if cmp $file ${LIB}/$file >/dev/null 2>&1; then
3066      rm -f ${LIB}/$file
3067    else
3068      # Find any include directives that use "file".
3069      for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
3070	dir=`echo $file | sed -e s'|/[^/]*$||'`
3071	required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
3072      done
3073    fi
3074  fi
3075done
3076
3077# sys/lc_core.h on some versions of OSF1/4.x pollutes the namespace by
3078# defining regex.h types.  This causes C++ library build and usage failures.
3079# Fixing this correctly requires checking and modifying 3 files.
3080for file in reg_types.h regex.h sys/lc_core.h; do
3081  if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
3082    cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
3083    chmod +w ${LIB}/$file 2>/dev/null
3084    chmod a+r ${LIB}/$file 2>/dev/null
3085  fi
3086done
3087if [ -r ${LIB}/reg_types.h ]; then
3088  if egrep '} regex_t;' ${LIB}/reg_types.h >/dev/null 2>&1; then
3089    if [ -r ${LIB}/sys/lc_core.h ]; then
3090      if egrep ' regex_t ' ${LIB}/sys/lc_core.h >/dev/null 2>&1; then
3091        if [ -r ${LIB}/regex.h ]; then
3092	  if egrep '__regex_t' ${LIB}/regex.h >/dev/null 2>&1; then
3093	    true;
3094	  else
3095	    echo Fixing reg_types.h, regex.h, sys/lc_core.h
3096	    for file in reg_types.h sys/lc_core.h; do
3097	      sed -e 's/regex_t/__regex_t/g' \
3098	        -e 's/regoff_t/__regoff_t/g' \
3099		-e 's/regmatch_t/__regmatch_t/g' \
3100		${LIB}/$file > ${LIB}/${file}.sed
3101	      rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
3102	    done
3103	    sed -e '/#include <reg_types.h>/a\
3104typedef __regex_t	regex_t;\
3105typedef __regoff_t	regoff_t;\
3106typedef __regmatch_t	regmatch_t;\
3107' \
3108	      ${LIB}/regex.h > ${LIB}/regex.h.sed
3109	    rm -f ${LIB}/regex.h; mv ${LIB}/regex.h.sed ${LIB}/regex.h
3110	  fi
3111	fi
3112      fi
3113    fi
3114  fi
3115fi
3116for file in reg_types.h regex.h sys/lc_core.h; do
3117  if cmp $file ${LIB}/$file >/dev/null 2>&1; then
3118    rm -f ${LIB}/$file
3119  else
3120    # Find any include directives that use "file".
3121    for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
3122      dir=`echo $file | sed -e s'|/[^/]*$||'`
3123      required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
3124    done
3125  fi
3126done
3127
3128# AIX headers define NULL to be cast to a void pointer, which is illegal
3129# in ANSI C++.
3130for file in curses.h dbm.h locale.h stdio.h stdlib.h string.h time.h unistd.h sys/dir.h sys/param.h sys/types.h ; do
3131  if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
3132    cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
3133    chmod +w ${LIB}/$file 2>/dev/null
3134    chmod a+r ${LIB}/$file 2>/dev/null
3135  fi
3136
3137  if [ -r ${LIB}/$file ]; then
3138    if egrep '#.*define.*NULL.*void' ${LIB}/$file >/dev/null 2>&1; then
3139      echo "Fixing $file, bad NULL macro"
3140      sed -e 's/^#[ 	]*define[ 	]*NULL[ 	]*((void[ 	]*\*)0)/#define NULL 0/' \
3141        ${LIB}/$file > ${LIB}/${file}.sed
3142      rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
3143      if cmp $file ${LIB}/$file >/dev/null 2>&1; then
3144        rm -f ${LIB}/$file
3145      else
3146        # Find any include directives that use "file".
3147        for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
3148  	  dir=`echo $file | sed -e s'|/[^/]*$||'`
3149	  required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
3150        done
3151      fi
3152    fi
3153  fi
3154done
3155
3156# HPUX 10.x sys/param.h defines MAXINT which clashes with values.h
3157file=sys/param.h
3158base=`basename $file`
3159if [ -r ${LIB}/$file ]; then
3160  file_to_fix=${LIB}/$file
3161else
3162  if [ -r ${INPUT}/$file ]; then
3163    file_to_fix=${INPUT}/$file
3164  else
3165    file_to_fix=""
3166  fi
3167fi
3168if [ \! -z "$file_to_fix" ]; then
3169  echo Checking $file_to_fix
3170  sed -e '/^#[ 	]*define[ 	]*MAXINT[ 	]/i\
3171#ifndef MAXINT
3172'\
3173      -e '/^#[ 	]*define[ 	]*MAXINT[ 	]/a\
3174#endif
3175' $file_to_fix > /tmp/$base
3176  if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
3177    true
3178  else
3179    echo Fixed $file_to_fix
3180    rm -f ${LIB}/$file
3181    cp /tmp/$base ${LIB}/$file
3182    chmod a+r ${LIB}/$file
3183    # Find any include directives that use "file".
3184    for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[ 	]*"\([^"]*\)".*$/\1/'`; do
3185      dir=`echo $file | sed -e s'|/[^/]*$||'`
3186      required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
3187    done
3188  fi
3189  rm -f /tmp/$base
3190fi
3191
3192
3193# This loop does not appear to do anything, because it uses file
3194# rather than $file when setting target.  It also appears to be
3195# unnecessary, since the main loop processes symbolic links.
3196#if $LINKS; then
3197#  echo 'Making internal symbolic non-directory links'
3198#  cd ${INPUT}
3199#  files=`find . -type l -print`
3200#  for file in $files; do
3201#    dest=`ls -ld $file | sed -n 's/.*-> //p'`
3202#    if expr "$dest" : '[^/].*' > /dev/null; then    
3203#      target=${LIB}/`echo file | sed "s|[^/]*\$|$dest|"`
3204#      if [ -f $target ]; then
3205#        ln -s $dest ${LIB}/$file >/dev/null 2>&1
3206#      fi
3207#    fi
3208#  done
3209#fi
3210
3211# Make sure that any include files referenced using double quotes
3212# exist in the fixed directory.  This comes last since otherwise
3213# we might end up deleting some of these files "because they don't
3214# need any change."
3215set x $required
3216shift
3217while [ $# != 0 ]; do
3218  newreq=
3219  while [ $# != 0 ]; do
3220    # $1 is the directory to copy from, $2 is the unfixed file,
3221    # $3 is the fixed file name.
3222    cd ${INPUT}
3223    cd $1
3224    if [ -r $2 ] && [ ! -r $3 ]; then
3225      cp $2 $3 >/dev/null 2>&1 || echo "Can't copy $2"
3226      chmod +w $3 2>/dev/null
3227      chmod a+r $3 2>/dev/null
3228      echo Copied $2
3229      for include in `egrep '^[ 	]*#[ 	]*include[ 	]*"[^/]' $3 | sed -e 's/^[ 	]*#[ 	]*include[ 	]*"\([^"]*\)".*$/\1/'`; do
3230	dir=`echo $2 | sed -e s'|/[^/]*$||'`
3231	dir2=`echo $3 | sed -e s'|/[^/]*$||'`
3232	newreq="$newreq $1 $dir/$include $dir2/$include"
3233      done
3234    fi
3235    shift; shift; shift
3236  done
3237  set x $newreq
3238  shift
3239done
3240
3241echo 'Cleaning up DONE files.'
3242cd $LIB
3243find . -name DONE -exec rm -f '{}' ';'
3244
3245echo 'Removing unneeded directories:'
3246cd $LIB
3247files=`find . -type d \! -name '.' -print | sort -r`
3248for file in $files; do
3249  rmdir $LIB/$file > /dev/null 2>&1
3250done
3251
3252# # # # # # # # # # # # # # # # # # # # #
3253#
3254# End of for INPUT directories
3255#
3256done
3257#
3258# # # # # # # # # # # # # # # # # # # # #
3259
3260cd $ORIGDIR
3261rm -f include/assert.h
3262cp ${srcdir}/assert.h include/assert.h || exit 1
3263chmod a+r include/assert.h
3264
3265exit 0
3266