home *** CD-ROM | disk | FTP | other *** search
/ Dream 57 / Amiga_Dream_57.iso / Amiga / Programmation / c / Docs / cxref-1.4a.lha / cxref-cc < prev    next >
Encoding:
Text File  |  1997-06-22  |  2.8 KB  |  134 lines

  1. #!/bin/sh
  2.  
  3. # $Header: /home/amb/cxref/RCS/cxref-cc 1.1 1997/06/22 10:04:59 amb Exp $
  4. #
  5. # C Cross Referencing & Documentation tool. Version 1.4.
  6. #
  7. # C compiler replacement to compile program and cross reference it.
  8. #
  9. # Written by Andrew M. Bishop
  10. #
  11. # This file Copyright 1997 Andrew M. Bishop
  12. # It may be distributed under the GNU Public License, version 2, or
  13. # any higher version.  See section COPYING of the GNU Public license
  14. # for conditions under which this file may be redistributed.
  15. #
  16.  
  17. # Print a usage statement.
  18.  
  19. if [ $# = 0 ]; then
  20.  
  21.     echo 'Usage: cxref-cc filename [CC-arguments]'
  22.     echo ''
  23.     echo 'filename        : The name of the file to compile and cross reference.'
  24.     echo 'CC-arguments    : Any number of arguments to the C compiler.'
  25.     echo ''
  26.     echo 'The C compiler is called first, and if this succeeds then cxref is called.'
  27.     echo 'You require a .cxref file to contain the cxref options.'
  28.     exit 1
  29.  
  30. fi
  31.  
  32. # Check for a .cxref file.
  33.  
  34. if [ ! -r .cxref ]; then
  35.  
  36.     echo 'cxref-cc: Error a .cxref file is required to use cxref-cc.'
  37.     echo '          If you do not need any arguments an empty file will work.'
  38.     exit 1
  39.  
  40. fi
  41.  
  42. # The variables that we are going to use.
  43.  
  44. if [ "x$CXREFCC" = x ]; then
  45.     if [ "x$CC" = x ]; then
  46.         CXREFCC=gcc
  47.     else
  48.         CXREFCC=`echo $CC | cut -d' ' -f1`
  49.         if [ `basename $CXREFCC` = cxref-cc ]; then
  50.             echo 'cxref-cc: Warning the CC variable points to cxref-cc, set CXREFCC instead.'
  51.             CXREFCC=gcc
  52.         fi
  53.     fi
  54. fi
  55.  
  56. CXREF=cxref
  57.  
  58. FILE=
  59.  
  60. CXREFFLAGS=
  61.  
  62. # Call the C compiler
  63.  
  64. $CXREFCC "$@"
  65.  
  66. if [ ! $? = 0 ]; then
  67.  
  68.     echo 'cxref-cc: The C compiler failed with an error status.'
  69.     exit 1
  70.  
  71. fi
  72.  
  73. # Loop over the arguments and sort them out.
  74.  
  75. # Note: Need to be careful because "-DFOO=BAR BAR" loses its quotes on parameter
  76. #       expansion, but must be passed to cxref as a single word.  We need to use
  77. #       a word separator since there are no arrays, so we use ^M.
  78.  
  79. while [ ! $# = 0 ]; do
  80.  
  81.     case $1 in
  82.  
  83.         # The arguments to keep
  84.  
  85.         -D)
  86.             CXREFFLAGS="$CXREFFLAGS
  87. $1
  88. $2"; shift;;
  89.         -D*)
  90.             CXREFFLAGS="$CXREFFLAGS
  91. $1";;
  92.  
  93.         -U)
  94.             CXREFFLAGS="$CXREFFLAGS
  95. $1
  96. $2"; shift;;
  97.         -U*)
  98.             CXREFFLAGS="$CXREFFLAGS
  99. $1";;
  100.  
  101.         -I)
  102.             CXREFFLAGS="$CXREFFLAGS
  103. $1
  104. $2"; shift;;
  105.         -I*)
  106.             CXREFFLAGS="$CXREFFLAGS
  107. $1";;
  108.  
  109.         # The filename (perhaps)
  110.  
  111.         *.c)
  112.             if [ "x$FILE" = x -a -r $1 ]; then
  113.                 FILE=$1;
  114.             fi;;
  115.  
  116.         # The arguments to throw away
  117.  
  118.         *)
  119.             ;;
  120.  
  121.     esac
  122.     shift
  123.  
  124. done
  125.  
  126. # Check that a file was specified
  127.  
  128. if [ "x$FILE" = x ]; then
  129.  
  130.     echo 'cxref-cc : Warning no file specified on the command line'
  131.     exit 0
  132.  
  133. fi
  134.  
  135. # Call cxref
  136.  
  137. # Note: We are using ^M as the word separator, as detailed above.
  138.  
  139. IFS=
  140. export IFS
  141.  
  142. $CXREF
  143. $FILE$CXREFFLAGS
  144.