Skip to content

Commit

Permalink
Define PY_MAJOR_VERSION automatically
Browse files Browse the repository at this point in the history
The selected python version is queried for its version and the
PY_MAJOR_VERSION is set appropriately using -D to the compiler.
  • Loading branch information
rikardn committed Sep 12, 2019
1 parent 251338b commit ccebb9c
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions Makefile.PL
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ $sel = { path => $sel } unless ref $sel eq 'HASH'; # in case the user entered a

print "Using $sel->{path}\n";

my $py_major_version = get_python_major_version($sel);

#============================================================================
# Interrogate the python interpreter (or the user) for required flags
#============================================================================
Expand All @@ -71,6 +73,7 @@ $sel->{libpython} =~ s/lib(.*)(?:\.\Q$Config{dlext}\E|\Q$Config{_a}\E)/-l$1/;
my @flags;
push @flags, debug_flag() if defined $gdb;
push @flags, '-DI_PY_DEBUG' if $debug;
push @flags, "-DPY_MAJOR_VERSION=$py_major_version";
push @flags, 'none (perl Makefile.PL --help for details)' unless @flags;
print <<END;
Using These Settings:
Expand Down Expand Up @@ -182,6 +185,15 @@ END
return 1;
}

sub get_python_major_version {
my $ref = shift;
my $exe = $ref->{path};
my $version = `$exe --version 2>&1`;

$version =~ /(\d+)\./;
return $1;
}

sub get_config_var {
my $ref = shift;
my $key = shift;
Expand Down

0 comments on commit ccebb9c

Please sign in to comment.