passing CFLAGS and LDFLAGS to ghc via Cabal?

Hi, This may seem like a strange question since most ghc compilation uses the NCG or llvm backends, but I want to ask about how/if one can pass CFLAGS/LDFLAGS to gcc from Cabal? So far I tried using --gcc-options="$RPM_OPT_FLAGS" (and also just exporting CFLAGS), but as far as I can tell (from --ghc-option=-v) the options are not passed by ghc to gcc. Is the problem that ghc first compiles C code to assembler before compiling the asm to an object file? (This is in the context of adding of trying to add debuginfo for C files to Fedora's Haskell packages, though I am not even sure if it is useful. Maybe it is a futile experiment?) Jens

On Fri, 24 Oct 2014 15:51:04 +0900
Jens Petersen
Hi,
This may seem like a strange question since most ghc compilation uses the NCG or llvm backends, but I want to ask about how/if one can pass CFLAGS/LDFLAGS to gcc from Cabal?
So far I tried using --gcc-options="$RPM_OPT_FLAGS" (and also just exporting CFLAGS), but as far as I can tell (from --ghc-option=-v) the options are not passed by ghc to gcc. Is the problem that ghc first compiles C code to assembler before compiling the asm to an object file?
(This is in the context of adding of trying to add debuginfo for C files to Fedora's Haskell packages, though I am not even sure if it is useful. Maybe it is a futile experiment?)
I believe the proper way to pass them is via --ghc-option="-optc$EACH_CFLAG -optl$EACH_LDFLAG -opta$EACH_ASFLAG" as Cabal uses ghc to compile .c/.cpp files. At least it's how we do it in gentoo https://github.com/gentoo-haskell/gentoo-haskell/blob/master/eclass/haskell-... to preserve debug syms and play with things like -Wl,--as-needed -Wl,--hash-style=gnu. -- Sergei

On 25 October 2014 05:10, Sergei Trofimovich
I believe the proper way to pass them is via --ghc-option="-optc$EACH_CFLAG -optl$EACH_LDFLAG -opta$EACH_ASFLAG" as Cabal uses ghc to compile .c/.cpp files.
Thanks Sergei that helped a lot. :) I can now get proper debuginfo generated for libraries, but somehow not for executables: but that looks like some ghc behaviour problem perhaps. http://pkgs.fedoraproject.org/cgit/ghc-rpm-macros.git/tree/macros.ghc?id=e5c...

On Mon, 27 Oct 2014 17:50:41 +0900
Jens Petersen
I can now get proper debuginfo generated for libraries, but somehow not for executables: but that looks like some ghc behaviour problem perhaps.
More likely cabal's feature. To avoid stripping we use --disable-executable-stripping (cabal-1.4+) option for 'Setup configure' phase (and then we strip binaries by package manager if user didn't request debugging support). -- Sergei
participants (2)
-
Jens Petersen
-
Sergei Trofimovich