[Omake] Testing whether a target has been defined

Jason Hickey jyh at cs.caltech.edu
Sat Jun 17 11:30:54 PDT 2006


Benjamin Pierce wrote:
> I want to write a .SUBDIRS directive something like this...
> 
>    .SUBDIRS: foo bar baz
>      if $(file-exists OMakefile)
>        include OMakefile
>        export
>      if <the phony target "test" was not defined by the OMakefile> then
>        test:
>          <blah blah>
> 
> Anybody know how can this be achieved?

One approach might be to wrap the rule function, which gets called 
whenever a rule is evaluated.  But it seems tricky, perhaps someone else 
has an easier way.

The wrapper would look like this, for saving all the actual targets to 
the TARGETS variable, so you can examine them later.

     old-rule = $(rule)

     TARGETS[] =

     rule(multiple, target, pattern, sources, options, body) =
         TARGETS[] += $(target)
         old-rule($(multiple), $(target), $(pattern), $(sources), 
$(options), $(body))
         export

One problem is that this discards the rule value.  This is usually ok, 
but you probably want to limit the scope of this definition.

Jason

-- 
Jason Hickey                  http://www.cs.caltech.edu/~jyh
Caltech Computer Science      Tel: 626-395-6568 FAX: 626-792-4257


More information about the Omake mailing list