]> mj.ucw.cz Git - libucw.git/blob - maint/abi-rename-symbols
asserts: Added ASSERT_MSG to print a debug msg together with assertion fail.
[libucw.git] / maint / abi-rename-symbols
1 #!/usr/bin/perl
2 # Re-generate symbol renaming defines
3 # (c) 2014 Martin Mares <mj@ucw.cz>
4
5 use common::sense;
6
7 my %renames = ();
8 open my $f, '<', 'maint/libucw.abi' or die;
9 my $current;
10 while (<$f>) {
11         chomp;
12         if (/^#\s*(.*)/) {
13                 $current = $1;
14         } else {
15                 push @{$renames{$current}}, $_;
16         }
17 }
18 close $f;
19
20 for my $g (sort keys %renames) {
21         my @symbols = sort @{$renames{$g}};
22         @symbols or next;
23
24         open my $in, '<', $g or die;
25         open my $out, '>', "$g.new" or die;
26         my $mode = 0;
27         my $cmt = 0;
28         while (<$in>) {
29                 if (!$mode) {
30                         if (m{^/\*$} && !$cmt) {
31                                 $cmt = 1;
32                         } elsif (m{^\s} ||
33                             m{^#include\s} ||
34                             m{^#define\s+_} ||
35                             m{^#ifndef\s+_} ||
36                             m{^\s*$}
37                            ) {
38                                 # Waiting for the right spot
39                         } elsif (m{^#ifdef CONFIG_UCW_CLEAN_ABI$}) {
40                                 $mode = 2;
41                                 next;
42                         } else {
43                                 $mode = 1;
44                                 print $out "#ifdef CONFIG_UCW_CLEAN_ABI\n";
45                                 for my $sym (@symbols) {
46                                         print $out "#define $sym ucw_$sym\n";
47                                 }
48                                 print $out "#endif\n\n";
49                         }
50                 } elsif ($mode == 2) {
51                         if (m{^$}) {
52                                 $mode = 0;
53                         }
54                         next;
55                 }
56                 print $out "$_";
57         }
58         $mode or die;
59         close $out;
60         close $in;
61         system "cmp", "-s", $g, "$g.new";
62         if ($?) {
63                 print "### $g: updated\n";
64                 rename "$g.new", $g or die;
65         } else {
66                 print "--- $g: not modified\n";
67                 unlink "$g.new" or die;
68         }
69 }