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 (rfg@ncd.com) (SCO |
---|
7 | # modifications by Ian Lance Taylor (ian@airs.com)). |
---|
8 | # |
---|
9 | # Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc. |
---|
10 | # |
---|
11 | # This file is part of GNU CC. |
---|
12 | # |
---|
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) |
---|
16 | # any later version. |
---|
17 | # |
---|
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. |
---|
22 | # |
---|
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. |
---|
27 | # |
---|
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. |
---|
39 | # |
---|
40 | # See README-fixinc for more information. |
---|
41 | |
---|
42 | # Directory containing the original header files. |
---|
43 | INPUT=${2-${INPUT-/usr/include}} |
---|
44 | |
---|
45 | # Fail if no arg to specify a directory for the output. |
---|
46 | if [ x$1 = x ] |
---|
47 | then echo fixincludes: no output directory specified |
---|
48 | exit 1 |
---|
49 | fi |
---|
50 | |
---|
51 | # Directory in which to store the results. |
---|
52 | LIB=${1?"fixincludes: output directory not specified"} |
---|
53 | |
---|
54 | # Make sure it exists. |
---|
55 | if [ ! -d $LIB ]; then |
---|
56 | mkdir $LIB || exit 1 |
---|
57 | fi |
---|
58 | |
---|
59 | ORIG_DIR=`pwd` |
---|
60 | |
---|
61 | # Make LIB absolute if it is relative. |
---|
62 | # Don't do this if not necessary, since may screw up automounters. |
---|
63 | case $LIB in |
---|
64 | /*) |
---|
65 | ;; |
---|
66 | *) |
---|
67 | cd $LIB; LIB=`${PWDCMD-pwd}` |
---|
68 | ;; |
---|
69 | esac |
---|
70 | |
---|
71 | echo 'Building fixincludes in ' ${LIB} |
---|
72 | |
---|
73 | # Determine whether this filesystem has symbolic links. |
---|
74 | if ln -s X $LIB/ShouldNotExist 2>/dev/null; then |
---|
75 | rm -f $LIB/ShouldNotExist |
---|
76 | LINKS=true |
---|
77 | else |
---|
78 | LINKS=false |
---|
79 | fi |
---|
80 | |
---|
81 | echo 'Making directories:' |
---|
82 | cd ${INPUT} |
---|
83 | if $LINKS; then |
---|
84 | files=`ls -LR | sed -n s/:$//p` |
---|
85 | else |
---|
86 | files=`find . -type d -print | sed '/^.$/d'` |
---|
87 | fi |
---|
88 | for file in $files; do |
---|
89 | rm -rf $LIB/$file |
---|
90 | if [ ! -d $LIB/$file ] |
---|
91 | then mkdir $LIB/$file |
---|
92 | fi |
---|
93 | done |
---|
94 | |
---|
95 | # treetops gets an alternating list |
---|
96 | # of old directories to copy |
---|
97 | # and the new directories to copy to. |
---|
98 | treetops="${INPUT} ${LIB}" |
---|
99 | |
---|
100 | if $LINKS; then |
---|
101 | echo 'Making internal symbolic directory links' |
---|
102 | for file in $files; do |
---|
103 | dest=`ls -ld $file | sed -n 's/.*-> //p'` |
---|
104 | if [ "$dest" ]; then |
---|
105 | cwd=`pwd` |
---|
106 | # In case $dest is relative, get to $file's dir first. |
---|
107 | cd ${INPUT} |
---|
108 | cd `echo ./$file | sed -n 's&[^/]*$&&p'` |
---|
109 | # Check that the target directory exists. |
---|
110 | # Redirections changed to avoid bug in sh on Ultrix. |
---|
111 | (cd $dest) > /dev/null 2>&1 |
---|
112 | if [ $? = 0 ]; then |
---|
113 | cd $dest |
---|
114 | # X gets the dir that the link actually leads to. |
---|
115 | x=`pwd` |
---|
116 | # If link leads back into ${INPUT}, |
---|
117 | # make a similar link here. |
---|
118 | if expr $x : "${INPUT}/.*" > /dev/null; then |
---|
119 | # Y gets the actual target dir name, relative to ${INPUT}. |
---|
120 | y=`echo $x | sed -n "s&${INPUT}/&&p"` |
---|
121 | echo $file '->' $y ': Making link' |
---|
122 | rm -fr ${LIB}/$file > /dev/null 2>&1 |
---|
123 | ln -s ${LIB}/$y ${LIB}/$file > /dev/null 2>&1 |
---|
124 | else |
---|
125 | # If the link is to outside ${INPUT}, |
---|
126 | # treat this directory as if it actually contained the files. |
---|
127 | # This line used to have $dest instead of $x. |
---|
128 | # $dest seemed to be wrong for links found in subdirectories |
---|
129 | # of ${INPUT}. Does this change break anything? |
---|
130 | treetops="$treetops $x ${LIB}/$file" |
---|
131 | fi |
---|
132 | fi |
---|
133 | cd $cwd |
---|
134 | fi |
---|
135 | done |
---|
136 | fi |
---|
137 | |
---|
138 | set - $treetops |
---|
139 | while [ $# != 0 ]; do |
---|
140 | # $1 is an old directory to copy, and $2 is the new directory to copy to. |
---|
141 | echo "Finding header files in $1:" |
---|
142 | cd ${INPUT} |
---|
143 | cd $1 |
---|
144 | files=`find . -name '*.h' -type f -print` |
---|
145 | echo 'Checking header files:' |
---|
146 | for file in $files; do |
---|
147 | if egrep '!__STDC__' $file >/dev/null; then |
---|
148 | if [ -r $file ]; then |
---|
149 | cp $file $2/$file >/dev/null 2>&1 || echo "Can't copy $file" |
---|
150 | chmod +w $2/$file |
---|
151 | chmod a+r $2/$file |
---|
152 | |
---|
153 | # The following have been removed from the sed command below |
---|
154 | # because it is more useful to leave these things in. |
---|
155 | # The only reason to remove them was for -pedantic, |
---|
156 | # which isn't much of a reason. -- rms. |
---|
157 | # /^[ ]*#[ ]*ident/d |
---|
158 | |
---|
159 | sed -e ' |
---|
160 | s/!__STDC__/!defined (__STRICT_ANSI__)/g |
---|
161 | ' $2/$file > $2/$file.sed |
---|
162 | mv $2/$file.sed $2/$file |
---|
163 | if cmp $file $2/$file >/dev/null 2>&1; then |
---|
164 | rm $2/$file |
---|
165 | else |
---|
166 | echo Fixed $file |
---|
167 | fi |
---|
168 | fi |
---|
169 | fi |
---|
170 | done |
---|
171 | shift; shift |
---|
172 | done |
---|
173 | |
---|
174 | # We shouldn't stay in the directory we just copied. |
---|
175 | cd ${INPUT} |
---|
176 | |
---|
177 | # Fix first broken decl of getcwd present on some svr4 systems. |
---|
178 | |
---|
179 | file=stdlib.h |
---|
180 | base=`basename $file` |
---|
181 | if [ -r ${LIB}/$file ]; then |
---|
182 | file_to_fix=${LIB}/$file |
---|
183 | else |
---|
184 | if [ -r ${INPUT}/$file ]; then |
---|
185 | file_to_fix=${INPUT}/$file |
---|
186 | else |
---|
187 | file_to_fix="" |
---|
188 | fi |
---|
189 | fi |
---|
190 | if [ \! -z "$file_to_fix" ]; then |
---|
191 | echo Checking $file_to_fix |
---|
192 | sed -e 's/getcwd(char \{0,\}\*, int)/getcwd(char *, size_t)/' $file_to_fix > /tmp/$base |
---|
193 | if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \ |
---|
194 | true |
---|
195 | else |
---|
196 | echo Fixed $file_to_fix |
---|
197 | rm -f ${LIB}/$file |
---|
198 | cp /tmp/$base ${LIB}/$file |
---|
199 | chmod a+r ${LIB}/$file |
---|
200 | fi |
---|
201 | rm -f /tmp/$base |
---|
202 | fi |
---|
203 | |
---|
204 | # Fix second broken decl of getcwd present on some svr4 systems. Also |
---|
205 | # fix the incorrect decl of profil present on some svr4 systems. |
---|
206 | |
---|
207 | file=unistd.h |
---|
208 | base=`basename $file` |
---|
209 | if [ -r ${LIB}/$file ]; then |
---|
210 | file_to_fix=${LIB}/$file |
---|
211 | else |
---|
212 | if [ -r ${INPUT}/$file ]; then |
---|
213 | file_to_fix=${INPUT}/$file |
---|
214 | else |
---|
215 | file_to_fix="" |
---|
216 | fi |
---|
217 | fi |
---|
218 | if [ \! -z "$file_to_fix" ]; then |
---|
219 | echo Checking $file_to_fix |
---|
220 | sed -e 's/getcwd(char \*, int)/getcwd(char *, size_t)/' $file_to_fix \ |
---|
221 | | sed -e 's/profil(unsigned short \*, unsigned int, unsigned int, unsigned int)/profil(unsigned short *, size_t, int, unsigned)/' > /tmp/$base |
---|
222 | if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \ |
---|
223 | true |
---|
224 | else |
---|
225 | echo Fixed $file_to_fix |
---|
226 | rm -f ${LIB}/$file |
---|
227 | cp /tmp/$base ${LIB}/$file |
---|
228 | chmod a+r ${LIB}/$file |
---|
229 | fi |
---|
230 | rm -f /tmp/$base |
---|
231 | fi |
---|
232 | |
---|
233 | # Fix third broken decl of getcwd on SCO. Also fix incorrect decl of |
---|
234 | # link. |
---|
235 | file=prototypes.h |
---|
236 | base=`basename $file` |
---|
237 | if [ -r ${LIB}/$file ]; then |
---|
238 | file_to_fix=${LIB}/$file |
---|
239 | else |
---|
240 | if [ -r ${INPUT}/$file ]; then |
---|
241 | file_to_fix=${INPUT}/$file |
---|
242 | else |
---|
243 | file_to_fix="" |
---|
244 | fi |
---|
245 | fi |
---|
246 | if [ \! -z "$file_to_fix" ]; then |
---|
247 | echo Checking $file_to_fix |
---|
248 | sed -e 's/getcwd(char \*, int)/getcwd(char *, size_t)/' $file_to_fix \ |
---|
249 | | sed -e 's/const int link(const char \*, char \*)/extern int link(const char *, const char *)/' > /tmp/$base |
---|
250 | if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \ |
---|
251 | true |
---|
252 | else |
---|
253 | echo Fixed $file_to_fix |
---|
254 | rm -f ${LIB}/$file |
---|
255 | cp /tmp/$base ${LIB}/$file |
---|
256 | chmod a+r ${LIB}/$file |
---|
257 | fi |
---|
258 | rm -f /tmp/$base |
---|
259 | fi |
---|
260 | |
---|
261 | # Fix an error in this file: the #if says _cplusplus, not the double |
---|
262 | # underscore __cplusplus that it should be |
---|
263 | file=tinfo.h |
---|
264 | if [ -r $file ] && [ ! -r ${LIB}/$file ]; then |
---|
265 | mkdir ${LIB}/rpcsvc 2>/dev/null |
---|
266 | cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file" |
---|
267 | chmod +w ${LIB}/$file 2>/dev/null |
---|
268 | chmod a+r ${LIB}/$file 2>/dev/null |
---|
269 | fi |
---|
270 | |
---|
271 | if [ -r ${LIB}/$file ]; then |
---|
272 | echo Fixing $file, __cplusplus macro |
---|
273 | sed -e 's/[ ]_cplusplus/ __cplusplus/' ${LIB}/$file > ${LIB}/${file}.sed |
---|
274 | rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file |
---|
275 | if cmp $file ${LIB}/$file >/dev/null 2>&1; then |
---|
276 | rm ${LIB}/$file |
---|
277 | fi |
---|
278 | fi |
---|
279 | |
---|
280 | # Fix prototype declaration of utime in sys/times.h. In 3.2v4.0 the |
---|
281 | # const is missing. |
---|
282 | file=sys/times.h |
---|
283 | if [ -r $file ] && [ ! -r ${LIB}/$file ]; then |
---|
284 | cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file" |
---|
285 | chmod +w ${LIB}/$file 2>/dev/null |
---|
286 | chmod a+r ${LIB}/$file 2>/dev/null |
---|
287 | fi |
---|
288 | |
---|
289 | if [ -r ${LIB}/$file ]; then |
---|
290 | echo Fixing $file, utime prototype |
---|
291 | sed -e 's/(const char \*, struct utimbuf \*);/(const char *, const struct utimbuf *);/' ${LIB}/$file > ${LIB}/${file}.sed |
---|
292 | rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file |
---|
293 | if cmp $file ${LIB}/$file >/dev/null 2>&1; then |
---|
294 | rm ${LIB}/$file |
---|
295 | fi |
---|
296 | fi |
---|
297 | |
---|
298 | # This function is borrowed from fixinclude.svr4 |
---|
299 | # The OpenServer math.h defines struct exception, which conflicts with |
---|
300 | # the class exception defined in the C++ file std/stdexcept.h. We |
---|
301 | # redefine it to __math_exception. This is not a great fix, but I |
---|
302 | # haven't been able to think of anything better. |
---|
303 | # |
---|
304 | # OpenServer's math.h declares abs as inline int abs... Unfortunately, |
---|
305 | # we blow over that one (with C++ linkage) and stick a new one in stdlib.h |
---|
306 | # with C linkage. So we eat the one out of math.h. |
---|
307 | file=math.h |
---|
308 | base=`basename $file` |
---|
309 | if [ -r ${LIB}/$file ]; then |
---|
310 | file_to_fix=${LIB}/$file |
---|
311 | else |
---|
312 | if [ -r ${INPUT}/$file ]; then |
---|
313 | file_to_fix=${INPUT}/$file |
---|
314 | else |
---|
315 | file_to_fix="" |
---|
316 | fi |
---|
317 | fi |
---|
318 | if [ \! -z "$file_to_fix" ]; then |
---|
319 | echo Checking $file_to_fix |
---|
320 | sed -e '/struct exception/i\ |
---|
321 | #ifdef __cplusplus\ |
---|
322 | #define exception __math_exception\ |
---|
323 | #endif'\ |
---|
324 | -e '/struct exception/a\ |
---|
325 | #ifdef __cplusplus\ |
---|
326 | #undef exception\ |
---|
327 | #endif' \ |
---|
328 | -e 's@inline int abs(int [a-z][a-z]*) {.*}@extern "C" int abs(int);@' \ |
---|
329 | $file_to_fix > /tmp/$base |
---|
330 | if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \ |
---|
331 | true |
---|
332 | else |
---|
333 | echo Fixed $file_to_fix |
---|
334 | rm -f ${LIB}/$file |
---|
335 | cp /tmp/$base ${LIB}/$file |
---|
336 | chmod a+r ${LIB}/$file |
---|
337 | fi |
---|
338 | rm -f /tmp/$base |
---|
339 | fi |
---|
340 | |
---|
341 | # |
---|
342 | # Also, the static functions lstat() and fchmod() in <sys/stat.h> |
---|
343 | # cause G++ grief since they're not wrapped in "if __cplusplus". |
---|
344 | # Fix that up now. |
---|
345 | # |
---|
346 | file=sys/stat.h |
---|
347 | if [ -r $file ] && [ ! -r ${LIB}/$file ]; then |
---|
348 | cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file" |
---|
349 | chmod +w ${LIB}/$file 2>/dev/null |
---|
350 | chmod a+r ${LIB}/$file 2>/dev/null |
---|
351 | fi |
---|
352 | |
---|
353 | if [ -r ${LIB}/$file ]; then |
---|
354 | echo Fixing $file, static definitions not C++-aware. |
---|
355 | sed -e '/^static int[ ]*/i\ |
---|
356 | #if __cplusplus\ |
---|
357 | extern "C"\ |
---|
358 | {\ |
---|
359 | #endif /* __cplusplus */ \ |
---|
360 | ' \ |
---|
361 | -e '/^}$/a\ |
---|
362 | #if __cplusplus\ |
---|
363 | }\ |
---|
364 | #endif /* __cplusplus */ \ |
---|
365 | ' ${LIB}/$file > ${LIB}/${file}.sed |
---|
366 | rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file |
---|
367 | if cmp $file ${LIB}/$file >/dev/null 2>&1; then |
---|
368 | rm -f ${LIB}/$file |
---|
369 | fi |
---|
370 | fi |
---|
371 | |
---|
372 | echo 'Removing unneeded directories:' |
---|
373 | cd $LIB |
---|
374 | files=`find . -type d -print | sort -r` |
---|
375 | for file in $files; do |
---|
376 | rmdir $LIB/$file > /dev/null 2>&1 |
---|
377 | done |
---|
378 | |
---|
379 | if $LINKS; then |
---|
380 | echo 'Making internal symbolic non-directory links' |
---|
381 | cd ${INPUT} |
---|
382 | files=`find . -type l -print` |
---|
383 | for file in $files; do |
---|
384 | dest=`ls -ld $file | sed -n 's/.*-> //p'` |
---|
385 | if expr "$dest" : '[^/].*' > /dev/null; then |
---|
386 | target=${LIB}/`echo file | sed "s|[^/]*\$|$dest|"` |
---|
387 | if [ -f $target ]; then |
---|
388 | ln -s $dest ${LIB}/$file >/dev/null 2>&1 |
---|
389 | fi |
---|
390 | fi |
---|
391 | done |
---|
392 | fi |
---|
393 | |
---|
394 | exit 0 |
---|