1 | |
---|
2 | #=============================================================== |
---|
3 | # |
---|
4 | # This shell script emulates the behaviour of the 'cmt buid dependencies' operation |
---|
5 | # but using the tool specified by the $(c_pp) macro (or cpp -M) instead |
---|
6 | # |
---|
7 | #=============================================================== |
---|
8 | |
---|
9 | function compute_dependencies () |
---|
10 | { |
---|
11 | file=$1 |
---|
12 | |
---|
13 | # Generate the expected format: |
---|
14 | # one single line |
---|
15 | # prefix is a make macro |
---|
16 | # ends with a dependency to the stamp file |
---|
17 | |
---|
18 | if [ -z "$c_pp" ]; then |
---|
19 | c_pp="cpp -M" |
---|
20 | fi |
---|
21 | |
---|
22 | a=`eval ${c_pp} ${allflags} ${file} | \ |
---|
23 | sed -e 's#[.]o:#_'"${suffix}"'_dependencies = #' -e 's#[\\]$##'` |
---|
24 | |
---|
25 | if test ! `echo ${a} | wc -w` = "0"; then |
---|
26 | line="`echo ${a}`" |
---|
27 | else |
---|
28 | line="${file_name}_${suffix}_dependencies = ${file}" |
---|
29 | fi |
---|
30 | |
---|
31 | if [ "$no_stamps" != yes ]; then |
---|
32 | stamp_output_base=${constituent}_deps/${file_name}_${suffix}.stamp |
---|
33 | stamp_output=${bin}${stamp_output_base} |
---|
34 | line="${line} \$(bin)${stamp_output_base}" |
---|
35 | |
---|
36 | # create or update the stamp file |
---|
37 | if [ -f "${stamp_output}" ]; then |
---|
38 | read old_stamp <${stamp_output} |
---|
39 | if [ "${line}" != "${old_stamp}" ]; then |
---|
40 | /bin/rm -f ${stamp_output} |
---|
41 | printf "${line}\n" >${stamp_output} |
---|
42 | fi |
---|
43 | else |
---|
44 | printf "${line}\n" >${stamp_output} |
---|
45 | fi |
---|
46 | |
---|
47 | #touch ${bin}/${constituent}_deps/${file_name}_${suffix}.stamp |
---|
48 | fi |
---|
49 | printf "${line}\n" |
---|
50 | } |
---|
51 | |
---|
52 | #-------------------------------------------- |
---|
53 | macro_value () |
---|
54 | { |
---|
55 | name=$1 |
---|
56 | shift |
---|
57 | sed -n '/^'${name}'=/{s#^'${name}'=##p;q}' ${tempmacros} |
---|
58 | # grep "^${name}=" ${tempmacros} | sed -e "s#^${name}=##" |
---|
59 | } |
---|
60 | |
---|
61 | #----------------------------------------------------- |
---|
62 | # Pre-compute all configuration parameters from CMT queries |
---|
63 | #----------------------------------------------------- |
---|
64 | function prepare_context () |
---|
65 | { |
---|
66 | /bin/rm -f ${tempmacros} |
---|
67 | cmt -quiet build tag_makefile > ${tempmacros} |
---|
68 | cmt -quiet filter ${tempmacros} ${tempmacros}A; mv ${tempmacros}A ${tempmacros} |
---|
69 | |
---|
70 | # /bin/rm -f ${tempconstituents} |
---|
71 | # cmt -quiet show constituents > ${tempconstituents} |
---|
72 | # cmt -quiet filter ${tempconstituents} ${tempconstituents}A; mv ${tempconstituents}A ${tempconstituents} |
---|
73 | } |
---|
74 | |
---|
75 | #------------------------------------------------------------------------------------------ |
---|
76 | # Main |
---|
77 | # |
---|
78 | # Expected arguments: |
---|
79 | # 1 : <constituent name> |
---|
80 | # 2 : [ options: -all_sources | -no_stamps | -out=<dependencies file> ] |
---|
81 | # 3... : <source file list> |
---|
82 | # |
---|
83 | #------------------------------------------------------------------------------------------ |
---|
84 | |
---|
85 | [ $# -gt 0 ] || exit |
---|
86 | constituent=$1 |
---|
87 | shift |
---|
88 | |
---|
89 | n=0 |
---|
90 | for f; do |
---|
91 | case ${f} in |
---|
92 | -all_sources) all_sources=yes; n=`expr $n + 1` ;; |
---|
93 | -no_stamps) no_stamps=yes; n=`expr $n + 1` ;; |
---|
94 | -out=*) output=`expr "$f" : '-out=\(.*\)'`; n=`expr $n + 1` ;; |
---|
95 | *) break ;; |
---|
96 | esac |
---|
97 | done |
---|
98 | shift $n |
---|
99 | |
---|
100 | #--------------- |
---|
101 | # Prepare temporary file management |
---|
102 | # |
---|
103 | tempprefix=/tmp/CMT$$ |
---|
104 | if test ! "${TMPDIR}" = ""; then |
---|
105 | tempprefix=${TMPDIR}/CMT$$ |
---|
106 | fi |
---|
107 | |
---|
108 | tempmacros=${tempprefix}/macros$$ |
---|
109 | tempconstituents=${tempprefix}/constituents$$ |
---|
110 | |
---|
111 | trap "if test -d ${tempprefix} ; then chmod -R +w ${tempprefix}; fi; /bin/rm -rf ${tempprefix}" 0 1 2 15 |
---|
112 | |
---|
113 | if test -d ${tempprefix} ; then chmod -R +w ${tempprefix}; fi |
---|
114 | /bin/rm -rf ${tempprefix} |
---|
115 | mkdir -p ${tempprefix} |
---|
116 | #--------------- |
---|
117 | |
---|
118 | #--------------- |
---|
119 | # prepare the context from CMT |
---|
120 | # |
---|
121 | prepare_context |
---|
122 | |
---|
123 | type=`cmt show constituent ${constituent} | cut -d' ' -f1` |
---|
124 | case "${type}" in |
---|
125 | application) type=app ;; |
---|
126 | library) type=lib ;; |
---|
127 | document) type=doc ;; |
---|
128 | esac |
---|
129 | |
---|
130 | incl=`macro_value includes` |
---|
131 | |
---|
132 | cflags=`macro_value cflags` |
---|
133 | pp_cflags=`macro_value pp_cflags` |
---|
134 | use_pp_cflags=`macro_value use_pp_cflags` |
---|
135 | const_pp_cflags=`macro_value ${constituent}_pp_cflags` |
---|
136 | type_pp_cflags=`macro_value ${type}_${constituent}_pp_cflags` |
---|
137 | use_cflags=`macro_value use_cflags` |
---|
138 | const_cflags=`macro_value ${constituent}_cflags` |
---|
139 | type_const_cflags=`macro_value ${type}_${constituent}_cflags` |
---|
140 | |
---|
141 | cppflags=`macro_value cppflags` |
---|
142 | pp_cppflags=`macro_value pp_cppflags` |
---|
143 | use_pp_cppflags=`macro_value use_pp_cppflags` |
---|
144 | const_pp_cppflags=`macro_value ${constituent}_pp_cppflags` |
---|
145 | type_pp_cppflags=`macro_value ${type}_${constituent}_pp_cppflags` |
---|
146 | use_cppflags=`macro_value use_cppflags` |
---|
147 | const_cppflags=`macro_value ${constituent}_cppflags` |
---|
148 | type_const_cppflags=`macro_value ${type}_${constituent}_cppflags` |
---|
149 | |
---|
150 | c_pp=`macro_value c_pp` |
---|
151 | |
---|
152 | if [ "$output" ]; then |
---|
153 | bin=`dirname $output`/ |
---|
154 | elif [ -z "$bin" ]; then |
---|
155 | bin=`macro_value bin` |
---|
156 | fi |
---|
157 | #-------------- |
---|
158 | |
---|
159 | #-------------- |
---|
160 | # Prepare the directory for the stamp files |
---|
161 | # |
---|
162 | if [ "$no_stamps" != yes ]; then |
---|
163 | mkdir -p ${bin}/${constituent}_deps |
---|
164 | fi |
---|
165 | #-------------- |
---|
166 | |
---|
167 | #-------------- |
---|
168 | # Prepare the dependency file |
---|
169 | # |
---|
170 | if [ -z "$output" ]; then |
---|
171 | output=${bin}${constituent}_dependencies.make |
---|
172 | fi |
---|
173 | #-------------- |
---|
174 | |
---|
175 | #-------------- |
---|
176 | # Loop over source files (if any) |
---|
177 | # |
---|
178 | for f; do |
---|
179 | suffix=`echo ${f} | sed -e 's#.*[.]##'` |
---|
180 | file_name=`basename ${f} .${suffix}` |
---|
181 | |
---|
182 | # First remove the old dependency line from the output |
---|
183 | |
---|
184 | if [ "$all_sources" != yes ]; then |
---|
185 | if test -f ${output}; then |
---|
186 | grep -v "${file_name}_${suffix}_dependencies" ${output} >${tempprefix}/t$$ |
---|
187 | mv ${tempprefix}/t$$ ${output} |
---|
188 | fi |
---|
189 | fi |
---|
190 | # echo "computing dependencies for ${file_name}.${suffix}" |
---|
191 | |
---|
192 | case ${suffix} in |
---|
193 | c ) allflags="${incl} ${cflags} ${pp_cflags} ${use_pp_cflags} ${const_pp_cflags} ${type_pp_cflags} ${use_cflags} ${const_cflags} ${type_const_cflags}" ;; |
---|
194 | C|cc|cxx|cpp ) allflags="${incl} ${cppflags} ${pp_cppflags} ${use_pp_cppflags} ${const_pp_cppflags} ${type_pp_cppflags} ${use_cppflags} ${const_cppflags} ${type_const_cppflags}" ;; |
---|
195 | * ) allflags="-x c++ ${incl} ${cppflags} ${pp_cppflags} ${use_pp_cppflags} ${const_pp_cppflags} ${type_pp_cppflags} ${use_cppflags} ${const_cppflags} ${type_const_cppflags}" ;; |
---|
196 | # c ) allflags="${incl} ${cflags} ${const_cflags} ${const_cpp_cflags}";; |
---|
197 | # C|cc|cxx|cpp ) allflags="${incl} ${cppflags} ${const_cppflags} ${const_cpp_cppflags}";; |
---|
198 | esac |
---|
199 | |
---|
200 | compute_dependencies ${f} >>${output} |
---|
201 | done |
---|
202 | #-------------- |
---|