Since you are already pointing out that your sed program is likely unportable,
I don't know any sed that would choke on it, actually.
/gl_MODULES(/ {
you would need a "ta" here too, to reset the flag.
:a s/)/)/ tb N ba :b s,^.*gl_MODULES([[ ]*\([^])]*\).*$,cached_specified_modules="\1",p }
You can also do something like :a /gl_[A-Z][A-Z]*([^)]*$/ N /)/! ba at the top, which would apply to all gl_SOMETHING macros. Paolo