1 <?xml version="1.0" encoding="iso-8859-1"?>
2 <sect1 id="options-phases">
3 <title>Options related to a particular phase</title>
5 <sect2 id="replacing-phases">
6 <title>Replacing the program for one or more phases</title>
7 <indexterm><primary>phases, changing</primary></indexterm>
9 <para>You may specify that a different program be used for one
10 of the phases of the compilation system, in place of whatever
11 the <command>ghc</command> has wired into it. For example, you
12 might want to try a different assembler. The following options
13 allow you to change the external program used for a given
14 compilation phase:</para>
19 <option>-pgmL</option> <replaceable>cmd</replaceable>
20 <indexterm><primary><option>-pgmL</option></primary></indexterm>
23 <para>Use <replaceable>cmd</replaceable> as the literate
30 <option>-pgmP</option> <replaceable>cmd</replaceable>
31 <indexterm><primary><option>-pgmP</option></primary></indexterm>
34 <para>Use <replaceable>cmd</replaceable> as the C
35 pre-processor (with <option>-cpp</option> only).</para>
41 <option>-pgmc</option> <replaceable>cmd</replaceable>
42 <indexterm><primary><option>-pgmc</option></primary></indexterm>
45 <para>Use <replaceable>cmd</replaceable> as the C
52 <option>-pgma</option> <replaceable>cmd</replaceable>
53 <indexterm><primary><option>-pgma</option></primary></indexterm>
56 <para>Use <replaceable>cmd</replaceable> as the
63 <option>-pgml</option> <replaceable>cmd</replaceable>
64 <indexterm><primary><option>-pgml</option></primary></indexterm>
67 <para>Use <replaceable>cmd</replaceable> as the
74 <option>-pgmdll</option> <replaceable>cmd</replaceable>
75 <indexterm><primary><option>-pgmdll</option></primary></indexterm>
78 <para>Use <replaceable>cmd</replaceable> as the DLL
85 <option>-pgmdep</option> <replaceable>cmd</replaceable>
86 <indexterm><primary><option>-pgmdep</option></primary></indexterm>
89 <para>Use <replaceable>cmd</replaceable> as the dependency
96 <option>-pgmF</option> <replaceable>cmd</replaceable>
97 <indexterm><primary><option>-pgmF</option></primary></indexterm>
100 <para>Use <replaceable>cmd</replaceable> as the
101 pre-processor (with <option>-F</option> only).</para>
108 <sect2 id="forcing-options-through">
109 <title>Forcing options to a particular phase</title>
110 <indexterm><primary>forcing GHC-phase options</primary></indexterm>
112 <para>Options can be forced through to a particlar compilation
113 phase, using the following flags:</para>
118 <option>-optL</option> <replaceable>option</replaceable>
119 <indexterm><primary><option>-optL</option></primary></indexterm>
122 <para>Pass <replaceable>option</replaceable> to the
123 literate pre-processor</para>
128 <option>-optP</option> <replaceable>option</replaceable>
129 <indexterm><primary><option>-optP</option></primary></indexterm>
132 <para>Pass <replaceable>option</replaceable> to CPP (makes
133 sense only if <option>-cpp</option> is also on).</para>
138 <option>-optF</option> <replaceable>option</replaceable>
139 <indexterm><primary><option>-optF</option></primary></indexterm>
142 <para>Pass <replaceable>option</replaceable> to the
143 custom pre-processor (see <xref linkend="pre-processor"/>).</para>
148 <option>-optc</option> <replaceable>option</replaceable>
149 <indexterm><primary><option>-optc</option></primary></indexterm>
152 <para>Pass <replaceable>option</replaceable> to the C compiler.</para>
157 <option>-opta</option> <replaceable>option</replaceable>
158 <indexterm><primary><option>-opta</option></primary></indexterm>
161 <para>Pass <replaceable>option</replaceable> to the assembler.</para>
166 <option>-optl</option> <replaceable>option</replaceable>
167 <indexterm><primary><option>-optl</option></primary></indexterm>
170 <para>Pass <replaceable>option</replaceable> to the linker.</para>
175 <option>-optdll</option> <replaceable>option</replaceable>
176 <indexterm><primary><option>-optdll</option></primary></indexterm>
179 <para>Pass <replaceable>option</replaceable> to the DLL generator.</para>
184 <option>-optdep</option> <replaceable>option</replaceable>
185 <indexterm><primary><option>-optdep</option></primary></indexterm>
188 <para>Pass <replaceable>option</replaceable> to the
189 dependency generator.</para>
194 <para>So, for example, to force an <option>-Ewurble</option>
195 option to the assembler, you would tell the driver
196 <option>-opta-Ewurble</option> (the dash before the E is
199 <para>GHC is itself a Haskell program, so if you need to pass
200 options directly to GHC's runtime system you can enclose them in
201 <literal>+RTS ... -RTS</literal> (see <xref
202 linkend="runtime-control"/>).</para>
206 <sect2 id="c-pre-processor">
207 <title>Options affecting the C pre-processor</title>
209 <indexterm><primary>pre-processing: cpp</primary></indexterm>
210 <indexterm><primary>C pre-processor options</primary></indexterm>
211 <indexterm><primary>cpp, pre-processing with</primary></indexterm>
217 <option>-cpp</option>
218 <indexterm><primary><option>-cpp</option></primary></indexterm>
221 <para>The C pre-processor <command>cpp</command> is run
222 over your Haskell code only if the <option>-cpp</option>
223 option <indexterm><primary>-cpp
224 option</primary></indexterm> is given. Unless you are
225 building a large system with significant doses of
226 conditional compilation, you really shouldn't need
233 <option>-D</option><replaceable>symbol</replaceable><optional>=<replaceable>value</replaceable></optional>
234 <indexterm><primary><option>-D</option></primary></indexterm>
237 <para>Define macro <replaceable>symbol</replaceable> in the
238 usual way. NB: does <emphasis>not</emphasis> affect
239 <option>-D</option> macros passed to the C compiler
240 when compiling via C! For those, use the
241 <option>-optc-Dfoo</option> hack… (see <xref
242 linkend="forcing-options-through"/>).</para>
248 <option>-U</option><replaceable>symbol</replaceable>
249 <indexterm><primary><option>-U</option></primary></indexterm>
252 <para> Undefine macro <replaceable>symbol</replaceable> in the
259 <option>-I</option><replaceable>dir</replaceable>
260 <indexterm><primary><option>-I</option></primary></indexterm>
263 <para> Specify a directory in which to look for
264 <literal>#include</literal> files, in the usual C
270 <para>The GHC driver pre-defines several macros when processing
271 Haskell source code (<filename>.hs</filename> or
272 <filename>.lhs</filename> files):</para>
278 <constant>__HASKELL98__</constant>
279 <indexterm><primary><literal>__HASKELL98__</literal></primary></indexterm>
282 <para>If defined, this means that GHC supports the
283 language defined by the Haskell 98 report.</para>
289 <constant>__HASKELL__=98</constant>
290 <indexterm><primary><constant>__HASKELL__=98</constant></primary></indexterm>
293 <para>In GHC 4.04 and later, the
294 <constant>__HASKELL__</constant>
295 macro is defined as having the value
296 <constant>98</constant>.</para>
302 <constant>__HASKELL1__</constant>
303 <indexterm><primary><constant>__HASKELL1__</constant></primary></indexterm>
306 <para>If defined to <replaceable>n</replaceable>, that
307 means GHC supports the Haskell language defined in the
308 Haskell report version <emphasis>1.n</emphasis>.
309 Currently 5. This macro is deprecated, and will probably
310 disappear in future versions.</para>
316 <constant>__GLASGOW_HASKELL__</constant>
317 <indexterm><primary><constant>__GLASGOW_HASKELL__</constant></primary></indexterm>
320 <para>For version <replaceable>n</replaceable> of the GHC
321 system, this will be <literal>#define</literal>d to
322 <replaceable>100n</replaceable>. For example, for version
323 5.00, it is 500.</para>
326 <constant>__GLASGOW_HASKELL__</constant>
327 will be undefined in all other implementations that
328 support C-style pre-processing.</para>
330 <para>(For reference: the comparable symbols for other
332 <constant>__HUGS__</constant>
334 <constant>__NHC__</constant>
336 <constant>__HBC__</constant>
337 for Chalmers.)</para>
339 <para>NB. This macro is set when pre-processing both
340 Haskell source and C source, including the C source
341 generated from a Haskell module
342 (i.e. <filename>.hs</filename>, <filename>.lhs</filename>,
343 <filename>.c</filename> and <filename>.hc</filename>
350 <constant>__CONCURRENT_HASKELL__</constant>
351 <indexterm><primary><constant>__CONCURRENT_HASKELL__</constant></primary></indexterm>
354 <para>This symbol is defined when pre-processing Haskell
355 (input) and pre-processing C (GHC output). Since GHC from
356 verion 4.00 now supports concurrent haskell by default,
357 this symbol is always defined.</para>
363 <constant>__PARALLEL_HASKELL__</constant>
364 <indexterm><primary><constant>__PARALLEL_HASKELL__</constant></primary></indexterm>
367 <para>Only defined when <option>-parallel</option> is in
368 use! This symbol is defined when pre-processing Haskell
369 (input) and pre-processing C (GHC output).</para>
374 <sect3 id="cpp-string-gaps">
375 <title>CPP and string gaps</title>
377 <para>A small word of warning: <option>-cpp</option> is not
378 friendly to “string gaps”.<indexterm><primary>-cpp
379 vs string gaps</primary></indexterm><indexterm><primary>string
380 gaps vs -cpp</primary></indexterm>. In other words, strings
381 such as the following:</para>
389 <para>don't work with <option>-cpp</option>;
390 <filename>/usr/bin/cpp</filename> elides the backslash-newline
393 <para>However, it appears that if you add a space at the end
394 of the line, then <command>cpp</command> (at least GNU
395 <command>cpp</command> and possibly other
396 <command>cpp</command>s) leaves the backslash-space pairs
397 alone and the string gap works as expected.</para>
401 <sect2 id="pre-processor">
402 <title>Options affecting a Haskell pre-processor</title>
404 <indexterm><primary>pre-processing: custom</primary></indexterm>
405 <indexterm><primary>Pre-processor options</primary></indexterm>
411 <indexterm><primary><option>-F</option></primary></indexterm>
414 <para>A custom pre-processor is run over your Haskell
415 source file only if the <option>-F</option> option
416 <indexterm><primary>-F</primary></indexterm> is
419 <para>Running a custom pre-processor at compile-time is in
420 some settings appropriate and useful. The
421 <option>-F</option> option lets you run a pre-processor as
422 part of the overall GHC compilation pipeline, which has
423 the advantage over running a Haskell pre-processor
424 separately in that it works in interpreted mode and you
425 can continue to take reap the benefits of GHC's
426 recompilation checker.</para>
428 <para>The pre-processor is run just before the Haskell
429 compiler proper processes the Haskell input, but after the
430 literate markup has been stripped away and (possibly) the
431 C pre-processor has washed the Haskell input.</para>
434 <option>-pgmF <replaceable>cmd</replaceable></option>
435 to select the program to use as the preprocessor. When
436 invoked, the <replaceable>cmd</replaceable> pre-processor
437 is given at least three arguments on its command-line: the
438 first argument is the name of the original source file,
439 the second is the name of the file holding the input, and
440 the third is the name of the file where
441 <replaceable>cmd</replaceable> should write its output
444 <para>Additional arguments to the pre-processor can be
445 passed in using the <option>-optF</option> option. These
446 are fed to <replaceable>cmd</replaceable> on the command
447 line after the three standard input and output
454 <sect2 id="options-C-compiler">
455 <title>Options affecting the C compiler (if applicable)</title>
457 <indexterm><primary>include-file options</primary></indexterm>
458 <indexterm><primary>C compiler options</primary></indexterm>
459 <indexterm><primary>GCC options</primary></indexterm>
461 <para>If you are compiling with lots of foreign calls, you may
462 need to tell the C compiler about some
463 <literal>#include</literal> files. There is no real pretty
464 way to do this, but you can use this hack from the
468 % ghc -c '-#include <X/Xlib.h>' Xstuff.lhs
473 <sect2 id="options-codegen">
474 <title>Options affecting code generation</title>
479 <option>-fasm</option>
480 <indexterm><primary><option>-fasm</option></primary></indexterm>
483 <para>Use GHC's native code generator rather than
484 compiling via C. This will compile faster (up to twice as
485 fast), but may produce code that is slightly slower than
486 compiling via C. <option>-fasm</option> is the default
487 when optimisation is off (see <xref
488 linkend="options-optimise"/>).</para>
494 <option>-fvia-C</option>
495 <indexterm><primary><option>-fvia-C</option></primary></indexterm>
498 <para>Compile via C instead of using the native code
499 generator. This is default for optimised compilations,
500 and on architectures for which GHC doesn't have a native
501 code generator.</para>
507 <option>-fno-code</option>
508 <indexterm><primary><option>-fno-code</option></primary></indexterm>
511 <para>Omit code generation (and all later phases)
512 altogether. Might be of some use if you just want to see
513 dumps of the intermediate compilation phases.</para>
519 <sect2 id="options-linker">
520 <title>Options affecting linking</title>
522 <indexterm><primary>linker options</primary></indexterm>
523 <indexterm><primary>ld options</primary></indexterm>
526 <para>GHC has to link your code with various libraries, possibly
527 including: user-supplied, GHC-supplied, and system-supplied
528 (<option>-lm</option> math library, for example).</para>
534 <option>-l</option><replaceable>lib</replaceable>
535 <indexterm><primary><option>-l</option></primary></indexterm>
538 <para>Link in the <replaceable>lib</replaceable> library.
539 On Unix systems, this will be in a file called
540 <filename>lib<replaceable>lib</replaceable>.a</filename>
542 <filename>lib<replaceable>lib</replaceable>.so</filename>
543 which resides somewhere on the library directories path.</para>
545 <para>Because of the sad state of most UNIX linkers, the
546 order of such options does matter. If library
547 <replaceable>foo</replaceable> requires library
548 <replaceable>bar</replaceable>, then in general
549 <option>-l</option><replaceable>foo</replaceable> should
550 come <emphasis>before</emphasis>
551 <option>-l</option><replaceable>bar</replaceable> on the
554 <para>There's one other gotcha to bear in mind when using
555 external libraries: if the library contains a
556 <literal>main()</literal> function, then this will be
557 linked in preference to GHC's own
558 <literal>main()</literal> function
559 (eg. <literal>libf2c</literal> and <literal>libl</literal>
560 have their own <literal>main()</literal>s). This is
561 because GHC's <literal>main()</literal> comes from the
562 <literal>HSrts</literal> library, which is normally
563 included <emphasis>after</emphasis> all the other
564 libraries on the linker's command line. To force GHC's
565 <literal>main()</literal> to be used in preference to any
566 other <literal>main()</literal>s from external libraries,
567 just add the option <option>-lHSrts</option> before any
568 other libraries on the command line.</para>
574 <option>-no-link</option>
575 <indexterm><primary><option>-no-link</option></primary></indexterm>
578 <para>Omit the link step. This flag can be useful if you
579 want to avoid linking in <option>--make</option> mode,
580 where linking is normally done automatically if the program
581 contains a <literal>Main</literal> module.</para>
587 <option>-package</option> <replaceable>name</replaceable>
588 <indexterm><primary><option>-package</option></primary></indexterm>
591 <para>If you are using a Haskell “package”
592 (see <xref linkend="packages"/>), don't forget to add the
593 relevant <option>-package</option> option when linking the
594 program too: it will cause the appropriate libraries to be
595 linked in with the program. Forgetting the
596 <option>-package</option> option will likely result in
597 several pages of link errors.</para>
603 <option>-framework</option> <replaceable>name</replaceable>
604 <indexterm><primary><option>-framework</option></primary></indexterm>
607 <para>On Darwin/MacOS X only, link in the framework <replaceable>name</replaceable>.
608 This option corresponds to the <option>-framework</option> option for Apple's Linker.
609 Please note that frameworks and packages are two different things - frameworks don't
610 contain any haskell code. Rather, they are Apple's way of packaging shared libraries.
611 To link to Apple's “Carbon” API, for example, you'd use
612 <option>-framework Carbon</option>.
619 <option>-L</option><replaceable>dir</replaceable>
620 <indexterm><primary><option>-L</option></primary></indexterm>
623 <para>Where to find user-supplied libraries…
624 Prepend the directory <replaceable>dir</replaceable> to
625 the library directories path.</para>
631 <option>-framework-path</option><replaceable>dir</replaceable>
632 <indexterm><primary><option>-framework-path</option></primary></indexterm>
635 <para>On Darwin/MacOS X only, prepend the directory <replaceable>dir</replaceable> to
636 the framework directories path. This option corresponds to the <option>-F</option>
637 option for Apple's Linker (<option>-F</option> already means something else for GHC).</para>
643 <option>-split-objs</option>
644 <indexterm><primary><option>-split-objs</option></primary></indexterm>
647 <para>Tell the linker to split the single object file that
648 would normally be generated into multiple object files,
649 one per top-level Haskell function or type in the module.
650 We use this feature for building GHC's libraries libraries
651 (warning: don't use it unless you know what you're
658 <option>-static</option>
659 <indexterm><primary><option>-static</option></primary></indexterm>
662 <para>Tell the linker to avoid shared Haskell libraries,
663 if possible. This is the default.</para>
669 <option>-dynamic</option>
670 <indexterm><primary><option>-dynamic</option></primary></indexterm>
673 <para>Tell the linker to use shared Haskell libraries, if
674 available (this option is only supported on Windows at the
675 moment, and also note that your distribution of GHC may
676 not have been supplied with shared libraries).</para>
682 <option>-main-is <replaceable>thing</replaceable></option>
683 <indexterm><primary><option>-main-is</option></primary></indexterm>
684 <indexterm><primary>specifying your own main function</primary></indexterm>
687 <para> The normal rule in Haskell is that your program must supply a <literal>main</literal>
688 function in module <literal>Main</literal>. When testing, it is often convenient
689 to change which function is the "main" one, and the <option>-main-is</option> flag
690 allows you to do so. The <replaceable>thing</replaceable> can be one of:
692 <listitem><para>A lower-case identifier <literal>foo</literal>. GHC assumes that the main function is <literal>Main.foo</literal>.</para></listitem>
693 <listitem><para>An module name <literal>A</literal>. GHC assumes that the main function is <literal>A.main</literal>.</para></listitem>
694 <listitem><para>An qualified name <literal>A.foo</literal>. GHC assumes that the main function is <literal>A.foo</literal>.</para></listitem>
696 Strictly speaking, <option>-main-is</option> is not a link-phase flag at all; it has no effect on the link step.
697 The flag must be specified when compiling the module containing the specified main function (e.g. module <literal>A</literal>
698 in the latter two items above. It has no effect for other modules (and hence can safely be given to <literal>ghc --make</literal>).
705 <option>-no-hs-main</option>
706 <indexterm><primary><option>-no-hs-main</option></primary></indexterm>
707 <indexterm><primary>linking Haskell libraries with foreign code</primary></indexterm>
710 <para>In the event you want to include ghc-compiled code
711 as part of another (non-Haskell) program, the RTS will not
712 be supplying its definition of <function>main()</function>
713 at link-time, you will have to. To signal that to the
714 compiler when linking, use
715 <option>-no-hs-main</option>. See also <xref linkend="using-own-main"/>.</para>
717 <para>Notice that since the command-line passed to the
718 linker is rather involved, you probably want to use
719 <command>ghc</command> to do the final link of your
720 `mixed-language' application. This is not a requirement
721 though, just try linking once with <option>-v</option> on
722 to see what options the driver passes through to the
725 <para>The <option>-no-hs-main</option> flag can also be
726 used to persuade the compiler to do the link step in
727 <option>--make</option> mode when there is no Haskell
728 <literal>Main</literal> module present (normally the
729 compiler will not attempt linking when there is no
730 <literal>Main</literal>).</para>
736 <option>-debug</option>
737 <indexterm><primary><option>-debug</option></primary></indexterm>
740 <para>Link the program with a debugging version of the
741 runtime system. The debugging runtime turns on numerous
742 assertions and sanity checks, and provides extra options
743 for producing debugging output at runtime (run the program
744 with <literal>+RTS -?</literal> to see a list).</para>
750 <option>-threaded</option>
751 <indexterm><primary><option>-threaded</option></primary></indexterm>
754 <para>Link the program with the "threaded" runtime system.
755 This version of the runtime is designed to be used in
756 programs that use multiple operating-system threads. It
757 supports calls to foreign-exported functions from multiple
758 OS threads. Calls to foreign functions are made using the
759 same OS thread that created the Haskell thread (if it was
760 created by a call-in), or an arbitrary OS thread otherwise
761 (if the Haskell thread was created by
762 <literal>forkIO</literal>).</para>
764 <para>More details on the use of "bound threads" in the
765 threaded runtime can be found in the <ulink
766 url="../libraries/base/Control.Concurrent.html"><literal>Control.Concurrent</literal></ulink> module.</para>
768 <para>The threaded RTS does <emphasis>not</emphasis>
769 support using multiple CPUs to speed up execution of a
770 multi-threaded Haskell program. The GHC runtime platform
771 is still single-threaded, but using the
772 <option>-threaded</option> option it can be used safely in
773 a multi-threaded environment.</para>
783 ;;; Local Variables: ***
785 ;;; sgml-parent-document: ("users_guide.xml" "book" "chapter") ***