summaryrefslogtreecommitdiff
path: root/util/lt.pl
blob: b7280b5624d02fe5963a68575ee01c67e6c4bdcc (plain)
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
#!/usr/bin/perl
#
# Copyright (C) 2016-2017  Internet Systems Consortium, Inc. ("ISC")
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
# AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
# PERFORMANCE OF THIS SOFTWARE.

# build configure.am with or without libtool stuff

require 5.000;
use strict;

# general arguments

my @optionlist = ("with", "without", "verbose");

# usage

my $usage = ("Usage: perl lt.pl [with|without] [verbose]\n");

# Parse arguments

my $with = 0;
my $verbose = 0;

foreach (@ARGV) {
    if (/^with$/i) {
	$with = 1;
    } elsif (/^without$/i) {
	$with = 0;
    } elsif (/^verbose$/i) {
	$verbose = 1;
    } else {
	die $usage;
    }
}

if ($verbose) {
    if ($with) {
	print STDERR "building the with libtool version\n";
    } else {
	print STDERR "building the without libtool version\n";
    }
}

# Perform 

my $line;
my $state = "top";
my $directives = 0;
my $included = 0;
my $escaped = 0;

foreach $line (<STDIN>) {
    chomp $line;
    if ($line =~ /^\@BEGIN WITH LIBTOOL$/) {
	if ($state eq "top") {
	    $state = "with";
	} elsif ($state eq "with") {
	    die "got WITH begin in WITH context\n";
	} elsif ($state eq "without") {
	    die "got WITH begin in WITHOUT context\n";
	}
	$directives += 1;
	next;
    } elsif ($line =~ /^\@BEGIN WITHOUT LIBTOOL$/) {
	if ($state eq "top") {
	    $state = "without";
	} elsif ($state eq "with") {
	    die "got WITHOUT begin in WITH context\n";
	} elsif ($state eq "without") {
	    die "got WITHOUT begin in WITHOUT context\n";
	}
	$directives += 1;
	next;
    } elsif ($line =~ /^\@END WITH LIBTOOL$/) {
	if ($state eq "with") {
	    $state = "top";
	} elsif ($state eq "top") {
	    die "got WITH end outside context\n";
	} elsif ($state eq "without") {
	    die "got WITH end in WITHOUT context\n";
	}
	$directives += 1;
	next;
    } elsif ($line =~ /^\@END WITHOUT LIBTOOL$/) {
	if ($state eq "without") {
	    $state = "top";
	} elsif ($state eq "top") {
	    die "got WITHOUT end outside context\n";
	} elsif ($state eq "with") {
	    die "got WITHOUT end in WITH context\n";
	}
	$directives += 1;
	next;
    } elsif ($line =~ /^@/) {
	die "git unknown directive '$line'\n";
    }

    if ($state eq "with") {
	if ($with) {
	    $included += 1;
	} else {
	    $escaped += 1;
	    next;
	}
    } elsif ($state eq "without") {
	if ($with) {
	    $escaped += 1;
	    next;
	} else {
	    $included += 1;
	}
    }
    print $line. "\n";
}

if ($verbose) {
    print STDERR "directives: $directives\n";
    print STDERR "included: $included\n";
    print STDERR "escaped: $escaped\n";
}

exit 0;