3 # fixinc.sco -- Install modified versions of SCO system include
6 # Based on fixinc.svr4 script by Ron Guilmette (rfg@ncd.com) (SCO
7 # modifications by Ian Lance Taylor (ian@airs.com)).
9 # Copyright (C) 1995, 1996, 1997, 1998 Free Software Foundation, Inc.
11 # This file is part of GNU CC.
13 # GNU CC is free software; you can redistribute it and/or modify
14 # it under the terms of the GNU General Public License as published by
15 # the Free Software Foundation; either version 2, or (at your option)
18 # GNU CC is distributed in the hope that it will be useful,
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 # GNU General Public License for more details.
23 # You should have received a copy of the GNU General Public License
24 # along with GNU CC; see the file COPYING. If not, write to
25 # the Free Software Foundation, 59 Temple Place - Suite 330,
26 # Boston, MA 02111-1307, USA.
28 # This script munges the native include files provided with SCO
29 # 3.2v4 systems so as to provide a reasonable namespace when
30 # compiling with gcc. The header files by default do not
31 # provide many essential definitions and declarations if
32 # __STDC__ is 1. This script modifies the header files to check
33 # for __STRICT_ANSI__ being defined instead. Once munged, the
34 # resulting new system include files are placed in a directory
35 # that GNU C will search *before* searching the /usr/include
36 # directory. This script should work properly for most SCO
37 # 3.2v4 systems. For other types of systems, you should use the
38 # `fixincludes' or the `fixinc.svr4' script instead.
40 # See README-fixinc for more information.
42 # Fail if no arg to specify a directory for the output.
44 then echo fixincludes: no output directory specified
48 # Directory in which to store the results.
49 LIB=${1?"fixincludes: output directory not specified"}
51 # Make sure it exists.
52 if [ ! -d $LIB ]; then
56 ORIG_DIR=`${PWDCMD-pwd}`
58 # Make LIB absolute if it is relative.
59 # Don't do this if not necessary, since may screw up automounters.
64 cd $LIB; LIB=`${PWDCMD-pwd}`
68 echo 'Building fixincludes in ' ${LIB}
70 # Determine whether this filesystem has symbolic links.
71 if ln -s X $LIB/ShouldNotExist 2>/dev/null; then
72 rm -f $LIB/ShouldNotExist
78 echo 'Making directories:'
79 # Directory containing the original header files.
81 if [ $# -eq 0 ] ; then
87 for INPUT in ${INLIST} ; do
92 files=`ls -LR | sed -n s/:$//p`
94 files=`find . -type d -print | sed '/^.$/d'`
96 for file in $files; do
98 if [ ! -d $LIB/$file ]
103 # treetops gets an alternating list
104 # of old directories to copy
105 # and the new directories to copy to.
106 treetops="${INPUT} ${LIB}"
109 echo 'Making internal symbolic directory links'
110 for file in $files; do
111 dest=`ls -ld $file | sed -n 's/.*-> //p'`
114 # In case $dest is relative, get to $file's dir first.
116 cd `echo ./$file | sed -n 's&[^/]*$&&p'`
117 # Check that the target directory exists.
118 # Redirections changed to avoid bug in sh on Ultrix.
119 (cd $dest) > /dev/null 2>&1
122 # X gets the dir that the link actually leads to.
124 # If link leads back into ${INPUT},
125 # make a similar link here.
126 if expr $x : "${INPUT}/.*" > /dev/null; then
127 # Y gets the actual target dir name, relative to ${INPUT}.
128 y=`echo $x | sed -n "s&${INPUT}/&&p"`
129 echo $file '->' $y ': Making link'
130 rm -fr ${LIB}/$file > /dev/null 2>&1
131 ln -s ${LIB}/$y ${LIB}/$file > /dev/null 2>&1
133 # If the link is to outside ${INPUT},
134 # treat this directory as if it actually contained the files.
135 # This line used to have $dest instead of $x.
136 # $dest seemed to be wrong for links found in subdirectories
137 # of ${INPUT}. Does this change break anything?
138 treetops="$treetops $x ${LIB}/$file"
147 while [ $# != 0 ]; do
148 # $1 is an old directory to copy, and $2 is the new directory to copy to.
149 echo "Finding header files in $1:"
152 files=`find . -name '*.h' -type f -print`
153 echo 'Checking header files:'
154 for file in $files; do
155 if egrep '!__STDC__' $file >/dev/null; then
156 if [ -r $file ]; then
157 cp $file $2/$file >/dev/null 2>&1 || echo "Can't copy $file"
161 # The following have been removed from the sed command below
162 # because it is more useful to leave these things in.
163 # The only reason to remove them was for -pedantic,
164 # which isn't much of a reason. -- rms.
168 s/!__STDC__/!defined (__STRICT_ANSI__)/g
169 ' $2/$file > $2/$file.sed
170 mv $2/$file.sed $2/$file
171 if cmp $file $2/$file >/dev/null 2>&1; then
182 # We shouldn't stay in the directory we just copied.
185 # Fix first broken decl of getcwd present on some svr4 systems.
188 base=`basename $file`.$$
189 if [ -r ${LIB}/$file ]; then
190 file_to_fix=${LIB}/$file
192 if [ -r ${INPUT}/$file ]; then
193 file_to_fix=${INPUT}/$file
198 if [ \! -z "$file_to_fix" ]; then
199 echo Checking $file_to_fix
200 sed -e 's/getcwd(char \{0,\}\*, int)/getcwd(char *, size_t)/' $file_to_fix > /tmp/$base
201 if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
204 echo Fixed $file_to_fix
206 cp /tmp/$base ${LIB}/$file
207 chmod a+r ${LIB}/$file
212 # Fix second broken decl of getcwd present on some svr4 systems. Also
213 # fix the incorrect decl of profil present on some svr4 systems.
216 base=`basename $file`.$$
217 if [ -r ${LIB}/$file ]; then
218 file_to_fix=${LIB}/$file
220 if [ -r ${INPUT}/$file ]; then
221 file_to_fix=${INPUT}/$file
226 if [ \! -z "$file_to_fix" ]; then
227 echo Checking $file_to_fix
228 sed -e 's/getcwd(char \*, int)/getcwd(char *, size_t)/' $file_to_fix \
229 | sed -e 's/profil(unsigned short \*, unsigned int, unsigned int, unsigned int)/profil(unsigned short *, size_t, int, unsigned)/' > /tmp/$base
230 if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
233 echo Fixed $file_to_fix
235 cp /tmp/$base ${LIB}/$file
236 chmod a+r ${LIB}/$file
241 # Fix third broken decl of getcwd on SCO. Also fix incorrect decl of
244 base=`basename $file`.$$
245 if [ -r ${LIB}/$file ]; then
246 file_to_fix=${LIB}/$file
248 if [ -r ${INPUT}/$file ]; then
249 file_to_fix=${INPUT}/$file
254 if [ \! -z "$file_to_fix" ]; then
255 echo Checking $file_to_fix
256 sed -e 's/getcwd(char \*, int)/getcwd(char *, size_t)/' $file_to_fix \
257 | sed -e 's/const int link(const char \*, char \*)/extern int link(const char *, const char *)/' > /tmp/$base
258 if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
261 echo Fixed $file_to_fix
263 cp /tmp/$base ${LIB}/$file
264 chmod a+r ${LIB}/$file
269 # Fix an error in this file: the #if says _cplusplus, not the double
270 # underscore __cplusplus that it should be
272 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
273 mkdir ${LIB}/rpcsvc 2>/dev/null
274 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
275 chmod +w ${LIB}/$file 2>/dev/null
276 chmod a+r ${LIB}/$file 2>/dev/null
279 if [ -r ${LIB}/$file ]; then
280 echo Fixing $file, __cplusplus macro
281 sed -e 's/[ ]_cplusplus/ __cplusplus/' ${LIB}/$file > ${LIB}/${file}.sed
282 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
283 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
288 # Fix prototype declaration of utime in sys/times.h. In 3.2v4.0 the
291 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
292 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
293 chmod +w ${LIB}/$file 2>/dev/null
294 chmod a+r ${LIB}/$file 2>/dev/null
297 if [ -r ${LIB}/$file ]; then
298 echo Fixing $file, utime prototype
299 sed -e 's/(const char \*, struct utimbuf \*);/(const char *, const struct utimbuf *);/' ${LIB}/$file > ${LIB}/${file}.sed
300 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
301 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
306 # This function is borrowed from fixinclude.svr4
307 # The OpenServer math.h defines struct exception, which conflicts with
308 # the class exception defined in the C++ file std/stdexcept.h. We
309 # redefine it to __math_exception. This is not a great fix, but I
310 # haven't been able to think of anything better.
312 # OpenServer's math.h declares abs as inline int abs... Unfortunately,
313 # we blow over that one (with C++ linkage) and stick a new one in stdlib.h
314 # with C linkage. So we eat the one out of math.h.
316 base=`basename $file`.$$
317 if [ -r ${LIB}/$file ]; then
318 file_to_fix=${LIB}/$file
320 if [ -r ${INPUT}/$file ]; then
321 file_to_fix=${INPUT}/$file
326 if [ \! -z "$file_to_fix" ]; then
327 echo Checking $file_to_fix
328 sed -e '/struct exception/i\
330 #define exception __math_exception\
332 -e '/struct exception/a\
336 -e 's@inline int abs(int [a-z][a-z]*) {.*}@extern "C" int abs(int);@' \
337 $file_to_fix > /tmp/$base
338 if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
341 echo Fixed $file_to_fix
343 cp /tmp/$base ${LIB}/$file
344 chmod a+r ${LIB}/$file
350 # Also, the static functions lstat() and fchmod() in <sys/stat.h>
351 # cause G++ grief since they're not wrapped in "if __cplusplus".
355 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
356 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
357 chmod +w ${LIB}/$file 2>/dev/null
358 chmod a+r ${LIB}/$file 2>/dev/null
361 if [ -r ${LIB}/$file ]; then
362 echo Fixing $file, static definitions not C++-aware.
363 sed -e '/^static int[ ]*/i\
367 #endif /* __cplusplus */ \
372 #endif /* __cplusplus */ \
373 ' ${LIB}/$file > ${LIB}/${file}.sed
374 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
375 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
380 # This fix has the regex modified from the from fixinc.wrap
381 # Avoid the definition of the bool type in the following files when using
382 # g++, since it's now an official type in the C++ language.
383 for file in term.h tinfo.h
385 if [ -r $INPUT/$file ]; then
386 echo Checking $INPUT/$file
388 if grep "typedef$w.*char$w.*bool$w*;" $INPUT/$file >/dev/null
392 cat <<__EOF__ >$LIB/$file
393 #ifndef _CURSES_H_WRAPPER
395 # define bool __curses_bool_t
397 #include_next <$file>
401 #define _CURSES_H_WRAPPER
402 #endif /* _CURSES_H_WRAPPER */
404 # Define _CURSES_H_WRAPPER at the end of the wrapper, not the start,
405 # so that if #include_next gets another instance of the wrapper,
406 # this will follow the #include_next chain until we arrive at
407 # the real system include file.
413 echo 'Removing unneeded directories:'
415 files=`find . -type d -print | sort -r`
416 for file in $files; do
417 rmdir $LIB/$file > /dev/null 2>&1
421 echo 'Making internal symbolic non-directory links'
423 files=`find . -type l -print`
424 for file in $files; do
425 dest=`ls -ld $file | sed -n 's/.*-> //p'`
426 if expr "$dest" : '[^/].*' > /dev/null; then
427 target=${LIB}/`echo file | sed "s|[^/]*\$|$dest|"`
428 if [ -f $target ]; then
429 ln -s $dest ${LIB}/$file >/dev/null 2>&1
437 if [ x${INSTALL_ASSERT_H} != x ]
440 rm -f include/assert.h
441 cp ${srcdir}/assert.h include/assert.h || exit 1
442 chmod a+r include/assert.h