3 ms·
Who uses m4? It has been around forever, but I have never really seen it used except in autoconf. When I looked at it (a long time ago) it struck me as really
by ykler 9y ago
Who uses m4? It has been around forever, but I have never really seen it used except in autoconf. When I looked at it (a long time ago) it struck me as really tricky and confusing, even more than lisp macros (but maybe on a par with TeX). However, this was just a first impression -- I didn't go too deep.
- chas 9y agoI have used it recently. I have a similar attitude towards m4 as shell scripts: they are good for quick hacks, proofs of concept, and very simple systems. When I need to sprinkle just a bit of macros on something, m4 is great. For example, a one-off piece of technical documentation I wrote is markdown interspersed with code examples. I wanted to make sure the code passed its unit tests, so it lives in separate files and I use m4 to include it into the bigger document. This is nicer than catting separate file chunks together because the text can all be contiguous, but if I needed to do anything more sophisticated I would probably switch to purpose-built templating or static site system.
- dflock 9y agoI've used it for really simple templating stuff with Dockerfiles - which it works fine for.
- kazinator 9y agoI once learned a lot about m4; more than twenty years ago. I remember all the features it has, like redefining the delimiters for macros, diversions, for loops and all that jazz. So it's not due to lack of familiarity that I won't use it; it is simply atrocious. Recently I needed a preprocessor (featuring just simple if/ifdef/elif/endif) in a Linux distro build system (Yocto). I didn't want to add anything new. To avoid inflicting m4 on myself and everyone who has to interact with this in the future, I wrote a simple awk script wrapped around cpp. The tiny awk script implements this pipeline, which involves encoding and decoding the input so that cpp never sees the syntax of the file: this is our 1 1 this is our original 2 2 --> [dec] original @ifdef FOO --[enc]--> #ifdef FOO --[cpp]--> 6 file input 4 @endif #endif file 6 this works with nearly any textual input. Your input can contain broken C tokens and comments and whatnot. I switched the # to @ to remind people that this isn't the C preprocessor, and because # is a comment character in the preprocessed language, which could look confusing.
- girvo 9y agoHeh, I've used it with Docker to generate config files at build time using build arguments and environment variables. Worked surprisingly well!