[Omake] Using Target outside of a rule body?
Aleksey Nogin
nogin at cs.caltech.edu
Thu Apr 20 13:17:19 PDT 2006
On 20.04.2006 11:28, Mike Furr wrote:
>>I have an OCaml project which spans several directories. To build the
>>final executable, I would like to just pass the "main" file and have
>>OMake figure out all of the object files that need to be linked in.
>>Something like:
>>
>>foo: $(filter %.cmx, $(target main.cmx).build-deps)
>> $(OCAMLOPTLINK) -o $@ $(file-sort .BUILDORDER, $+)
>>
>>However, attempts to use the Target object in the rule declaration gives
>>the error "this function can be called only in rule bodies".
>
> Of course, as soon as I posted this, I realized there is no need to
> actually have the target list in the declaration. a dependence on
> main.cmx will pull in everything else transitively! Grabbing the
> build-deps in the body works just fine.
You might want to also add a :value: dependency to make sure that when
some of the .o change (without main.cmx), the binary would still get
rebuilt.
Something like (untested)
digest-deps(file) =
cmx = $(dependencies-all $(file))
objs = $(replacesuffixes .cmx, .o, $(cmx))
return $(digest $(cmx) $(objs))
foo: main.cmx :value: $(digest-deps main.cmx)
...
Note, BTW, the build-deps field (which can be replaces by the
"dependencies" function call) only gives you the immediate dependencies,
while what you might want here is all the dependencies collected
recursively (use the dependency-all function for that). The
dependency-all, might give too much - for example in case one of the
source files is generated by another OCaml program that is also a part
of the project.
--
Aleksey Nogin
Home Page: http://nogin.org/
E-Mail: nogin at cs.caltech.edu (office), aleksey at nogin.org (personal)
Office: Moore 04, tel: (626) 395-2200
More information about the OMake-Devel
mailing list