Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

F#, Linux and makefiles

I intend to distribute an F# program as both binary and source so the user has the option of recompiling it if desired. On Windows, I understand how to do this: provide .fsproj and .sln files, which both Visual Studio and MSBuild can understand.

On Linux, the traditional solution for C programs is a makefile. This depends on gcc being directly available, which it always is.

The F# compiler can be installed on Linux and works under Mono, so that's fine so far. However, as far as I can tell, it doesn't create a scenario where fsc runs the compiler, instead the command is mono ...path.../fsc.exe. This is also fine, except I don't know what the path is going to be. So the full command to run the compiler in my case could be mono ~/FSharp-2.0.0.0/bin/fsc.exe types.fs tptp.fs main.fs -r FSharp.PowerPack.dll except that I'm not sure where fsc.exe will actually be located on the user's machine.

Is there a way to find that out within a makefile, or would it be better to fall back on just explaining the above in the documentation and relying on the user to modify the command according to his setup?

like image 490
rwallace Avatar asked Jan 21 '23 23:01

rwallace


1 Answers

If you don't want to use autoconf just write up README and say us how to setup tools to compile your program. For example, you can require as to use binfmt_misc kernel module to allow system to automatically use right starter program for files with known format as to $PATH must contain path to fsc.exe, so your Makefile simply will be like following code:

FILES=types.fs tptp.fs main.fs

target.exe: ${FILES}
        fsc.exe -o $@  ${FILES} -r FSharp.PowerPack.dll

Or you can allow user to point to compiler by using makefile variables:

MONO=/usr/bin/mono
FSC=/usr/local/fsharp/bin/fsc.exe
COMPILER=${MONO} ${FSC}
FILES=types.fs tptp.fs main.fs

target.exe: ${FILES}
        ${COMPILER} -o $@  ${FILES} -r FSharp.PowerPack.dll
like image 109
ssp Avatar answered Jan 28 '23 05:01

ssp