MSWin32 (native windows) support #15

Merged
merged 4 commits into from Dec 14, 2013
View
10 Raw.xs
@@ -8,6 +8,10 @@
#include <ffi.h>
+#ifdef __MINGW32__
+#include <stdint.h>
+#endif
+
#include "perl_math_int64.h"
#include "perl_math_int64.c"
@@ -189,13 +193,19 @@ new(class, library, function, ret_type, ...)
GetLastError();
ffi_raw -> handle = LoadLibrary(library_name);
+
+ if(ffi_raw->handle == NULL)
+ Perl_croak(aTHX_ "library not found");
/*if ((error = GetLastError()) != NULL)
Perl_croak(aTHX_ error);*/
ffi_raw -> fn = GetProcAddress(
ffi_raw -> handle, function_name
);
+
+ if(ffi_raw -> fn == NULL)
+ Perl_croak(aTHX_ "function not found");
/*if ((error = GetLastError()) != NULL)
Perl_croak(aTHX_ error);*/
View
@@ -23,3 +23,7 @@ Devel::CheckLib = 0
[PruneFiles]
filename = README.pod
+
+[OSPrereqs / MSWin32]
+Alien::MSYS = 0
+Alien::o2dll = 0
View
@@ -9,6 +9,10 @@ override _build_MakeFile_PL_template => sub {
my $template = <<'TEMPLATE';
sub MY::postamble {
+ if($^O eq 'MSWin32')
+ {
+ return "\t$^X -MAlien::MSYS=msys_run -e \"chdir 'xs/libffi'; msys_run 'sh configure MAKEILFO=true --disable-builddir --with-pic'; msys_run 'make'\"\n\n";
+ }
return <<'MAKE_LIBFFI';
$(MYEXTLIB):
cd xs/libffi && ./configure MAKEINFO=true --disable-builddir --with-pic && $(MAKE)
View
@@ -4,3 +4,5 @@ extern void argless() {
printf("ok - argless\n");
fflush(stdout);
}
+
+void boot_01_argless() {}
View
@@ -14,9 +14,20 @@ sub compile {
source => $src_file,
extra_compiler_flags => '-std=gnu99'
);
- my $lib_file = $b -> link(objects => $obj_file);
-
- return $lib_file;
+
+ if($^O ne 'MSWin32') {
+ my $lib_file = $b -> link(objects => $obj_file);
+ return $lib_file;
+ } else {
+ my $name = $src_file;
+ $name =~ s/\.c$//;
+ $name =~ s/^.*(\/|\\)//;
+ require Alien::o2dll;
+ Alien::o2dll::o2dll(-o => "$name.dll", $obj_file);
+ rename "$name.dll", "t/$name.dll";
+ rename "$name.dll.a", "t/$name.dll.a";
+ "t/$name.dll";
+ }
}
1;