You can also look at this discussion
Furthermore a recently added feature can ease the implementation. It is relevant for setting LEGO_* vars and it has been discussed here: