Prima
view release on metacpan or search on metacpan
Makefile.PL view on Meta::CPAN
use strict;
use warnings;
use 5.012;
package MY::orderedhash;
require Tie::Hash;
our @ISA = qw(Tie::ExtraHash);
sub tie { CORE::tie my %a, $_[0], $_[1]; \%a }
sub TIEHASH { bless [{%{$_[1]}}], $_[0] }
sub FIRSTKEY { $_[0][1] = [ sort keys %{$_[0][0]} ]; shift @{ $_[0][1] } }
sub NEXTKEY { shift @{ $_[0][1] } }
package MY;
use strict;
use warnings;
use lib '.';
use Cwd;
use Config;
use DynaLoader;
use Prima::sys::Gencls;
use ExtUtils::MakeMaker;
use File::Find;
use File::Path;
use File::Basename;
use File::Copy;
use vars qw(
$ARGV_STR
$COUTOFLAG
$COUTEXEFLAG
$CLIBPATHFLAG
$CLINKPREFIX
$LDLIBFLAG
$LDOUTFLAG
$TMPDIR
$NULLDEV
$SCRIPT_EXT
$LD_LIB_EXT
$LIB_EXT
$LIB_PREFIX
$LDFLAGS
$LDDLFLAGS
@LIBS
@INCPATH
@LIBPATH
%DEFINES
%PREREQ
%PASSIVE_CODECS
@ACTIVE_CODECS
$DL_LOAD_FLAGS
$DISTNAME
$CWD
$SHQUOTE
$DEFFILE
$OPTIMIZE
$CC_OPENMP
$LD_OPENMP
%ALL_PM_INSTALL
%ALL_MAN_INSTALL
%MODVERSIONS
$PKGCONFIG
);
use vars qw(
%cmd_options
%passthru_options
$Win32
$Win64
$unix
$cygwin
$mingw
$MacOSX
$platform
$flavor
$path_sep
%alldeps
@pm_files
@prima_files
@pod_files
@c_files
@h_files
@o_files
@exe_files
@cls_files
@target_clean
%cache_find_files
$binary_prereq
$compiler_type
$compiler_subtype
$compiler_version
@Prima_exports
$win32_use_dlltool
$cygwin_fake_Slib
$force_cccdl
Makefile.PL view on Meta::CPAN
%ALL_PM_INSTALL = (
# PM
( map { $_ => '$(INST_LIBDIR)/'. $_ } @prima_files ),
# INC
( map {
my $k = $_;
$k =~ s/^include\///;
( $_ => '$(INST_LIBDIR)/Prima/CORE/' . $k )
} @h_files ),
# POD
( map {
my $k = $_;
$k =~ s/^pod\///;
$_ => '$(INST_LIBDIR)/' . $k
} @pod_files ),
# examples
( map { $_ => '$(INST_LIBDIR)/Prima/' . $_ } <examples/*> ),
);
%ALL_MAN_INSTALL = (
map {
my $target = $_;
$target =~ s/\//::/g;
$target =~ s/\.\w+$//;
$_ => '$(INST_MAN3DIR)/'. $target . '.$(MAN3EXT)'
}
(@pm_files, grep { /pod$/ } @pod_files)
);
}
sub gcc { $compiler_type eq 'gcc' }
sub setup_environment
{
if ( $Config{ccname} =~ /\bgcc/ ) {
$compiler_type = 'gcc';
} else {
$compiler_type = $Config{ccname};
}
if ( $Win32 and not $cygwin ) {
$SCRIPT_EXT = '.bat';
$SHQUOTE = '"';
if (gcc) {
$win32_use_dlltool = $Config{dlltool} || 'dlltool';
$mingw = 1;
}
} else {
$SCRIPT_EXT = '';
$SHQUOTE = "'";
}
$OPTIMIZE = $Config{optimize};
if ( $compiler_type eq 'cl') {
$COUTOFLAG = '-Fo';
$COUTEXEFLAG = '-Fe';
$CLIBPATHFLAG = '/LIBPATH:';
$CLINKPREFIX = '/link';
$CLINKPREFIX .= " $1" if $Config{libs} =~ /(bufferoverflowU.lib)/i;
$LDLIBFLAG = '';
$LDOUTFLAG = '/OUT:';
$LD_LIB_EXT = '.lib';
$OPTIMIZE = '-Zi' if $cmd_options{DEBUG};
$CC_OPENMP = '/openmp';
$LD_OPENMP = '';
# link flag is /DEBUG, but we don't care because ActiveState has it on by default anyway
}
else {
$COUTOFLAG = '-o ';
$COUTEXEFLAG = '-o ';
$CLIBPATHFLAG = '-L';
$CLINKPREFIX = '';
$LDLIBFLAG = '-l';
$LDOUTFLAG = '-o ';
$LD_LIB_EXT = '';
$OPTIMIZE = '-g' if $cmd_options{DEBUG};
$CC_OPENMP = '-fopenmp';
$LD_OPENMP = '-fopenmp';
$OPTIMIZE .= ' -Wall' if gcc;
if ($cmd_options{DEBUG}) {
$passthru_options{LDDLFLAGS} .= ' -g';
$passthru_options{LDDLFLAGS} =~ s/(^| )\-s\b//;
}
}
$DEFFILE = 'Prima.def';
$LIB_EXT = ($cygwin ? '.dll' : '') . $Config{ _a};
$LIB_PREFIX = ($cygwin || $mingw) ? 'lib' : '';
$LDFLAGS = '';
open F, 'Prima.pm' or die "Cannot open Prima.pm:$!\n";
my ($ver1, $ver2);
while (<F>) {
next unless m/\$VERSION[^\.\d]*(\d+)\.([_\d]+)/;
$ver1 = $1, $ver2 = $2, last;
}
close F;
die "Cannot find VERSION string in Prima.pm\n" unless defined $ver1;
printlog "Version: $ver1.$ver2\n";
my $PATCHLEVEL = defined($Config{PATCHLEVEL}) ? $Config{PATCHLEVEL} : $Config{PERL_PATCHLEVEL};
my $SUBVERSION = defined($Config{SUBVERSION}) ? $Config{SUBVERSION} : $Config{PERL_SUBVERSION};
my $REVISION = defined($Config{REVISION}) ? $Config{REVISION} : $Config{PERL_REVISION};
%DEFINES = (
PRIMA_VERSION => $ver1,
PRIMA_SUBVERSION => $ver2,
PERL_PATCHLEVEL => $PATCHLEVEL,
PERL_SUBVERSION => $SUBVERSION,
PRIMA_CORE => 1,
PERL_POLLUTE => 1,
);
if ( $platform eq 'win32') {
$DEFINES{PRIMA_PLATFORM_WINDOWS} = 1;
} else {
$DEFINES{PRIMA_PLATFORM_X11} = 1;
}
$TMPDIR = $ENV{ TMPDIR} || $ENV{ TEMPDIR} || ( $Win32 ? ( $ENV{ TEMP} || "$ENV{SystemDrive}\\TEMP") : "/tmp");
$NULLDEV = 'makefile.log';
printlog "Flavor: ";
$flavor = $^O;
if ( $Win32 and not $cygwin ) {
if ( $Config{myuname} =~ /strawberry\-?perl/i) {
$flavor = 'strawberry';
} elsif ( `perl -V` =~ /activeperl/i) {
$flavor = 'activestate';
}
$flavor .= ( $Config{ptrsize} == 8 ) ? '64' : '32';
} elsif ( $cygwin ) {
$flavor .= ( $Config{ptrsize} == 8 ) ? '64' : '32';
$flavor .= '.x11';
Makefile.PL view on Meta::CPAN
local *CF;
open CF, "<$cfile" or die "Cannot open $cfile: $!";
while ( <CF>) {
chomp;
next unless /^\s*\#\s*include\s+"([^\"]+)"/;
my $incfile = $1;
my $i = find_file( $incfile);
$incfile = defined($i) ? $i : "include/generic/$incfile";
$incfile = canon_name( $incfile);
unless ( exists $included->{ $incfile}) {
push @{ $alldeps{ $cfile}}, $incfile;
push @{ $deps->{ $cfile}}, $incfile;
$included->{ $incfile} = 1;
}
my @subdeps = find_cdeps( $incfile, $deps, $included);
push @{ $deps->{ $cfile}}, @subdeps;
push @{ $alldeps{ $cfile}}, @subdeps;
}
close CF;
return @{ $deps->{ $cfile}};
}
sub cc_command_line
{
my ( $srcf, $objf, $exef, $compile_only, $dl) = @_;
my $ccflags = $Config{ccflags};
$ccflags =~ s/\b\-W(all|error|\d)w*//i;
my $cc = "$Config{cc} $ccflags";
$cc .= " $cmd_options{EXTRA_CCFLAGS}" if length $cmd_options{EXTRA_CCFLAGS};
$cc .= " $passthru_options{DEFINE}" if length $passthru_options{DEFINE};
$cc .= " $Config{cccdlflags}" if $dl || $force_cccdl;
$cc .= " $Config{ccdlflags}" if $dl && !$compile_only;
$cc .= " -c " if $compile_only;
$cc .= ' ' . join(' ', map { "-I$_" } @INCPATH);
$cc .= " $passthru_options{INC}" if length $passthru_options{INC};
$cc .= $compile_only ? " $COUTOFLAG$objf" : " $COUTEXEFLAG$exef";
$cc .= " $COUTOFLAG$objf" if $compiler_type eq 'cl' && !$compile_only;
$cc .= ' ' . join(' ', map { "$CLIBPATHFLAG$_"} @LIBPATH) unless $compile_only || ( $compiler_type eq 'cl');
$cc .= " $srcf";
return $cc if $compile_only;
$cc .= " $passthru_options{LDDLFLAGS}" if gcc;
$cc .= " $CLINKPREFIX";
$cc .= " $LDFLAGS";
$cc .= ' ' . join(' ', map { "\"$CLIBPATHFLAG\\\"$_\\\"\"" } @LIBPATH) if $compiler_type eq 'cl';
$cc .= ' ' . join(' ', map { "$LDLIBFLAG$_$LD_LIB_EXT"} @LIBS);
$cc .= " $passthru_options{LIBS}" if length $passthru_options{LIBS};
$cc .= " $cmd_options{EXTRA_LDFLAGS}" if length $cmd_options{EXTRA_LDFLAGS};
$cc =~ s/\-bundle// if $MacOSX;
return $cc;
}
sub ld_command_line
{
my ( $dstf) = shift;
my $ld = "$passthru_options{LD} $passthru_options{LDDLFLAGS}";
$ld .= " $LDFLAGS";
$ld .= " $cmd_options{EXTRA_LDFLAGS}" if length $cmd_options{EXTRA_LDFLAGS};
$ld .= " $LDOUTFLAG$dstf @_";
$ld .= ' ' . join(' ', map { "$LDLIBFLAG$_$LD_LIB_EXT"} @LIBS);
return $ld;
}
sub null_output
{
open OLDSTDOUT, ">&STDOUT" or die "STDOUT dup failed: $!";
open OLDSTDERR, ">&STDERR" or die "STDERR dup failed: $!";
# $NULLDEV = ( $Win32) ? "CON" : "/dev/tty";
# $NULLDEV = ( $Win32) ? "NUL" : "/dev/null";
if ( $^O !~ /linux/) {
close STDOUT;
close STDERR;
}
open STDOUT, ">>$NULLDEV" or die "STDOUT redirect failed: $!";
open STDERR, ">&STDOUT" or die "STDERR redirect failed: $!";
if ( -f $NULLDEV ) {
$offset_makefile_log = -s $NULLDEV;
undef $captured_makefile_log;
}
}
sub restore_output
{
if ( $^O !~ /linux/) {
close STDOUT;
close STDERR;
}
open STDOUT, ">&OLDSTDOUT" or die "STDOUT restoration failed: $!";
open STDERR, ">&OLDSTDERR" or die "STDERR restoration failed: $!";
close OLDSTDOUT;
close OLDSTDERR;
if ( -f $NULLDEV ) {
if ( open MAKEFILELOG, '<', $NULLDEV) {
binmode MAKEFILELOG;
seek MAKEFILELOG, $offset_makefile_log, 0;
local $/;
$captured_makefile_log = <MAKEFILELOG>;
print "\n", $captured_makefile_log if $cmd_options{VERBOSE};
close MAKEFILELOG;
}
}
}
sub tempfile
{
my $mask = shift;
my $name;
my $n = 0;
do {
$name = sprintf $mask, $n++;
} while ( -e $name);
return $name;
}
sub compile
{
my ( $text, $compile_only, @extra) = @_;
Makefile.PL view on Meta::CPAN
push @libpath, "$cwd/auto/Prima";
push @libs, "Prima$LD_LIB_EXT";
}
my $libpath = join( ',', map {"'$_'"} @libpath);
unless ( $unix or gcc) {
$libpath[-1] = '$(lib)/auto/Prima';
}
my $libpathi = join( ',', map {"'$_'"} @libpath);
my $ldlibs = join( ',', map {"'$_'"} @libs);
my ($libs, $libsi) = ('','');
if ( $cygwin) {
$libs = "-L$cwd/blib/arch/auto/Prima -lPrima";
$libsi = '-L$(lib)/auto/Prima -lPrima';
} elsif ( $Win32) {
$libs = "$cwd/blib/arch/auto/Prima/${LIB_PREFIX}Prima$LIB_EXT";
$libsi = '$(lib)' . "/auto/Prima/${LIB_PREFIX}Prima$LIB_EXT";
}
my $cc_openmp = $cmd_options{WITH_OPENMP} ? $CC_OPENMP : '';
open F, "> Prima/Config.pm" or die "cannot open Prima/Config.pm:$!\n";
print F <<CONFIG;
# This file was automatically generated.
# Do not edit, you'll loose your changes anyway.
package Prima::Config;
use strict;
use warnings;
use vars qw(%Config %Config_inst);
%Config_inst = (
incpaths => [ $ippi ],
gencls => '\$(bin)${ifs}prima-gencls$SCRIPT_EXT',
tmlink => '\$(bin)${ifs}prima-tmlink$SCRIPT_EXT',
libname => '\$(lib)${ifs}auto${ifs}Prima${ifs}${LIB_PREFIX}Prima$LIB_EXT',
dlname => '\$(lib)${ifs}auto${ifs}Prima${ifs}Prima.$Config{dlext}',
ldpaths => [$libpathi],
inc => '$inci',
libs => '$libsi',
);
%Config = (
ifs => '\\$ifs',
quote => '\\$SHQUOTE',
platform => '$platform',
incpaths => [ $ipp ],
gencls => ${_quotepath("$cwd/blib/script/prima-gencls$SCRIPT_EXT")},
tmlink => ${_quotepath("$cwd/blib/script/prima-tmlink$SCRIPT_EXT")},
scriptext => ${_quote($SCRIPT_EXT)},
genclsoptions => '--tml --h --inc',
cobjflag => ${_quote($COUTOFLAG)},
coutexecflag => ${_quote($COUTEXEFLAG)},
clinkprefix => ${_quote($CLINKPREFIX)},
clibpathflag => ${_quote($CLIBPATHFLAG)},
cdefs => [],
libext => ${_quote($LIB_EXT)},
libprefix => ${_quote($LIB_PREFIX)},
libname => ${_quotepath("$cwd/blib/arch/auto/Prima/${LIB_PREFIX}Prima$LIB_EXT")},
dlname => ${_quotepath("$cwd/blib/arch/auto/Prima/Prima.$Config{dlext}")},
ldoutflag => ${_quote($LDOUTFLAG)},
ldlibflag => ${_quote($LDLIBFLAG)},
ldlibpathflag => ${_quote($CLIBPATHFLAG)},
ldpaths => [$libpath],
ldlibs => [$ldlibs],
ldlibext => ${_quote($LD_LIB_EXT)},
inline => ${_quote($DEFINES{__INLINE__})},
dl_load_flags => $DL_LOAD_FLAGS,
optimize => '$OPTIMIZE',
openmp => '$cc_openmp',
inc => '$inc',
define => '',
libs => '$libs',
);
1;
CONFIG
close F;
}
sub create_par_list
{
open F, ">", "utils/par.txt" or die "Cannot open utils/par.txt:$!";
find( sub {
return unless -f;
return if /\.p[lm]$/i || /^(VB|prima-cfgmaint)$/;
my $d = $File::Find::dir;
return if $d =~ /examples/;
print F "$d/$_\n";
}, 'Prima');
close F;
}
# executed from inside makefiles
sub command_postinstall
{
my %opt = map { split /=/, $_, 2 } @_;
if ( $opt{slib} ) {
my $f = "$opt{dest}/auto/Prima/$opt{slib}";
open F, ">", $f or warn "** warning: Cannot write to a fake lib '$f': Prima extensions won't build\n";
close F;
}
my $fn_cfg = "$opt{dest}/Prima/Config.pm";
print "Updating config $fn_cfg\n";
open F, $fn_cfg or die "cannot open $fn_cfg:$!\n";
open FF, "> $fn_cfg.tmp" or die "cannot open $fn_cfg.tmp:$!\n";
my ( $c_state, $ci_state) = (0,0);
my (%ci, %vars);
%vars = %opt;
if ( $^O =~ /mswin32/i) {
s/\//\\/g for values %vars;
}
print FF <<HEADER;
# This file was automatically generated.
package Prima::Config;
( run in 0.239 second using v1.01-cache-2.11-cpan-a5abf4f5562 )