#!/usr/bin/env perl =head1 TITLE gen-version.pl -- script to generate version information for HLL compilers =cut use 5.008; use strict; use warnings; use Digest::SHA; use File::Find; use File::Spec; use POSIX 'strftime'; my $prefix = shift // ''; my $static_nqp_home = shift // ''; my $libdir = shift // ''; my $backend = shift // ''; open(my $fh, '<', 'VERSION') or die $!; my $VERSION = <$fh>; close($fh); # .git is a file and not a directory in submodule if (-e '.git' && open(my $GIT, '-|', 'git describe --tags "--match=20*"')) { $VERSION = <$GIT>; close($GIT); } chomp $VERSION; my $sha = Digest::SHA->new; find(sub { return unless /\.nqp\z/; $sha->addfile($_) }, "src"); if ($backend eq 'moar') { $sha->addfile(File::Spec->catfile($libdir, 'MAST', $_)) for qw(Nodes.nqp Ops.nqp); } # add everything that could change the generated nqp-config.nqp and thus NQP's # sources, despite src/ not getting touched $sha->add(join "\0", $VERSION, $prefix, $static_nqp_home, $libdir); my $source_digest = $sha->hexdigest; print <<"END_VERSION"; sub hll-config(\$config) { \$config := '$VERSION'; \$config := '$prefix'; \$config := '$static_nqp_home'; \$config := '$static_nqp_home'; \$config := '$libdir'; \$config := '$source_digest'; } END_VERSION 0;