home *** CD-ROM | disk | FTP | other *** search
/ Education Sampler 1992 [NeXTSTEP] / Education_1992_Sampler.iso / NeXT / GnuSource / cc-61.0.1 / cc / fixincludes < prev    next >
Text File  |  1991-05-31  |  9KB  |  379 lines

  1. #! /bin/sh
  2. # Install modified versions of certain ANSI-incompatible system header files
  3. # which are fixed to work correctly with ANSI C
  4. # and placed in a directory that GNU C will search.
  5. # This works properly on a Sun in system version 3.4;
  6. # for other versions, you had better check.
  7.  
  8. # Directory in which to store the results.
  9. LIB=${LIB-/usr/local/lib/gcc-include}
  10.  
  11. # Make sure it exists.
  12. if [ ! -d $LIB ]; then
  13.   mkdir $LIB || exit 1
  14. fi
  15.  
  16. # Determine whether this system has symbolic links.
  17. if ln -s X $LIB/ShouldNotExist 2>/dev/null; then
  18.   rm -f $LIB/ShouldNotExist
  19.   LINKS=true
  20. else
  21.   LINKS=false
  22. fi
  23.  
  24. echo 'Making directories:'
  25. cd /usr/include
  26. if $LINKS; then
  27.   files=`ls -LR | sed -n s/:$//p`
  28. else
  29.   files=`find . -type d -print | sed '/^.$/d'`
  30. fi
  31. for file in $files; do
  32.   rm -rf $LIB/$file
  33.   if [ ! -d $LIB/$file ]
  34.   then mkdir $LIB/$file
  35.   fi
  36. done
  37.  
  38. # treetops gets an alternating list
  39. # of old directories to copy
  40. # and the new directories to copy to.
  41. treetops="/usr/include ${LIB}"
  42.  
  43. if $LINKS; then
  44.   echo 'Making internal symbolic directory links'
  45.   for file in $files; do
  46.     dest=`ls -ld $file | sed -n 's/.*-> //p'`
  47.     if [ "$dest" ]; then    
  48.       cwd=`pwd`
  49.       # In case $dest is relative, get to $file's dir first.
  50.       cd /usr/include
  51.       cd `echo ./$file | sed -n 's&[^/]*$&&p'`
  52.       # Check that the target directory exists.
  53.       # Redirections changed to avoid bug in sh on Ultrix.
  54.       (cd $dest) > /dev/null 2>&1
  55.       if [ $? = 0 ]; then
  56.     cd $dest
  57.     # X gets the dir that the link actually leads to.
  58.     x=`pwd`
  59.     # If link leads back into /usr/include,
  60.     # make a similar link here.
  61.     if expr $x : '/usr/include/.*' > /dev/null; then
  62.       # Y gets the actual target dir name, relative to /usr/include.
  63.       y=`echo $x | sed -n 's&/usr/include/&&p'`
  64.       echo $file '->' $y ': Making link'
  65.       rm -fr ${LIB}/$file > /dev/null 2>&1
  66.       ln -s ${LIB}/$y ${LIB}/$file > /dev/null 2>&1
  67.     else
  68.       # If the link is to outside /usr/include,
  69.       # treat this directory as if it actually contained the files.
  70. # This line used to have $dest instead of $x.
  71. # $dest seemed to be wrong for links found in subdirectories
  72. # of /usr/include.  Does this change break anything?
  73.       treetops="$treetops $x ${LIB}/$file"
  74.     fi
  75.       fi
  76.       cd $cwd
  77.     fi
  78.   done
  79. fi
  80.  
  81. set - $treetops
  82. while [ $# != 0 ]; do
  83.   # $1 is an old directory to copy, and $2 is the new directory to copy to.
  84.   echo "Finding header files in $1:"
  85.   cd /usr/include
  86.   cd $1
  87.   files=`find . -name '*.h' -type f -print`
  88.   echo 'Checking header files:'
  89. # Note that BSD43_* are used on recent MIPS systems.
  90.   for file in $files; do
  91.     if egrep '[     ]_IO[A-Z]*\(|[     ]BSD43__IO[A-Z]*\(|#define._IO|#define.BSD43__IO|CTRL' $file > /dev/null; then
  92.       echo Fixing $file
  93.       if [ -r $file ]; then
  94.     cp $file $2/$file >/dev/null 2>&1    \
  95.     || echo "Can't copy $file"
  96.     chmod +w $2/$file
  97.     sed -e '
  98.                    :loop
  99.       /\\$/            N
  100.       /\\$/            b loop
  101.       /[     ]_IO[A-Z]*[     ]*(/    s/(\(.\),/('\''\1'\'',/
  102.       /[     ]BSD43__IO[A-Z]*[     ]*(/    s/(\(.\),/('\''\1'\'',/
  103.       /#define._IO/        s/'\''x'\''/x/g
  104.       /#define.BSD43__IO/        s/'\''x'\''/x/g
  105.       /[^A-Z]CTRL[     ]*(/    s/\([^'\'']\))/'\''\1'\'')/
  106.       /#define.CTRL/        s/'\''c'\''/c/g
  107.       /#define._CTRL/        s/'\''c'\''/c/g
  108.       /#define.BSD43_CTRL/        s/'\''c'\''/c/g
  109.     ' $2/$file > $2/$file.sed
  110.     mv $2/$file.sed $2/$file
  111.     if cmp $file $2/$file >/dev/null 2>&1; then
  112.        echo Deleting $2/$file\; no fixes were needed.
  113.        rm $2/$file
  114.     fi
  115.       fi
  116.     fi
  117.   done
  118.   shift; shift
  119. done
  120.  
  121. cd /usr/include
  122.  
  123. # Fix one other error in this file: a mismatched quote not inside a C comment.
  124. file=sundev/vuid_event.h
  125. if [ -r $file ]; then
  126.   if [ ! -r ${LIB}/$file ]; then
  127.     cp $file ${LIB}/$file >/dev/null 2>&1    \
  128.     || echo "Can't copy $file"
  129.     chmod +w ${LIB}/$file
  130.   fi
  131. fi
  132.  
  133. if [ -r ${LIB}/$file ]; then
  134.   echo Fixing $file comment
  135.   ex ${LIB}/$file <<EOF
  136.   g/doesn't/s/doesn't/does not/
  137.   wq
  138. EOF
  139.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  140.     echo Deleting ${LIB}/$file\; no fixes were needed.
  141.     rm ${LIB}/$file
  142.   fi
  143. fi
  144.  
  145. # Fix this Sun file to avoid intefering with stddef.h.
  146.  
  147. file=sys/stdtypes.h
  148. if [ -r $file ]; then
  149.   if [ ! -r ${LIB}/$file ]; then
  150.     cp $file ${LIB}/$file >/dev/null 2>&1    \
  151.     || echo "Can't copy $file"
  152.     chmod +w ${LIB}/$file
  153.   fi
  154. fi
  155.  
  156. if [ -r ${LIB}/$file ]; then
  157.   echo Fixing $file comment
  158.   ex ${LIB}/$file <<EOF
  159.   /size_t.*;/
  160.   i
  161. #ifndef _SIZE_T
  162. #define _SIZE_T
  163. .
  164.   /size_t/+1
  165.   i
  166. #endif
  167. .
  168.   /ptrdiff_t.*;/
  169.   i
  170. #ifndef _PTRDIFF_T
  171. #define _PTRDIFF_T
  172. .
  173.   /ptrdiff_t/+1
  174.   i
  175. #endif
  176. .
  177.   /wchar_t.*;/
  178.   i
  179. #ifndef _WCHAR_T
  180. #define _WCHAR_T
  181. .
  182.   /wchar_t/+1
  183.   i
  184. #endif
  185. .
  186.   wq
  187. EOF
  188.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  189.     echo Deleting ${LIB}/$file\; no fixes were needed.
  190.     rm ${LIB}/$file
  191.   fi
  192. fi
  193.  
  194. # Fix an error in this file: a missing semi-colon at the end of the statsswtch
  195. # structure definition.
  196. file=rpcsvc/rstat.h
  197. if [ -r $file ]; then
  198.   if [ ! -r ${LIB}/$file ]; then
  199.     cp $file ${LIB}/$file >/dev/null 2>&1    \
  200.     || echo "Can't copy $file"
  201.     chmod +w ${LIB}/$file
  202.   fi
  203. fi
  204.  
  205. if [ -r ${LIB}/$file ]; then
  206.   echo Fixing $file, definition of statsswtch
  207.   ex ${LIB}/$file <<EOF
  208.   g/boottime$/s//&;/
  209.   wq
  210. EOF
  211.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  212.     echo Deleting ${LIB}/$file\; no fixes were needed.
  213.     rm ${LIB}/$file
  214.   fi
  215. fi
  216.  
  217. # Fix an error in this file: a missing semi-colon at the end of the nodeent
  218. # structure definition.
  219. file=netdnet/dnetdb.h
  220. if [ -r $file ]; then
  221.   if [ ! -r ${LIB}/$file ]; then
  222.     cp $file ${LIB}/$file >/dev/null 2>&1    \
  223.     || echo "Can't copy $file"
  224.     chmod +w ${LIB}/$file
  225.   fi
  226. fi
  227.  
  228. if [ -r ${LIB}/$file ]; then
  229.   echo Fixing $file, definition of nodeent
  230.   ex ${LIB}/$file <<EOF
  231.   g/na_addr/s//&;/
  232.   wq
  233. EOF
  234.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  235.     echo Deleting ${LIB}/$file\; no fixes were needed.
  236.     rm ${LIB}/$file
  237.   fi
  238. fi
  239.  
  240. # Check for bad #ifdef line (in Ultrix 4.1)
  241.  
  242. file=sys/file.h
  243. if [ -r $file ]; then
  244.   if [ ! -r ${LIB}/$file ]; then
  245.     mkdir ${LIB}/rpcsvc 2>&-
  246.     cp $file ${LIB}/$file >/dev/null 2>&1    \
  247.     || echo "Can't copy $file"
  248.     chmod +w ${LIB}/$file
  249.   fi
  250. fi
  251.  
  252. if [ -r ${LIB}/$file ]; then
  253.   echo Fixing $file, bad \#ifdef line
  254.   ex ${LIB}/$file <<EOF
  255.   g/^#ifdef KERNEL && !defined/
  256.   s/#ifdef KERNEL && !defined/#if defined(KERNEL) \&\& !defined/
  257.   wq
  258. EOF
  259.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  260.     echo Deleting ${LIB}/$file\; no fixes were needed.
  261.     rm ${LIB}/$file
  262.   fi
  263. fi
  264.  
  265. # Check for superfluous `static' (in Ultrix 4.2)
  266.  
  267. file=machine/cpu.h
  268. if [ -r $file ]; then
  269.   if [ ! -r ${LIB}/$file ]; then
  270.     mkdir ${LIB}/machine 2>&-
  271.     cp $file ${LIB}/$file >/dev/null 2>&1    \
  272.     || echo "Can't copy $file"
  273.     chmod +w ${LIB}/$file
  274.   fi
  275. fi
  276.  
  277. if [ -r ${LIB}/$file ]; then
  278.   echo Fixing $file, superfluous static
  279.   ex ${LIB}/$file <<EOF
  280.   g/^static struct tlb_pid_state/
  281.   s/static//
  282.   wq
  283. EOF
  284.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  285.     echo Deleting ${LIB}/$file\; no fixes were needed.
  286.     rm ${LIB}/$file
  287.   else
  288. # This file has an alternative name, mips/cpu.h.  Fix that name, too.
  289.     if cmp machine/cpu.h mips/cpu.h > /dev/null 2>& 1; then
  290.       mkdir ${LIB}/mips 2>&-
  291.       ln ${LIB}/$file ${LIB}/mips/cpu.h 
  292.     fi
  293.   fi
  294. fi
  295.  
  296. # Deal with yet another challenge, this in X11/Xmu.h
  297. file=X11/Xmu.h
  298. if [ -r $file ]; then
  299.   if [ ! -r ${LIB}/$file ]; then
  300.     mkdir ${LIB}/X11 2>&-
  301.     cp $file ${LIB}/$file >/dev/null 2>&1    \
  302.     || echo "Can't copy $file"
  303.     chmod +w ${LIB}/$file
  304.   fi
  305. fi
  306.  
  307. if [ -r ${LIB}/$file ]; then
  308.   echo Fixing $file sprintf declaration
  309.   ex ${LIB}/$file <<EOF
  310.   /^extern char \*    sprintf();$/c
  311. #ifndef __STDC__
  312. extern char *    sprintf();
  313. #endif /* !defined __STDC__ */
  314. .
  315.   wq
  316. EOF
  317.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  318.     echo Deleting ${LIB}/$file\; no fixes were needed.
  319.     rm ${LIB}/$file
  320.   fi
  321. fi
  322.  
  323. # Check for missing ';' in struct
  324.  
  325. file=netinet/ip.h
  326. if [ -r $file ]; then
  327.   if [ ! -r ${LIB}/$file ]; then
  328.     mkdir ${LIB}/netinet 2>&-
  329.     sed -e '/^struct/,/^};/s/}$/};/' $file > ${LIB}/$file
  330.     cmp $file ${LIB}/$file >&- && rm -f ${LIB}/$file
  331.   fi
  332. fi
  333.  
  334. # Fix the CAT macro in memvar.h.
  335.  
  336. file=pixrect/memvar.h
  337. if [ -r $file ]; then
  338.   if [ ! -r ${LIB}/$file ]; then
  339.     mkdir ${LIB}/pixrect 2>&-
  340.     sed -e '/^#define.CAT(a,b)/ s/IDENT(a)b/a##b/g' $file > ${LIB}/$file
  341.     cmp $file ${LIB}/$file >&- && rm -f ${LIB}/$file
  342.   fi
  343. fi
  344.  
  345. # Check for yet more missing ';' in struct (in SunOS 4.0.x)
  346.  
  347. file=rpcsvc/rusers.h
  348. if [ -r $file ]; then
  349.   if [ ! -r ${LIB}/$file ]; then
  350.     mkdir ${LIB}/rpcsvc 2>&-
  351.     sed -e '/^struct/,/^};/s/_cnt$/_cnt;/' $file > ${LIB}/$file
  352.     cmp $file ${LIB}/$file >&- && rm -f ${LIB}/$file
  353.   fi
  354. fi
  355.  
  356. echo 'Removing unneeded directories:'
  357. cd $LIB
  358. files=`find . -type d -print | sort -r`
  359. for file in $files; do
  360.   rmdir $LIB/$file > /dev/null 2>&1
  361. done
  362.  
  363. if $LINKS; then
  364.   echo 'Making internal symbolic non-directory links'
  365.   cd /usr/include
  366.   files=`find . -type l -print`
  367.   for file in $files; do
  368.     dest=`ls -ld $file | sed -n 's/.*-> //p'`
  369.     if expr "$dest" : '[^/].*' > /dev/null; then    
  370.       target=${LIB}/`echo file | sed "s|[^/]*\$|$dest|"`
  371.       if [ -f $target ]; then
  372.         ln -s $dest ${LIB}/$file >/dev/null 2>&1
  373.       fi
  374.     fi
  375.   done
  376. fi
  377.  
  378. exit 0
  379.