fixed copyright symbol
[AROS.git] / tools / cxref / cxref-cc
blob9a791576cc3b55640bf2817dd6d86629b00020a4
1 #!/bin/sh
3 # $Header$
5 # C Cross Referencing & Documentation tool. Version 1.5d.
7 # C compiler replacement to compile program and cross reference it.
9 # Written by Andrew M. Bishop
11 # This file Copyright 1997,98,2002 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.
17 # Print a usage statement.
19 if [ $# = 0 ]; then
21 echo 'Usage: cxref-cc filename [CC-arguments]' 1>&2
22 echo '' 1>&2
23 echo 'filename : The name of the file to compile and cross reference.' 1>&2
24 echo 'CC-arguments : Any number of arguments to the C compiler.' 1>&2
25 echo '' 1>&2
26 echo 'The C compiler is called first, and if this succeeds then cxref is called.' 1>&2
27 echo 'You require a .cxref file to contain the cxref options.' 1>&2
28 exit 1
32 # Check for a .cxref file.
34 if [ ! -r .cxref ]; then
36 echo 'cxref-cc: Error a .cxref file is required to use cxref-cc.' 1>&2
37 echo ' If you do not need any arguments an empty file will work.' 1>&2
38 exit 1
42 # The variables that we are going to use.
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.' 1>&2
51 CXREFCC=gcc
56 CXREF=cxref
58 FILE=
59 FILESTDIN=
61 CXREFFLAGS=
63 # Call the C compiler
65 $CXREFCC "$@"
67 if [ ! $? = 0 ]; then
69 echo 'cxref-cc: The C compiler failed with an error status.' 1>&2
70 exit 1
74 # Loop over the arguments and sort them out.
76 # Note: Need to be careful because "-DFOO=BAR BAR" loses its quotes on parameter
77 # expansion, but must be passed to cxref as a single word. We need to use
78 # a word separator since there are no arrays, so we use ^M.
80 while [ ! $# = 0 ]; do
82 case $1 in
84 # The arguments to keep
86 -D)
87 CXREFFLAGS="$CXREFFLAGS
89 $2"; shift;;
90 -D*)
91 CXREFFLAGS="$CXREFFLAGS
92 $1";;
94 -U)
95 CXREFFLAGS="$CXREFFLAGS
97 $2"; shift;;
98 -U*)
99 CXREFFLAGS="$CXREFFLAGS
100 $1";;
103 CXREFFLAGS="$CXREFFLAGS
105 $2"; shift;;
106 -I*)
107 CXREFFLAGS="$CXREFFLAGS
108 $1";;
110 # The filename (perhaps)
112 *.c)
113 if [ "x$FILE" = x -a -r $1 ]; then
114 FILE="
115 $1";
116 fi;;
119 FILESTDIN=yes;;
121 # The arguments to throw away
126 esac
127 shift
129 done
131 # Check that a real file was specified
133 if [ "x$FILE" = x ]; then
135 if [ "x$FILESTDIN" = xyes ]; then
136 echo 'cxref-cc: Cannot use stdin "-" as a filename with cxref-cc' 1>&2
137 else
138 echo 'cxref-cc: Warning no file specified on the command line' 1>&2
140 exit 0
144 # Call cxref
146 # Note: We are using ^M as the word separator, as detailed above.
148 IFS=
149 export IFS
151 $CXREF$FILE$CXREFFLAGS
153 if [ ! $? = 0 ]; then
155 echo 'cxref-cc: Cxref exited with error status' 1>&2
156 exit 1