2 # preautoconf - generate lists of sources for doxygen to extract docs from
4 # Copyright (C) 2005,2007,2013,2018 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
24 # version.h is generated by configure, and isn't listed in BUILT_SOURCES.
25 my %built_sources = qw(include/xapian/version.h 1);
28 $1 eq '.' or chdir $1 or die $!;
32 for (parse_makefile_am
("")) {
36 my @sourcedoc_src = ();
39 next if m!^tests/! || $_ eq 'include/xapian/errordispatch.h';
40 my $src = $built_sources{$_} ?
'$(top_builddir)' : '$T';
43 push @apidoc_src, $src;
45 push @sourcedoc_src, $src;
49 open MAKEFRAG
, ">docs/docsource.tmp" or die $!;
50 print MAKEFRAG
"APIDOC_SRC=", join("\\\n\t", "", @apidoc_src), "\n";
51 print MAKEFRAG
"SOURCEDOC_SRC=", join("\\\n\t", "", @sourcedoc_src), "\n";
52 close MAKEFRAG
or do { unlink "docs/docsource.tmp"; die $! };
53 rename "docs/docsource.tmp", "docs/docsource.mk" or do { unlink "docs/docsource.tmp"; die $! };
55 open MAKEFRAG
, ">docsource.tmp" or die $!;
56 print MAKEFRAG
"docsource.mk: preautoreconf\n";
57 print MAKEFRAG
"\tcd \$(top_srcdir) && '$^X' ./preautoreconf\n";
58 # Add dummy rules so that "make" works even if a Makefile.am is removed.
60 print MAKEFRAG
"\n$_:\n";
62 close MAKEFRAG
or do { unlink "docsource.tmp"; die $! };
63 rename "docsource.tmp", "docsource.mk" or do { unlink "docsource.tmp"; die $! };
67 sub parse_makefile_am
{
71 my $makefile_am = $dir . "Makefile.am";
73 open M
, "<$makefile_am" or die "$makefile_am: $!\n";
74 push @makefile_am, $makefile_am;
86 if (/^\s*(\w+)\s*[+:]?=\s*(.*?)\s*(?:#.*)?$/) {
88 if (exists $v{$var}) {
92 if ($var =~ /_(?:SOURCE|HEADER)S$/) {
96 } elsif (/^\s*include\s+(\S+)/ && $1 ne 'docsource.mk') {
97 # automake looks for a nested included file starting from the
98 # directory which the original file was in, so the behaviour
101 open INC
, "<$inc" or die "$inc: $!\n";
102 push @makefile_am, $inc;
103 unshift @pending, <INC
>;
113 if (exists $v{BUILT_SOURCES
}) {
114 for (map {/^$/ ?
() : $dir.$_} split /\s+/,
115 expand
('BUILT_SOURCES', \
%v)) {
116 $built_sources{$_}++;
122 push @src, map {/^$/ ?
() : $dir.$_} split /\s+/, expand
($_, \
%v);
125 my $subdirs = $v{DIST_SUBDIRS
} || $v{SUBDIRS
} || '';
126 for (split /\s+/, $subdirs) {
128 push @src, parse_makefile_am
("$dir$_/");
134 my ($var, $from, $to, $vref);
135 if (scalar @_ == 2) {
138 ($var, $from, $to, $vref) = @_;
141 my $val = $$vref{$var};
143 # Deal with $(FOO:.bar=.c) pattern substitutions.
146 $val =~ s/\Q$from\E(?:\s|$)/$to/g;
150 print STDERR
"$0: Unknown variable: \$($var)\n";
153 $val =~ s/\$\((\w+)(?::([^=)]+)=([^=)]+))?\)/expand($1, $2, $3, $vref)/eg;