source: CMT/v1r20p20070517/mgr/cmt_build_deps.sh

Last change on this file was 79, checked in by arnault, 19 years ago

Fixing session - see CL#275

  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 3.6 KB
Line 
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
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
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#--------------------------------------------
35macro_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#-----------------------------------------------------
46function 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
67constituent=$1
68shift
69
70all_sources=$1
71shift
72
73files=$*
74
75#---------------
76# Prepare temporary file management
77#
78tempprefix=/tmp/CMT$$
79if test ! "${TMP}" = ""; then
80  tempprefix=${TMP}/CMT$$
81fi
82
83tempmacros=${tempprefix}/macros$$
84tempconstituents=${tempprefix}/constituents$$
85
86trap "if test -d ${tempprefix} ; then chmod -R +w ${tempprefix}; fi; /bin/rm -rf ${tempprefix}" 0 1 2 15
87
88if test -d ${tempprefix} ; then chmod -R +w ${tempprefix}; fi
89/bin/rm -rf ${tempprefix}
90mkdir -p ${tempprefix}
91#---------------
92
93#---------------
94# prepare the context from CMT
95#
96prepare_context
97
98incl=`macro_value includes`
99
100cflags=`macro_value cflags`
101const_cflags=`macro_value ${constituent}_cflags`
102const_pp_cflags=`macro_value ${constituent}_pp_cflags`
103
104cppflags=`macro_value cppflags`
105const_cppflags=`macro_value ${constituent}_cppflags`
106const_pp_cppflags=`macro_value ${constituent}_pp_cppflags`
107
108bin=`macro_value bin`
109#--------------
110
111#--------------
112# Prepare the directory for the stamp files
113#
114mkdir -p ${bin}/${constituent}_deps
115#--------------
116
117#--------------
118# Prepare the dependency file
119#
120output=${bin}${constituent}_dependencies.make
121#--------------
122
123#--------------
124# Loop over source files (if any)
125#
126for 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}
146done
147#--------------
148
149
150
Note: See TracBrowser for help on using the repository browser.