]> git.saurik.com Git - bison.git/blame - etc/prefix-gnulib-mk
tests: cleanup.
[bison.git] / etc / prefix-gnulib-mk
CommitLineData
feda5527
AD
1#! /usr/bin/perl -w
2
3use strict;
4use IO::File;
5
6my $prefix = "lib/";
7
8# contents ($FILE_NAME)
9# ---------------------
10sub contents ($)
11{
12 my ($file) = @_;
13 local $/; # Turn on slurp-mode.
14 my $f = new IO::File "< $file" or die "$file";
15 my $contents = $f->getline or die "$file";
16 $f->close;
17 return $contents;
18}
19
20# prefix_word ($WORD)
21# -------------------
22# Do not prefix special words such as variable dereferences. Also,
23# "Makefile" is really "Makefile", since precisely there is no
24# lib/Makefile.
25sub prefix_word ($)
26{
27 local ($_) = @_;
28 $_ = $prefix . $_
29 unless m{^\$\(\w+\)} || $_ eq "Makefile";
30 return $_;
31}
32
33
34# prefix_words ($TEXT)
35# --------------------
36sub prefix_words ($)
37{
38 local ($_) = @_;
39 s{(\S+)}{prefix_word($1)}gem;
40 return $_;
41}
42
43
44# prefix_assignment ($LHS-AND-ASSIGN-OP, $RHS)
45# --------------------------------------------
46sub prefix_assignment ($$)
47{
48 my ($lhs_and_assign_op, $rhs) = @_;
49 my $res;
50
51 # Some variables are initialized by gnulib.mk, and we don't want
52 # that. Change '=' to '+='.
11c073b7 53 if ($lhs_and_assign_op =~ /^(SUBDIRS|EXTRA_DIST|BUILT_SOURCES|SUFFIXES|MOSTLYCLEANFILES|CLEANFILES|DISTCLEANFILES|MAINTAINERCLEANFILES|AM_CFLAGS|AM_CPPFLAGS|AM_GNU_GETTEXT) =/)
feda5527
AD
54 {
55 $lhs_and_assign_op =~ s/=/+=/;
56 }
57 # We don't want to inherit gnulib's AUTOMAKE_OPTIONS, comment them.
58 elsif ($lhs_and_assign_op =~ /^AUTOMAKE_OPTIONS =/)
59 {
60 $lhs_and_assign_op =~ s/^/# /;
61 }
62 # Don't touch suffixes.
63 elsif ($lhs_and_assign_op =~ /^SUFFIXES /)
64 {
65 }
66 # The words are (probably) paths to files in lib/: prefix them.
67 else
68 {
69 $rhs = prefix_words($rhs)
70 }
71
72 # Variables which name depend on the location: libbison_a_SOURCES =>
73 # lib_libbison_a_SOURCES.
74 $lhs_and_assign_op =~ s/(libbison)/lib_$1/g;
75
feda5527
AD
76 return $lhs_and_assign_op . $rhs;
77}
78
79# prefix $CONTENTS
80# ----------------
81# $CONTENTS is a Makefile content. Post-process it so that each file-name
82# is prefixed with $prefix (e.g., "lib/").
83#
84# Relies heavily on the regularity of the file generated by gnulib-tool.
85sub prefix ($)
86{
87 # Work on $_.
88 local ($_) = @_;
89
90 # Prefix all the occurrence of files in rules. If there is nothing
91 # after in the :, it's probably a phony target, or a suffix rule.
92 # Don't touch it.
75f94c6d 93 s{^([-\w/]+\.[-\w.]+ *: *\S.*)$}
feda5527
AD
94 {prefix_words($1)}gem;
95
96 # Prefix files in variables.
97 s{^([\w.]+\s*\+?=)(.*)$}
98 {prefix_assignment($1, $2)}gem;
99
100 # These three guys escape all the other regular rules.
101 s{(charset\.alias|ref-add\.sed|ref-del\.sed)}{$prefix$1}g;
102 # Unfortunately, as a result we sometimes have lib/lib.
d1b55e81 103 s{($prefix){2}}{$1}g;
feda5527
AD
104
105 # $(srcdir) is actually $(top_srcdir)/lib.
106 s{\$\(srcdir\)}{\$(top_srcdir)/lib}g;
107
108 # Sometimes, t-$@ is used instead of $@-t, which, of course, does
109 # not work when we have a $@ with a directory in it.
110 s{t-\$\@}{\$\@-t}g;
111
d1b55e81
AD
112 # Some AC_SUBST patterns remain and would better be Make macros.
113 s{\@(MKDIR_P)\@}{\$($1)}g;
114
115 # Adjust paths in mkdir.
116 s{(\$\(MKDIR_P\))\s*(\w+)}{$1 $prefix$2}g;
117
feda5527
AD
118 return $_;
119}
120
121# process ($IN)
122# -------------
123sub process ($)
124{
125 my ($file) = @_;
126 my ($bak) = "$file.bak";
127 rename ($file, $bak) or die;
128 my $contents = contents ($bak);
129 $contents = prefix ($contents);
130 my $out = new IO::File(">$file") or die;
131 print $out $contents;
132}
133
d1b55e81 134process ("${prefix}gnulib.mk")
feda5527
AD
135
136
137### Setup "GNU" style for perl-mode and cperl-mode.
138## Local Variables:
139## perl-indent-level: 2
140## perl-continued-statement-offset: 2
141## perl-continued-brace-offset: 0
142## perl-brace-offset: 0
143## perl-brace-imaginary-offset: 0
144## perl-label-offset: -2
145## cperl-indent-level: 2
146## cperl-brace-offset: 0
147## cperl-continued-brace-offset: 0
148## cperl-label-offset: -2
149## cperl-extra-newline-before-brace: t
150## cperl-merge-trailing-else: nil
151## cperl-continued-statement-offset: 2
152## End: