+ local($is_hc_file) = 1; #Is the C code .hc or .c? Assume .hc for now
+
+ $lit2pgm_hscpp = $ifile if ($ifile =~ /\.hs$/);
+
+ # OK, let's strip off some literate junk:
+ &runLit2pgm($in_lit2pgm, $lit2pgm_hscpp) if ($ifile =~ /\.lhs$/);
+ #
+ @File_options = ();
+
+ # Scan the top of the de-litted file for {-# OPTIONS #-} pragmas
+ &check_for_source_options($lit2pgm_hscpp);
+ # options found in the source file take a back seat, i.e., we scan
+ # them first. Only process the command line again if source file
+ # contained anything of interest *or* there's more than one
+ # input file (we have to reset the options).
+ #
+ if ( $#Input_file >= 0 || $#File_options >= 0) {
+ @File_options = (@File_options, @Cmd_opts);
+
+ # Now process the command line
+ &initDriverGlobals();
+ &processArgs(@File_options);
+ }
+ #
+ # Having got the effective command line scanned, set up
+ # the various options in prep for some real work.
+ #
+ # check the sanity of the BuildTag we're about to use,
+ # and if needs be, add some more flags and setup to
+ # the different phases.
+ #
+ &setupBuildFlags();
+ &setupOptimiseFlags();
+ &setupMachOpts();
+ &setupIncPaths();
+ &setupHeapStackSize();
+
+ #
+ # These two variables need to be set after the
+ # command-line has been processed and the build options
+ # have be seen set up. This is because command-line options
+ # can control whether to compile vias C or not.
+ #
+ local($do_cc) = ( $Do_cc != -1) # i.e., it was set explicitly
+ ? $Do_cc
+ : ( ($HscOut eq '-C=') ? 1 : 0 );
+ local($do_as) = $Do_as;
+ local($hsc_out) = ( $HscOut eq '-C=' ) ? "$Tmp_prefix.hc" : "$Tmp_prefix.s" ;
+
+ if ($ifile =~ /.lhs$/ || $ifile =~ /.hs$/ ) {
+ ;
+ } elsif ($ifile =~ /\.hc$/ || $ifile =~ /_hc$/ ) { # || $ifile =~ /\.$Isuffix$/o) # ToDo: better
+ $do_hscpp = 0; $do_hsc = 0; $do_cc = 1;
+ $hsc_out = $ifile;
+ } elsif ($ifile =~ /\.c$/) {
+ $do_hscpp = 0; $do_hsc = 0; $do_cc = 1;
+ $hsc_out = $ifile; $is_hc_file = 0;
+ } elsif ($ifile =~ /\.s$/) {
+ $do_hscpp = 0; $do_hsc = 0; $do_cc = 0;
+ $cc_as = $ifile;
+ } else { # don't know what it is, but nothing to do herein...
+ $do_hscpp = 0; $do_hsc = 0; $do_cc = 0; $do_as = 0;
+ }
+
+ # hack to avoid running hscpp
+ $HsCpp = $Cat if ! $Cpp_flag_set;
+
+ &runHscpp($in_lit2pgm, $lit2pgm_hscpp, $hscpp_hsc)
+ if $do_hscpp;
+\end{code}
+
+We now think about whether to run hsc/cc or not (when hsc produces .s
+stuff, it effectively takes the place of both phases).
+
+To get the output file name right: for each phase that we are {\em
+not} going to run, set its input (i.e., the output of its preceding
+phase) to @"$ifile_root.<suffix>"@.
+\begin{code}
+ local($going_interactive) = $HscOut eq '-N=' || $ifile_root eq '_stdin';
+
+ #
+ # Warning issued if -keep-hc-file-too is used without
+ # -fvia-C (or the equivalent)
+ #
+ if ( $HscOut ne '-C=' && $Keep_hc_file_too ) {
+ print STDERR "Warning: Native code generator to be used, -keep-hc-file-too will be ignored\n";
+ }
+
+ if (! $do_cc && ! $do_as) { # stopping after hsc
+ $hsc_out = ($Specific_output_file ne '')
+ ? $Specific_output_file
+ : &odir_ify($ifile_root, ($HscOut eq '-C=') ? 'hc' : 's');
+
+ $ofile_target = $hsc_out; # reset
+ }
+
+ if (! $do_as) { # stopping after gcc (or hsc)
+ $cc_as = ($Specific_output_file ne '')
+ ? $Specific_output_file
+ : &odir_ify($ifile_root, ( $Only_preprocess_C ) ? 'i' : 's');
+
+ $ofile_target = $cc_as; # reset
+ }
+
+\end{code}
+
+
+Now the Haskell compiler, C compiler, and assembler
+
+\begin{code}
+ if ($do_hsc) {
+ &runHscAndProcessInterfaces( $ifile, $hscpp_hsc, $ifile_root,
+ $ofile_target, $hifile_target);
+ }
+
+ if ($do_cc) {
+ &runGcc ($is_hc_file, $hsc_out, $cc_as_o);
+ &runMangler($is_hc_file, $cc_as_o, $cc_as, $ifile_root);
+ }
+
+ &split_asm_file($cc_as) if $do_as && $SplitObjFiles;
+
+ &runAs($as_out, $ifile_root) if $do_as;
+\end{code}
+
+Finally, decide what to queue up for linker input.
+\begin{code}
+ # tentatively assume we will eventually produce linker input:
+ push(@Link_file, &odir_ify($ifile_root, 'o'));
+
+#ToDo: local($or_isuf) = ($Isuffix eq '') ? '' : "|$Isuffix";
+
+ if ( $ifile !~ /\.(lhs|hs|hc|c|s)$/ && $ifile !~ /_hc$/ ) {
+ print STDERR "$Pgm: don't recognise suffix on `$ifile'; passing it through to linker\n"
+ if $ifile !~ /\.a$/;
+
+ # oops; we tentatively pushed the wrong thing; fix & do the right thing
+ pop(@Link_file); push(@Link_file, $ifile);
+ }
+
+
+} # end of ProcessInputFile
+\end{code}