]>
Commit | Line | Data |
---|---|---|
feda5527 AD |
1 | #! /usr/bin/perl -w |
2 | ||
3 | use strict; | |
4 | use IO::File; | |
5 | ||
6 | my $prefix = "lib/"; | |
7 | ||
8 | # contents ($FILE_NAME) | |
9 | # --------------------- | |
10 | sub 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. | |
25 | sub prefix_word ($) | |
26 | { | |
27 | local ($_) = @_; | |
28 | $_ = $prefix . $_ | |
29 | unless m{^\$\(\w+\)} || $_ eq "Makefile"; | |
30 | return $_; | |
31 | } | |
32 | ||
33 | ||
34 | # prefix_words ($TEXT) | |
35 | # -------------------- | |
36 | sub 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 | # -------------------------------------------- | |
46 | sub 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 | ||
76 | # Do not use gl_LIBOBJS, but its prefixed version. | |
77 | $rhs =~ s/gl_LIBOBJS/gl_PREFIXED_LIBOBJS/g; | |
78 | ||
79 | return $lhs_and_assign_op . $rhs; | |
80 | } | |
81 | ||
82 | # prefix $CONTENTS | |
83 | # ---------------- | |
84 | # $CONTENTS is a Makefile content. Post-process it so that each file-name | |
85 | # is prefixed with $prefix (e.g., "lib/"). | |
86 | # | |
87 | # Relies heavily on the regularity of the file generated by gnulib-tool. | |
88 | sub prefix ($) | |
89 | { | |
90 | # Work on $_. | |
91 | local ($_) = @_; | |
92 | ||
93 | # Prefix all the occurrence of files in rules. If there is nothing | |
94 | # after in the :, it's probably a phony target, or a suffix rule. | |
95 | # Don't touch it. | |
96 | s{^([\w.]+ *: *\w.*)$} | |
97 | {prefix_words($1)}gem; | |
98 | ||
99 | # Prefix files in variables. | |
100 | s{^([\w.]+\s*\+?=)(.*)$} | |
101 | {prefix_assignment($1, $2)}gem; | |
102 | ||
103 | # These three guys escape all the other regular rules. | |
104 | s{(charset\.alias|ref-add\.sed|ref-del\.sed)}{$prefix$1}g; | |
105 | # Unfortunately, as a result we sometimes have lib/lib. | |
106 | s{lib/lib/}{lib/}g; | |
107 | ||
108 | # $(srcdir) is actually $(top_srcdir)/lib. | |
109 | s{\$\(srcdir\)}{\$(top_srcdir)/lib}g; | |
110 | ||
111 | # Sometimes, t-$@ is used instead of $@-t, which, of course, does | |
112 | # not work when we have a $@ with a directory in it. | |
113 | s{t-\$\@}{\$\@-t}g; | |
114 | ||
115 | return $_; | |
116 | } | |
117 | ||
118 | # process ($IN) | |
119 | # ------------- | |
120 | sub process ($) | |
121 | { | |
122 | my ($file) = @_; | |
123 | my ($bak) = "$file.bak"; | |
124 | rename ($file, $bak) or die; | |
125 | my $contents = contents ($bak); | |
126 | $contents = prefix ($contents); | |
127 | my $out = new IO::File(">$file") or die; | |
128 | print $out $contents; | |
129 | } | |
130 | ||
131 | process ("lib/gnulib.mk") | |
132 | ||
133 | ||
134 | ### Setup "GNU" style for perl-mode and cperl-mode. | |
135 | ## Local Variables: | |
136 | ## perl-indent-level: 2 | |
137 | ## perl-continued-statement-offset: 2 | |
138 | ## perl-continued-brace-offset: 0 | |
139 | ## perl-brace-offset: 0 | |
140 | ## perl-brace-imaginary-offset: 0 | |
141 | ## perl-label-offset: -2 | |
142 | ## cperl-indent-level: 2 | |
143 | ## cperl-brace-offset: 0 | |
144 | ## cperl-continued-brace-offset: 0 | |
145 | ## cperl-label-offset: -2 | |
146 | ## cperl-extra-newline-before-brace: t | |
147 | ## cperl-merge-trailing-else: nil | |
148 | ## cperl-continued-statement-offset: 2 | |
149 | ## End: |