INN commit: trunk/storage (Makefile buildconfig.in)
INN Commit
rra at isc.org
Fri Dec 18 20:41:51 UTC 2020
Date: Friday, December 18, 2020 @ 12:41:51
Author: iulius
Revision: 10454
Improve the generation of storage and overview-related files
Enhance storage/buildconfig to add lists of files to be removed at
various cleanup levels. METHOD_SOURCES, EXTRA_SOURCES, and PROGRAMS were
handled by separate code paths that were identical except for the names.
This cried out to be replaced by a table-driven approach.
The Makefile-related data could end up in either %storage or %overview,
and so had to be merged and re-sorted before Make.methods could be
written. Change this to use a new %makefile variable containing the
Makefile-related data for both storage and overview methods.
Patch from Bo Lindbergh.
Modified:
trunk/storage/Makefile
trunk/storage/buildconfig.in
----------------+
Makefile | 7 +++
buildconfig.in | 99 +++++++++++++++++++++++++++++--------------------------
2 files changed, 59 insertions(+), 47 deletions(-)
Modified: Makefile
===================================================================
--- Makefile 2020-12-12 21:03:16 UTC (rev 10453)
+++ Makefile 2020-12-18 20:41:51 UTC (rev 10454)
@@ -41,14 +41,19 @@
programs: $(PROGRAMS)
-clean clobber distclean:
+clean:
rm -f *.o *.lo */*.o */*.lo libstorage.la libstorage.a
rm -f $(PROGRAMS) libstorage_pure_*.a .pure
rm -f buildconfig libstorage$(PROFSUFFIX).a
rm -rf .libs */.libs
+ rm -f $(RM_CLEAN)
+clobber distclean: clean
+ rm -f $(RM_DISTCLEAN)
+
maintclean: distclean
rm -f Make.methods methods.c methods.h ovmethods.c ovmethods.h
+ rm -f $(RM_MAINTCLEAN)
$(FIXSCRIPT):
@echo Run configure before running make. See INSTALL for details.
Modified: buildconfig.in
===================================================================
--- buildconfig.in 2020-12-12 21:03:16 UTC (rev 10453)
+++ buildconfig.in 2020-12-18 20:41:51 UTC (rev 10454)
@@ -21,6 +21,24 @@
@OVERVIEW = qw(open groupstats groupadd groupdel add cancel opensearch search
closesearch getartinfo expiregroup ctl close);
+my(%filelistix, @filelistnames, $filelistparam);
+
+BEGIN {
+ # All known file lists.
+ # (*.config param name => Make.methods variable name)
+ my @filelists=(
+ sources => "METHOD_SOURCES",
+ "extra-sources" => "EXTRA_SOURCES",
+ programs => "PROGRAMS",
+ clean => "RM_CLEAN",
+ distclean => "RM_DISTCLEAN",
+ maintclean => "RM_MAINTCLEAN",
+ );
+ %filelistix = map(($filelists[$_*2] => $_), 0 .. @filelists/2-1);
+ @filelistnames = map($filelists[$_*2+1], 0 .. @filelists/2-1);
+ $filelistparam = join("|", map(quotemeta($_), keys(%filelistix)));
+}
+
# Used to make heredocs more readable.
sub unquote { my ($string) = @_; $string =~ s/^:( {0,7}|\t)//gm; $string }
@@ -27,12 +45,8 @@
# Parse a method.config file for a storage method, putting information about
# that storage method into the given hash ref.
sub parse_config {
- my ($dir, $file, $config) = @_;
+ my ($dir, $file, $config, $makefile) = @_;
local $_;
- $$config{sources} ||= [];
- $$config{extra} ||= [];
- $$config{programs} ||= [];
- $$config{makefiles} ||= [];
open (CONFIG, "$dir/$file") or die "Can't open $dir/$file: $!\n";
while (<CONFIG>) {
s/^\s+//;
@@ -49,18 +63,11 @@
. "allocated in $$config{number}{$number}\n";
}
$$config{number}{$dir} = $number;
- } elsif (/^sources\s*=\s*(.*)/) {
- my $sources = $1;
- my @sources = split (' ', $sources);
- push (@{ $$config{sources} }, map { "$dir/$_" } @sources);
- } elsif (/^extra-sources\s*=\s*(.*)/) {
- my $extra = $1;
- my @extra = split (' ', $extra);
- push (@{ $$config{extra} }, map { "$dir/$_" } @extra);
- } elsif (/^programs\s*=\s*(.*)/) {
- my $programs = $1;
- my @programs = split (' ', $programs);
- push (@{ $$config{programs} }, map { "$dir/$_" } @programs);
+ } elsif (/^($filelistparam)\s*=\s*(.*)/) {
+ my $ix = $filelistix{$1};
+ my $files = $2;
+ my @files = sort(split(" ", $files));
+ push(@{$$makefile{filelists}->[$ix]}, map { "$dir/$_" } @files);
} else {
warn "$dir/$file: ignoring unknown line: $_\n";
}
@@ -68,10 +75,11 @@
# If there is a makefile fragment in the directory, note it.
if (-f "$dir/method.mk") {
- push (@{ $$config{makefiles} }, "$dir/method.mk");
+ push (@{ $$makefile{makefiles} }, "$dir/method.mk");
} elsif (-f "$dir/ovmethod.mk") {
- push (@{ $$config{makefiles} }, "$dir/ovmethod.mk");
+ push (@{ $$makefile{makefiles} }, "$dir/ovmethod.mk");
}
+ push(@{$makefile->{dirs}}, $dir);
}
# Write out include directives for a list of files.
@@ -105,7 +113,7 @@
my ($fh, $config, $prefix) = @_;
my $method;
for $method (sort keys %{ $$config{method} }) {
- printf $fh "#define ${prefix}_%-30s%d\n", uc ($method),
+ printf $fh "# define ${prefix}_%-30s%d\n", uc ($method),
$$config{number}{$$config{method}{$method}};
}
}
@@ -131,15 +139,15 @@
open (H, '> methods.h.new') or die "Can't open methods.h.new: $!\n";
print H unquote (<<'EOE');
-: /* This file is automatically generated by buildconfig */
+: /* This file is automatically generated by buildconfig. */
:
: #ifndef METHODS_H
-: #define METHODS_H 1
+: # define METHODS_H 1
:
-: #include "interface.h"
+: # include "interface.h"
:
EOE
- print H '#define NUM_STORAGE_METHODS ',
+ print H '# define NUM_STORAGE_METHODS ',
scalar (keys %{ $$storage{method} }), "\n\n";
write_constants (\*H, $storage, 'TOKEN');
print H unquote (<<'EOE');
@@ -172,15 +180,15 @@
open (H, '> ovmethods.h.new') or die "Can't open ovmethods.h.new: $!\n";
print H unquote (<<'EOE');
-: /* This file is automatically generated by buildconfig */
+: /* This file is automatically generated by buildconfig. */
:
: #ifndef OVMETHODS_H
-: #define OVMETHODS_H 1
+: # define OVMETHODS_H 1
:
-: #include "ovinterface.h"
+: # include "ovinterface.h"
:
EOE
- print H '#define NUM_OV_METHODS ',
+ print H '# define NUM_OV_METHODS ',
scalar (keys %{ $$overview{method} }), "\n";
print H unquote (<<'EOE');
:
@@ -213,14 +221,15 @@
# Write out the makefile fragment for overview and storage methods.
sub write_makefile {
- my ($dirs, $sources, $extra, $programs, $makefiles) = @_;
+ my ($makefile) = @_;
open (MAKE, '> Make.methods.new')
or die "Can't create Make.methods.new: $!\n";
- print MAKE "# This file is automatically generated by buildconfig\n\n";
- print MAKE makefile_var ('METHOD_SOURCES', @$sources);
- print MAKE makefile_var ('EXTRA_SOURCES', @$extra);
- print MAKE makefile_var ('PROGRAMS', @$programs);
- for (@$makefiles) {
+ print MAKE "# This file is automatically generated by buildconfig.\n\n";
+ for (0 .. $#filelistnames) {
+ print MAKE makefile_var($filelistnames[$_],
+ @{$makefile->{filelists}->[$_]});
+ }
+ for (@{$makefile->{makefiles}}) {
print MAKE "\n\n## Included from $_\n\n";
open (FRAG, $_) or die "Can't open $_: $!\n";
print MAKE <FRAG>;
@@ -229,7 +238,12 @@
rename ('Make.methods.new', 'Make.methods');
}
-my ($dir, %storage, %overview);
+my ($dir, %storage, %overview, %makefile);
+%makefile = (
+ filelists => [ map([], @filelistnames) ],
+ makefiles => [],
+ dirs => [],
+);
if (!-d 'cnfs') {
if (-d 'storage/cnfs') {
chdir 'storage' or die "Can't chdir to storage: $!\n";
@@ -241,18 +255,11 @@
my @dirs = sort readdir D;
for $dir (@dirs) {
if (-e "$dir/method.config") {
- parse_config ($dir, 'method.config', \%storage);
+ parse_config ($dir, 'method.config', \%storage, \%makefile);
+ } elsif (-e "$dir/ovmethod.config") {
+ parse_config ($dir, 'ovmethod.config', \%overview, \%makefile);
}
- if (-e "$dir/ovmethod.config") {
- parse_config ($dir, 'ovmethod.config', \%overview);
- }
}
write_storage (\%storage);
write_overview (\%overview);
- at dirs = (sort values %{ $storage{method} },
- sort values %{ $overview{method} });
-my @sources = (sort @{ $storage{sources} }, sort @{ $overview{sources} });
-my @extra = (sort @{ $storage{extra} }, sort @{ $overview{extra} });
-my @programs = sort (@{ $storage{programs} }, @{ $overview{programs} });
-my @makefiles = sort (@{ $storage{makefiles} }, @{ $overview{makefiles} });
-write_makefile (\@dirs, \@sources, \@extra, \@programs, \@makefiles);
+write_makefile (\%makefile);
More information about the inn-committers
mailing list