make

developmentLinux/Unix
The make command is one of the most frequently used commands in Linux/Unix-like operating systems. make Build automation tool

Quick Reference

Command Name:

make

Category:

development

Platform:

Linux/Unix

Basic Usage:

make [options] [arguments]

Common Use Cases

    Syntax

    make [options] [target...]

    Options

    Option Description
    -j [N], --jobs[=N] Allow N jobs at once; infinite jobs with no arg
    -k, --keep-going Keep going when some targets can't be made
    -f FILE, --file=FILE, --makefile=FILE Read FILE as a makefile
    -C DIR, --directory=DIR Change to directory DIR before reading makefile
    -B, --always-make Unconditionally make all targets
    -n, --just-print, --dry-run Don't actually run any commands; just print them
    -s, --silent, --quiet Don't echo commands
    -d, --debug Print lots of debugging information
    -p, --print-data-base Print make's internal database
    -v, --version Print the version number of make and exit
    -w, --print-directory Print the current directory
    --no-print-directory Turn off -w, even if it was turned on implicitly
    -I DIR, --include-dir=DIR Search DIR for included makefiles
    -L, --check-symlink-times Use the latest mtime between symlinks and target
    -o FILE, --old-file=FILE, --assume-old=FILE Consider FILE to be very old and don't remake it
    -W FILE, --what-if=FILE, --new-file=FILE, --assume-new=FILE Consider FILE to be infinitely new
    --warn-undefined-variables Warn when an undefined variable is referenced

    Examples

    How to Use These Examples

    The examples below show common ways to use the make command. Try them in your terminal to see the results. You can copy any example by clicking on the code block.

    # Basic Examples Basic
    make
    Run the default target in the Makefile.
    make clean
    Run the "clean" target from the Makefile.
    # Advanced Examples Advanced
    make -j4 Run up to 4 commands simultaneously (parallel build). make -f custom.mk target Use custom.mk instead of the default Makefile. make CFLAGS="-O3 -Wall" target Override the CFLAGS variable for this build. make -n Print the commands that would be executed, but don't execute them. make -C src/ Change to the src/ directory before reading the Makefile. make -B target Force rebuilding of target, even if it's up-to-date. make target1 target2 Build multiple targets sequentially. make -d Print debugging information about make's decisions. make V=1 Common convention to enable verbose output in many projects.

    Try It Yourself

    Practice makes perfect! The best way to learn is by trying these examples on your own system with real files.

    Understanding Syntax

    Pay attention to the syntax coloring: commands, options, and file paths are highlighted differently.

    Notes

    The 'make' command is a build automation tool that automatically builds executable programs and libraries from source code by reading files called Makefiles which specify how to derive the target program. It's widely used in software development to automate complex build processes and ensure that only necessary parts of a project are rebuilt when changes occur. Key features of the make command: 1. Dependency Management: Make tracks dependencies between files, rebuilding targets only when their dependencies have changed, which saves time during development. 2. Parallel Execution: With the -j option, make can execute multiple build commands simultaneously, significantly speeding up build times on multi-core systems. 3. Rule-based Processing: Makefiles contain rules that specify how to create target files from source files, with pattern rules allowing for concise representation of repetitive build steps. 4. Variables and Conditionals: Make supports variables, conditional statements, and functions, providing flexibility in defining build processes. 5. Incremental Builds: By checking file timestamps, make performs incremental builds, only recompiling files that have changed since the last build. 6. Cross-platform Capability: While originally developed for Unix systems, make is available on virtually all platforms and is a cornerstone of cross-platform development. 7. Project Organization: Make helps organize complex projects with multiple components, libraries, and executables into manageable build processes. A typical Makefile consists of: - Targets: Files to be created - Prerequisites: Files that targets depend on - Recipes: Commands to execute to build targets from prerequisites - Variables: To store reusable values - Rules: Both explicit and pattern-based (implicit) rules - Directives: For including other makefiles, conditional processing, etc. Make is used in various contexts: - Compiling large software projects - Managing documentation generation - Automating deployment processes - Running test suites - Any task that involves file dependencies and transformations While newer build systems like CMake, Ninja, Bazel, or language-specific tools have emerged, make remains relevant due to its ubiquity, simplicity for basic projects, and the vast number of existing projects that use it. It's a fundamental tool for software developers working in C, C++, and many other compiled languages, and understanding make is essential for working with open-source software and legacy codebases. In modern development workflows, make is often used as the low-level build tool that other higher-level build systems ultimately generate files for, creating a bridge between new tooling and established build practices.

    Related Commands

    These commands are frequently used alongside make or serve similar purposes:

    Use Cases

    Learn By Doing

    The best way to learn Linux commands is by practicing. Try out these examples in your terminal to build muscle memory and understand how the make command works in different scenarios.

    $ make
    View All Commands