1 | |
---|
2 | #=============================================================== |
---|
3 | # |
---|
4 | # This shell script emulates the behaviour of the 'cmt buid dependencies' operation |
---|
5 | # but using 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 | a=`eval cpp -M ${allflags} ${file} | \ |
---|
19 | sed -e 's#[.]o:#_'"${suffix}"'_dependencies = #' -e 's#[\\]$##'` |
---|
20 | |
---|
21 | if test ! `echo ${a} | wc -w` = "0"; then |
---|
22 | echo -n ${a} |
---|
23 | else |
---|
24 | echo -n "${file_name}_${suffix}_dependencies = ${file}" |
---|
25 | fi |
---|
26 | |
---|
27 | echo " \$(bin)${constituent}_deps/${file_name}_${suffix}.stamp" |
---|
28 | |
---|
29 | # create or update the stamp file |
---|
30 | |
---|
31 | touch ${bin}/${constituent}_deps/${file_name}_${suffix}.stamp |
---|
32 | } |
---|
33 | |
---|
34 | #-------------------------------------------- |
---|
35 | macro_value () |
---|
36 | { |
---|
37 | name=$1 |
---|
38 | shift |
---|
39 | |
---|
40 | grep "^${name}=" ${tempmacros} | sed -e "s#^${name}=##" |
---|
41 | } |
---|
42 | |
---|
43 | #----------------------------------------------------- |
---|
44 | # Pre-compute all configuration parameters from CMT queries |
---|
45 | #----------------------------------------------------- |
---|
46 | function prepare_context () |
---|
47 | { |
---|
48 | /bin/rm -f ${tempmacros} |
---|
49 | cmt -quiet build tag_makefile > ${tempmacros} |
---|
50 | cmt -quiet filter ${tempmacros} ${tempmacros}A; mv ${tempmacros}A ${tempmacros} |
---|
51 | |
---|
52 | # /bin/rm -f ${tempconstituents} |
---|
53 | # cmt -quiet show constituents > ${tempconstituents} |
---|
54 | # cmt -quiet filter ${tempconstituents} ${tempconstituents}A; mv ${tempconstituents}A ${tempconstituents} |
---|
55 | } |
---|
56 | |
---|
57 | #------------------------------------------------------------------------------------------ |
---|
58 | # Main |
---|
59 | # |
---|
60 | # Expected arguments: |
---|
61 | # 1 : <constituent name> |
---|
62 | # 2 : -all_sources |
---|
63 | # 3... : <source file list> |
---|
64 | # |
---|
65 | #------------------------------------------------------------------------------------------ |
---|
66 | |
---|
67 | constituent=$1 |
---|
68 | shift |
---|
69 | |
---|
70 | all_sources=$1 |
---|
71 | shift |
---|
72 | |
---|
73 | files=$* |
---|
74 | |
---|
75 | #--------------- |
---|
76 | # Prepare temporary file management |
---|
77 | # |
---|
78 | tempprefix=/tmp/CMT$$ |
---|
79 | if test ! "${TMP}" = ""; then |
---|
80 | tempprefix=${TMP}/CMT$$ |
---|
81 | fi |
---|
82 | |
---|
83 | tempmacros=${tempprefix}/macros$$ |
---|
84 | tempconstituents=${tempprefix}/constituents$$ |
---|
85 | |
---|
86 | trap "if test -d ${tempprefix} ; then chmod -R +w ${tempprefix}; fi; /bin/rm -rf ${tempprefix}" 0 1 2 15 |
---|
87 | |
---|
88 | if test -d ${tempprefix} ; then chmod -R +w ${tempprefix}; fi |
---|
89 | /bin/rm -rf ${tempprefix} |
---|
90 | mkdir -p ${tempprefix} |
---|
91 | #--------------- |
---|
92 | |
---|
93 | #--------------- |
---|
94 | # prepare the context from CMT |
---|
95 | # |
---|
96 | prepare_context |
---|
97 | |
---|
98 | incl=`macro_value includes` |
---|
99 | |
---|
100 | cflags=`macro_value cflags` |
---|
101 | const_cflags=`macro_value ${constituent}_cflags` |
---|
102 | const_pp_cflags=`macro_value ${constituent}_pp_cflags` |
---|
103 | |
---|
104 | cppflags=`macro_value cppflags` |
---|
105 | const_cppflags=`macro_value ${constituent}_cppflags` |
---|
106 | const_pp_cppflags=`macro_value ${constituent}_pp_cppflags` |
---|
107 | |
---|
108 | bin=`macro_value bin` |
---|
109 | #-------------- |
---|
110 | |
---|
111 | #-------------- |
---|
112 | # Prepare the directory for the stamp files |
---|
113 | # |
---|
114 | mkdir -p ${bin}/${constituent}_deps |
---|
115 | #-------------- |
---|
116 | |
---|
117 | #-------------- |
---|
118 | # Prepare the dependency file |
---|
119 | # |
---|
120 | output=${bin}${constituent}_dependencies.make |
---|
121 | #-------------- |
---|
122 | |
---|
123 | #-------------- |
---|
124 | # Loop over source files (if any) |
---|
125 | # |
---|
126 | for f in `echo ${files}`; do |
---|
127 | suffix=`echo ${f} | sed -e 's#.*[.]##'` |
---|
128 | file_name=`basename ${f} .${suffix}` |
---|
129 | |
---|
130 | # First remove the old dependency line from the output |
---|
131 | |
---|
132 | if test -f ${output}; then |
---|
133 | grep -v "${file_name}_${suffix}_dependencies" ${output} >t$$; mv t$$ ${output} |
---|
134 | fi |
---|
135 | |
---|
136 | echo "computing dependencies for ${file_name}.${suffix}" |
---|
137 | |
---|
138 | case ${suffix} in |
---|
139 | c ) allflags="${incl} ${cflags} ${const_cflags} ${const_cpp_cflags}";; |
---|
140 | C|cc|cxx|cpp ) allflags="${incl} ${cppflags} ${const_cppflags} ${const_cpp_cppflags}";; |
---|
141 | esac |
---|
142 | |
---|
143 | echo "cpp -M ${allflags} ${f}" |
---|
144 | |
---|
145 | compute_dependencies ${f} >>${output} |
---|
146 | done |
---|
147 | #-------------- |
---|
148 | |
---|
149 | |
---|
150 | |
---|