eatonphil
eatonphil

Reputation: 13672

ocamlbuild specify output location/name

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

Upvotes: 1

Views: 848

Answers (2)

ivg
ivg

Reputation: 35210

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.

Upvotes: 2

alifirat
alifirat

Reputation: 2927

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.

Upvotes: 1

Related Questions