]> Dogcows Code - chaz/yoink/blob - build/compile.sh
testing new non-autotools build system
[chaz/yoink] / build / compile.sh
1 #!/bin/sh
2 #
3 # CCDEPS-GCC (C) 2002 Emile van Bergen. Distribution of this file is allowed
4 # under the conditions detailed in the GNU General Public License (GPL). See
5 # the file COPYING for more information.
6 #
7 # This script compiles and/or links one or more source or object files into a
8 # object file or executable target, and outputs all extra dependencies found
9 # while doing so in a file named target.d, which can be used by GNU Make.
10 #
11 # The script should be invoked the same way as your C compiler, that is,
12 # specifying the target using a -o option and the source or object files as
13 # non-option arguments. It will generate dependencies in the form
14 #
15 # target target.d: dir/file1.c dir/file2.c header1.h header2.h
16 # dir/file1.c dir/file2.c header1.h header2.h:
17 #
18 # This version is intended for GCC, which can do compilation and dependency
19 # generation in one step. The name of the GCC version (default gcc) can be
20 # overridden using the CC environment variable.
21 #
22 # CHANGELOG
23 #
24 # 2003/1/8: EvB: adapted for gcc 3.2, still handles 2.95 as well.
25 #
26 # This was necessary because gcc 3.2 handles -MD differently than gcc 2.95:
27 # where the old version generated a .d file for each source, in the current
28 # directory, the new one does almost completely what this script intended to
29 # do: generate one .d file in the same directory and with the same file name
30 # as the target.
31 #
32 # The only fixups 3.2's .d files still need are:
33 #
34 # - changing the file name; gcc 3.2 strips the suffix of the target before
35 # appending the .d, so targets x and x.o will both produce x.d, which is
36 # not what we want;
37 #
38 # - adding the implicit dependencies as prerequisiteless targets, so that
39 # make will just consider the target out of date if one does not exist
40 # anymore;
41 #
42 # - adding the .d file as depending on the same prerequisites as our real
43 # target so that it will be considered out of date if one of the files
44 # mentioned in it are updated or missing.
45 #
46 # Basically, this version does all that by simply including the file
47 # <strippedtarget>.d file in the list of .d files we look for. We may end
48 # up generating the same file name, but that already was handled correctly.
49 # Otherwise we perform the normal routine, so that we /know/ the targets will
50 # be correct, directories and all, regardless of variations in gcc behaviour.
51
52 test -x "functions.sh" && . "functions.sh"
53 test -x "build/functions.sh" && . "build/functions.sh"
54
55 export CC=$1
56 shift
57
58
59 cmdline=""
60 # After having passed the arguments, they have already been parsed once by
61 # the shell, so they needed to be re-quoted.
62 for arg in "$@"
63 do
64 arg="$(quote_string "$arg")"
65 cmdline="$cmdline $arg"
66 done
67
68
69 while [ x"$1" != x ]
70 do
71 case "$1" in
72 -o) tgt="$2" ; shift ;; # target specifier option
73 -x|-u|-b|-V) shift ;; # options with arg after space
74 -*) ;; # standard options
75 *) fil="$fil $1" ;; # source or object files
76 esac
77 shift
78 done
79
80 #if [ x"$CC" = x ]
81 #then
82 #CC=gcc
83 #export CC
84 #fi
85
86 # If we're not processing any .c files (link only), run gcc as-is and we're done
87
88 expr "$fil" : ".*\.c" >/dev/null || exec $CC $cmdline
89
90 # Otherwise, run the gcc with the -MD option, which generates a .d file
91 # in the current directory for each .c or .cc source file processed.
92 #
93 # These files are post-processed (replacing the incorrectly named target
94 # with the real target specified with -o, and adding the .d file), concatenated
95 # into one .d file that is named based on the target name, and put in the
96 # correct directory. Further, all prerequisites are added as bare targets,
97 # preventing errors when files are missing due to renaming or restructuring
98 # headers, but causing the files dependent on them to be considered out of
99 # date. (GNU Make feature).
100 #
101 # Makefiles must include the .d files like this: -include $(OBJS_$(d):.o=.d)
102 # or, when compiling and linking in one step: -include $(TGTS_$(d):%=%.d)
103
104 dep=$tgt.d
105 rm -f $dep
106
107 #echo $CC -MD $cmdline
108 eval "$CC -MD $cmdline"
109 res=$?
110
111 dgcc3=`echo $tgt | sed -e 's/\.[^.]*$//'`.d
112 dgcc=`echo $fil | sed -e 's/[^ ]*\.[^c]//' -e 's/\.cpp/\.d/g' -e 's/\.cc/\.d/g' -e 's/\.c/\.d/g' -e 's%.*/%%g'`
113
114 for tf in $dgcc3 $dgcc
115 do
116 if [ -f $tf ] && mv $tf $dep.tmp
117 then
118 sed -e "s%.*:%$tgt $dep:%" < $dep.tmp >> $dep
119 sed -e 's%^.*:%%' -e 's%^ *%%' -e 's% *\\$%%' -e 's%$%:%' \
120 < $dep.tmp >> $dep
121 rm -f $dep.tmp
122 found=1
123 fi
124 done
125
126 [ x"$found" = x"1" ] && exit $res
127
128 echo ERROR: $0: Cannot find any compiler-generated dependency files\!
129 exit 1
130
This page took 0.038598 seconds and 5 git commands to generate.