summaryrefslogtreecommitdiff
path: root/rename-macro.pl
blob: 1af6a86f65f37ed71e4d439e18c66f83671efb76 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#! /usr/bin/env perl
# rename-macro
# Rename an autoconf-archive macro, obsoleting the old name
# Usage: rename-macro PREFIX FROM TO
#   If there is no prefix to remove, make the prefix some
#   string that does not occur in the files being modified.


use strict;
use warnings;

my ($prefix, $old, $new) = @ARGV;

my $old_name = uc($old);
$old_name =~ s/\..*$//;

my $new_name = uc($new);
$new_name =~ s/\..*$//;

my $insertion = <<END;
# OBSOLETE MACRO
#
#   Renamed to $new_name
#
END
chomp $insertion;

open IN, $old or die "could not read $old\n";
my $text = do { local $/, <IN> };

my $new_text = $text;
$new_text =~ s/$old_name/$new_name/g;
$new_text =~ s/$prefix/AX_/g;
open OUTFILE, ">$new" or die "could not read $new";
print OUTFILE $new_text;

my $old_text = $text;
$old_text =~ s/^\# SYNOPSIS/"$insertion\n\# SYNOPSIS"/me;
open OUTFILE, ">$old" or die "could not write $old";
print OUTFILE $old_text;

system "git add $new";