Declare what your C or C++ project builds. Keep how it builds in one shared file.
BINS := hello
hello_SOURCES := Hello.cc
include ../Makefile.inccomponent Makefile ──include──▶ Makefile.inc ──▶ build/… + package/…
project data mechanics artifacts
Run make. You get:
- Incremental builds with automatic header tracking
- Executables, libraries, tests, and packaged resources
- Predictable per-platform artifact directories
- Standard compiler and linker overrides
No configure step. No generator. Just GNU Make and a compiler.
A two-source executable with header tracking:
- CXXFLAGS += -g -O3 -std=c++17 -pedantic -Wall
- SOURCES := Main.cc Greeter.cc
- OBJECTS := $(SOURCES:%.cc=build/%.o)
- DEPENDS := $(OBJECTS:.o=.d)
-
- app: $(OBJECTS)
- $(CXX) $(LDFLAGS) $^ $(LDLIBS) -o $@
-
- build/%.o: %.cc
- @mkdir -p $(@D)
- $(CXX) $(CPPFLAGS) $(CXXFLAGS) -MMD -MP -c $< -o $@
-
- -include $(DEPENDS)
+ BINS := app
+ app_SOURCES := Main.cc Greeter.cc
+
+ include ../Makefile.incThe removed mechanics live once in Makefile.inc, not in every component.
BINS := server
DYNLIBS := libmetrics
STATICLIBS := libprotocol
TESTS := ParserTest SocketTest
server_SOURCES := Main.cc Server.cc
libmetrics_SOURCES := Metrics.cc
libprotocol_SOURCES := Frame.cc Parser.cc
SUBDIRS := tools
CHECKDIRS := functionaltests
RESOURCES := conf
include Makefile.incmake production package + local tests
make check production package + every test
| Need | Use |
|---|---|
| Tiny or unusual build | Hand-written Make |
| Small, repeatable C/C++ build | LazyMake |
| Source packages that probe varied Unix hosts or features | Autoconf and Automake |
| Package discovery, exports, or IDE generation | CMake or Meson |
| Hermetic builds, remote execution, or shared caching | Bazel or similar |
- Include
Makefile.inclast. Its location defines the project root. - Targets:
BINS,DYNLIBS,STATICLIBS, andTESTS. - Composition:
SUBDIRS,CHECKDIRS, andRESOURCES. - Sources:
<target>_SOURCES; defaults to<target>.cc. - Extensions:
.c,.cc,.cpp, and.cxx. - Global settings:
CC,CXX,CPPFLAGS,CFLAGS,CXXFLAGS,LDFLAGS, andLDLIBS. - Per-target settings:
<target>_CPPFLAGS,<target>_CFLAGS,<target>_CXXFLAGS,<target>_LDFLAGS,<target>_LDLIBS, and<target>_STATICLIBS.
| Command | Result |
|---|---|
make |
Package plus local tests |
make package |
Production targets, resources, and SUBDIRS |
make check |
Build and run all tests |
make <name> |
One declared target |
make clean |
Current component's build state |
make distclean |
Every build and package variant |
Separate incompatible artifacts with BUILD_VARIANT:
make BUILD_VARIANT=debug CXXFLAGS=-O0build/<os>-<architecture>/<variant>/<component>/<target>/
package/<os>-<architecture>/<variant>/{bin,lib}/
make -C examples/main_deliverable
make -C examples/shared_lib
make -C examples/mixed_sources
make -C examples/test_suite checkRequires GNU Make 3.81+, a C/C++ toolchain, and basic host utilities. Validate
LazyMake with make -C tests host; use make -C tests docker for Ubuntu ARM64 and
AMD64.