简体   繁体   English

F#,Linux和makefile

[英]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. 我打算将F#程序分发为二进制和源代码,以便用户可以根据需要重新编译它。 On Windows, I understand how to do this: provide .fsproj and .sln files, which both Visual Studio and MSBuild can understand. 在Windows上,我理解如何执行此操作:提供.fsproj和.sln文件,Visual Studio和MSBuild都可以理解这些文件。

On Linux, the traditional solution for C programs is a makefile. 在Linux上,C程序的传统解决方案是makefile。 This depends on gcc being directly available, which it always is. 这取决于gcc直接可用,它始终是。

The F# compiler can be installed on Linux and works under Mono, so that's fine so far. F#编译器可以安装在Linux上并在Mono下工作,所以到目前为止一切正常。 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 . 但是,据我所知,它不会创建fsc运行编译器的场景,而是命令是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. 所以在我的情况下运行编译器的完整命令可能是mono ~/FSharp-2.0.0.0/bin/fsc.exe types.fs tptp.fs main.fs -r FSharp.PowerPack.dll除了我不确定其中fsc.exe实际上位于用户的计算机上。

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? 有没有办法在makefile中找到它,或者最好是在文档中解释上述内容并依赖用户根据他的设置修改命令?

If you don't want to use autoconf just write up README and say us how to setup tools to compile your program. 如果您不想使用autoconf,请编写README并告诉我们如何设置工具来编译您的程序。 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: 例如,您可以要求使用binfmt_misc内核模块以允许系统自动使用正确的启动程序来处理已知格式的文件,因为$ PATH必须包含fsc.exe的路径,因此您的Makefile就像下面的代码:

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: 或者您可以允许用户使用makefile变量指向编译器:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM