3 #Basic Script configuration
4 mtlkfront_do_output_processing
=y
6 print_when_preprocessing
=y
8 do_logger_preprocessing
=y
12 test "x`echo $1 | grep '\.\(c\|cpp\)$'`" != x
15 logger_preprocessing_enabled
()
17 test "x$do_logger_preprocessing" = "xy"
20 check_mtlk_inc_source_file
()
22 awk "/^[[:blank:]]*\#include[[:blank:]]+[\"\<]mtlkinc\.h[\"\>]/ { exit 0; } \
23 /^[[:blank:]]*\#include/ { print NR; exit 1; }" < $1 &&
29 check_mtlk_inc_header_file
()
31 awk "/^[[:blank:]]*\#include[[:blank:]]+[\"\<]mtlkinc\.h[\"\>]/ { print NR; exit 1; }" < $1 &&
41 LINE_NO
=`check_mtlk_inc_source_file $1`
43 LINE_NO
=`check_mtlk_inc_header_file $1`
46 if [ "$LINE_NO" != "" ] ;
48 echo $1\
($LINE_NO\
) : error
: wrong mtlkinc.h inclusion
55 #Output-postprocessing part
56 #Performs output preprocessing and symlinks parsing to hide rebasing
57 if test x
"$mtlkfront_do_output_processing" = x
"y"; then
58 FILTER_CMD
=do_filtering
68 my $builddir=path_to_regexp($ARGV[0]);
76 #Get all substrings that look like file names from the string
77 if(@file_names = ($line =~ /[\w\d\.\/\-]+\/+/g))
79 foreach my $file_name (@file_names)
81 my $full_name=trim(`([ -e $file_name ] && readlink -f $file_name) || echo $file_name`);
82 my $file_name_regexp = path_to_regexp($file_name);
83 $line =~ s/$file_name_regexp/$full_name\//;
87 $line =~ s/$builddir/$srcdir/g;
88 #Remove multiple consequent slashes
89 $line =~ s/([a-zA-Z0-9_\.\-])\/+([a-zA-Z0-9_\.\-])/\1\/\2/g;
97 $string =~ s/[\s\r]+$//;
101 sub path_to_regexp($)
104 $path =~ s/([\:\\\/\.\,\-])/\\$1/g;
106 }' "`readlink -f $abs_builddir`/" "`readlink -f $abs_top_srcdir`/"
111 { $
* 2>$abs_builddir/.$$.stderr
; echo $?
>$abs_builddir/.$$.pipe.result
; } |
$FILTER_CMD
112 $FILTER_CMD < $abs_builddir/.$$.stderr
1>&2
114 RESULT_VAL
=`cat $abs_builddir/.$$.pipe.result`
116 rm -f $abs_builddir/.$$.pipe.result
$abs_builddir/.$$.stderr
121 run_stderr_filtered
() {
123 { $
* 2>$abs_builddir/.$$.stderr
; echo $?
>$abs_builddir/.$$.pipe.result
; }
124 $FILTER_CMD < $abs_builddir/.$$.stderr
1>&2
126 RESULT_VAL
=`cat $abs_builddir/.$$.pipe.result`
128 rm -f $abs_builddir/.$$.pipe.result
$abs_builddir/.$$.stderr
134 #Performs static code checks and logprep preprocessing
135 if test "x$logger_origin_name" = x
; then
136 logger_origin_name
=UNKNOWN_ORIGIN
;
139 if test "x$logger_binary_name" = x
; then
140 logger_binary_name
=UNKNOWN_ELF
;
143 if test "x$logger_origin_id" = x
; then
144 logger_origin_id
=255;
147 # We use heuristics telling that file name
148 # is the last parameter of the compile command
149 FILE_NAME
=`awk '{print $NF;exit;}'<<END
153 #If file is .C of .CPP and compilation do preprocessing with logprep
154 if logger_preprocessing_enabled
&& \
155 is_source_file
$FILE_NAME && \
156 test "x`echo $* | grep -v -w '[-]E'`" != x
; then
158 # Build dependencies list
159 MKDEP_CMD
=`echo $* | \
160 sed -e's|-M[TF][[:space:]][[:space:]]*[^[:space:]][^[:space:]]*||g' \
161 -e's|\(-Wp,\)*-M[DP][[:space:]][[:space:]]*||g' \
162 -e's|\(-Wp,\)*-M[DP]\,[^[:space:]]*||g' \
163 -e"s|-o[[:space:]][[:space:]]*[^[:space:]][^[:space:]]*| -D__MTLK_DEPENDENCY_GENERATION_PATH -MM -MT $FILE_NAME|g"`
165 # Create logmacros.[ch] and loggroups.h because source code depends on them
166 for file in $abs_builddir/logmacros.h
$abs_builddir/logmacros.c
$abs_builddir/loggroups.h
; do
167 test -e $file ||
touch $file
170 TOP_SRCDIR
=`readlink -f $abs_top_srcdir`
171 RAW_DEPS
="`run_stderr_filtered $MKDEP_CMD`" ||
exit 10
172 DEPS
=`echo $RAW_DEPS | \
173 awk '{ for (i = 1; i <= NF; i++) print $i }' | \
175 grep -v '\\.mod\\.c$' | \
177 grep -v 'logmacros\\.[hc]' | \
178 xargs -n 1 -r readlink -f | \
181 # DEPS already contains name of file being compiled, so we just need
182 # to run logprep for each file in list
183 for file in $DEPS; do
184 TIMESTAMP_FILE
=$abs_builddir/`echo $file | sed -e"s|$TOP_SRCDIR|./.logprep_ts/|g"`.logprep_ts
185 if test ! -e $TIMESTAMP_FILE -o $file -nt $TIMESTAMP_FILE; then
186 (test x
$print_when_checking = xy
) && ( (test -e $TIMESTAMP_FILE && echo " CK [M] $file") ||
echo " CK $file" )
187 check_mtlk_inc
$file ||
exit $?
188 (test x
$print_when_preprocessing = xy
) && ( (test -e $TIMESTAMP_FILE && echo " LP [M] $file") ||
echo " LP $file" )
189 logpreprocessed_file
=$abs_builddir/`basename $file`_$$.lgprpd
190 perl
$abs_tools_srcdir/rtlogger
/logprep
/logprep.pl gcc \
191 $logger_origin_id $logger_origin_name \
192 $abs_builddir/loggroups.h
$abs_builddir/logmacros.h \
193 $abs_builddir/logmacros.c
$abs_builddir/$logger_origin_name.scd
$logger_binary_name \
194 < $file > $logpreprocessed_file ||
{ echo Logprep error
while processing
file $file && exit 1; }
195 #Do not rebuild all sources because of loggger database changes
196 touch -m -t 198001010000.00 $abs_builddir/loggroups.h
$abs_builddir/logmacros.c
$abs_builddir/logmacros.h
197 #Do rebuild logmacro_database.o because it could be new macros were added
198 rm -f $abs_builddir/logmacro_database.o
200 if diff -q $file $logpreprocessed_file >/dev
/null
2>&1; then
201 rm -f $logpreprocessed_file
203 mv $logpreprocessed_file $file
205 mkdir
-p `dirname $TIMESTAMP_FILE` && touch $TIMESTAMP_FILE
211 (test x
$trace_commands = xy
) && (echo "MTLKFRONT invoked for: $*" 1>&2)
213 #Here we put logger origin ID into the marker supplied by Makefile.am.common
214 PREPROCESSED_COMMAND
=`echo $* | sed -e"s|LOG_LOCAL_OID=MTLKFRONT_WILL_FILL_IT|LOG_LOCAL_OID=$logger_origin_id|g"`
216 (test x
$trace_commands = xy
) && (echo "MTLKFRONT will invoke: $PREPROCESSED_COMMAND" 1>&2)
218 run_filtered
$PREPROCESSED_COMMAND