OSDN Git Service

Use pwd if PWDCMD is not defined
[pf3gnuchains/gcc-fork.git] / gcc / fixinc.sco
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 # 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 where gcc sources (and sometimes special include files) live.
40 SRCDIR=${3-${SRCDIR-.}}
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 # Fix first broken decl of getcwd present on some svr4 systems.
175
176 file=stdlib.h
177 base=`basename $file`
178 if [ -r ${LIB}/$file ]; then
179   file_to_fix=${LIB}/$file
180 else
181   if [ -r ${INPUT}/$file ]; then
182     file_to_fix=${INPUT}/$file
183   else
184     file_to_fix=""
185   fi
186 fi
187 if [ \! -z "$file_to_fix" ]; then
188   echo Checking $file_to_fix
189   sed -e 's/getcwd(char \{0,\}\*, int)/getcwd(char *, size_t)/' $file_to_fix > /tmp/$base
190   if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
191     true
192   else
193     echo Fixed $file_to_fix
194     rm -f ${LIB}/$file
195     cp /tmp/$base ${LIB}/$file
196     chmod a+r ${LIB}/$file
197   fi
198   rm -f /tmp/$base
199 fi
200
201 # Fix second broken decl of getcwd present on some svr4 systems.  Also
202 # fix the incorrect decl of profil present on some svr4 systems.
203
204 file=unistd.h
205 base=`basename $file`
206 if [ -r ${LIB}/$file ]; then
207   file_to_fix=${LIB}/$file
208 else
209   if [ -r ${INPUT}/$file ]; then
210     file_to_fix=${INPUT}/$file
211   else
212     file_to_fix=""
213   fi
214 fi
215 if [ \! -z "$file_to_fix" ]; then
216   echo Checking $file_to_fix
217   sed -e 's/getcwd(char \*, int)/getcwd(char *, size_t)/' $file_to_fix \
218     | sed -e 's/profil(unsigned short \*, unsigned int, unsigned int, unsigned int)/profil(unsigned short *, size_t, int, unsigned)/' > /tmp/$base
219   if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
220     true
221   else
222     echo Fixed $file_to_fix
223     rm -f ${LIB}/$file
224     cp /tmp/$base ${LIB}/$file
225     chmod a+r ${LIB}/$file
226   fi
227   rm -f /tmp/$base
228 fi
229
230 # Fix an error in this file: the #if says _cplusplus, not the double
231 # underscore __cplusplus that it should be
232 file=tinfo.h
233 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
234   mkdir ${LIB}/rpcsvc 2>/dev/null
235   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
236   chmod +w ${LIB}/$file 2>/dev/null
237   chmod a+r ${LIB}/$file 2>/dev/null
238 fi
239
240 if [ -r ${LIB}/$file ]; then
241   echo Fixing $file, __cplusplus macro
242   sed -e 's/[   ]_cplusplus/ __cplusplus/' ${LIB}/$file > ${LIB}/${file}.sed
243   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
244   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
245     rm ${LIB}/$file
246   fi
247 fi
248
249 echo 'Removing unneeded directories:'
250 cd $LIB
251 files=`find . -type d -print | sort -r`
252 for file in $files; do
253   rmdir $LIB/$file > /dev/null 2>&1
254 done
255
256 if $LINKS; then
257   echo 'Making internal symbolic non-directory links'
258   cd ${INPUT}
259   files=`find . -type l -print`
260   for file in $files; do
261     dest=`ls -ld $file | sed -n 's/.*-> //p'`
262     if expr "$dest" : '[^/].*' > /dev/null; then    
263       target=${LIB}/`echo file | sed "s|[^/]*\$|$dest|"`
264       if [ -f $target ]; then
265         ln -s $dest ${LIB}/$file >/dev/null 2>&1
266       fi
267     fi
268   done
269 fi
270
271 cd ${ORIG_DIR}
272
273 echo 'Replacing <sys/byteorder.h>'
274 rm -f ${LIB}/sys/byteorder.h
275 cp ${SRCDIR}/byteorder.h ${LIB}/sys/byteorder.h
276
277 exit 0