--- config/auto/snprintf.pm;1	Wed Aug 30 19:03:40 2006
+++ config/auto/snprintf.pm;	Sun Sep  3 23:21:26 2006
@@ -29,17 +29,20 @@
     my ($self, $conf) = @_;
 
     cc_gen('config/auto/snprintf/test.in');
-    cc_build();
-    my $res = cc_run() or die "Can't run the snprintf testing program: $!";
-    cc_clean();
+    eval { cc_build() };
+    my $res = 'no';
+    unless ($@) {
+        $res = cc_run() or die "Can't run the snprintf testing program: $!";
+        cc_clean();
 
-    if ($res =~ /snprintf/) {
-        $conf->data->set(HAS_SNPRINTF => 1);
-    }
-    if ($res =~ /^C99 snprintf/) {
-        $conf->data->set(HAS_C99_SNPRINTF => 1);
-    } elsif ($res =~ /^old snprintf/) {
-        $conf->data->set(HAS_OLD_SNPRINTF => 1);
+        if ($res =~ /snprintf/) {
+            $conf->data->set(HAS_SNPRINTF => 1);
+        }
+        if ($res =~ /^C99 snprintf/) {
+            $conf->data->set(HAS_C99_SNPRINTF => 1);
+        } elsif ($res =~ /^old snprintf/) {
+            $conf->data->set(HAS_OLD_SNPRINTF => 1);
+        }
     }
     print " ($res) " if $conf->options->get('verbose');
 
--- config/auto.byteorder/test_c.in;1	Wed Aug 30 19:03:34 2006
+++ config/auto.byteorder/test_c.in;	Sun Sep  3 18:12:55 2006
@@ -12,7 +12,12 @@
 	}
 	else {
                 w.w = 0x08070605; 
+#ifdef VMS
+                w.w <<= 16; 
+                w.w <<= 16; 
+#else
                 w.w <<= 32; 
+#endif
                 w.w |= 0x04030201;
 	}
 
--- config/gen/config_h.pm;1	Wed Aug 30 19:03:46 2006
+++ config/gen/config_h.pm;	Sun Sep  3 23:41:13 2006
@@ -46,7 +46,8 @@
     );
 
     my $hh = "include/parrot/has_header.h";
-    open(HH, ">$hh.tmp")
+    my $hh_tmp = ($^O eq 'VMS') ? "${hh}_tmp" : "$hh.tmp";
+    open(HH, ">$hh_tmp")
         or die "Can't open has_header.h: $!";
 
     print HH <<EOF;
@@ -120,7 +121,7 @@
 
     close HH;
 
-    move_if_diff("$hh.tmp", $hh);
+    move_if_diff($hh_tmp, $hh);
 
     return $self;
 }
--- config/gen/core_pmcs.pm;1	Wed Aug 30 19:03:46 2006
+++ config/gen/core_pmcs.pm;	Sun Sep  3 23:54:38 2006
@@ -39,7 +39,8 @@
     my ($self, $conf) = @_;
 
     my $file = "include/parrot/core_pmcs.h";
-    open(OUT, ">$file.tmp");
+    my $file_tmp = ($^O eq 'VMS') ? "${file}_tmp" : "$file.tmp";
+    open(OUT, ">$file_tmp");
 
     print OUT <<"END_H";
 /*
@@ -68,7 +69,7 @@
 
     close OUT;
 
-    move_if_diff("$file.tmp", $file);
+    move_if_diff($file_tmp, $file);
 
     return;
 }
@@ -78,9 +79,10 @@
     my ($self, $conf) = @_;
 
     my $file = "src/core_pmcs.c";
+    my $file_tmp = ($^O eq 'VMS') ? "${file}_tmp" : "$file.tmp";
     my @pmcs = split(/ /, $conf->data->get('pmc_names'));
 
-    open(OUT, ">$file.tmp");
+    open(OUT, ">$file_tmp");
 
     print OUT <<"END_C";
 /*
@@ -136,7 +138,7 @@
 
     close OUT;
 
-    move_if_diff("$file.tmp", $file);
+    move_if_diff($file_tmp, $file);
 
     return;
 }
@@ -146,9 +148,10 @@
     my ($self, $conf) = @_;
 
     my $file = "lib/Parrot/PMC.pm";
+    my $file_tmp = ($^O eq 'VMS') ? "${file}_tmp" : "$file.tmp";
     my @pmcs = split(/ /, $conf->data->get('pmc_names'));
 
-    open(OUT, ">$file.tmp");
+    open(OUT, ">$file_tmp");
 
     print OUT <<'END_PM';
 # DO NOT EDIT THIS FILE
@@ -181,7 +184,7 @@
 
     close OUT;
 
-    move_if_diff("$file.tmp", $file);
+    move_if_diff($file_tmp, $file);
 
     return;
 }
--- config/gen/parrot_include.pm;1	Wed Aug 30 19:03:46 2006
+++ config/gen/parrot_include.pm;	Sun Sep  3 23:57:18 2006
@@ -72,7 +72,8 @@
                 $in_def = $1;
                 $last_val = -1;
                 %values   = ();
-                open INC, ">$inc.tmp" or die "Can't write $inc.tmp";
+                my $inc_tmp = ($^O eq 'VMS') ? "${inc}_tmp" : "$inc.tmp";
+                open INC, ">$inc_tmp" or die "Can't write $inc_tmp";
                 print INC "/*\n" if $inc =~ /\.h/;
                 print INC <<"EOF";
 # DO NOT EDIT THIS FILE.
@@ -90,9 +91,9 @@
                 close INC;
                 my $destfile = ($inc =~ m[/]) ? "$inc" : "$destdir/$inc";
 
-                #move_if_diff("$inc.tmp", "$destdir/$inc");
+                #move_if_diff($inc_tmp, "$destdir/$inc");
                 #push(@generated, "$destdir/$inc");
-                move_if_diff("$inc.tmp", "$destfile");
+                move_if_diff($inc_tmp, "$destfile");
                 push(@generated, "$destfile");
                 $in_def = '';
                 next;
--- config/init.hints/vms.pm;1	Wed Aug 30 19:03:46 2006
+++ config/init.hints/vms.pm;	Sun Sep  3 23:29:08 2006
@@ -5,27 +5,49 @@
 
 use strict;
 
+sub vmsify_cc_args {
+    my ($inp) = @_;
+    return '' unless defined $inp;
+    my @inp = split /\s+/, $inp;
+    my @defs = ();
+    for $inp (@inp) {
+        if ($inp =~ /^-D(.+)$/) {
+            push @defs, "\"$1\"";
+        }
+    }
+    return '/Define=('.join(',',@defs).')';
+}
+
 sub runstep
 {
     my ($self, $conf) = @_;
 
+    my $arch = `write sys\$output f\$getsyi("arch_type")`;
+    chomp $arch;
+    # DEC C 6.0 on VMS VAX does not have this qualifier
+    my $noansi_alias = ($arch == 1) ? '' : '/NoAnsi_Alias';
+
     $conf->data->set(
-        ccflags => qq{/Standard=Relaxed_ANSI/Prefix=All/Obj=.obj/NoList/NOANSI_ALIAS/include="./include"},
+        ccflags => qq{/Standard=Relaxed_ANSI/Prefix=All/Obj=.obj/NoList$noansi_alias/include="./include"},
         perl    => "MCR $^X",
-        exe     => "exe"
+        exe     => ".exe"
     );
 
     {
         local $^W;    # no warnings on redefinition
 
         *Parrot::Configure::Step::cc_build = sub {
+            my ($cc_args, $link_args) = @_;
+            $cc_args = vmsify_cc_args($cc_args);
+            die "Non-empty link_args '$link_args'" if defined $link_args;
             my ($cc, $ccflags) = $conf->data->get(qw(cc ccflags));
-            system("$cc $ccflags test.c") and die "C compiler died!";
+            system("$cc $ccflags $cc_args test.c") and die "C compiler died!";
             system("link/exe=test test")        and die "Link failed!";
         };
 
         *Parrot::Configure::Step::cc_run = sub {
-            `mcr []test`;
+            my $args = join(' ', @_);
+            `mcr []test $args`;
         };
     }
 }
--- lib/parrot.configure/step.pm;1	Wed Aug 30 19:03:20 2006
+++ lib/parrot.configure/step.pm;	Sun Sep  3 17:21:38 2006
@@ -243,9 +243,11 @@
 {
     my ($source, $target, %options) = @_;
 
+    my $target_tmp = ($^O eq 'VMS') ? "${target}_tmp" : "$target.tmp";
+
     open my $in, '<', $source or die "Can't open $source: $!";
 
-    open my $out, '>', "$target.tmp" or die "Can't open $target.tmp: $!";
+    open my $out, '>', $target_tmp or die "Can't open $target_tmp: $!";
 
     if ($options{commentType}) {
         my @comment = (
@@ -367,7 +369,7 @@
     close($in)  or die "Can't close $source: $!";
     close($out) or die "Can't close $target: $!";
 
-    move_if_diff("$target.tmp", $target, $options{ignorePattern});
+    move_if_diff($target_tmp, $target, $options{ignorePattern});
 }
 
 =item C<_run_command($command, $out, $err)>
@@ -405,6 +407,10 @@
     open STDOUT, ">$out" or die "Can't redirect stdout" if $out;
     open STDERR, ">$err" or die "Can't redirect stderr" if $err;
 
+    if ($^O eq 'VMS') {
+        $command = 'MCR '.VMS::Filespec::vmsify($command);
+    }
+
     system $command;
     my $exit_code = $? >> 8;
 
