source: CMT/HEAD/mgr/cmt_build_deps.sh @ 652

Last change on this file since 652 was 474, checked in by rybkin, 16 years ago

See C.L. 375

  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 5.7 KB
RevLine 
[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]9function 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]18if [ -z "$c_pp" ]; then
19    c_pp="cpp -M"
20fi
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]31if [ "$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
48fi
49printf "${line}\n"
[2]50}
51
[79]52#--------------------------------------------
53macro_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#-----------------------------------------------------
64function 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]86constituent=$1
87shift
[2]88
[474]89n=0
90for 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
97done
98shift $n
[79]99
100#---------------
101# Prepare temporary file management
102#
103tempprefix=/tmp/CMT$$
[474]104if test ! "${TMPDIR}" = ""; then
105  tempprefix=${TMPDIR}/CMT$$
[79]106fi
107
108tempmacros=${tempprefix}/macros$$
109tempconstituents=${tempprefix}/constituents$$
110
111trap "if test -d ${tempprefix} ; then chmod -R +w ${tempprefix}; fi; /bin/rm -rf ${tempprefix}" 0 1 2 15
112
113if test -d ${tempprefix} ; then chmod -R +w ${tempprefix}; fi
114/bin/rm -rf ${tempprefix}
115mkdir -p ${tempprefix}
116#---------------
117
118#---------------
119# prepare the context from CMT
120#
121prepare_context
122
[474]123type=`cmt show constituent ${constituent} | cut -d' ' -f1`
124case "${type}" in
125    application) type=app ;;
126    library) type=lib ;;
127    document) type=doc ;;
128esac
129
[79]130incl=`macro_value includes`
131
132cflags=`macro_value cflags`
[474]133pp_cflags=`macro_value pp_cflags`
134use_pp_cflags=`macro_value use_pp_cflags`
135const_pp_cflags=`macro_value ${constituent}_pp_cflags`
136type_pp_cflags=`macro_value ${type}_${constituent}_pp_cflags`
137use_cflags=`macro_value use_cflags`
[79]138const_cflags=`macro_value ${constituent}_cflags`
[474]139type_const_cflags=`macro_value ${type}_${constituent}_cflags`
[79]140
141cppflags=`macro_value cppflags`
[474]142pp_cppflags=`macro_value pp_cppflags`
143use_pp_cppflags=`macro_value use_pp_cppflags`
144const_pp_cppflags=`macro_value ${constituent}_pp_cppflags`
145type_pp_cppflags=`macro_value ${type}_${constituent}_pp_cppflags`
146use_cppflags=`macro_value use_cppflags`
[79]147const_cppflags=`macro_value ${constituent}_cppflags`
[474]148type_const_cppflags=`macro_value ${type}_${constituent}_cppflags`
[79]149
[474]150c_pp=`macro_value c_pp`
151
152if [ "$output" ]; then
153    bin=`dirname $output`/
154elif [ -z "$bin" ]; then
155    bin=`macro_value bin`
156fi
[79]157#--------------
158
159#--------------
160# Prepare the directory for the stamp files
161#
[474]162if [ "$no_stamps" != yes ]; then
[79]163mkdir -p ${bin}/${constituent}_deps
[474]164fi
[79]165#--------------
166
167#--------------
168# Prepare the dependency file
169#
[474]170if [ -z "$output" ]; then
[79]171output=${bin}${constituent}_dependencies.make
[474]172fi
[79]173#--------------
174
175#--------------
176# Loop over source files (if any)
177#
[474]178for 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]184if [ "$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]189fi
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]201done
[79]202#--------------
Note: See TracBrowser for help on using the repository browser.