git-tag-release: Point at release branch
[xapian.git] / xapian-bindings / swig-depcomp
blob23978c33a0a617b7b46926e9a2cfa7585ec82afd
1 #!/usr/bin/perl
2 # swig-depcomp: Wrap call to SWIG and generate and adjust dependencies.
4 # Copyright 2012,2013 Olly Betts
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License as
8 # published by the Free Software Foundation; either version 2 of the
9 # License, or (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
19 # USA
21 use strict;
22 use warnings;
24 if (@ARGV < 2) {
25 die "Syntax: $0 SWIG ARGS...\n";
28 my $swig = shift @ARGV;
29 my @swig_args = @ARGV;
31 my $tmp_deps = 'swig_d.tmp';
33 unshift @swig_args, ('-MD', '-MF', $tmp_deps);
35 system($swig, @swig_args) == 0 or die $!;
37 open TMPDEPS, '<', $tmp_deps or die $!;
38 unlink $tmp_deps;
40 open DEPS, '>', "${tmp_deps}2" or die $!;
41 my $target;
43 my @sources = ();
44 while (<TMPDEPS>) {
45 if (!defined $target) {
46 /(.*):/ or next;
47 $target = $1;
48 if (exists $ENV{'stamp'}) {
49 $_ = "$ENV{'stamp'}: \\\n";
51 } else {
52 my $line = $_;
53 s/\\$//;
54 push @sources, split;
55 $_ = $line;
57 print DEPS $_;
60 # Generate dummy rules for the sources, so that if one gets removed we can
61 # still rebuild successfully.
62 for (@sources) {
63 print DEPS "\n$_:\n";
66 close DEPS or die $!;
68 $target =~ s/(?:\..*)$/.d/;
69 rename "${tmp_deps}2", $target or die $!;