File: preautoreconf

package info (click to toggle)
xapian-core 1.4.3-2~bpo8%2B1
  • links: PTS, VCS
  • area: main
  • in suites: jessie-backports
  • size: 21,224 kB
  • sloc: cpp: 113,806; ansic: 8,723; sh: 4,433; perl: 836; makefile: 567; tcl: 317; python: 40
file content (154 lines) | stat: -rwxr-xr-x 4,220 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#!/usr/bin/perl -w
# preautoconf - generate lists of sources for doxygen to extract docs from
#
# Copyright (C) 2005,2007,2013 Olly Betts
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

use strict;

my @makefile_am;
# version.h is generated by configure, and isn't listed in BUILT_SOURCES.
my %built_sources = qw(include/xapian/version.h 1);

if ($0 =~ m!(.*)/!) {
    $1 eq '.' or chdir $1 or die $!;
}

my %s;
for (parse_makefile_am("")) {
    $s{$_}++;
}
my @apidoc_src = ();
my @sourcedoc_src = ();
for (sort keys %s) {
    s!^\./!!;
    next if m!^tests/! || $_ eq 'include/xapian/errordispatch.h';
    my $src = $built_sources{$_} ? '$(top_builddir)' : '$T';
    $src .= "/$_";
    if (m!^include/!) {
	push @apidoc_src, $src;
    } else {
	push @sourcedoc_src, $src;
    }
}

open MAKEFRAG, ">docs/docsource.tmp" or die $!;
print MAKEFRAG "APIDOC_SRC=", join("\\\n\t", "", @apidoc_src), "\n";
print MAKEFRAG "SOURCEDOC_SRC=", join("\\\n\t", "", @sourcedoc_src), "\n";
close MAKEFRAG or do { unlink "docs/docsource.tmp"; die $! };
rename "docs/docsource.tmp", "docs/docsource.mk" or do { unlink "docs/docsource.tmp"; die $! };

open MAKEFRAG, ">docsource.tmp" or die $!;
print MAKEFRAG "docsource.mk: preautoreconf\n";
print MAKEFRAG "\tcd \$(top_srcdir) && ./preautoreconf\n";
# Add dummy rules so that "make" works even if a Makefile.am is removed.
for (@makefile_am) {
    print MAKEFRAG "\n$_:\n";
}
close MAKEFRAG or do { unlink "docsource.tmp"; die $! };
rename "docsource.tmp", "docsource.mk" or do { unlink "docsource.tmp"; die $! };

exit 0;

sub parse_makefile_am {
    my $dir = shift;
    my %v;
    my @l;
    my $makefile_am = $dir . "Makefile.am";
    my @pending = ();
    open M, "<$makefile_am" or die "$makefile_am: $!\n";
    push @makefile_am, $makefile_am;
    while (<M>) {
pending:
	chomp;
	while (s/\\$/ /) {
	    if (@pending) {
		$_ .= shift @pending;
	    } else {
		$_ .= <M>;
	    }
	    chomp;
	}
	if (/^\s*(\w+)\s*[+:]?=\s*(.*?)\s*(?:#.*)?$/) {
	    my $var = $1;
	    if (exists $v{$var}) {
		$v{$var} .= " $2";
	    } else {
		$v{$var} = $2;
		if ($var =~ /_(?:SOURCE|HEADER)S$/) {
		    push @l, $var;
		}
	    }
	} elsif (/^\s*include\s+(\S+)/ && $1 ne 'docsource.mk') {
	    # automake looks for a nested included file starting from the
	    # directory which the original file was in, so the behaviour
	    # here is correct.
	    my $inc = $dir . $1;
	    open INC, "<$inc" or die "$inc: $!\n";
	    push @makefile_am, $inc;
	    unshift @pending, <INC>;
	    close INC;
	}
	if (@pending) {
	    $_ = shift @pending;
	    goto pending;
	}
    }
    close M;

    if (exists $v{BUILT_SOURCES}) {
	for (map {/^$/ ? () : $dir.$_} split /\s+/,
		expand('BUILT_SOURCES', \%v)) {
	    $built_sources{$_}++;
	}
    }

    my @src;
    for (@l) {
	push @src, map {/^$/ ? () : $dir.$_} split /\s+/, expand($_, \%v);
    }

    my $subdirs = $v{DIST_SUBDIRS} || $v{SUBDIRS} || '';
    for (split /\s+/, $subdirs) {
	next if $_ eq ".";
	push @src, parse_makefile_am("$dir$_/");
    }
    return @src;
}

sub expand {
   my ($var, $from, $to, $vref);
   if (scalar @_ == 2) {
      ($var, $vref) = @_;
   } else {
      ($var, $from, $to, $vref) = @_;
   }

   my $val = $$vref{$var};

   # Deal with $(FOO:.bar=.c) pattern substitutions.
   if (defined $from) {
       my $x = $val;
       $val =~ s/\Q$from\E(?:\s|$)/$to/g;
   }

   if (!defined $val) {
       print STDERR "$0: Unknown variable: \$($var)\n";
       return "";
   }
   $val =~ s/\$\((\w+)(?::([^=)]+)=([^=)]+))?\)/expand($1, $2, $3, $vref)/eg;
   return $val;
}