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>
109 <sect2 id="forcing-options-through">
110 <title>Forcing options to a particular phase</title>
111 <indexterm><primary>forcing GHC-phase options</primary></indexterm>
113 <para>Options can be forced through to a particlar compilation
114 phase, using the following flags:</para>
119 <option>-optL</option> <replaceable>option</replaceable>
120 <indexterm><primary><option>-optL</option></primary></indexterm>
123 <para>Pass <replaceable>option</replaceable> to the
124 literate pre-processor</para>
129 <option>-optP</option> <replaceable>option</replaceable>
130 <indexterm><primary><option>-optP</option></primary></indexterm>
133 <para>Pass <replaceable>option</replaceable> to CPP (makes
134 sense only if <option>-cpp</option> is also on).</para>
139 <option>-optF</option> <replaceable>option</replaceable>
140 <indexterm><primary><option>-optF</option></primary></indexterm>
143 <para>Pass <replaceable>option</replaceable> to the
144 custom pre-processor (see <xref linkend="pre-processor"/>).</para>
149 <option>-optc</option> <replaceable>option</replaceable>
150 <indexterm><primary><option>-optc</option></primary></indexterm>
153 <para>Pass <replaceable>option</replaceable> to the C compiler.</para>
158 <option>-opta</option> <replaceable>option</replaceable>
159 <indexterm><primary><option>-opta</option></primary></indexterm>
162 <para>Pass <replaceable>option</replaceable> to the assembler.</para>
167 <option>-optl</option> <replaceable>option</replaceable>
168 <indexterm><primary><option>-optl</option></primary></indexterm>
171 <para>Pass <replaceable>option</replaceable> to the linker.</para>
176 <option>-optdll</option> <replaceable>option</replaceable>
177 <indexterm><primary><option>-optdll</option></primary></indexterm>
180 <para>Pass <replaceable>option</replaceable> to the DLL generator.</para>
185 <option>-optdep</option> <replaceable>option</replaceable>
186 <indexterm><primary><option>-optdep</option></primary></indexterm>
189 <para>Pass <replaceable>option</replaceable> to the
190 dependency generator.</para>
195 <para>So, for example, to force an <option>-Ewurble</option>
196 option to the assembler, you would tell the driver
197 <option>-opta-Ewurble</option> (the dash before the E is
200 <para>GHC is itself a Haskell program, so if you need to pass
201 options directly to GHC's runtime system you can enclose them in
202 <literal>+RTS ... -RTS</literal> (see <xref
203 linkend="runtime-control"/>).</para>
207 <sect2 id="c-pre-processor">
208 <title>Options affecting the C pre-processor</title>
210 <indexterm><primary>pre-processing: cpp</primary></indexterm>
211 <indexterm><primary>C pre-processor options</primary></indexterm>
212 <indexterm><primary>cpp, pre-processing with</primary></indexterm>
218 <option>-cpp</option>
219 <indexterm><primary><option>-cpp</option></primary></indexterm>
222 <para>The C pre-processor <command>cpp</command> is run
223 over your Haskell code only if the <option>-cpp</option>
224 option <indexterm><primary>-cpp
225 option</primary></indexterm> is given. Unless you are
226 building a large system with significant doses of
227 conditional compilation, you really shouldn't need
234 <option>-D</option><replaceable>symbol</replaceable><optional>=<replaceable>value</replaceable></optional>
235 <indexterm><primary><option>-D</option></primary></indexterm>
238 <para>Define macro <replaceable>symbol</replaceable> in the
239 usual way. NB: does <emphasis>not</emphasis> affect
240 <option>-D</option> macros passed to the C compiler
241 when compiling via C! For those, use the
242 <option>-optc-Dfoo</option> hack… (see <xref
243 linkend="forcing-options-through"/>).</para>
249 <option>-U</option><replaceable>symbol</replaceable>
250 <indexterm><primary><option>-U</option></primary></indexterm>
253 <para> Undefine macro <replaceable>symbol</replaceable> in the
260 <option>-I</option><replaceable>dir</replaceable>
261 <indexterm><primary><option>-I</option></primary></indexterm>
264 <para> Specify a directory in which to look for
265 <literal>#include</literal> files, in the usual C
271 <para>The GHC driver pre-defines several macros when processing
272 Haskell source code (<filename>.hs</filename> or
273 <filename>.lhs</filename> files).</para>
275 <para>The symbols defined by GHC are listed below. To check which
276 symbols are defined by your local GHC installation, the following
277 trick is useful:</para>
279 <screen>$ ghc -E -optP-dM -cpp foo.hs
280 $ cat foo.hspp</screen>
282 <para>(you need a file <filename>foo.hs</filename>, but it isn't
283 actually used).</para>
288 <constant>__HASKELL98__</constant>
289 <indexterm><primary><literal>__HASKELL98__</literal></primary></indexterm>
292 <para>If defined, this means that GHC supports the
293 language defined by the Haskell 98 report.</para>
299 <constant>__HASKELL__=98</constant>
300 <indexterm><primary><constant>__HASKELL__=98</constant></primary></indexterm>
303 <para>In GHC 4.04 and later, the
304 <constant>__HASKELL__</constant>
305 macro is defined as having the value
306 <constant>98</constant>.</para>
312 <constant>__HASKELL1__</constant>
313 <indexterm><primary><constant>__HASKELL1__</constant></primary></indexterm>
316 <para>If defined to <replaceable>n</replaceable>, that
317 means GHC supports the Haskell language defined in the
318 Haskell report version <emphasis>1.n</emphasis>.
319 Currently 5. This macro is deprecated, and will probably
320 disappear in future versions.</para>
326 <constant>__GLASGOW_HASKELL__</constant>
327 <indexterm><primary><constant>__GLASGOW_HASKELL__</constant></primary></indexterm>
331 <literal><replaceable>x</replaceable>.<replaceable>y</replaceable>.<replaceable>z</replaceable></literal>
333 <constant>__GLASGOW_HASKELL__</constant>
334 is the integer <replaceable>xyy</replaceable> (if
335 <replaceable>y</replaceable> is a single digit, then a leading zero
336 is added, so for example in version 6.2 of GHC,
337 <literal>__GLASGOW_HASKELL__==602</literal>). More
338 information in <xref linkend="version-numbering"/>.</para>
341 <constant>__GLASGOW_HASKELL__</constant>
342 will be undefined in all other implementations that
343 support C-style pre-processing.</para>
345 <para>(For reference: the comparable symbols for other
347 <constant>__HUGS__</constant>
349 <constant>__NHC__</constant>
351 <constant>__HBC__</constant>
354 <para>NB. This macro is set when pre-processing both
355 Haskell source and C source, including the C source
356 generated from a Haskell module
357 (i.e. <filename>.hs</filename>, <filename>.lhs</filename>,
358 <filename>.c</filename> and <filename>.hc</filename>
365 <constant>__CONCURRENT_HASKELL__</constant>
366 <indexterm><primary><constant>__CONCURRENT_HASKELL__</constant></primary></indexterm>
369 <para>This symbol is defined when pre-processing Haskell
370 (input) and pre-processing C (GHC output). Since GHC from
371 verion 4.00 now supports concurrent haskell by default,
372 this symbol is always defined.</para>
378 <constant>__PARALLEL_HASKELL__</constant>
379 <indexterm><primary><constant>__PARALLEL_HASKELL__</constant></primary></indexterm>
382 <para>Only defined when <option>-parallel</option> is in
383 use! This symbol is defined when pre-processing Haskell
384 (input) and pre-processing C (GHC output).</para>
390 <constant><replaceable>os</replaceable>_OS=1</constant>
393 <para>This define allows conditional compilation based on
394 the Operating System, where<replaceable>os</replaceable> is
395 the name of the current Operating System
396 (eg. <literal>linux</literal>, <literal>mingw32</literal>
397 for Windows, <literal>solaris</literal>, etc.).</para>
403 <constant><replaceable>arch</replaceable>_ARCH=1</constant>
406 <para>This define allows conditional compilation based on
407 the host architecture, where<replaceable>arch</replaceable>
408 is the name of the current architecture
409 (eg. <literal>i386</literal>, <literal>x86_64</literal>,
410 <literal>powerpc</literal>, <literal>sparc</literal>,
416 <sect3 id="cpp-string-gaps">
417 <title>CPP and string gaps</title>
419 <para>A small word of warning: <option>-cpp</option> is not
420 friendly to “string gaps”.<indexterm><primary>-cpp
421 vs string gaps</primary></indexterm><indexterm><primary>string
422 gaps vs -cpp</primary></indexterm>. In other words, strings
423 such as the following:</para>
425 <programlisting>strmod = "\
429 <para>don't work with <option>-cpp</option>;
430 <filename>/usr/bin/cpp</filename> elides the backslash-newline
433 <para>However, it appears that if you add a space at the end
434 of the line, then <command>cpp</command> (at least GNU
435 <command>cpp</command> and possibly other
436 <command>cpp</command>s) leaves the backslash-space pairs
437 alone and the string gap works as expected.</para>
441 <sect2 id="pre-processor">
442 <title>Options affecting a Haskell pre-processor</title>
444 <indexterm><primary>pre-processing: custom</primary></indexterm>
445 <indexterm><primary>Pre-processor options</primary></indexterm>
451 <indexterm><primary><option>-F</option></primary></indexterm>
454 <para>A custom pre-processor is run over your Haskell
455 source file only if the <option>-F</option> option
456 <indexterm><primary>-F</primary></indexterm> is
459 <para>Running a custom pre-processor at compile-time is in
460 some settings appropriate and useful. The
461 <option>-F</option> option lets you run a pre-processor as
462 part of the overall GHC compilation pipeline, which has
463 the advantage over running a Haskell pre-processor
464 separately in that it works in interpreted mode and you
465 can continue to take reap the benefits of GHC's
466 recompilation checker.</para>
468 <para>The pre-processor is run just before the Haskell
469 compiler proper processes the Haskell input, but after the
470 literate markup has been stripped away and (possibly) the
471 C pre-processor has washed the Haskell input.</para>
474 <option>-pgmF <replaceable>cmd</replaceable></option>
475 to select the program to use as the preprocessor. When
476 invoked, the <replaceable>cmd</replaceable> pre-processor
477 is given at least three arguments on its command-line: the
478 first argument is the name of the original source file,
479 the second is the name of the file holding the input, and
480 the third is the name of the file where
481 <replaceable>cmd</replaceable> should write its output
484 <para>Additional arguments to the pre-processor can be
485 passed in using the <option>-optF</option> option. These
486 are fed to <replaceable>cmd</replaceable> on the command
487 line after the three standard input and output
494 <sect2 id="options-C-compiler">
495 <title>Options affecting the C compiler (if applicable)</title>
497 <indexterm><primary>include-file options</primary></indexterm>
498 <indexterm><primary>C compiler options</primary></indexterm>
499 <indexterm><primary>GCC options</primary></indexterm>
501 <para>If you are compiling with lots of foreign calls, you may
502 need to tell the C compiler about some
503 <literal>#include</literal> files. There is no real pretty
504 way to do this, but you can use this hack from the
507 <screen>% ghc -c '-#include <X/Xlib.h>' Xstuff.lhs</screen>
511 <sect2 id="options-codegen">
512 <title>Options affecting code generation</title>
517 <option>-fasm</option>
518 <indexterm><primary><option>-fasm</option></primary></indexterm>
521 <para>Use GHC's native code generator rather than
522 compiling via C. This will compile faster (up to twice as
523 fast), but may produce code that is slightly slower than
524 compiling via C. <option>-fasm</option> is the default
525 when optimisation is off (see <xref
526 linkend="options-optimise"/>).</para>
532 <option>-fvia-C</option>
533 <indexterm><primary><option>-fvia-C</option></primary></indexterm>
536 <para>Compile via C instead of using the native code
537 generator. This is default for optimised compilations,
538 and on architectures for which GHC doesn't have a native
539 code generator.</para>
545 <option>-fno-code</option>
546 <indexterm><primary><option>-fno-code</option></primary></indexterm>
549 <para>Omit code generation (and all later phases)
550 altogether. Might be of some use if you just want to see
551 dumps of the intermediate compilation phases.</para>
557 <sect2 id="options-linker">
558 <title>Options affecting linking</title>
560 <indexterm><primary>linker options</primary></indexterm>
561 <indexterm><primary>ld options</primary></indexterm>
564 <para>GHC has to link your code with various libraries, possibly
565 including: user-supplied, GHC-supplied, and system-supplied
566 (<option>-lm</option> math library, for example).</para>
572 <option>-l</option><replaceable>lib</replaceable>
573 <indexterm><primary><option>-l</option></primary></indexterm>
576 <para>Link in the <replaceable>lib</replaceable> library.
577 On Unix systems, this will be in a file called
578 <filename>lib<replaceable>lib</replaceable>.a</filename>
580 <filename>lib<replaceable>lib</replaceable>.so</filename>
581 which resides somewhere on the library directories path.</para>
583 <para>Because of the sad state of most UNIX linkers, the
584 order of such options does matter. If library
585 <replaceable>foo</replaceable> requires library
586 <replaceable>bar</replaceable>, then in general
587 <option>-l</option><replaceable>foo</replaceable> should
588 come <emphasis>before</emphasis>
589 <option>-l</option><replaceable>bar</replaceable> on the
592 <para>There's one other gotcha to bear in mind when using
593 external libraries: if the library contains a
594 <literal>main()</literal> function, then this will be
595 linked in preference to GHC's own
596 <literal>main()</literal> function
597 (eg. <literal>libf2c</literal> and <literal>libl</literal>
598 have their own <literal>main()</literal>s). This is
599 because GHC's <literal>main()</literal> comes from the
600 <literal>HSrts</literal> library, which is normally
601 included <emphasis>after</emphasis> all the other
602 libraries on the linker's command line. To force GHC's
603 <literal>main()</literal> to be used in preference to any
604 other <literal>main()</literal>s from external libraries,
605 just add the option <option>-lHSrts</option> before any
606 other libraries on the command line.</para>
612 <option>-no-link</option>
613 <indexterm><primary><option>-no-link</option></primary></indexterm>
616 <para>Omit the link step. This flag can be useful if you
617 want to avoid linking in <option>--make</option> mode,
618 where linking is normally done automatically if the program
619 contains a <literal>Main</literal> module.</para>
625 <option>-package</option> <replaceable>name</replaceable>
626 <indexterm><primary><option>-package</option></primary></indexterm>
629 <para>If you are using a Haskell “package”
630 (see <xref linkend="packages"/>), don't forget to add the
631 relevant <option>-package</option> option when linking the
632 program too: it will cause the appropriate libraries to be
633 linked in with the program. Forgetting the
634 <option>-package</option> option will likely result in
635 several pages of link errors.</para>
641 <option>-framework</option> <replaceable>name</replaceable>
642 <indexterm><primary><option>-framework</option></primary></indexterm>
645 <para>On Darwin/MacOS X only, link in the framework <replaceable>name</replaceable>.
646 This option corresponds to the <option>-framework</option> option for Apple's Linker.
647 Please note that frameworks and packages are two different things - frameworks don't
648 contain any haskell code. Rather, they are Apple's way of packaging shared libraries.
649 To link to Apple's “Carbon” API, for example, you'd use
650 <option>-framework Carbon</option>.
657 <option>-L</option><replaceable>dir</replaceable>
658 <indexterm><primary><option>-L</option></primary></indexterm>
661 <para>Where to find user-supplied libraries…
662 Prepend the directory <replaceable>dir</replaceable> to
663 the library directories path.</para>
669 <option>-framework-path</option><replaceable>dir</replaceable>
670 <indexterm><primary><option>-framework-path</option></primary></indexterm>
673 <para>On Darwin/MacOS X only, prepend the directory <replaceable>dir</replaceable> to
674 the framework directories path. This option corresponds to the <option>-F</option>
675 option for Apple's Linker (<option>-F</option> already means something else for GHC).</para>
681 <option>-split-objs</option>
682 <indexterm><primary><option>-split-objs</option></primary></indexterm>
685 <para>Tell the linker to split the single object file that
686 would normally be generated into multiple object files,
687 one per top-level Haskell function or type in the module.
688 We use this feature for building GHC's libraries libraries
689 (warning: don't use it unless you know what you're
696 <option>-static</option>
697 <indexterm><primary><option>-static</option></primary></indexterm>
700 <para>Tell the linker to avoid shared Haskell libraries,
701 if possible. This is the default.</para>
707 <option>-dynamic</option>
708 <indexterm><primary><option>-dynamic</option></primary></indexterm>
711 <para>Tell the linker to use shared Haskell libraries, if
712 available (this option is only supported on Windows at the
713 moment, and also note that your distribution of GHC may
714 not have been supplied with shared libraries).</para>
720 <option>-main-is <replaceable>thing</replaceable></option>
721 <indexterm><primary><option>-main-is</option></primary></indexterm>
722 <indexterm><primary>specifying your own main function</primary></indexterm>
725 <para> The normal rule in Haskell is that your program must supply a <literal>main</literal>
726 function in module <literal>Main</literal>. When testing, it is often convenient
727 to change which function is the "main" one, and the <option>-main-is</option> flag
728 allows you to do so. The <replaceable>thing</replaceable> can be one of:
730 <listitem><para>A lower-case identifier <literal>foo</literal>. GHC assumes that the main function is <literal>Main.foo</literal>.</para></listitem>
731 <listitem><para>An module name <literal>A</literal>. GHC assumes that the main function is <literal>A.main</literal>.</para></listitem>
732 <listitem><para>An qualified name <literal>A.foo</literal>. GHC assumes that the main function is <literal>A.foo</literal>.</para></listitem>
734 Strictly speaking, <option>-main-is</option> is not a link-phase flag at all; it has no effect on the link step.
735 The flag must be specified when compiling the module containing the specified main function (e.g. module <literal>A</literal>
736 in the latter two items above. It has no effect for other modules (and hence can safely be given to <literal>ghc --make</literal>).
743 <option>-no-hs-main</option>
744 <indexterm><primary><option>-no-hs-main</option></primary></indexterm>
745 <indexterm><primary>linking Haskell libraries with foreign code</primary></indexterm>
748 <para>In the event you want to include ghc-compiled code
749 as part of another (non-Haskell) program, the RTS will not
750 be supplying its definition of <function>main()</function>
751 at link-time, you will have to. To signal that to the
752 compiler when linking, use
753 <option>-no-hs-main</option>. See also <xref linkend="using-own-main"/>.</para>
755 <para>Notice that since the command-line passed to the
756 linker is rather involved, you probably want to use
757 <command>ghc</command> to do the final link of your
758 `mixed-language' application. This is not a requirement
759 though, just try linking once with <option>-v</option> on
760 to see what options the driver passes through to the
763 <para>The <option>-no-hs-main</option> flag can also be
764 used to persuade the compiler to do the link step in
765 <option>--make</option> mode when there is no Haskell
766 <literal>Main</literal> module present (normally the
767 compiler will not attempt linking when there is no
768 <literal>Main</literal>).</para>
774 <option>-debug</option>
775 <indexterm><primary><option>-debug</option></primary></indexterm>
778 <para>Link the program with a debugging version of the
779 runtime system. The debugging runtime turns on numerous
780 assertions and sanity checks, and provides extra options
781 for producing debugging output at runtime (run the program
782 with <literal>+RTS -?</literal> to see a list).</para>
788 <option>-threaded</option>
789 <indexterm><primary><option>-threaded</option></primary></indexterm>
792 <para>Link the program with the "threaded" runtime system.
793 This version of the runtime is designed to be used in
794 programs that use multiple operating-system threads. It
795 supports calls to foreign-exported functions from multiple
796 OS threads. Calls to foreign functions are made using the
797 same OS thread that created the Haskell thread (if it was
798 created by a call-in), or an arbitrary OS thread otherwise
799 (if the Haskell thread was created by
800 <literal>forkIO</literal>).</para>
802 <para>More details on the use of "bound threads" in the
803 threaded runtime can be found in the <ulink
804 url="../libraries/base/Control.Concurrent.html"><literal>Control.Concurrent</literal></ulink> module.</para>
806 <para>The threaded RTS does <emphasis>not</emphasis>
807 support using multiple CPUs to speed up execution of a
808 multi-threaded Haskell program. The GHC runtime platform
809 is still single-threaded, but using the
810 <option>-threaded</option> option it can be used safely in
811 a multi-threaded environment.</para>
820 ;;; Local Variables: ***
822 ;;; sgml-parent-document: ("users_guide.xml" "book" "chapter" "sect1") ***