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>
18 <term><option>-pgmL</option> <replaceable>cmd</replaceable></term>
19 <indexterm><primary><option>-pgmL</option></primary>
22 <para>Use <replaceable>cmd</replaceable> as the literate
28 <term><option>-pgmP</option> <replaceable>cmd</replaceable></term>
29 <indexterm><primary><option>-pgmP</option></primary>
32 <para>Use <replaceable>cmd</replaceable> as the C
33 pre-processor (with <option>-cpp</option> only).</para>
38 <term><option>-pgmc</option> <replaceable>cmd</replaceable></term>
39 <indexterm><primary><option>-pgmc</option></primary>
42 <para>Use <replaceable>cmd</replaceable> as the C
48 <term><option>-pgma</option> <replaceable>cmd</replaceable></term>
49 <indexterm><primary><option>-pgma</option></primary>
52 <para>Use <replaceable>cmd</replaceable> as the
58 <term><option>-pgml</option> <replaceable>cmd</replaceable></term>
59 <indexterm><primary><option>-pgml</option></primary>
62 <para>Use <replaceable>cmd</replaceable> as the
68 <term><option>-pgmdll</option> <replaceable>cmd</replaceable></term>
69 <indexterm><primary><option>-pgmdll</option></primary>
72 <para>Use <replaceable>cmd</replaceable> as the DLL
78 <term><option>-pgmdep</option> <replaceable>cmd</replaceable></term>
79 <indexterm><primary><option>-pgmdep</option></primary>
82 <para>Use <replaceable>cmd</replaceable> as the dependency
88 <term><option>-pgmF</option> <replaceable>cmd</replaceable></term>
89 <indexterm><primary><option>-pgmF</option></primary>
92 <para>Use <replaceable>cmd</replaceable> as the
93 pre-processor (with <option>-F</option> only).</para>
100 <sect2 id="forcing-options-through">
101 <title>Forcing options to a particular phase</title>
102 <indexterm><primary>forcing GHC-phase options</primary></indexterm>
104 <para>Options can be forced through to a particlar compilation
105 phase, using the following flags:</para>
109 <term><option>-optL</option> <replaceable>option</replaceable></term>
110 <indexterm><primary><option>-optL</option></primary>
113 <para>Pass <replaceable>option</replaceable> to the
114 literate pre-processor</para>
118 <term><option>-optP</option> <replaceable>option</replaceable></term>
119 <indexterm><primary><option>-optP</option></primary>
122 <para>Pass <replaceable>option</replaceable> to CPP (makes
123 sense only if <option>-cpp</option> is also on).</para>
127 <term><option>-optF</option> <replaceable>option</replaceable></term>
128 <indexterm><primary><option>-optF</option></primary>
131 <para>Pass <replaceable>option</replaceable> to the
132 custom pre-processor (see <xref linkend="pre-processor"/>).</para>
136 <term><option>-optc</option> <replaceable>option</replaceable></term>
137 <indexterm><primary><option>-optc</option></primary>
140 <para>Pass <replaceable>option</replaceable> to the C compiler.</para>
144 <term><option>-opta</option> <replaceable>option</replaceable></term>
145 <indexterm><primary><option>-opta</option></primary>
148 <para>Pass <replaceable>option</replaceable> to the assembler.</para>
152 <term><option>-optl</option> <replaceable>option</replaceable></term>
153 <indexterm><primary><option>-optl</option></primary>
156 <para>Pass <replaceable>option</replaceable> to the linker.</para>
160 <term><option>-optdll</option> <replaceable>option</replaceable></term>
161 <indexterm><primary><option>-optdll</option></primary>
164 <para>Pass <replaceable>option</replaceable> to the DLL generator.</para>
168 <term><option>-optdep</option> <replaceable>option</replaceable></term>
169 <indexterm><primary><option>-optdep</option></primary>
172 <para>Pass <replaceable>option</replaceable> to the
173 dependency generator.</para>
178 <para>So, for example, to force an <option>-Ewurble</option>
179 option to the assembler, you would tell the driver
180 <option>-opta-Ewurble</option> (the dash before the E is
183 <para>GHC is itself a Haskell program, so if you need to pass
184 options directly to GHC's runtime system you can enclose them in
185 <literal>+RTS ... -RTS</literal> (see <xref
186 linkend="runtime-control"/>).</para>
190 <sect2 id="c-pre-processor">
191 <title>Options affecting the C pre-processor</title>
193 <indexterm><primary>pre-processing: cpp</primary></indexterm>
194 <indexterm><primary>C pre-processor options</primary></indexterm>
195 <indexterm><primary>cpp, pre-processing with</primary></indexterm>
200 <term><option>-cpp</option></term>
201 <indexterm><primary><option>-cpp</option></primary></indexterm>
203 <para>The C pre-processor <command>cpp</command> is run
204 over your Haskell code only if the <option>-cpp</option>
205 option <indexterm><primary>-cpp
206 option</primary></indexterm> is given. Unless you are
207 building a large system with significant doses of
208 conditional compilation, you really shouldn't need
214 <term><option>-D</option><replaceable>symbol</replaceable><optional>=<replaceable>value</replaceable></optional></term>
215 <indexterm><primary><option>-D</option></primary></indexterm>
217 <para>Define macro <replaceable>symbol</replaceable> in the
218 usual way. NB: does <emphasis>not</emphasis> affect
219 <option>-D</option> macros passed to the C compiler
220 when compiling via C! For those, use the
221 <option>-optc-Dfoo</option> hack… (see <xref
222 linkend="forcing-options-through"/>).</para>
227 <term><option>-U</option><replaceable>symbol</replaceable></term>
228 <indexterm><primary><option>-U</option></primary></indexterm>
230 <para> Undefine macro <replaceable>symbol</replaceable> in the
236 <term><option>-I</option><replaceable>dir</replaceable></term>
237 <indexterm><primary><option>-I</option></primary></indexterm>
239 <para> Specify a directory in which to look for
240 <literal>#include</literal> files, in the usual C
246 <para>The GHC driver pre-defines several macros when processing
247 Haskell source code (<filename>.hs</filename> or
248 <filename>.lhs</filename> files):</para>
253 <term><constant>__HASKELL98__</constant></term>
254 <indexterm><primary><literal>__HASKELL98__</literal></primary></indexterm>
256 <para>If defined, this means that GHC supports the
257 language defined by the Haskell 98 report.</para>
262 <term><constant>__HASKELL__=98</constant></term>
263 <indexterm><primary><constant>__HASKELL__=98</constant></primary></indexterm>
265 <para>In GHC 4.04 and later, the
266 <constant>__HASKELL__</constant>
267 macro is defined as having the value
268 <constant>98</constant>.</para>
273 <term><constant>__HASKELL1__</constant></term>
274 <indexterm><primary><constant>__HASKELL1__
275 </constant></primary></indexterm>
277 <para>If defined to <replaceable>n</replaceable>, that
278 means GHC supports the Haskell language defined in the
279 Haskell report version <emphasis>1.n</emphasis>.
280 Currently 5. This macro is deprecated, and will probably
281 disappear in future versions.</para>
286 <term><constant>__GLASGOW_HASKELL__</constant></term>
287 <indexterm><primary><constant>__GLASGOW_HASKELL__</constant></primary></indexterm>
289 <para>For version <replaceable>n</replaceable> of the GHC
290 system, this will be <literal>#define</literal>d to
291 <replaceable>100n</replaceable>. For example, for version
292 5.00, it is 500.</para>
295 <constant>__GLASGOW_HASKELL__</constant>
296 will be undefined in all other implementations that
297 support C-style pre-processing.</para>
299 <para>(For reference: the comparable symbols for other
301 <constant>__HUGS__</constant>
303 <constant>__NHC__</constant>
305 <constant>__HBC__</constant>
306 for Chalmers.)</para>
308 <para>NB. This macro is set when pre-processing both
309 Haskell source and C source, including the C source
310 generated from a Haskell module
311 (i.e. <filename>.hs</filename>, <filename>.lhs</filename>,
312 <filename>.c</filename> and <filename>.hc</filename>
318 <term><constant>__CONCURRENT_HASKELL__</constant></term>
319 <indexterm><primary><constant>__CONCURRENT_HASKELL__</constant></primary></indexterm>
321 <para>This symbol is defined when pre-processing Haskell
322 (input) and pre-processing C (GHC output). Since GHC from
323 verion 4.00 now supports concurrent haskell by default,
324 this symbol is always defined.</para>
329 <term><constant>__PARALLEL_HASKELL__</constant></term>
330 <indexterm><primary><constant>__PARALLEL_HASKELL__</constant></primary></indexterm>
332 <para>Only defined when <option>-parallel</option> is in
333 use! This symbol is defined when pre-processing Haskell
334 (input) and pre-processing C (GHC output).</para>
339 <sect3 id="cpp-string-gaps">
340 <title>CPP and string gaps</title>
342 <para>A small word of warning: <option>-cpp</option> is not
343 friendly to “string gaps”.<indexterm><primary>-cpp
344 vs string gaps</primary></indexterm><indexterm><primary>string
345 gaps vs -cpp</primary></indexterm>. In other words, strings
346 such as the following:</para>
354 <para>don't work with <option>-cpp</option>;
355 <filename>/usr/bin/cpp</filename> elides the backslash-newline
358 <para>However, it appears that if you add a space at the end
359 of the line, then <command>cpp</command> (at least GNU
360 <command>cpp</command> and possibly other
361 <command>cpp</command>s) leaves the backslash-space pairs
362 alone and the string gap works as expected.</para>
366 <sect2 id="pre-processor">
367 <title>Options affecting a Haskell pre-processor</title>
369 <indexterm><primary>pre-processing: custom</primary></indexterm>
370 <indexterm><primary>Pre-processor options</primary></indexterm>
374 <term><option>-F</option></term>
375 <indexterm><primary><option>-F</option></primary></indexterm>
377 <para>A custom pre-processor is run over your Haskell
378 source file only if the <option>-F</option> option
379 <indexterm><primary>-F</primary></indexterm> is
382 <para>Running a custom pre-processor at compile-time is in
383 some settings appropriate and useful. The
384 <option>-F</option> option lets you run a pre-processor as
385 part of the overall GHC compilation pipeline, which has
386 the advantage over running a Haskell pre-processor
387 separately in that it works in interpreted mode and you
388 can continue to take reap the benefits of GHC's
389 recompilation checker.</para>
391 <para>The pre-processor is run just before the Haskell
392 compiler proper processes the Haskell input, but after the
393 literate markup has been stripped away and (possibly) the
394 C pre-processor has washed the Haskell input.</para>
397 <option>-pgmF <replaceable>cmd</replaceable></option>
398 to select the program to use as the preprocessor. When
399 invoked, the <replaceable>cmd</replaceable> pre-processor
400 is given at least three arguments on its command-line: the
401 first argument is the name of the original source file,
402 the second is the name of the file holding the input, and
403 the third is the name of the file where
404 <replaceable>cmd</replaceable> should write its output
407 <para>Additional arguments to the pre-processor can be
408 passed in using the <option>-optF</option> option. These
409 are fed to <replaceable>cmd</replaceable> on the command
410 line after the three standard input and output
417 <sect2 id="options-C-compiler">
418 <title>Options affecting the C compiler (if applicable)</title>
420 <indexterm><primary>include-file options</primary></indexterm>
421 <indexterm><primary>C compiler options</primary></indexterm>
422 <indexterm><primary>GCC options</primary></indexterm>
424 <para>If you are compiling with lots of foreign calls, you may
425 need to tell the C compiler about some
426 <literal>#include</literal> files. There is no real pretty
427 way to do this, but you can use this hack from the
431 % ghc -c '-#include <X/Xlib.h>' Xstuff.lhs
436 <sect2 id="options-codegen">
437 <title>Options affecting code generation</title>
441 <term><option>-fasm</option></term>
442 <indexterm><primary><option>-fasm</option></primary></indexterm>
444 <para>Use GHC's native code generator rather than
445 compiling via C. This will compile faster (up to twice as
446 fast), but may produce code that is slightly slower than
447 compiling via C. <option>-fasm</option> is the default
448 when optimisation is off (see <xref
449 linkend="options-optimise"/>).</para>
454 <term><option>-fvia-C</option></term>
455 <indexterm><primary><option>-fvia-C</option></primary>
458 <para>Compile via C instead of using the native code
459 generator. This is default for optimised compilations,
460 and on architectures for which GHC doesn't have a native
461 code generator.</para>
466 <term><option>-fno-code</option></term>
467 <indexterm><primary><option>-fno-code</option></primary>
470 <para>Omit code generation (and all later phases)
471 altogether. Might be of some use if you just want to see
472 dumps of the intermediate compilation phases.</para>
478 <sect2 id="options-linker">
479 <title>Options affecting linking</title>
481 <indexterm><primary>linker options</primary></indexterm>
482 <indexterm><primary>ld options</primary></indexterm>
485 <para>GHC has to link your code with various libraries, possibly
486 including: user-supplied, GHC-supplied, and system-supplied
487 (<option>-lm</option> math library, for example).</para>
492 <term><option>-l</option><replaceable>lib</replaceable></term>
493 <indexterm><primary><option>-l</option></primary></indexterm>
495 <para>Link in the <replaceable>lib</replaceable> library.
496 On Unix systems, this will be in a file called
497 <filename>lib<replaceable>lib</replaceable>.a</filename>
499 <filename>lib<replaceable>lib</replaceable>.so</filename>
500 which resides somewhere on the library directories path.</para>
502 <para>Because of the sad state of most UNIX linkers, the
503 order of such options does matter. If library
504 <replaceable>foo</replaceable> requires library
505 <replaceable>bar</replaceable>, then in general
506 <option>-l</option><replaceable>foo</replaceable> should
507 come <emphasis>before</emphasis>
508 <option>-l</option><replaceable>bar</replaceable> on the
511 <para>There's one other gotcha to bear in mind when using
512 external libraries: if the library contains a
513 <literal>main()</literal> function, then this will be
514 linked in preference to GHC's own
515 <literal>main()</literal> function
516 (eg. <literal>libf2c</literal> and <literal>libl</literal>
517 have their own <literal>main()</literal>s). This is
518 because GHC's <literal>main()</literal> comes from the
519 <literal>HSrts</literal> library, which is normally
520 included <emphasis>after</emphasis> all the other
521 libraries on the linker's command line. To force GHC's
522 <literal>main()</literal> to be used in preference to any
523 other <literal>main()</literal>s from external libraries,
524 just add the option <option>-lHSrts</option> before any
525 other libraries on the command line.</para>
530 <term><option>-no-link</option></term>
532 <primary><option>-no-link</option></primary>
535 <para>Omit the link step. This flag can be useful if you
536 want to avoid linking in <option>--make</option> mode,
537 where linking is normally done automatically if the program
538 contains a <literal>Main</literal> module.</para>
543 <term><option>-package</option> <replaceable>name</replaceable></term>
544 <indexterm><primary><option>-package</option></primary></indexterm>
546 <para>If you are using a Haskell “package”
547 (see <xref linkend="packages"/>), don't forget to add the
548 relevant <option>-package</option> option when linking the
549 program too: it will cause the appropriate libraries to be
550 linked in with the program. Forgetting the
551 <option>-package</option> option will likely result in
552 several pages of link errors.</para>
557 <term><option>-framework</option> <replaceable>name</replaceable></term>
558 <indexterm><primary><option>-framework</option></primary></indexterm>
560 <para>On Darwin/MacOS X only, link in the framework <replaceable>name</replaceable>.
561 This option corresponds to the <option>-framework</option> option for Apple's Linker.
562 Please note that frameworks and packages are two different things - frameworks don't
563 contain any haskell code. Rather, they are Apple's way of packaging shared libraries.
564 To link to Apple's “Carbon” API, for example, you'd use
565 <option>-framework Carbon</option>.
571 <term><option>-L</option><replaceable>dir</replaceable></term>
572 <indexterm><primary><option>-L</option></primary></indexterm>
574 <para>Where to find user-supplied libraries…
575 Prepend the directory <replaceable>dir</replaceable> to
576 the library directories path.</para>
581 <term><option>-framework-path</option><replaceable>dir</replaceable></term>
582 <indexterm><primary><option>-framework-path</option></primary></indexterm>
584 <para>On Darwin/MacOS X only, prepend the directory <replaceable>dir</replaceable> to
585 the framework directories path. This option corresponds to the <option>-F</option>
586 option for Apple's Linker (<option>-F</option> already means something else for GHC).</para>
591 <term><option>-split-objs</option></term>
592 <indexterm><primary><option>-split-objs</option></primary></indexterm>
594 <para>Tell the linker to split the single object file that
595 would normally be generated into multiple object files,
596 one per top-level Haskell function or type in the module.
597 We use this feature for building GHC's libraries libraries
598 (warning: don't use it unless you know what you're
604 <term><option>-static</option></term>
605 <indexterm><primary><option>-static</option></primary></indexterm>
607 <para>Tell the linker to avoid shared Haskell libraries,
608 if possible. This is the default.</para>
613 <term><option>-dynamic</option></term>
614 <indexterm><primary><option>-dynamic</option></primary></indexterm>
616 <para>Tell the linker to use shared Haskell libraries, if
617 available (this option is only supported on Windows at the
618 moment, and also note that your distribution of GHC may
619 not have been supplied with shared libraries).</para>
624 <term><option>-main-is <replaceable>thing</replaceable></option></term>
625 <indexterm><primary><option>-main-is</option></primary></indexterm>
626 <indexterm><primary>specifying your own main function</primary></indexterm>
628 <para> The normal rule in Haskell is that your program must supply a <literal>main</literal>
629 function in module <literal>Main</literal>. When testing, it is often convenient
630 to change which function is the "main" one, and the <option>-main-is</option> flag
631 allows you to do so. The <replaceable>thing</replaceable> can be one of:
633 <listitem><para>A lower-case identifier <literal>foo</literal>. GHC assumes that the main function is <literal>Main.foo</literal>.</para></listitem>
634 <listitem><para>An module name <literal>A</literal>. GHC assumes that the main function is <literal>A.main</literal>.</para></listitem>
635 <listitem><para>An qualified name <literal>A.foo</literal>. GHC assumes that the main function is <literal>A.foo</literal>.</para></listitem>
637 Strictly speaking, <option>-main-is</option> is not a link-phase flag at all; it has no effect on the link step.
638 The flag must be specified when compiling the module containing the specified main function (e.g. module <literal>A</literal>
639 in the latter two items above. It has no effect for other modules (and hence can safely be given to <literal>ghc --make</literal>).
645 <term><option>-no-hs-main</option></term>
646 <indexterm><primary><option>-no-hs-main</option></primary></indexterm>
647 <indexterm><primary>linking Haskell libraries with foreign code</primary></indexterm>
649 <para>In the event you want to include ghc-compiled code
650 as part of another (non-Haskell) program, the RTS will not
651 be supplying its definition of <function>main()</function>
652 at link-time, you will have to. To signal that to the
653 compiler when linking, use
654 <option>-no-hs-main</option>. See also <xref linkend="using-own-main"/>.</para>
656 <para>Notice that since the command-line passed to the
657 linker is rather involved, you probably want to use
658 <command>ghc</command> to do the final link of your
659 `mixed-language' application. This is not a requirement
660 though, just try linking once with <option>-v</option> on
661 to see what options the driver passes through to the
664 <para>The <option>-no-hs-main</option> flag can also be
665 used to persuade the compiler to do the link step in
666 <option>--make</option> mode when there is no Haskell
667 <literal>Main</literal> module present (normally the
668 compiler will not attempt linking when there is no
669 <literal>Main</literal>).</para>
674 <term><option>-debug</option></term>
675 <indexterm><primary><option>-debug</option></primary>
678 <para>Link the program with a debugging version of the
679 runtime system. The debugging runtime turns on numerous
680 assertions and sanity checks, and provides extra options
681 for producing debugging output at runtime (run the program
682 with <literal>+RTS -?</literal> to see a list).</para>
687 <term><option>-threaded</option></term>
688 <indexterm><primary><option>-threaded</option></primary>
691 <para>Link the program with the "threaded" runtime system.
692 This version of the runtime is designed to be used in
693 programs that use multiple operating-system threads. It
694 supports calls to foreign-exported functions from multiple
695 OS threads. Calls to foreign functions are made using the
696 same OS thread that created the Haskell thread (if it was
697 created by a call-in), or an arbitrary OS thread otherwise
698 (if the Haskell thread was created by
699 <literal>forkIO</literal>).</para>
701 <para>More details on the use of "bound threads" in the
702 threaded runtime can be found in the <ulink
703 url="../libraries/base/Control.Concurrent.html"><literal>Control.Concurrent</literal></ulink> module.</para>
705 <para>The threaded RTS does <emphasis>not</emphasis>
706 support using multiple CPUs to speed up execution of a
707 multi-threaded Haskell program. The GHC runtime platform
708 is still single-threaded, but using the
709 <option>-threaded</option> option it can be used safely in
710 a multi-threaded environment.</para>
720 ;;; Local Variables: ***
722 ;;; sgml-parent-document: ("users_guide.xml" "book" "chapter") ***