| 1 | #!/usr/bin/perl |
|---|
| 2 | |
|---|
| 3 | use strict; |
|---|
| 4 | use warnings; |
|---|
| 5 | |
|---|
| 6 | my $old_extension = 'last_gcc'; |
|---|
| 7 | my $extension = 'last_compiler'; |
|---|
| 8 | |
|---|
| 9 | my $args = scalar(@ARGV); |
|---|
| 10 | if ($args!=2) { die "Usage: check_same_compiler_version.pl name version\n"; } |
|---|
| 11 | |
|---|
| 12 | my $name = $ARGV[0]; |
|---|
| 13 | my $version = $ARGV[1]; |
|---|
| 14 | |
|---|
| 15 | my $arbhome = $ENV{'ARBHOME'}; |
|---|
| 16 | (-d $arbhome) || die "\$arbhome has to contain the name of a directory.\n"; |
|---|
| 17 | |
|---|
| 18 | opendir(ARBHOME,$arbhome) || die "can't read directory '$arbhome' (Reason: $!)"; |
|---|
| 19 | my @found_version_files = (); |
|---|
| 20 | foreach (readdir(ARBHOME)) { |
|---|
| 21 | if (/\.$extension$/ig) { push @found_version_files, $_; } |
|---|
| 22 | if (/\.$old_extension$/ig) { push @found_version_files, $_; } |
|---|
| 23 | } |
|---|
| 24 | closedir(ARBHOME); |
|---|
| 25 | |
|---|
| 26 | my $result = 0; |
|---|
| 27 | my $found = scalar(@found_version_files); |
|---|
| 28 | |
|---|
| 29 | my $currVersion = $version.'.'.$name.'.'.$extension; |
|---|
| 30 | my $obsoleteVersion = $version.'.'.$old_extension; |
|---|
| 31 | |
|---|
| 32 | if ($found == 0) { # first compilation -> create file |
|---|
| 33 | my $flagfile = $arbhome.'/'.$currVersion; |
|---|
| 34 | open(FLAG,">$flagfile") || die "can't create '$flagfile' (Reason: $!)"; |
|---|
| 35 | print FLAG "- The last compilation was done using '$name $version'.\n"; |
|---|
| 36 | close(FLAG); |
|---|
| 37 | } |
|---|
| 38 | elsif ($found != 1) { |
|---|
| 39 | die "Multiple compiler version files were found -- 'make rebuild' is your friend"; |
|---|
| 40 | } |
|---|
| 41 | else { |
|---|
| 42 | my $lastVersion = $found_version_files[0]; |
|---|
| 43 | if ($lastVersion eq $obsoleteVersion) { |
|---|
| 44 | print "[ renaming $obsoleteVersion -> $currVersion ]\n"; |
|---|
| 45 | my $command = "mv $obsoleteVersion $currVersion"; |
|---|
| 46 | system("$command") ==0 || die "can't execute '$command' (Reason: $?)"; |
|---|
| 47 | } |
|---|
| 48 | elsif ($lastVersion ne $currVersion) { |
|---|
| 49 | my $command = "cat $lastVersion"; |
|---|
| 50 | system("$command") ==0 || die "can't execute '$command' (Reason: $?)"; |
|---|
| 51 | print "- Your current compiler version is '$name $version'.\n"; |
|---|
| 52 | print "Use 'make rebuild' to recompile with a different compiler version or\n"; |
|---|
| 53 | print "use 'make clean' to cleanup build and then compile again.\n"; |
|---|
| 54 | $result = 1; |
|---|
| 55 | } |
|---|
| 56 | } |
|---|
| 57 | |
|---|
| 58 | exit($result); |
|---|