cabal: question on compiling build prerequisites
Peter Selinger
selinger at mathstat.dal.ca
Sun Dec 8 18:50:21 UTC 2013
Hi John,
thanks for your reply! So say my package directory contains two files:
Test.hs
PreProc.hs
What you are suggesting is:
ghc Test.hs -F -pgmF ./PreProc
However, this gives the error message:
ghc: could not execute: ./PreProc
And indeed, while GHC is smart enough to automatically run a
preprocessor, it is not smart enough to automatically *compile* the
preprocessor. So it needs to be compiled beforehand, which would be
Cabal's job.
But strangely, there doesn't seem to be a way to get Cabal to do this
(apart from doing some very low-level hacking in the Setup.hs file).
Hence my question.
In a related problem, and more generally, the .cabal format seems to
be lacking any way to specify things (packages, built programs) that
are prerequisites of Setup.hs, as opposed to of the libraries or
executables being built. So if my Setup.hs imports some non-base
package, there is no way to ensure it is actually installed before
Setup.hs is compiled or run.
I'm ccing this to the cabal-devel list, because it's apparently a more
appropriate place to discuss this than libraries at haskell.org.
Thanks, -- Peter
John Lato wrote:
>
> Ghc has a flag -pgmF that you can use for this. You'd need to include your
> preprocessor source in the extra-source-files field of build-depends. In
> this case cabal won't know anything about the preprocessor, ghc will run it
> directly.
> On Dec 6, 2013 7:31 PM, "Peter Selinger" <selinger at mathstat.dal.ca> wrote:
>
> > This may be a silly question, but I can't seem to find the answer in
> > the documentation.
> >
> > I would like to create a Cabal package where some of the source files
> > use a custom pre-processor. The pre-processor is itself a Haskell
> > program, let's say MyPreProc.hs in the package's root directory.
> >
> > I figured out how to activate the preprocessor, for example,
> >
> > cabal build --ghc-options="-F -pgmF ./MyPreProc"
> >
> > I also figured out how to achieve the same effect using hooks.
> >
> > However, there is one problem: how can I tell cabal to actually
> > compile MyPreProc.hs before any of the commands using the preprocessor
> > are run? The package's Setup.hs file is automatically compiled during
> > "cabal configure". I would like MyPreProc.hs to be compiled at the
> > same time as well - or at least some time before the proprocessor
> > needs to be used.
> >
> > The .cabal file contains all kinds of related variables, such as
> > "build-depends" (but only packages can be listed here, not programs to
> > be compiled), "other-modules" (but these modules would already require
> > the pre-processor, so the pre-processor should be compiled first),
> > "build-tools" (but this only refers to external programs).
> >
> > My current solution is to make the pre-processor a shell script,
> > rather than a Haskell program. But this is ugly and not portable
> > (won't work in Windows, for example).
> >
> > To clarify: my custom preprocessor is local to this package. It has no
> > independent value, so it would not make sense to publish it as a
> > separate package just so that I can add it to build-depends.
> >
> > Is there a known solution to this problem?
> >
> > Thanks, -- Peter
> > _______________________________________________
> > Libraries mailing list
> > Libraries at haskell.org
> > http://www.haskell.org/mailman/listinfo/libraries
> >
More information about the cabal-devel
mailing list