Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I know in advance where cabal will place a generated executable?

Tags:

haskell

cabal

When I run cabal build for my project, it places my compiled executable in

dist-newstyle/build/$PLATFORM/$GHC/$PACKAGE-$VERSION/x/$PACKAGE/build/$PACKAGE/$PACKAGE

I'm using a Makefile to run cabal build as needed when I need to run the executable.

Since I'm working on different platforms at various times, I need a way to tell my Makefile what to expect the $PLATFORM value to be.

There's a couple ways I could go about this:

  • run cabal build once unconditionally, and then use wildcards:

    BIN := $(wildcard dist-newstyle/build/*/ghc-*/foo-*/x/foo/build/foo/foo)
    
  • use uname to predict what the platform will be

    BIN := dist-newstyle/build/$(shell uname -m)-$(shell uname -s | some magic)/ghc-$(shell ghc --version | some magic)/foo-$(VERSION)/x/foo/build/foo/foo
    
  • give up on making sure the binary is up to date within the Makefile and just run cabal run unconditionally

Any of those would work, but I would like to know if I could just ask cabal to tell me where it expects to place an executable.

Is there a cabal command I can run to tell me what $PLATFORM and/or $GHC values it detects?

like image 718
rampion Avatar asked Dec 07 '20 13:12

rampion


1 Answers

cabal exec which $EXENAME$ will give you the full path of the compiled executable.

like image 149
sclv Avatar answered Oct 22 '22 10:10

sclv