Merge pull request #64 from BenceJanosSzabo/master
[deliverable/titan.core.git] / compiler2 / titanver
1 #!/bin/sh
2 ###############################################################################
3 # Copyright (c) 2000-2015 Ericsson Telecom AB
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"
11 perlexe=`which perl 2>/dev/null | sed -n 's/[^\/]*\(\/.*perl\)/\1/p'`
12 # Do it the hard way if not found
13 if [ -z "${perlexe}" ] ; then
14
15 GCCVER=`strings -a -10 ${1+"$@"} | sed -n '
16 s/.*TITAN: [0-9][0-9]* PLATFORM: [A-Z0-9][A-Z0-9]* //
17 /GCC/ {
18 p
19 }
20 /Sun C++/ {
21 s/.*\(Sun C++ *[0-9]\.[0-9]\).*/\1/g
22 p
23 }
24 ' | sort -u`;
25
26 if [ `echo "${GCCVER}" | wc -l` != 1 ]; then
27 echo -e "Error! Object files compiled with different compilers were detected:
28 ${GCCVER}
29 Please clean and rebuild your project.";
30 exit 1;
31 else
32 : ; # no news is good news
33 fi
34
35 exit 0; # avoid flowing into Perl
36 fi
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
41 eval 'exec ${perlexe} -x $0 ${1+"$@"} ;'
42 if 0;
43 use strict;
44 use vars qw($r $v);
45
46 my $compiler = 'GCC';
47
48 my %versions;
49
50 my $objdump = `/bin/sh -c "which objdump" 2>/dev/null`;
51 chomp $objdump;
52 exit 0 if ($objdump !~ m!^/! or !@ARGV); # go quiet if no objdump or @ARGV is empty
53
54 my $comment = '';
55
56 my @sections = qw( .titan .comment );
57 my $found_ver;
58
59 my $cmdline;
60
61 open (PIPE, $cmdline = "$objdump -s -j " . join(' -j ', @sections) . " @ARGV |") or die "open failed: $!";
62
63 my $obj = '?';
64
65 while (<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
109 close (PIPE) or die "close failed: $!";
110
111 if ( 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
122 Parse the output of objdump, which looks like this:
123
124 core/XmlReader.o: file format elf64-x86-64
125
126 Contents 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
131 Options:
132 -r=x.x.x expected GCC version
133 -v verbose
134
135 Error 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.034534 seconds and 5 git commands to generate.