Skip to main content

🍞 mbake

mbake logo
A Makefile formatter and linter. It only took 50 years!

License: MIT Python 3.9+ PyPI - mbake Code style: black PyPI Downloads

Features

  • Smart formatting: Tabs for recipes, consistent spacing, line continuation cleanup
  • Intelligent .PHONY detection: Automatically identifies and manages phony targets
  • Syntax validation: Ensures Makefiles are valid before and after formatting
  • Configurable rules: Customize behavior via a project .bake.toml or {XDG_CONFIG_HOME}/bake.toml
  • CI/CD ready: Check mode for automated formatting validation
  • VSCode extension: Full editor integration available

Installation

# Install from PyPI
pip install mbake

# Or install VSCode extension
# Search for "mbake Makefile Formatter" in VSCode Extensions

Quick Start

# Format a Makefile
mbake format Makefile

# Check if formatting is needed (CI/CD mode)
mbake format --check Makefile

# Validate Makefile syntax
mbake validate Makefile

# Initialize configuration
mbake init

Usage

Basic Commands

# Format files
mbake format Makefile                   # Format single file
mbake format --check Makefile           # Check formatting (CI/CD)
mbake format --diff Makefile            # Show changes without modifying

# Validate syntax
mbake validate Makefile                 # Check Makefile syntax with GNU make

# Configuration
mbake init                              # Create config file
mbake config                            # Show current settings
mbake config --path                     # Show which config file is used
mbake update                            # Update to latest version

Key Options

  • --check: Check formatting without making changes (perfect for CI/CD)
  • --diff: Show what changes would be made
  • --backup: Create backup before formatting
  • --validate: Validate syntax after formatting
  • --timeout: Timeout in seconds for the --validate syntax check (default: syntax_check_timeout from the config file, or 10)
  • --config: Use custom configuration file

Configuration

mbake looks for a configuration file in this order:

  1. --config PATH, if given
  2. .bake.toml in the current directory, or else in the nearest parent directory that has one
  3. ~/.bake.toml if it exists, otherwise $XDG_CONFIG_HOME/bake.toml (default ~/.config/bake.toml), which mbake init creates

A .bake.toml from step 2 that cannot be loaded is skipped with a warning on stderr, and the search continues in the parent directories. A file from step 3 that cannot be loaded is also skipped with a warning, and the built-in defaults are used; mbake config reports it as an error instead. An invalid --config file is always an error. Run mbake config to see which file is used and its settings.

Create a config file with mbake init. Key settings:

[formatter]
# Spacing and formatting
space_around_assignment = true          # CC=gcc to CC = gcc
space_after_colon = true                # myapp.o:myapp.c to myapp.o: myapp.c
normalize_line_continuations = true     # Clean up backslash continuations
remove_trailing_whitespace = true       # Remove trailing spaces
fix_missing_recipe_tabs = true          # Convert spaces to tabs in recipes

# Variable alignment
align_variable_assignments = false      # Align consecutive assignments
align_across_comments = false           # Continue alignment across comments

# .PHONY management
auto_insert_phony_declarations = false  # Auto-detect and insert .PHONY
group_phony_declarations = false        # Group multiple .PHONY lines
phony_at_top = false                    # Place .PHONY at file top

Smart .PHONY Detection

mbake intelligently detects phony targets by analyzing recipe commands:

# These are automatically detected as phony
test:
 npm test

clean:
 rm -f *.o

deploy:
 ssh user@server 'systemctl restart app'

# This creates a file, so it's NOT phony
myapp.o: myapp.c
 gcc -c myapp.c -o myapp.o

Enable auto-insertion in your config:

[formatter]
auto_insert_phony_declarations = true

Examples

Before and After

# Before: Inconsistent spacing and indentation
CC:=gcc
CFLAGS= -Wall -g
SOURCES=main.c \
  utils.c \
    helper.c

all: $(TARGET)
    $(CC) $(CFLAGS) -o $@ $^

clean:
    rm -f *.o
# After: Clean, consistent formatting
CC := gcc
CFLAGS = -Wall -g
SOURCES = main.c \
  utils.c \
  helper.c

all: $(TARGET)
	$(CC) $(CFLAGS) -o $@ $^

clean:
	rm -f *.o

Disable Formatting

Use special comments to disable formatting in specific regions:

# bake-format off
CUSTOM_FORMAT= \
      1 \
  45678 \
#bake-format on

The lines between the markers are not reformatted and stay directly after their # bake-format off line, even when formatting adds or removes lines elsewhere. At the end of the file, the usual final-newline handling still applies. Line numbers in error and warning messages count the lines inside disabled regions.

CI/CD Integration

# GitHub Actions example
- name: Check Makefile formatting
  run: |
    pip install mbake
    mbake format --check Makefile

Exit codes: 0 (success), 1 (needs formatting), 2 (error)

Contributing

Contributions welcome! See CONTRIBUTING.md for details.

# Development setup
git clone https://github.com/ebodshojaei/bake.git
cd mbake
pip install -e ".[dev]"
pytest  # Run tests

License

MIT License - see LICENSE for details.

Metadata

Release files for mbake 1.5.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mbake 1.5.0
File Size Uploaded Provenance Actions
mbake-1.5.0.tar.gz 384.8 kB Without provenance Details for mbake-1.5.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for mbake 1.5.0
File Interpreter ABI Platform Actions
mbake-1.5.0-py3-none-any.whl Python 3 none any Details for mbake-1.5.0-py3-none-any.whl

Total release size: 571.6 kB

Release files / mbake-1.5.0.tar.gz

Download URL mbake-1.5.0.tar.gz
Size 384.8 kB
Tags Source
SHA-256 checksum
How to use checksums
fe8ee29e67d3c0688d0677f901d16d8660e79074ae2dec9dd436d558afb58698
BLAKE2b-256 checksum
How to use checksums
4ffb00188bf6e344262031c813667d0be270d80c5eda068454b160115ca4d8e5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.7

Release files / mbake-1.5.0-py3-none-any.whl

Download URL mbake-1.5.0-py3-none-any.whl
Size 186.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
077b3a8a7b3de8b60b06e8bdd3b759b666315a2024de4c13a97b6c34c45453a4
BLAKE2b-256 checksum
How to use checksums
a7170c28c19adde1329bfc1c6d9251febe0a42872770a1a4cff709b2e2a4a517
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.7

Security for mbake 1.5.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.5.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page