ocamlbuild specify output location/name

三世轮回 提交于 2019-12-08 04:20:02

问题


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

回答1:


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).

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

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

After the file is finished, run

oasis setup

that will generate Makefile and configure script. Run

./configure

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)

And finally, usual pair of

make && make install 

Will do the work.

OCamlfind

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.

After the meta is written, you can use ocamlfind install subcommand which has a -destdir option.

But ocamlfind doesn't handle executables, only libraries. So this may not suit you.




回答2:


With entering ocamlbuild --help, I cannot find a such option.

One solution is to write a script doing this :

#!/bin/bash 

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

EDIT:

Following suggestion of ivg, you should replace the line mv myapp.native bin/myapp by cp -L myapp.native bin/myapp.

Maybe someone can give this option, which I found interesting but in the user manual, there is not. So one solution is to use script.



来源:https://stackoverflow.com/questions/30619162/ocamlbuild-specify-output-location-name

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!