package Config_w64;

require ExtUtils::FakeConfig;

my $cc_p = ( ExtUtils::FakeConfig::find_program( 'gcc' ) )[0];
$cc_p || die "Unable to find compiler 'gcc'";
$cc_p =~ s/[\\\/]bin[\\\/]?$//;

my $dmake = ( ExtUtils::FakeConfig::find_program( 'dmake' ) )[1];
$dmake || die "Unable to find dmake";

my $CONFIGPERL = $Config::Config{prefix};

my($ccflags, $libs, $perllibs, $libperl, $archlib);

my $arch = $Config::Config{archname};
my $bperllib = $Config::Config{libperl};

$ccflags = ' -DNDEBUG -O2 -DWIN32 -D_CONSOLE -DNO_STRICT -DHAVE_DES_FCRYPT -DCONSERVATIVE -DUSE_SITECUSTOMIZE -DPRIVLIB_LAST_IN_INC -DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS -DUSE_PERLIO -DPERL_MSVCRT_READFIX';
$libs    = ' -lmoldname -lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 -lshell32 -lole32 -loleaut32 -lnetapi32 -luuid -lws2_32 -lmpr -lwinmm -lversion -lodbc32 -lodbccp32 -lcomctl32';
$perllibs = $libs;

if( ($bperllib eq 'perl58.lib') && ($arch eq 'MSWin32-x64-multi-thread' ) ){
    # perl 5.8 x64
    $ccflags  .= ' -DWIN64 -DNO_HASH_SEED';
    $libperl  = 'libperl58.a';
    $archlib  = 'x86_64-w64-mingw32';
    
} elsif( ($bperllib eq 'perl510.lib') && ($arch eq 'MSWin32-x64-multi-thread' ) ) {
    # perl 5.10 x64
    $ccflags  .= ' -DWIN64';
    $libperl  = 'libperl510.a';
    $archlib  = 'x86_64-w64-mingw32';
    
} elsif( ($bperllib eq 'perl512.lib') && ($arch eq 'MSWin32-x64-multi-thread' ) ) {
    # perl 5.12 x64
    $ccflags  .= ' -DWIN64';
    $libperl  = 'libperl512.a';
    $archlib  = 'x86_64-w64-mingw32';

} elsif( ($bperllib eq 'perl514.lib') && ($arch eq 'MSWin32-x64-multi-thread' ) ) {
    # perl 5.14 x64
    $ccflags  .= ' -DWIN64';
    $libperl  = 'libperl514.a';
    $archlib  = 'x86_64-w64-mingw32';

    
}  elsif( ($bperllib eq 'perl58.lib') && ($arch eq 'MSWin32-x86-multi-thread' ) ) {
    # perl 5.8 x86
   $ccflags  .= ' -DNO_HASH_SEED';
   $libperl  = 'libperl58.a';
   $archlib  = 'i686-w64-mingw32';
   
}  elsif( ($bperllib eq 'perl510.lib') && ($arch eq 'MSWin32-x86-multi-thread' ) ) {
    # perl 5.10 x86
   $libperl  = 'libperl510.a';
   $archlib  = 'i686-w64-mingw32';
   
}  elsif( ($bperllib eq 'perl512.lib') && ($arch eq 'MSWin32-x86-multi-thread' ) ) {
    # perl 5.12 x86
   $libperl  = 'libperl512.a';
   $archlib  = 'i686-w64-mingw32';

}  elsif( ($bperllib eq 'perl514.lib') && ($arch eq 'MSWin32-x86-multi-thread' ) ) {
    # perl 5.14 x86
   $libperl  = 'libperl514.a';
   $archlib  = 'i686-w64-mingw32';


} else {
    die qq(Archname $arch and perllib $bperllib is not supported by Config_w64);
}

my %values = (
    cc          => 'gcc',
    ccname      => 'gcc',
    ccflags     => $ccflags,
    _a          => '.a',
    _o          => '.o',
    ar          => 'ar',
    cpp         => 'gcc -E',
    libpth      => qq(\"$cc_p\\lib\" \"$cc_p\\$archlib\\lib\"),
    cppminus    => '-',
    cpprun      => 'gcc -E',
    cppstdin    => 'gcc -E',
    ccversion   => '',
    gccversion  => '4.4.7',
    ld          => 'g++',
    lddlflags   => qq(-s -mdll -L\"$CONFIGPERL\\lib\\CORE\"),
    ldflags     => qq(-s -L\"$CONFIGPERL\\lib\\CORE\"),
    lib_ext     => '.a',
    libc        => '-lmsvcrt',
    libperl     => $libperl,
    make        => $dmake,
    nm          => 'nm',
    obj_ext     => '.o',
    optimize    => '-s -O2',
    libs        => $libs,
    perllibs    => $perllibs,
    i64type     => 'long long',
    u64type     => 'unsigned long long',
    quadtype    => 'long long',
    uquadtype   => 'unsigned long long',
    d_casti32   => 'define',
    
);

eval 'use ExtUtils::FakeConfig %values';

1;

