ocamlbuild 指定输出 location/name

ocamlbuild specify output location/name

我可以使用 ocamlbuild 工具指定构建位置和文件名吗?我希望能够说(用伪代码):

ocamlbuild myapp.ml -b native -o bin/myapp

输入ocamlbuild --help,我找不到这样的选项。

一个解决方案是编写一个脚本来执行此操作:

#!/bin/bash 

ocalmbuild myapp.native // build your executable
mv myapp.native bin/myapp // rename it

编辑:

根据 ivg 的建议,您应该将行 mv myapp.native bin/myapp 替换为 cp -L myapp.native bin/myapp

也许有人可以提供这个选项,我觉得这很有趣,但在用户手册中没有。所以一种解决方案是使用脚本。

没有这样的选项,但 ocamlbuild 是可扩展的,允许您使用 Options.add 添加自己的选项。当然,您还需要添加一些实现。基本上,劫持 native 的规则并使用安装程序扩展它可能会奏效。要扩展 ocamlbuild,您应该 write a plugin (other option is to create your own standalone executable, and use it instead of ocamlbuild, that is what we're doing in our project)。

但对于大多数用途而言,使用 ocamlfindoasis 等标准工具就足够了。我建议看看后者,因为它更高级。

绿洲

使用 oasis 您需要编写一个简单的 _oasis 文件(或使用 oasis quickstart 以交互方式编写)。最小文件看起来像这样:

OASISFormat: 0.4
Name:        myapp
Version:     0.0.1
Synopsis:    My first application in oasis
Authors:     Authors list
Maintainers: Maintainer Name 
License:     MIT
Copyrights:  (C) Copyright Holder
Plugins:     META (0.4), DevFiles (0.4)
BuildTools: ocamlbuild

Executable "myapp"
  Path:           .
  MainIs:         myapp.ml
  Install:        true
  CompiledObject: best

文件完成后,运行

oasis setup

将生成 Makefileconfigure 脚本。 运行

./configure

像往常一样检查和设置您的环境。例如,./configure --prefix=$HOME 将设置您的构建系统以安装到您的主文件夹中(即,到 ~/bin 等的可执行文件)。我通常更喜欢安装到 opam 堆栈上,并使用 ./configure --prefix=$(opam config var env)

最后,通常一对

make && make install 

会做的。

OCamlfind

ocamlfind 仍然需要您编写 META 文件。通常他们只是通过复制粘贴和编辑一些现有项目的 META 文件来编写它们。不过写一个也不难,很好documented.

meta 写入后,可以使用ocamlfind install 子命令,其中有一个-destdir 选项。

但是 ocamlfind 不处理可执行文件,只处理库。所以这可能不适合你。