'Failed to locate m4' and misleading shims on Mac

I was recently building percona-server on my Mac (I'm running Sonoma 14.6.1), and I've been hitting this error:

$ make
...
[ 57%] Built target gen_lex_hash
[ 57%] [BISON][mysql_parser] Building parser with bison 3.8.2
xcode-select: Failed to locate 'm4', requesting installation of command line developer tools.

Since this is a development machine I use daily, it surely had XCode's CLI tools installed. But the error above kept forcing Mac to re-download and install them again.

However, that did not help, and I repetitively hit that error. In this specific case, it was the m4 executable that was missing. Quick googling didn't give much because M4 in the context of Mac more commonly refers to a CPU name :)

All I learned was that M4 is a macro processing language by the GNU Foundation.

I then realized that /usr/bin/m4 on my Mac is a shim provided by XCode, which is what triggers the re-install of command line tools. It seemed like maybe XCode used to include it, but not anymore?

My system had the shim, but XCode was not installing m4 as part of the CLI tools.

I ended up installing it from brew (brew install m4 && brew link m4), and that fixed the issue.

The lesson here turned out to be not to trust XCode's shims. And maybe this quick post helps someone who runs into a similar issue.

Written in September 2024.
Kir Shatrov

Kir Shatrov helps businesses to grow by scaling the infrastructure. He writes about software, scalability and the ecosystem. Follow him on Twitter to get the latest updates.