5 ms·
I'm curious if anyone is still using this tool today. Back when I used it (~8-ish years ago) I found it to be a godsend.
by brodouevencode 7y ago
I'm curious if anyone is still using this tool today. Back when I used it (~8-ish years ago) I found it to be a godsend.
- tannhaeuser 7y agoIt's used by autotools, and about 15 years ago I used it to generate BIND (dns server) configs, and sendmail.conf files, too. But I'd rather not use if I don't have to :) m4 is still POSIX, though, and maybe someone can elaborate on m4 and tell us about it's strength in times of JSON and (ya|to)ml configs, which I also don't like, perhaps because they're misnamed IMO as "markup languages".
- brodouevencode 7y agoThis too is one of the ways I was using it back then. Working in a small CMS shop we were responsible for hosting Drupal sites with custom DNS, and all that. We used m4 to build out the BIND configs, Drupal config files, logging configs, and Apache configs.
- cryptonector 7y agoFor JSON, see jq (https://stedolan.github.io/jq https://stedolan.github.io/jq).
- enriquto 7y agoI do, from time to time. It's nice to have a preprocessor for normal text files. Yet, most often I find it more practical to use sed or awk for my needs.
- adrianN 7y agoI use it as a simple static site generator and for generating C++. The thing I dislike most is that it uses ` and ' for quoting and there is no easy way of escaping quotes.
- kevin_thibedeau 7y agoYou can change the quote chars. This is why autotools use [].
- kevin_thibedeau 7y agoI wrote a large package of macros for a niche assembler using M4. It has some sophisticated things like a code generator for non-infix expressions. M4 was a blessing and a curse. It is very powerful and saved me from implementing my own macro language but debugging is not for the faint of heart once you get into anything complicated. https://github.com/kevinpt/opbasm/blob/master/opbasm/picoblaze.m4 https://github.com/kevinpt/opbasm/blob/master/opbasm/picobla... Michael Breen's notes are indispensable documentation on how to make effective use of the language.
- throwaway_pdp09 7y agoI'm a fan of M4, and I don't know what these are doing but it surely looks too complex. You have defines within defines and OMG just an extract .. (just a snip follows) `define(`_'''$`'1```_LENGTH',strlenc(''$`'2``))'dnl `; "''$`'2``"' `ifdef(`PB3', ''$`'1```: calltable($4, $1, estr('''$`'2```))dnl return',dnl `table '''$`'1```#, [dec2pbhex(cstr('''$`'2```))] '''$`'1```: loadaddr($2, $3, _'''$`'1```_STR) jump __`'$5`'_handler _'''$`'1```_STR: load&return $1, '''$`'1```#')' )')' I have to ask if this is right, or whether a parser would have been a whole lot less work. Credit for your skillz, but that looks like so much pain.
- kevin_thibedeau 7y agoThese are macros that generate user configurable codegen macros. I couldn't hard code register assignments so everything dynamically generated is prepared with these monstrosities. They also can't have fixed names since some need to be invoked multiple times with different parameters. FWIW I didn't intend for things to go this far. I just started with some simple macros and it snowballed.
- mauvehaus 7y agoSome years ago at a former employer I used to for generating some Java 5 code. I needed (as I hazily recall) an interface of accessors, immutable implementation, and a factory for the same couple dozen members. It was a lot of boilerplate and the list was changing a fair amount over the course of development. It worked great, and I got it plugged into the ant build without too much difficulty. I'm told the person who took over that codebase was equal parts perplexed and horrified by it. They ripped out the m4 code generation and just put the generated files directly in the source tree. As the codebase had stabilized, the purpose that m4 served was basically gone. So, not still in use, but if I found myself in the same situation today, I'd explore other options and consider doing the same thing. Interface default methods might cover some of the need at this point, but it's so far back, I'm hazy on the details. The nice thing about doing this sort of code generation with m4 rather than the C preprocessor is that m4 preserves formatting (like line breaks) a lot better. Even if you're not using any of the other functionality of m4 (and there's a lot), that alone makes figuring out where things went wrong easier.
- jiggerypokery 7y agoI work for a telecom where we've used it to generate network configs for a long time. We just got rid of it because it's impossible to hire people who know it and nobody (new hire or existing people) want to learn it either
- kd5bjo 7y agoI dusted it off this semester to help with some complicated reports I needed to make. I needed to include lots of graphs from simulation runs with various parameters. I encoded the parameter values in the graphs’ filenames, and used m4 to write the corresponding gnuplot control file. After tying everything together with make, I could include plots for any parameter as I was writing the report and have the relevant data generated as necessary. All without re-running simulations that had already produced results.
- spsrich2 7y agonot today but I used m4 in the late 80s to generate appropriate makefiles from a single source to allow me to compile my programs on HP-ux, Apollo Aegis, SunOS, AIX, etc. Happy days.
- vbezhenar 7y agoUsed it for some C code, because CPP was not able to accomplish what I wanted. m4 was more powerful and I was able to finish my task. Thankfully I never used it in context of sendmail or autotools, so no reason to hate it for me, I guess.