source: CMT/v1r26p20160527/mgr/cmt_build_deps.sh

Last change on this file 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
Line 
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
9function 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
18if [ -z "$c_pp" ]; then
19    c_pp="cpp -M"
20fi
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
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}"
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
48fi
49printf "${line}\n"
50}
51
52#--------------------------------------------
53macro_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#-----------------------------------------------------
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}
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
86constituent=$1
87shift
88
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
99
100#---------------
101# Prepare temporary file management
102#
103tempprefix=/tmp/CMT$$
104if test ! "${TMPDIR}" = ""; then
105  tempprefix=${TMPDIR}/CMT$$
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
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
130incl=`macro_value includes`
131
132cflags=`macro_value cflags`
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`
138const_cflags=`macro_value ${constituent}_cflags`
139type_const_cflags=`macro_value ${type}_${constituent}_cflags`
140
141cppflags=`macro_value cppflags`
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`
147const_cppflags=`macro_value ${constituent}_cppflags`
148type_const_cppflags=`macro_value ${type}_${constituent}_cppflags`
149
150c_pp=`macro_value c_pp`
151
152if [ "$output" ]; then
153    bin=`dirname $output`/
154elif [ -z "$bin" ]; then
155    bin=`macro_value bin`
156fi
157#--------------
158
159#--------------
160# Prepare the directory for the stamp files
161#
162if [ "$no_stamps" != yes ]; then
163mkdir -p ${bin}/${constituent}_deps
164fi
165#--------------
166
167#--------------
168# Prepare the dependency file
169#
170if [ -z "$output" ]; then
171output=${bin}${constituent}_dependencies.make
172fi
173#--------------
174
175#--------------
176# Loop over source files (if any)
177#
178for 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
184if [ "$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
189fi
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}
201done
202#--------------
Note: See TracBrowser for help on using the repository browser.