Generated by GPT-5-mini| M4 (computer language) | |
|---|---|
| Name | M4 |
| Paradigm | Macro processor |
| Designer | Dennis Ritchie, Brian Kernighan |
| Developer | Bell Labs |
| First appeared | 1977 |
| Latest release version | GNU m4 1.4.19 |
| Typing | N/A |
| Filename extensions | .m4, .mac |
M4 (computer language) is a general-purpose macro processing language originally developed at Bell Labs in the 1970s. It was created as a preprocessing tool for Unix software development and later adopted into projects at AT&T, MIT, and within the Free Software Foundation ecosystem. M4 influenced other tools in the Unix philosophy and found use in building systems including sendmail, autoconf, and glibc packaging.
M4 was developed in the context of Unix research at Bell Labs by contributors associated with projects at AT&T and researchers influenced by the work at MIT. Early implementations emerged alongside languages and tools such as C (programming language), ed (text editor), and awk (programming language), reflecting an era that also produced utilities like troff and nroff. The language spread through distributions connected to BSD (operating system) and System V (Unix), and later entered the GNU Project maintained by the Free Software Foundation. Key adoption milestones included integration into sendmail configuration, templating for autoconf, and scripting for pkg-config workflows.
M4's design emphasizes textual macro expansion for source generation in environments such as Unix toolchains and GNU Project builds. It provides facilities for defining and invoking macros, file inclusion, conditional expansion, and string manipulation—features that made it suitable for projects at Bell Labs and utilities associated with AT&T and Sun Microsystems. Built-in primitives support quoting, argument counting, and runtime evaluation that interoperates with other components of Unix environments, including pipelines and makefile-driven builds seen in projects like GNU Make and Autoconf Archive. M4 implementations often aim for portability across POSIX-compliant systems and integrate into packaging workflows for distributions like Debian and Red Hat Enterprise Linux.
M4's syntax centers on macros defined with directives that reflect the heritage of tools such as troff and parsers used in Bell Labs projects. Macro definition and invocation are token-based: names followed by arguments in parentheses or whitespace produce expansions, while quoting mechanisms prevent premature expansion—techniques paralleling string handling in languages like C (programming language) and Perl. Standard macros include defining, undefining, and conditional tests; numeric and string operations mirror functionality found in awk (programming language) and sed (stream editor). M4 supports file inclusion, enabling modular configuration consistent with practices at MIT and Stanford research labs. Advanced users implement recursive macros and meta-macros for templating roles akin to those served by Template Toolkit in other ecosystems.
Multiple implementations exist, reflecting evolution across projects and vendors. The GNU implementation, maintained by the Free Software Foundation, is widely used in Linux distributions such as Debian and Fedora (operating system). Historical variants appeared in System V (Unix), BSD (operating system) forks, and proprietary UNIXes from Sun Microsystems and HP. Third-party derivatives and extensions were produced for integration with build automation systems like Autotools and packaging suites used by Gentoo and Arch Linux. Research and tooling projects at institutions such as MIT and Carnegie Mellon University have produced macros and wrappers that adapted M4 to domain-specific tasks.
M4 has been used to preprocess configuration and source files in projects like sendmail, where macro expansion simplifies complex configuration templates, and in autoconf, where M4 macro files encapsulate platform tests and portability checks used across GNU software. Developers have used M4 to generate code in C (programming language) projects, to assemble documentation for systems like troff and to produce repetitive boilerplate for make (software)-driven builds. In packaging ecosystems such as those for Debian and RPM (file format), M4 has been applied to template scripts and spec generation. Academic projects at Stanford and Berkeley Software Distribution labs used M4 for experiment setup and reproducible generation of test harnesses.
M4 influenced the design of later macro and templating tools used in open-source and research environments, informing approaches taken by systems like Autoconf, Autotools, and parts of GNU Build System. Its role in early Unix tooling positioned it alongside foundational contributions from Dennis Ritchie and Ken Thompson and made it a component of numerous historical Bell Labs-era projects. While modern configuration management and templating systems (for example, Ansible, Jinja2, CMake) often replace M4 in new projects, its footprint remains in legacy codebases, distribution packaging, and academic toolchains developed at MIT, Carnegie Mellon University, and University of California, Berkeley. M4's conceptual lineage traces into macro preprocessing practices found across free software infrastructures and continues to be studied in software archaeology and systems research.
Category:Unix programming tools Category:Macro languages