DevTools

GNU Make CLI

GNU Make commands for build automation.

33 commands
Windows MacOS Linux
#build-automation #compilation

Basic Usage

Build the default target
make
Build the all target explicitly
make all
Run the clean target
make clean
Use a specific makefile
make -f custom.mk
Run make in a different directory
make -C /path/to/project
Build with 4 parallel jobs
make -j4
Build with all available CPU cores
make -j$(nproc)

Variables

Override the CC variable on command line
make CC=clang
Pass custom compiler flags
make CFLAGS="-O2 -Wall"
Let environment variables override makefile
make -e
Print database and filter for CC variable
make -p | grep CC
Warn when undefined variables are used
make --warn-undefined-variables

Targets

Run the install target
make install
Run the uninstall target
make uninstall
Run the test target
make test
Build multiple targets in sequence
make build deploy
Touch targets instead of building them
make -t
Pretend file.c was just modified
make -W file.c

Debugging

Dry run showing commands without executing
make -n
Print detailed debug information
make -d
Show target and prerequisite tracing
make --trace
Print the full internal database
make -p
Check if target is up to date silently
make -q target
Show basic debug information only
make --debug=basic

Common Patterns

Install to a custom prefix
make PREFIX=/usr/local install
Stage install into a temporary directory
make DESTDIR=/tmp/staging install
Keep going after errors in other targets
make -k
Unconditionally rebuild all targets
make -B
Run silently without printing commands
make -s
Ignore all errors during execution
make -i

Quick Commands

Build using all available CPU cores in parallel
make -j$(nproc)
Dry run showing commands without executing them
make -n
Clean and rebuild the entire project
make clean all