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 # This file is part of GNU CC.
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)
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.
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, 59 Temple Place - Suite 330,
24 # Boston, MA 02111-1307, USA.
26 # This script munges the native include files provided with SCO
27 # 3.2v4 systems so as to provide a reasonable namespace when
28 # compiling with gcc. The header files by default do not
29 # provide many essential definitions and declarations if
30 # __STDC__ is 1. This script modifies the header files to check
31 # for __STRICT_ANSI__ being defined instead. Once munged, the
32 # resulting new system include files are placed in a directory
33 # that GNU C will search *before* searching the /usr/include
34 # directory. This script should work properly for most SCO
35 # 3.2v4 systems. For other types of systems, you should use the
36 # `fixincludes' or the `fixinc.svr4' script instead.
38 # See README-fixinc for more information.
40 # Directory containing the original header files.
41 INPUT=${2-${INPUT-/usr/include}}
43 # Fail if no arg to specify a directory for the output.
45 then echo fixincludes: no output directory specified
49 # Directory in which to store the results.
50 LIB=${1?"fixincludes: output directory not specified"}
52 # Make sure it exists.
53 if [ ! -d $LIB ]; then
59 # Make LIB absolute if it is relative.
60 # Don't do this if not necessary, since may screw up automounters.
65 cd $LIB; LIB=`${PWDCMD-pwd}`
69 echo 'Building fixincludes in ' ${LIB}
71 # Determine whether this filesystem has symbolic links.
72 if ln -s X $LIB/ShouldNotExist 2>/dev/null; then
73 rm -f $LIB/ShouldNotExist
79 echo 'Making directories:'
82 files=`ls -LR | sed -n s/:$//p`
84 files=`find . -type d -print | sed '/^.$/d'`
86 for file in $files; do
88 if [ ! -d $LIB/$file ]
93 # treetops gets an alternating list
94 # of old directories to copy
95 # and the new directories to copy to.
96 treetops="${INPUT} ${LIB}"
99 echo 'Making internal symbolic directory links'
100 for file in $files; do
101 dest=`ls -ld $file | sed -n 's/.*-> //p'`
104 # In case $dest is relative, get to $file's dir first.
106 cd `echo ./$file | sed -n 's&[^/]*$&&p'`
107 # Check that the target directory exists.
108 # Redirections changed to avoid bug in sh on Ultrix.
109 (cd $dest) > /dev/null 2>&1
112 # X gets the dir that the link actually leads to.
114 # If link leads back into ${INPUT},
115 # make a similar link here.
116 if expr $x : "${INPUT}/.*" > /dev/null; then
117 # Y gets the actual target dir name, relative to ${INPUT}.
118 y=`echo $x | sed -n "s&${INPUT}/&&p"`
119 echo $file '->' $y ': Making link'
120 rm -fr ${LIB}/$file > /dev/null 2>&1
121 ln -s ${LIB}/$y ${LIB}/$file > /dev/null 2>&1
123 # If the link is to outside ${INPUT},
124 # treat this directory as if it actually contained the files.
125 # This line used to have $dest instead of $x.
126 # $dest seemed to be wrong for links found in subdirectories
127 # of ${INPUT}. Does this change break anything?
128 treetops="$treetops $x ${LIB}/$file"
137 while [ $# != 0 ]; do
138 # $1 is an old directory to copy, and $2 is the new directory to copy to.
139 echo "Finding header files in $1:"
142 files=`find . -name '*.h' -type f -print`
143 echo 'Checking header files:'
144 for file in $files; do
145 if egrep '!__STDC__' $file >/dev/null; then
146 if [ -r $file ]; then
147 cp $file $2/$file >/dev/null 2>&1 || echo "Can't copy $file"
151 # The following have been removed from the sed command below
152 # because it is more useful to leave these things in.
153 # The only reason to remove them was for -pedantic,
154 # which isn't much of a reason. -- rms.
158 s/!__STDC__/!defined (__STRICT_ANSI__)/g
159 ' $2/$file > $2/$file.sed
160 mv $2/$file.sed $2/$file
161 if cmp $file $2/$file >/dev/null 2>&1; then
172 # Fix first broken decl of getcwd present on some svr4 systems.
175 base=`basename $file`
176 if [ -r ${LIB}/$file ]; then
177 file_to_fix=${LIB}/$file
179 if [ -r ${INPUT}/$file ]; then
180 file_to_fix=${INPUT}/$file
185 if [ \! -z "$file_to_fix" ]; then
186 echo Checking $file_to_fix
187 sed -e 's/getcwd(char \{0,\}\*, int)/getcwd(char *, size_t)/' $file_to_fix > /tmp/$base
188 if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
191 echo Fixed $file_to_fix
193 cp /tmp/$base ${LIB}/$file
194 chmod a+r ${LIB}/$file
199 # Fix second broken decl of getcwd present on some svr4 systems. Also
200 # fix the incorrect decl of profil present on some svr4 systems.
203 base=`basename $file`
204 if [ -r ${LIB}/$file ]; then
205 file_to_fix=${LIB}/$file
207 if [ -r ${INPUT}/$file ]; then
208 file_to_fix=${INPUT}/$file
213 if [ \! -z "$file_to_fix" ]; then
214 echo Checking $file_to_fix
215 sed -e 's/getcwd(char \*, int)/getcwd(char *, size_t)/' $file_to_fix \
216 | sed -e 's/profil(unsigned short \*, unsigned int, unsigned int, unsigned int)/profil(unsigned short *, size_t, int, unsigned)/' > /tmp/$base
217 if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
220 echo Fixed $file_to_fix
222 cp /tmp/$base ${LIB}/$file
223 chmod a+r ${LIB}/$file
228 # Fix third broken decl of getcwd on SCO. Also fix incorrect decl of
231 base=`basename $file`
232 if [ -r ${LIB}/$file ]; then
233 file_to_fix=${LIB}/$file
235 if [ -r ${INPUT}/$file ]; then
236 file_to_fix=${INPUT}/$file
241 if [ \! -z "$file_to_fix" ]; then
242 echo Checking $file_to_fix
243 sed -e 's/getcwd(char \*, int)/getcwd(char *, size_t)/' $file_to_fix \
244 | sed -e 's/const int link(const char \*, char \*)/extern int link(const char *, const char *)/' > /tmp/$base
245 if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
248 echo Fixed $file_to_fix
250 cp /tmp/$base ${LIB}/$file
251 chmod a+r ${LIB}/$file
256 # Fix an error in this file: the #if says _cplusplus, not the double
257 # underscore __cplusplus that it should be
259 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
260 mkdir ${LIB}/rpcsvc 2>/dev/null
261 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
262 chmod +w ${LIB}/$file 2>/dev/null
263 chmod a+r ${LIB}/$file 2>/dev/null
266 if [ -r ${LIB}/$file ]; then
267 echo Fixing $file, __cplusplus macro
268 sed -e 's/[ ]_cplusplus/ __cplusplus/' ${LIB}/$file > ${LIB}/${file}.sed
269 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
270 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
275 # Fix prototype declaration of utime in sys/times.h. In 3.2v4.0 the
278 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
279 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
280 chmod +w ${LIB}/$file 2>/dev/null
281 chmod a+r ${LIB}/$file 2>/dev/null
284 if [ -r ${LIB}/$file ]; then
285 echo Fixing $file, utime prototype
286 sed -e 's/(const char \*, struct utimbuf \*);/(const char *, const struct utimbuf *);/' ${LIB}/$file > ${LIB}/${file}.sed
287 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
288 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
293 echo 'Removing unneeded directories:'
295 files=`find . -type d -print | sort -r`
296 for file in $files; do
297 rmdir $LIB/$file > /dev/null 2>&1
301 echo 'Making internal symbolic non-directory links'
303 files=`find . -type l -print`
304 for file in $files; do
305 dest=`ls -ld $file | sed -n 's/.*-> //p'`
306 if expr "$dest" : '[^/].*' > /dev/null; then
307 target=${LIB}/`echo file | sed "s|[^/]*\$|$dest|"`
308 if [ -f $target ]; then
309 ln -s $dest ${LIB}/$file >/dev/null 2>&1