Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LazyMake

Declare what your C or C++ project builds. Keep how it builds in one shared file.

BINS := hello
hello_SOURCES := Hello.cc

include ../Makefile.inc
component 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.

See what disappears

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.inc

The removed mechanics live once in Makefile.inc, not in every component.

Grow by adding declarations

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.inc
make          production package + local tests
make check    production package + every test

Pick the right tool

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

Reference

  • Include Makefile.inc last. Its location defines the project root.
  • Targets: BINS, DYNLIBS, STATICLIBS, and TESTS.
  • Composition: SUBDIRS, CHECKDIRS, and RESOURCES.
  • Sources: <target>_SOURCES; defaults to <target>.cc.
  • Extensions: .c, .cc, .cpp, and .cxx.
  • Global settings: CC, CXX, CPPFLAGS, CFLAGS, CXXFLAGS, LDFLAGS, and LDLIBS.
  • 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=-O0
build/<os>-<architecture>/<variant>/<component>/<target>/
package/<os>-<architecture>/<variant>/{bin,lib}/

Try it

make -C examples/main_deliverable
make -C examples/shared_lib
make -C examples/mixed_sources
make -C examples/test_suite check

Requires 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.

About

A small, top-down build system for C and C++ projects. Keep component Makefiles declarative while one shared Makefile.inc handles compilation, testing, and packaging.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages