11.1Sjmcneill#!/usr/bin/perl -w
21.1Sjmcneill
31.1Sjmcneilluse strict;
41.1Sjmcneill
51.1Sjmcneill#
61.1Sjmcneill# Generate a version from available information
71.1Sjmcneill#
81.1Sjmcneill
91.1Sjmcneillmy $prefix = shift @ARGV;
101.1Sjmcneillmy $root = shift @ARGV;
111.1Sjmcneill
121.1Sjmcneill
131.1Sjmcneillif ( not defined $root ) {
141.1Sjmcneill	die "usage: $0 prefix root-dir\n";
151.1Sjmcneill}
161.1Sjmcneill
171.1Sjmcneillif ( ! -d $root ) {
181.1Sjmcneill	die "root directory $root not found\n";
191.1Sjmcneill}
201.1Sjmcneill
211.1Sjmcneillmy $version = "unknown";
221.1Sjmcneillmy $tainted = "";
231.1Sjmcneill
241.1Sjmcneillif ( -d "$root/.git" ) {
251.1Sjmcneill	# attempt to work out git version. only do so
261.1Sjmcneill	# on a linux build host, as cygwin builds are
271.1Sjmcneill	# already slow enough
281.1Sjmcneill
291.1Sjmcneill	if ( -f "/usr/bin/git" || -f "/usr/local/bin/git" ) {
301.1Sjmcneill		if (not open(F, "git --git-dir $root/.git rev-parse --verify HEAD|")) {
311.1Sjmcneill			$version = "no git version";
321.1Sjmcneill		}
331.1Sjmcneill		else {
341.1Sjmcneill			$version = <F>;
351.1Sjmcneill			$version =~ s/[ \r\n]*$//;     # chomp may not be enough (cygwin).
361.1Sjmcneill			$version =~ s/^[ \r\n]*//;     # chomp may not be enough (cygwin).
371.1Sjmcneill		}
381.1Sjmcneill
391.1Sjmcneill		if (open(G, "git --git-dir $root/.git status --porcelain|")) {
401.1Sjmcneill			$tainted = <G>;
411.1Sjmcneill			$tainted =~ s/[ \r\n]*$//;     # chomp may not be enough (cygwin).
421.1Sjmcneill			$tainted =~ s/^[ \r\n]*//;     # chomp may not be enough (cygwin).
431.1Sjmcneill			if (length $tainted) {
441.2Sskrll			$version = join ' ', $version, "(tainted)";
451.2Sskrll		}
461.2Sskrll		else {
471.2Sskrll			$version = join ' ', $version, "(clean)";
481.2Sskrll         }
491.1Sjmcneill		}
501.1Sjmcneill	}
511.1Sjmcneill}
521.1Sjmcneill
531.1Sjmcneillmy $hostname = `hostname`;
541.1Sjmcneill$hostname =~ s/[ \r\n]*$//;     # chomp may not be enough (cygwin).
551.1Sjmcneill$hostname =~ s/^[ \r\n]*//;     # chomp may not be enough (cygwin).
561.1Sjmcneill
571.1Sjmcneill
581.1Sjmcneillprint STDERR "Version $version\n";
591.1Sjmcneillprint <<EOF;
601.1Sjmcneill#include "${prefix}_build_info.h"
611.1Sjmcneill#include <linux/broadcom/vc_debug_sym.h>
621.1Sjmcneill
631.1SjmcneillVC_DEBUG_DECLARE_STRING_VAR( ${prefix}_build_hostname, "$hostname" );
641.1SjmcneillVC_DEBUG_DECLARE_STRING_VAR( ${prefix}_build_version, "$version" );
651.1SjmcneillVC_DEBUG_DECLARE_STRING_VAR( ${prefix}_build_time,    __TIME__ );
661.1SjmcneillVC_DEBUG_DECLARE_STRING_VAR( ${prefix}_build_date,    __DATE__ );
671.1Sjmcneill
681.1Sjmcneillconst char *vchiq_get_build_hostname( void )
691.1Sjmcneill{
701.1Sjmcneill   return vchiq_build_hostname;
711.1Sjmcneill}
721.1Sjmcneill
731.1Sjmcneillconst char *vchiq_get_build_version( void )
741.1Sjmcneill{
751.1Sjmcneill   return vchiq_build_version;
761.1Sjmcneill}
771.1Sjmcneill
781.1Sjmcneillconst char *vchiq_get_build_date( void )
791.1Sjmcneill{
801.1Sjmcneill   return vchiq_build_date;
811.1Sjmcneill}
821.1Sjmcneill
831.1Sjmcneillconst char *vchiq_get_build_time( void )
841.1Sjmcneill{
851.1Sjmcneill   return vchiq_build_time;
861.1Sjmcneill}
871.1SjmcneillEOF
88