2 # preautoconf - generate lists of sources for doxygen to extract docs from
4 # Copyright (C) 2005,2007,2013 Olly Betts
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 # version.h is generated by configure, and isn't listed in BUILT_SOURCES.
24 my %built_sources = qw(include/xapian/version.h 1);
27 $1 eq '.' or chdir $1 or die $!;
31 for (parse_makefile_am
("")) {
35 my @sourcedoc_src = ();
38 next if m!^tests/! || $_ eq 'include/xapian/errordispatch.h';
39 my $src = $built_sources{$_} ?
'$(top_builddir)' : '$T';
42 push @apidoc_src, $src;
44 push @sourcedoc_src, $src;
48 open MAKEFRAG
, ">docs/docsource.tmp" or die $!;
49 print MAKEFRAG
"APIDOC_SRC=", join("\\\n\t", "", @apidoc_src), "\n";
50 print MAKEFRAG
"SOURCEDOC_SRC=", join("\\\n\t", "", @sourcedoc_src), "\n";
51 close MAKEFRAG
or do { unlink "docs/docsource.tmp"; die $! };
52 rename "docs/docsource.tmp", "docs/docsource.mk" or do { unlink "docs/docsource.tmp"; die $! };
54 open MAKEFRAG
, ">docsource.tmp" or die $!;
55 print MAKEFRAG
"docsource.mk: preautoreconf\n";
56 print MAKEFRAG
"\tcd \$(top_srcdir) && ./preautoreconf\n";
57 # Add dummy rules so that "make" works even if a Makefile.am is removed.
59 print MAKEFRAG
"\n$_:\n";
61 close MAKEFRAG
or do { unlink "docsource.tmp"; die $! };
62 rename "docsource.tmp", "docsource.mk" or do { unlink "docsource.tmp"; die $! };
66 sub parse_makefile_am
{
70 my $makefile_am = $dir . "Makefile.am";
72 open M
, "<$makefile_am" or die "$makefile_am: $!\n";
73 push @makefile_am, $makefile_am;
85 if (/^\s*(\w+)\s*[+:]?=\s*(.*?)\s*(?:#.*)?$/) {
87 if (exists $v{$var}) {
91 if ($var =~ /_(?:SOURCE|HEADER)S$/) {
95 } elsif (/^\s*include\s+(\S+)/ && $1 ne 'docsource.mk') {
96 # automake looks for a nested included file starting from the
97 # directory which the original file was in, so the behaviour
100 open INC
, "<$inc" or die "$inc: $!\n";
101 push @makefile_am, $inc;
102 unshift @pending, <INC
>;
112 if (exists $v{BUILT_SOURCES
}) {
113 for (map {/^$/ ?
() : $dir.$_} split /\s+/,
114 expand
('BUILT_SOURCES', \
%v)) {
115 $built_sources{$_}++;
121 push @src, map {/^$/ ?
() : $dir.$_} split /\s+/, expand
($_, \
%v);
124 my $subdirs = $v{DIST_SUBDIRS
} || $v{SUBDIRS
} || '';
125 for (split /\s+/, $subdirs) {
127 push @src, parse_makefile_am
("$dir$_/");
133 my ($var, $from, $to, $vref);
134 if (scalar @_ == 2) {
137 ($var, $from, $to, $vref) = @_;
140 my $val = $$vref{$var};
142 # Deal with $(FOO:.bar=.c) pattern substitutions.
145 $val =~ s/\Q$from\E(?:\s|$)/$to/g;
149 print STDERR
"$0: Unknown variable: \$($var)\n";
152 $val =~ s/\$\((\w+)(?::([^=)]+)=([^=)]+))?\)/expand($1, $2, $3, $vref)/eg;