Fearless M4 For The Win

Long Form


The M4 macro preprocessor is a tool that inspires fear in the hearts of many open tech developers. This is kind of pathetic. I'll show you how to quickly, easily and fearlessly build useful prototype tools in M4.


The M4 macro preprocessor is designed to act as a generic text-to-text translator; it applies macros to text flexibly and programmably.

M4 has a somewhat deserved reputation for being tricky to write and debug, but I am perpetually astonished at the terror that it inspires in many otherwise inquisitive and courageous folk. One cause may be the use of M4 as a front-end for Sendmail configuration and for Autotools. Unfortunately, these use cases are far from being M4 poster children.

With some simple care and precautions, I’ve found that I can build highly-functional prototype tools using M4 in a fraction of the time it would take me using any other method I’m aware of.

I will show some examples of systems my students and I have built: a compiler backend, a plan generator, the first generation of XCB, and a text formatter. I will also discuss the principles of tool construction in M4, and we will construct a prototype of some sort as a demonstration.

Speaking experience

I would estimate that I have given about 50 public talks and more than 1000 classroom presentations. My talk (http://opensourcebridge.org/sessions/579) last year at Open Source Bridge seems to have been well-received, as well as my colleagues' and my joint talk (http://opensourcebridge.org/sessions/583).


  • Beach headshot 320x200

    Bart Massey

    Portland State University


    Bart Massey has been geeking around with community computing for 35 years, and has been involved in Free Software and Open Source since its inception. For the past 15 years, he has been a CS Prof at Portland State University, where he works in open tech, software engineering, artificial intelligence and low-level software development.

    Bart’s titles include Member of the PSU MCECS Innovation Program Board and past Secretary of the X.Org Foundation Board. Bart is the architect of the X library XCB, a modern replacement for Xlib, and the author of the XCB image extension. His current open tech interests include Haskell, open hardware and building bridges between pieces of the open tech community. He was one of the original participants in the Open Source Bridge conversation.