I'm facing the following problem: I insist on using
m4_include([some/file.m4]) in my configure.ac file, where some/file.m4 then contains patterns like 'AC_INIT' and 'LT_INIT' that are necessary for libtoolize to work. In otherwords, I need configure.ac to be preprocessed by m4 before libtoollize feeds it to sed looking for those patterns.
I do NOT want to generate configure.ac (if I can avoid it). The only hook that libtoolize provides that can help me is that they look for the environment variable SED and use that instead of /bin/sed when found.
I wrote a shell script that analyses sed arguments and passes them on to the real sed. Unfortunately, libtoolize concatenates m4local.ac and configure.ac and feeds that to $SED at some point, so looking for an input file named 'configure.ac' fails. Nevertheless, after analyzing the arguments passed to $SED I can just concatenate all input files and/or stdin, because in the end it has to work by reading from a stream (stdin) anyway.
The problem that I am facing therefore is the following:
My script must read from stdin and write to stdout, until it encounters a line like
m4_include([cwm4/configure_ac_top.m4]) which it then should swallow and instead insert the contents of cwm4/configure_ac_top.m4, no other m4 preprocessing is necessary, just the includes will do. In fact, as sed is also used for countless other little things it would be downright dangerous to do any other preprocessing than the m4_include's. However I need it to be recursive as well: if an included file contains a line
m4_sinclude([lt_init.m4]) then also that file needs to be included.
I found multiple question and their answers on this site that ask how to insert one file into another, but then the file name of the to-be inserted file is known (not read from the original file), it isn't recursive and in many cases it wasn't reading from stdin (but from the first, known, file by name).
dnl-- except lines matching
m4_include--, pipe that to m4, then strip off your leading
dnl's with another sed