|
|
1.1 root 1: #! /bin/sh
2: #
3: # fixinc.sco -- Install modified versions of SCO system include
4: # files.
5: #
6: # Based on fixinc.svr4 script by Ron Guilmette ([email protected]) (SCO
7: # modifications by Ian Lance Taylor ([email protected])).
8: #
9: # This file is part of GNU CC.
10: #
11: # GNU CC is free software; you can redistribute it and/or modify
12: # it under the terms of the GNU General Public License as published by
13: # the Free Software Foundation; either version 2, or (at your option)
14: # any later version.
15: #
16: # GNU CC is distributed in the hope that it will be useful,
17: # but WITHOUT ANY WARRANTY; without even the implied warranty of
18: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19: # GNU General Public License for more details.
20: #
21: # You should have received a copy of the GNU General Public License
22: # along with GNU CC; see the file COPYING. If not, write to
23: # the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
24: #
25: # This script munges the native include files provided with SCO
26: # 3.2v4 systems so as to provide a reasonable namespace when
27: # compiling with gcc. The header files by default do not
28: # provide many essential definitions and declarations if
29: # __STDC__ is 1. This script modifies the header files to check
30: # for __STRICT_ANSI__ being defined instead. Once munged, the
31: # resulting new system include files are placed in a directory
32: # that GNU C will search *before* searching the /usr/include
33: # directory. This script should work properly for most SCO
34: # 3.2v4 systems. For other types of systems, you should use the
35: # `fixincludes' or the `fixinc.svr4' script instead.
36: #
37: # See README-fixinc for more information.
38:
39: # Directory containing the original header files.
40: INPUT=${2-${INPUT-/usr/include}}
41:
42: # Fail if no arg to specify a directory for the output.
43: if [ x$1 = x ]
44: then echo fixincludes: no output directory specified
45: exit 1
46: fi
47:
48: # Directory in which to store the results.
49: LIB=${1?"fixincludes: output directory not specified"}
50:
51: # Make sure it exists.
52: if [ ! -d $LIB ]; then
53: mkdir $LIB || exit 1
54: fi
55:
56: ORIG_DIR=`pwd`
57:
1.1.1.2 root 58: # Make LIB absolute if it is relative.
59: # Don't do this if not necessary, since may screw up automounters.
60: case $LIB in
61: /*)
62: ;;
63: *)
64: cd $LIB; LIB=`${PWDCMD-pwd}`
65: ;;
66: esac
1.1 root 67:
68: echo 'Building fixincludes in ' ${LIB}
69:
70: # Determine whether this filesystem has symbolic links.
71: if ln -s X $LIB/ShouldNotExist 2>/dev/null; then
72: rm -f $LIB/ShouldNotExist
73: LINKS=true
74: else
75: LINKS=false
76: fi
77:
78: echo 'Making directories:'
79: cd ${INPUT}
80: if $LINKS; then
81: files=`ls -LR | sed -n s/:$//p`
82: else
83: files=`find . -type d -print | sed '/^.$/d'`
84: fi
85: for file in $files; do
86: rm -rf $LIB/$file
87: if [ ! -d $LIB/$file ]
88: then mkdir $LIB/$file
89: fi
90: done
91:
92: # treetops gets an alternating list
93: # of old directories to copy
94: # and the new directories to copy to.
95: treetops="${INPUT} ${LIB}"
96:
97: if $LINKS; then
98: echo 'Making internal symbolic directory links'
99: for file in $files; do
100: dest=`ls -ld $file | sed -n 's/.*-> //p'`
101: if [ "$dest" ]; then
102: cwd=`pwd`
103: # In case $dest is relative, get to $file's dir first.
104: cd ${INPUT}
105: cd `echo ./$file | sed -n 's&[^/]*$&&p'`
106: # Check that the target directory exists.
107: # Redirections changed to avoid bug in sh on Ultrix.
108: (cd $dest) > /dev/null 2>&1
109: if [ $? = 0 ]; then
110: cd $dest
111: # X gets the dir that the link actually leads to.
112: x=`pwd`
113: # If link leads back into ${INPUT},
114: # make a similar link here.
115: if expr $x : "${INPUT}/.*" > /dev/null; then
116: # Y gets the actual target dir name, relative to ${INPUT}.
117: y=`echo $x | sed -n "s&${INPUT}/&&p"`
118: echo $file '->' $y ': Making link'
119: rm -fr ${LIB}/$file > /dev/null 2>&1
120: ln -s ${LIB}/$y ${LIB}/$file > /dev/null 2>&1
121: else
122: # If the link is to outside ${INPUT},
123: # treat this directory as if it actually contained the files.
124: # This line used to have $dest instead of $x.
125: # $dest seemed to be wrong for links found in subdirectories
126: # of ${INPUT}. Does this change break anything?
127: treetops="$treetops $x ${LIB}/$file"
128: fi
129: fi
130: cd $cwd
131: fi
132: done
133: fi
134:
135: set - $treetops
136: while [ $# != 0 ]; do
137: # $1 is an old directory to copy, and $2 is the new directory to copy to.
138: echo "Finding header files in $1:"
139: cd ${INPUT}
140: cd $1
141: files=`find . -name '*.h' -type f -print`
142: echo 'Checking header files:'
143: for file in $files; do
144: if egrep '!__STDC__' $file >/dev/null; then
145: if [ -r $file ]; then
146: cp $file $2/$file >/dev/null 2>&1 || echo "Can't copy $file"
147: chmod +w $2/$file
1.1.1.2 root 148: chmod a+r $2/$file
1.1 root 149:
150: # The following have been removed from the sed command below
151: # because it is more useful to leave these things in.
152: # The only reason to remove them was for -pedantic,
153: # which isn't much of a reason. -- rms.
154: # /^[ ]*#[ ]*ident/d
155:
156: sed -e '
157: s/!__STDC__/!defined (__STRICT_ANSI__)/g
158: ' $2/$file > $2/$file.sed
159: mv $2/$file.sed $2/$file
160: if cmp $file $2/$file >/dev/null 2>&1; then
161: rm $2/$file
1.1.1.2 root 162: else
163: echo Fixed $file
1.1 root 164: fi
165: fi
166: fi
167: done
168: shift; shift
169: done
170:
171: # Fix first broken decl of getcwd present on some svr4 systems.
172:
173: file=stdlib.h
174: base=`basename $file`
175: if [ -r ${LIB}/$file ]; then
176: file_to_fix=${LIB}/$file
177: else
178: if [ -r ${INPUT}/$file ]; then
179: file_to_fix=${INPUT}/$file
180: else
181: file_to_fix=""
182: fi
183: fi
184: if [ \! -z "$file_to_fix" ]; then
185: echo Checking $file_to_fix
186: sed -e 's/getcwd(char \{0,\}\*, int)/getcwd(char *, size_t)/' $file_to_fix > /tmp/$base
187: if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
1.1.1.2 root 188: true
1.1 root 189: else
190: echo Fixed $file_to_fix
191: rm -f ${LIB}/$file
192: cp /tmp/$base ${LIB}/$file
1.1.1.2 root 193: chmod a+r ${LIB}/$file
1.1 root 194: fi
195: rm -f /tmp/$base
196: fi
197:
198: # Fix second broken decl of getcwd present on some svr4 systems. Also
199: # fix the incorrect decl of profil present on some svr4 systems.
200:
201: file=unistd.h
202: base=`basename $file`
203: if [ -r ${LIB}/$file ]; then
204: file_to_fix=${LIB}/$file
205: else
206: if [ -r ${INPUT}/$file ]; then
207: file_to_fix=${INPUT}/$file
208: else
209: file_to_fix=""
210: fi
211: fi
212: if [ \! -z "$file_to_fix" ]; then
213: echo Checking $file_to_fix
214: sed -e 's/getcwd(char \*, int)/getcwd(char *, size_t)/' $file_to_fix \
215: | sed -e 's/profil(unsigned short \*, unsigned int, unsigned int, unsigned int)/profil(unsigned short *, size_t, int, unsigned)/' > /tmp/$base
216: if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
1.1.1.2 root 217: true
1.1 root 218: else
219: echo Fixed $file_to_fix
220: rm -f ${LIB}/$file
221: cp /tmp/$base ${LIB}/$file
1.1.1.2 root 222: chmod a+r ${LIB}/$file
1.1 root 223: fi
224: rm -f /tmp/$base
225: fi
226:
1.1.1.3 ! root 227: # Fix third broken decl of getcwd on SCO. Also fix incorrect decl of
! 228: # link.
! 229: file=prototypes.h
! 230: base=`basename $file`
! 231: if [ -r ${LIB}/$file ]; then
! 232: file_to_fix=${LIB}/$file
! 233: else
! 234: if [ -r ${INPUT}/$file ]; then
! 235: file_to_fix=${INPUT}/$file
! 236: else
! 237: file_to_fix=""
! 238: fi
! 239: fi
! 240: if [ \! -z "$file_to_fix" ]; then
! 241: echo Checking $file_to_fix
! 242: sed -e 's/getcwd(char \*, int)/getcwd(char *, size_t)/' $file_to_fix \
! 243: | sed -e 's/const int link(const char \*, char \*)/extern int link(const char *, const char *)/' > /tmp/$base
! 244: if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
! 245: true
! 246: else
! 247: echo Fixed $file_to_fix
! 248: rm -f ${LIB}/$file
! 249: cp /tmp/$base ${LIB}/$file
! 250: chmod a+r ${LIB}/$file
! 251: fi
! 252: rm -f /tmp/$base
! 253: fi
! 254:
1.1 root 255: # Fix an error in this file: the #if says _cplusplus, not the double
256: # underscore __cplusplus that it should be
257: file=tinfo.h
258: if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
259: mkdir ${LIB}/rpcsvc 2>/dev/null
260: cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
261: chmod +w ${LIB}/$file 2>/dev/null
1.1.1.2 root 262: chmod a+r ${LIB}/$file 2>/dev/null
1.1 root 263: fi
264:
265: if [ -r ${LIB}/$file ]; then
266: echo Fixing $file, __cplusplus macro
267: sed -e 's/[ ]_cplusplus/ __cplusplus/' ${LIB}/$file > ${LIB}/${file}.sed
268: rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
269: if cmp $file ${LIB}/$file >/dev/null 2>&1; then
270: rm ${LIB}/$file
271: fi
272: fi
273:
1.1.1.3 ! root 274: # Fix prototype declaration of utime in sys/times.h. In 3.2v4.0 the
! 275: # const is missing.
! 276: file=sys/times.h
! 277: if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
! 278: cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
! 279: chmod +w ${LIB}/$file 2>/dev/null
! 280: chmod a+r ${LIB}/$file 2>/dev/null
! 281: fi
! 282:
! 283: if [ -r ${LIB}/$file ]; then
! 284: echo Fixing $file, utime prototype
! 285: sed -e 's/(const char \*, struct utimbuf \*);/(const char *, const struct utimbuf *);/' ${LIB}/$file > ${LIB}/${file}.sed
! 286: rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
! 287: if cmp $file ${LIB}/$file >/dev/null 2>&1; then
! 288: rm ${LIB}/$file
! 289: fi
! 290: fi
! 291:
1.1 root 292: echo 'Removing unneeded directories:'
293: cd $LIB
294: files=`find . -type d -print | sort -r`
295: for file in $files; do
296: rmdir $LIB/$file > /dev/null 2>&1
297: done
298:
299: if $LINKS; then
300: echo 'Making internal symbolic non-directory links'
301: cd ${INPUT}
302: files=`find . -type l -print`
303: for file in $files; do
304: dest=`ls -ld $file | sed -n 's/.*-> //p'`
305: if expr "$dest" : '[^/].*' > /dev/null; then
306: target=${LIB}/`echo file | sed "s|[^/]*\$|$dest|"`
307: if [ -f $target ]; then
308: ln -s $dest ${LIB}/$file >/dev/null 2>&1
309: fi
310: fi
311: done
312: fi
313:
314: exit 0
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.