#!/bin/sh ############################################################################### # Copyright (c) 2000-2015 Ericsson Telecom AB # All rights reserved. This program and the accompanying materials # are made available under the terms of the Eclipse Public License v1.0 # which accompanies this distribution, and is available at # http://www.eclipse.org/legal/epl-v10.html ############################################################################### # Find Perl in the path # Can't use `perl -e 'print $^X'` because that may print just "perl" perlexe=`which perl 2>/dev/null | sed -n 's/[^\/]*\(\/.*perl\)/\1/p'` # Do it the hard way if not found if [ -z "${perlexe}" ] ; then GCCVER=`strings -a -10 ${1+"$@"} | sed -n ' s/.*TITAN: [0-9][0-9]* PLATFORM: [A-Z0-9][A-Z0-9]* // /GCC/ { p } /Sun C++/ { s/.*\(Sun C++ *[0-9]\.[0-9]\).*/\1/g p } ' | sort -u`; if [ `echo "${GCCVER}" | wc -l` != 1 ]; then echo -e "Error! Object files compiled with different compilers were detected: ${GCCVER} Please clean and rebuild your project."; exit 1; else : ; # no news is good news fi exit 0; # avoid flowing into Perl fi #! Here begins the real -*- perl -*- -ws #line 34 # The above directive should be adjusted to the line number of ** this ** line eval 'exec ${perlexe} -x $0 ${1+"$@"} ;' if 0; use strict; use vars qw($r $v); my $compiler = 'GCC'; my %versions; my $objdump = `/bin/sh -c "which objdump" 2>/dev/null`; chomp $objdump; exit 0 if ($objdump !~ m!^/! or !@ARGV); # go quiet if no objdump or @ARGV is empty my $comment = ''; my @sections = qw( .titan .comment ); my $found_ver; my $cmdline; open (PIPE, $cmdline = "$objdump -s -j " . join(' -j ', @sections) . " @ARGV |") or die "open failed: $!"; my $obj = '?'; while () { chomp; next unless length; if (/^([^:]+):\s+file format/) { if (length($comment)) { ($found_ver) = $comment =~ /GCC: \([^)]*\) (\d\.\d+(?:\.\d+)?)/; $found_ver ||= 'unknown!'; print "$compiler version was $found_ver for $obj\n" if $v; push @{$versions{$found_ver}}, $obj; if (defined $r and $r ne $found_ver) { if (!$v) { # found version was not written, do it now warn "$compiler was $found_ver for $obj\n"; } die " $r was expected\n"; } } $obj = $1; $comment = ''; } elsif (my ($text) = m/^ \s* \d{4,} # offset \s [0-9a-fA-F ]{8} # first group of hex digits \s [0-9a-fA-F ]{8} # these should be [[:xdigit:] ] but rhea's perl is ancient :( \s [0-9a-fA-F ]{8} \s [0-9a-fA-F ]{8} \s\s (.+) # up to 16 characters of "plain" text $/x) { $comment .= $text; } } close (PIPE) or die "close failed: $!"; if ( scalar keys %versions > 1 ) { while ( my ($ver, $ref) = each %versions ) { warn "Compiled with $compiler $ver: ", join(', ', @$ref), "\n"; } die "Error! All object files should be compiled with the same compiler version.\n" . "The following $compiler versions were detected: ", join(', ', keys %versions); } __END__ Parse the output of objdump, which looks like this: core/XmlReader.o: file format elf64-x86-64 Contents of section .comment: 0000 00474343 3a202847 4e552920 342e342e .GCC: (GNU) 4.4. 0010 30203230 30393032 31332028 65787065 0 20090213 (expe 0020 72696d65 6e74616c 2900 rimental). Options: -r=x.x.x expected GCC version -v verbose Error conditions: ** -r=XXX supplied and one of the objects fail to match ** more than one GCC version detected