+-- generates a Perl skript starting a parallel prg under PVM
+mk_pvm_wrapper_script :: String -> String -> String -> String
+mk_pvm_wrapper_script pvm_executable pvm_executable_base sysMan = unlines $
+ [
+ "eval 'exec perl -S $0 ${1+\"$@\"}'",
+ " if $running_under_some_shell;",
+ "# =!=!=!=!=!=!=!=!=!=!=!",
+ "# This script is automatically generated: DO NOT EDIT!!!",
+ "# Generated by Glasgow Haskell Compiler",
+ "# ngoqvam choHbogh vaj' vIHoHnISbej !!!!",
+ "#",
+ "$pvm_executable = '" ++ pvm_executable ++ "';",
+ "$pvm_executable_base = '" ++ pvm_executable_base ++ "';",
+ "$SysMan = '" ++ sysMan ++ "';",
+ "",
+ {- ToDo: add the magical shortcuts again iff we actually use them -- HWL
+ "# first, some magical shortcuts to run "commands" on the binary",
+ "# (which is hidden)",
+ "if ($#ARGV == 1 && $ARGV[0] eq '+RTS' && $ARGV[1] =~ /^--((size|file|strip|rm|nm).*)/ ) {",
+ " local($cmd) = $1;",
+ " system("$cmd $pvm_executable");",
+ " exit(0); # all done",
+ "}", -}
+ "",
+ "# Now, run the real binary; process the args first",
+ "$ENV{'PE'} = $pvm_executable_base;", -- ++ pvm_executable_base,
+ "$debug = '';",
+ "$nprocessors = 0; # the default: as many PEs as machines in PVM config",
+ "@nonPVM_args = ();",
+ "$in_RTS_args = 0;",
+ "",
+ "args: while ($a = shift(@ARGV)) {",
+ " if ( $a eq '+RTS' ) {",
+ " $in_RTS_args = 1;",
+ " } elsif ( $a eq '-RTS' ) {",
+ " $in_RTS_args = 0;",
+ " }",
+ " if ( $a eq '-d' && $in_RTS_args ) {",
+ " $debug = '-';",
+ " } elsif ( $a =~ /^-qN(\\d+)/ && $in_RTS_args ) {",
+ " $nprocessors = $1;",
+ " } elsif ( $a =~ /^-qp(\\d+)/ && $in_RTS_args ) {",
+ " $nprocessors = $1;",
+ " } else {",
+ " push(@nonPVM_args, $a);",
+ " }",
+ "}",
+ "",
+ "local($return_val) = 0;",
+ "# Start the parallel execution by calling SysMan",
+ "system(\"$SysMan $debug $pvm_executable $nprocessors @nonPVM_args\");",
+ "$return_val = $?;",
+ "# ToDo: fix race condition moving files and flushing them!!",
+ "system(\"cp $ENV{'HOME'}/$pvm_executable_base.???.gr .\") if -f \"$ENV{'HOME'}/$pvm_executable_base.002.gr\";",
+ "exit($return_val);"
+ ]
+
+-----------------------------------------------------------------------------
+-- Complain about non-dynamic flags in OPTIONS pragmas
+
+checkProcessArgsResult flags basename suff
+ = do when (not (null flags)) (throwDyn (ProgramError (
+ basename ++ "." ++ suff
+ ++ ": static flags are not allowed in {-# OPTIONS #-} pragmas:\n\t"
+ ++ unwords flags)) (ExitFailure 1))
+