[2] | 1 | |
---|
[79] | 2 | #=============================================================== |
---|
| 3 | # |
---|
| 4 | # This shell script emulates the behaviour of the 'cmt buid dependencies' operation |
---|
[474] | 5 | # but using the tool specified by the $(c_pp) macro (or cpp -M) instead |
---|
[79] | 6 | # |
---|
| 7 | #=============================================================== |
---|
[2] | 8 | |
---|
[79] | 9 | function compute_dependencies () |
---|
[2] | 10 | { |
---|
| 11 | file=$1 |
---|
| 12 | |
---|
[79] | 13 | # Generate the expected format: |
---|
| 14 | # one single line |
---|
| 15 | # prefix is a make macro |
---|
| 16 | # ends with a dependency to the stamp file |
---|
[2] | 17 | |
---|
[474] | 18 | if [ -z "$c_pp" ]; then |
---|
| 19 | c_pp="cpp -M" |
---|
| 20 | fi |
---|
| 21 | |
---|
| 22 | a=`eval ${c_pp} ${allflags} ${file} | \ |
---|
[79] | 23 | sed -e 's#[.]o:#_'"${suffix}"'_dependencies = #' -e 's#[\\]$##'` |
---|
[2] | 24 | |
---|
[79] | 25 | if test ! `echo ${a} | wc -w` = "0"; then |
---|
[474] | 26 | line="`echo ${a}`" |
---|
[79] | 27 | else |
---|
[474] | 28 | line="${file_name}_${suffix}_dependencies = ${file}" |
---|
[79] | 29 | fi |
---|
| 30 | |
---|
[474] | 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}" |
---|
[79] | 35 | |
---|
| 36 | # create or update the stamp file |
---|
[474] | 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 |
---|
[79] | 46 | |
---|
[474] | 47 | #touch ${bin}/${constituent}_deps/${file_name}_${suffix}.stamp |
---|
| 48 | fi |
---|
| 49 | printf "${line}\n" |
---|
[2] | 50 | } |
---|
| 51 | |
---|
[79] | 52 | #-------------------------------------------- |
---|
| 53 | macro_value () |
---|
| 54 | { |
---|
| 55 | name=$1 |
---|
| 56 | shift |
---|
[474] | 57 | sed -n '/^'${name}'=/{s#^'${name}'=##p;q}' ${tempmacros} |
---|
| 58 | # grep "^${name}=" ${tempmacros} | sed -e "s#^${name}=##" |
---|
[79] | 59 | } |
---|
[2] | 60 | |
---|
[79] | 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} |
---|
[2] | 69 | |
---|
[79] | 70 | # /bin/rm -f ${tempconstituents} |
---|
| 71 | # cmt -quiet show constituents > ${tempconstituents} |
---|
| 72 | # cmt -quiet filter ${tempconstituents} ${tempconstituents}A; mv ${tempconstituents}A ${tempconstituents} |
---|
| 73 | } |
---|
[2] | 74 | |
---|
[79] | 75 | #------------------------------------------------------------------------------------------ |
---|
| 76 | # Main |
---|
| 77 | # |
---|
| 78 | # Expected arguments: |
---|
| 79 | # 1 : <constituent name> |
---|
[474] | 80 | # 2 : [ options: -all_sources | -no_stamps | -out=<dependencies file> ] |
---|
[79] | 81 | # 3... : <source file list> |
---|
| 82 | # |
---|
| 83 | #------------------------------------------------------------------------------------------ |
---|
[2] | 84 | |
---|
[474] | 85 | [ $# -gt 0 ] || exit |
---|
[79] | 86 | constituent=$1 |
---|
| 87 | shift |
---|
[2] | 88 | |
---|
[474] | 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 |
---|
[79] | 99 | |
---|
| 100 | #--------------- |
---|
| 101 | # Prepare temporary file management |
---|
| 102 | # |
---|
| 103 | tempprefix=/tmp/CMT$$ |
---|
[474] | 104 | if test ! "${TMPDIR}" = ""; then |
---|
| 105 | tempprefix=${TMPDIR}/CMT$$ |
---|
[79] | 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 | |
---|
[474] | 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 | |
---|
[79] | 130 | incl=`macro_value includes` |
---|
| 131 | |
---|
| 132 | cflags=`macro_value cflags` |
---|
[474] | 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` |
---|
[79] | 138 | const_cflags=`macro_value ${constituent}_cflags` |
---|
[474] | 139 | type_const_cflags=`macro_value ${type}_${constituent}_cflags` |
---|
[79] | 140 | |
---|
| 141 | cppflags=`macro_value cppflags` |
---|
[474] | 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` |
---|
[79] | 147 | const_cppflags=`macro_value ${constituent}_cppflags` |
---|
[474] | 148 | type_const_cppflags=`macro_value ${type}_${constituent}_cppflags` |
---|
[79] | 149 | |
---|
[474] | 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 |
---|
[79] | 157 | #-------------- |
---|
| 158 | |
---|
| 159 | #-------------- |
---|
| 160 | # Prepare the directory for the stamp files |
---|
| 161 | # |
---|
[474] | 162 | if [ "$no_stamps" != yes ]; then |
---|
[79] | 163 | mkdir -p ${bin}/${constituent}_deps |
---|
[474] | 164 | fi |
---|
[79] | 165 | #-------------- |
---|
| 166 | |
---|
| 167 | #-------------- |
---|
| 168 | # Prepare the dependency file |
---|
| 169 | # |
---|
[474] | 170 | if [ -z "$output" ]; then |
---|
[79] | 171 | output=${bin}${constituent}_dependencies.make |
---|
[474] | 172 | fi |
---|
[79] | 173 | #-------------- |
---|
| 174 | |
---|
| 175 | #-------------- |
---|
| 176 | # Loop over source files (if any) |
---|
| 177 | # |
---|
[474] | 178 | for f; do |
---|
[79] | 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 | |
---|
[474] | 184 | if [ "$all_sources" != yes ]; then |
---|
[79] | 185 | if test -f ${output}; then |
---|
[474] | 186 | grep -v "${file_name}_${suffix}_dependencies" ${output} >${tempprefix}/t$$ |
---|
| 187 | mv ${tempprefix}/t$$ ${output} |
---|
[79] | 188 | fi |
---|
[474] | 189 | fi |
---|
| 190 | # echo "computing dependencies for ${file_name}.${suffix}" |
---|
[79] | 191 | |
---|
| 192 | case ${suffix} in |
---|
[474] | 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}";; |
---|
[79] | 198 | esac |
---|
| 199 | |
---|
| 200 | compute_dependencies ${f} >>${output} |
---|
[2] | 201 | done |
---|
[79] | 202 | #-------------- |
---|