home *** CD-ROM | disk | FTP | other *** search
/ OpenStep 4.2J (Developer) / os42jdev.iso / NextDeveloper / Source / GNU / gcc / fixinc.dgux < prev    next >
Text File  |  1995-06-15  |  5KB  |  186 lines

  1. #!/bin/sh
  2. #
  3. # modified for dgux by hassey@dg-rtp.dg.com based on
  4. #
  5. #   fixinc.svr4  written by Ron Guilmette (rfg@ncd.com).
  6. #
  7. # This file is part of GNU CC.
  8. # GNU CC is free software; you can redistribute it and/or modify
  9. # it under the terms of the GNU General Public License as published by
  10. # the Free Software Foundation; either version 2, or (at your option)
  11. # any later version.
  12. # GNU CC is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. # GNU General Public License for more details.
  16. # You should have received a copy of the GNU General Public License
  17. # along with GNU CC; see the file COPYING.  If not, write to
  18. # the Free Software Foundation, 59 Temple Place - Suite 330,
  19. # Boston, MA 02111-1307, USA.
  20. #
  21. #
  22. #    See README-fixinc for more information.
  23.  
  24. # Directory containing the original header files.
  25. INPUT=${2-${INPUT-/usr/include}}
  26.  
  27. # Fail if no arg to specify a directory for the output.
  28. if [ x$1 = x ]
  29. then echo fixincludes: no output directory specified
  30. exit 1
  31. fi
  32.  
  33. # Directory in which to store the results.
  34. LIB=${1?"fixincludes: output directory not specified"}
  35.  
  36. # Make sure it exists.
  37. if [ ! -d $LIB ]; then
  38.   mkdir $LIB || exit 1
  39. fi
  40.  
  41. ORIG_DIR=`pwd`
  42.  
  43. # Make LIB absolute if it is relative.
  44. # Don't do this if not necessary, since may screw up automounters.
  45. case $LIB in
  46. /*)
  47.     ;;
  48. *)
  49.     cd $LIB; LIB=`${PWDCMD-pwd}`
  50.     ;;
  51. esac
  52.  
  53. echo 'Building fixincludes in ' ${LIB}
  54.  
  55. # Determine whether this filesystem has symbolic links.
  56. if ln -s X $LIB/ShouldNotExist 2>/dev/null; then
  57.   rm -f $LIB/ShouldNotExist
  58.   LINKS=true
  59. else
  60.   LINKS=false
  61. fi
  62.  
  63. echo 'Making directories:'
  64. cd ${INPUT}
  65. if $LINKS; then
  66.   files=`ls -LR | sed -n s/:$//p`
  67. else
  68.   files=`find . -type d -print | sed '/^.$/d'`
  69. fi
  70. for file in $files; do
  71.   rm -rf $LIB/$file
  72.   if [ ! -d $LIB/$file ]
  73.   then mkdir $LIB/$file
  74.   fi
  75. done
  76.  
  77. # treetops gets an alternating list
  78. # of old directories to copy
  79. # and the new directories to copy to.
  80. treetops="${INPUT} ${LIB}"
  81.  
  82. if $LINKS; then
  83.   echo 'Making internal symbolic directory links'
  84.   for file in $files; do
  85.     dest=`ls -ld $file | sed -n 's/.*-> //p'`
  86.     if [ "$dest" ]; then    
  87.       cwd=`pwd`
  88.       # In case $dest is relative, get to $file's dir first.
  89.       cd ${INPUT}
  90.       cd `echo ./$file | sed -n 's&[^/]*$&&p'`
  91.       # Check that the target directory exists.
  92.       # Redirections changed to avoid bug in sh on Ultrix.
  93.       (cd $dest) > /dev/null 2>&1
  94.       if [ $? = 0 ]; then
  95.     cd $dest
  96.     # X gets the dir that the link actually leads to.
  97.     x=`pwd`
  98.     # If link leads back into ${INPUT},
  99.     # make a similar link here.
  100.     if expr $x : "${INPUT}/.*" > /dev/null; then
  101.       # Y gets the actual target dir name, relative to ${INPUT}.
  102.       y=`echo $x | sed -n "s&${INPUT}/&&p"`
  103.       # DOTS is the relative path from ${LIB}/$file's dir back to ${LIB}.
  104.       dots=`echo "$file" |
  105.         sed -e 's@^./@@' -e 's@/./@/@g' -e 's@[^/][^/]*@..@g' -e 's@..$@@'`
  106.       echo $file '->' $dots$y ': Making link'
  107.       rm -fr ${LIB}/$file > /dev/null 2>&1
  108.       ln -s $dots$y ${LIB}/$file > /dev/null 2>&1
  109.     else
  110.       # If the link is to outside ${INPUT},
  111.       # treat this directory as if it actually contained the files.
  112. # This line used to have $dest instead of $x.
  113. # $dest seemed to be wrong for links found in subdirectories
  114. # of ${INPUT}.  Does this change break anything?
  115.       treetops="$treetops $x ${LIB}/$file"
  116.     fi
  117.       fi
  118.       cd $cwd
  119.     fi
  120.   done
  121. fi
  122.  
  123. # Completely replace <_int_varargs.h> with a file that defines
  124. # va_list and gnuc_va_list
  125.  
  126. file=_int_varargs.h
  127. if [ -r ${INPUT}/$file ]; then
  128.   echo Replacing $file
  129.   cat > ${LIB}/$file << EOF
  130. /* This file was generated by fixinc.dgux.  */
  131. #ifndef __INT_VARARGS_H
  132. #define __INT_VARARGS_H
  133.  
  134. #if defined(__m88k__) && defined (__DGUX__)
  135. #ifndef __GNUC_VA_LIST
  136. #define __GNUC_VA_LIST
  137. typedef struct
  138. {
  139.   int  __va_arg;        /* argument number */
  140.   int *__va_stk;        /* start of args passed on stack */
  141.   int *__va_reg;        /* start of args passed in regs */
  142. } __gnuc_va_list;
  143. #endif /* not __GNUC_VA_LIST */
  144. #endif /* 88k && dgux */
  145.  
  146. #ifndef _VA_LIST_
  147. #define _VA_LIST_
  148. typedef __gnuc_va_list va_list;
  149. #endif /* _VA_LIST_ */
  150.  
  151. #endif /* __INT_VARARGS_H */
  152.  
  153. EOF
  154.   chmod a+r ${LIB}/$file
  155. fi
  156.  
  157. echo 'Removing unneeded directories:'
  158. cd $LIB
  159. files=`find . -type d -print | sort -r`
  160. for file in $files; do
  161.   rmdir $LIB/$file > /dev/null 2>&1
  162. done
  163.  
  164. if $LINKS; then
  165.   echo 'Making internal symbolic non-directory links'
  166.   cd ${INPUT}
  167.   files=`find . -type l -print`
  168.   for file in $files; do
  169.     dest=`ls -ld $file | sed -n 's/.*-> //p'`
  170.     if expr "$dest" : '[^/].*' > /dev/null; then    
  171.       target=${LIB}/`echo file | sed "s|[^/]*\$|$dest|"`
  172.       if [ -f $target ]; then
  173.         ln -s $dest ${LIB}/$file >/dev/null 2>&1
  174.       fi
  175.     fi
  176.   done
  177. fi
  178.  
  179. cd ${ORIG_DIR}
  180.  
  181. exit 0
  182.  
  183.