From 02877e89b5fef74a179ae125bf0246d52e172b9f Mon Sep 17 00:00:00 2001 From: Stephan Barth Date: Fri, 8 Nov 2024 02:15:46 +0100 Subject: [PATCH] build(utils/makefilelogger.pl): Debug tools for Makefiles. --- utils/makefilelogger.pl | 53 +++++++++++++++++++++++++++++++++++++++++ utils/wrapmakelog.sh | 8 +++++++ 2 files changed, 61 insertions(+) create mode 100755 utils/makefilelogger.pl create mode 100755 utils/wrapmakelog.sh diff --git a/utils/makefilelogger.pl b/utils/makefilelogger.pl new file mode 100755 index 000000000..7054187a5 --- /dev/null +++ b/utils/makefilelogger.pl @@ -0,0 +1,53 @@ +#!/usr/bin/env perl + +use strict; +use warnings; + +my $fh = undef; +open($fh, '<', $ARGV[0]) or die "Could not read '$ARGV[0]', because: $!"; +my @cont = <$fh>; + +my %exports = (); +for(@cont) { + m#^export\s+([^=\s]+)# and $exports{$1} = 1 +} +my @exports = sort keys %exports; + +my @lined = (); +for(0..$#cont) { + $lined[$_] = [$_, $cont[$_]] +} +@lined = grep { $_->[1]!~m&^\s*#& } @lined; + +for my $i(0..$#lined-1) { + my $this = $lined[$i][1]; + my $next = $lined[$i+1][1]; + if($this=~m#^([^\s:]+):#) { + my $targetPattern = $1; + if($next=~m#^\t#) { + my $cl = $lined[$i]; + push @$cl, qq#\t\@echo "== PATTERN $targetPattern TARGET \$@" >> makelogger\n#; + push @$cl, qq#\t@ echo " \\\$\$($_) = '\$($_)'" >> makelogger\n# for @exports; + push @$cl, qq#\t@ echo "" >> makelogger\n#; + } + } +} + +my %out = (); +for my $i(0..$#cont) { + $out{$i} = $cont[$i] +} + +for(@lined) { + $out{$_->[0]} = $_ +} + +for my $i(0..$#cont) { + my $tc = $out{$i}; + if(ref $tc) { + print $tc->[$_] for 1..$#$tc + } else { + print $tc; + } +} + diff --git a/utils/wrapmakelog.sh b/utils/wrapmakelog.sh new file mode 100755 index 000000000..2fe1bbc7d --- /dev/null +++ b/utils/wrapmakelog.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env bash + +: > makelogger + +utils/makefilelogger.pl Makefile > Makefile-loggingsymbols + +make -f Makefile-loggingsymbols "$@" +