Merge pull request #64 from BenceJanosSzabo/master
[deliverable/titan.core.git] / compiler2 / titanver
CommitLineData
970ed795
EL
1#!/bin/sh
2###############################################################################
3abe9331 3# Copyright (c) 2000-2015 Ericsson Telecom AB
970ed795
EL
4# All rights reserved. This program and the accompanying materials
5# are made available under the terms of the Eclipse Public License v1.0
6# which accompanies this distribution, and is available at
7# http://www.eclipse.org/legal/epl-v10.html
8###############################################################################
9# Find Perl in the path
10# Can't use `perl -e 'print $^X'` because that may print just "perl"
11perlexe=`which perl 2>/dev/null | sed -n 's/[^\/]*\(\/.*perl\)/\1/p'`
12# Do it the hard way if not found
13if [ -z "${perlexe}" ] ; then
14
15GCCVER=`strings -a -10 ${1+"$@"} | sed -n '
16s/.*TITAN: [0-9][0-9]* PLATFORM: [A-Z0-9][A-Z0-9]* //
17/GCC/ {
18p
19}
20/Sun C++/ {
21s/.*\(Sun C++ *[0-9]\.[0-9]\).*/\1/g
22p
23}
24' | sort -u`;
25
26if [ `echo "${GCCVER}" | wc -l` != 1 ]; then
27 echo -e "Error! Object files compiled with different compilers were detected:
28${GCCVER}
29Please clean and rebuild your project.";
30 exit 1;
31else
32 : ; # no news is good news
33fi
34
35exit 0; # avoid flowing into Perl
36fi
37
38#! Here begins the real -*- perl -*- -ws
39#line 34
40# The above directive should be adjusted to the line number of ** this ** line
41eval 'exec ${perlexe} -x $0 ${1+"$@"} ;'
42if 0;
43use strict;
44use vars qw($r $v);
45
46my $compiler = 'GCC';
47
48my %versions;
49
50my $objdump = `/bin/sh -c "which objdump" 2>/dev/null`;
51chomp $objdump;
52exit 0 if ($objdump !~ m!^/! or !@ARGV); # go quiet if no objdump or @ARGV is empty
53
54my $comment = '';
55
56my @sections = qw( .titan .comment );
57my $found_ver;
58
59my $cmdline;
60
61open (PIPE, $cmdline = "$objdump -s -j " . join(' -j ', @sections) . " @ARGV |") or die "open failed: $!";
62
63my $obj = '?';
64
65while (<PIPE>)
66{
67 chomp;
68 next unless length;
69 if (/^([^:]+):\s+file format/) {
70 if (length($comment)) {
71 ($found_ver) = $comment =~ /GCC: \([^)]*\) (\d\.\d+(?:\.\d+)?)/;
72 $found_ver ||= 'unknown!';
73
74 print "$compiler version was $found_ver for $obj\n" if $v;
75
76 push @{$versions{$found_ver}}, $obj;
77
78 if (defined $r and $r ne $found_ver)
79 {
80 if (!$v) { # found version was not written, do it now
81 warn "$compiler was $found_ver for $obj\n";
82 }
83
84 die " $r was expected\n";
85 }
86 }
87 $obj = $1;
88 $comment = '';
89 }
90 elsif (my ($text) =
91 m/^ \s*
92 \d{4,} # offset
93 \s
94 [0-9a-fA-F ]{8} # first group of hex digits
95 \s
96 [0-9a-fA-F ]{8} # these should be [[:xdigit:] ] but rhea's perl is ancient :(
97 \s
98 [0-9a-fA-F ]{8}
99 \s
100 [0-9a-fA-F ]{8}
101 \s\s
102 (.+) # up to 16 characters of "plain" text
103 $/x) {
104
105 $comment .= $text;
106 }
107}
108
109close (PIPE) or die "close failed: $!";
110
111if ( scalar keys %versions > 1 ) {
112 while ( my ($ver, $ref) = each %versions ) {
113 warn "Compiled with $compiler $ver: ", join(', ', @$ref), "\n";
114 }
115 die "Error! All object files should be compiled with the same compiler version.\n"
116 . "The following $compiler versions were detected: ", join(', ', keys %versions);
117}
118
119__END__
120
121
122Parse the output of objdump, which looks like this:
123
124core/XmlReader.o: file format elf64-x86-64
125
126Contents of section .comment:
127 0000 00474343 3a202847 4e552920 342e342e .GCC: (GNU) 4.4.
128 0010 30203230 30393032 31332028 65787065 0 20090213 (expe
129 0020 72696d65 6e74616c 2900 rimental).
130
131Options:
132 -r=x.x.x expected GCC version
133 -v verbose
134
135Error conditions:
136
137** -r=XXX supplied and one of the objects fail to match
138** more than one GCC version detected
139
This page took 0.048783 seconds and 5 git commands to generate.