ocamlbuild指定输出位置/名称 [英] ocamlbuild specify output location/name
问题描述
我可以使用ocamlbuild工具指定构建位置和文件名吗?我想说(用伪代码):
Can I specify the build location and file name with the ocamlbuild tool? I would like to be able to say (in pseudocode):
ocamlbuild myapp.ml -b native -o bin/myapp
推荐答案
没有这样的选项,但是ocamlbuild
是可扩展的,并允许您使用Options.add
添加自己的选项.当然,您还需要添加一些实现.基本上,劫持native
的规则并通过安装过程进行扩展可能会起作用.要扩展ocamlbuild
,您应该编写一个插件(另一种方法是创建您的插件拥有独立的可执行文件,并使用它代替ocamlbuild,这就是我们在项目).
There is no such option, but ocamlbuild
is extensible and allows you to add your own options with Options.add
. Of course, you will also need to add some implementation. Basically, hijacking the rule for native
and extending it with installation procedure may work. To extend ocamlbuild
you should 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).
但是对于大多数用途而言,使用ocamlfind
,oasis
之类的标准工具就足够了.我建议您看一下后者,因为它比较高级.
But for most purposes it is enough to use standard tools like ocamlfind
, oasis
. I would suggest to look at the latter, as it is more high-level.
使用oasis
,您需要编写一个简单的_oasis
文件(或使用oasis quickstart
进行交互编写).最小文件如下所示:
With oasis
you need to write a simple _oasis
file (or use oasis quickstart
to write it interactively). The minimum file would look something like this:
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
将会生成Makefile
和configure
脚本.运行
./configure
像往常一样
检查和设置您的环境.例如,./configure --prefix=$HOME
将设置您的构建系统以安装到您的主文件夹中(即,安装到~/bin
的可执行文件中,等等).我通常更喜欢安装在opam堆栈上,并使用./configure --prefix=$(opam config var env)
as usual to check and setup your environment. E.g., ./configure --prefix=$HOME
will setup your build system to install into your home folder (i.e., to executables to ~/bin
, etc). I usually prefer to install onto opam stack, and use ./configure --prefix=$(opam config var env)
最后,通常是一对
make && make install
会做这项工作.
ocamlfind
仍然需要您写入META文件.通常,他们只是通过复制粘贴和编辑现有项目中的META文件来编写它们.但是写一个并不难,因为它很好有记载的.
ocamlfind
will still require your to write META file. Usually they write them by just copy-pasting and editing the META file from some existing project. But it is not hard to write one, as it is very well documented.
在编写元文件之后,可以使用具有-destdir
选项的ocamlfind install
子命令.
After the meta is written, you can use ocamlfind install
subcommand which has a -destdir
option.
但是ocamlfind
不处理可执行文件,仅处理库.因此,这可能不适合您.
But ocamlfind
doesn't handle executables, only libraries. So this may not suit you.
这篇关于ocamlbuild指定输出位置/名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!