summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/util/gcc-gte.pl
blob: b9981cf6fe542330139245c9936129700768c8c5 (plain) (blame)
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
#!/usr/bin/env perl
#
# Simple GCC version check
#
# I have a feeling this could be better-implemented, because
# it seems like the regex results should be available in an
# array (i.e $RESULT[1] == $1 or something), but whatever.
# But for now, this works fine. - Steven
#

use strict;
use warnings;

my $gcc = $ARGV[0];
my $min = $ARGV[1];

if ( `which $gcc 2> /dev/null` ) {
} else {
	die "Can't detect GCC version ($gcc is missing?)\n";
}

my $local = `$gcc -dumpversion`;
my $pattern = "([0-9]+).([0-9]+).([0-9]+)";

if ($local =~ $pattern) {
} else {
	die "Version '$local' is malformed.\n";
}

my $local_major = $1;
my $local_minor = $2;
my $local_patch = $3;

if ($min =~ $pattern) {
} else {
	die "Version '$min' is malformed.\n";
}

my $min_major = $1;
my $min_minor = $2;
my $min_patch = $3;

if ($local_major > $min_major) {
	print "1";
	exit 0;
}

if ($local_major < $min_major) {
	print "0";
	exit 0;
}

if ($local_minor > $min_minor) {
	print "1";
	exit 0;
}

if ($local_minor < $min_minor) {
	print "0";
	exit 0;
}

if ($local_patch < $min_patch) {
	print "0";
	exit 0;
}

print "1";
exit 0;