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 ~/.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 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
  • --config: Use custom configuration file

Configuration

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

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.

Release files for mbake 1.4.6

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.4.6
File Size Uploaded
mbake-1.4.6.tar.gz 3.1 MB Details

Built distribution (wheel)

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

Total release size: 3.2 MB

Release files / mbake-1.4.6.tar.gz

Download URL mbake-1.4.6.tar.gz
Size 3.1 MB
Tags Source
SHA-256 checksum
How to use checksums
31b91955326150e7bd7a5abb4e9dc40acde7c2f892edeb4e1abb8b10b19f8113
BLAKE2b-256 checksum
How to use checksums
277a71331f29bfe3fa4c312d05556759e9aacb7f9fa90f5f39aaaa9de46bd995
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

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

Download URL mbake-1.4.6-py3-none-any.whl
Size 82.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8c7055b0961769a53b0e401ea2dee9f9096e63d7f58149bb29d6757fd52dbbf0
BLAKE2b-256 checksum
How to use checksums
84830ecabd3c6afca46387adf212289867327b77afa973584c3dac9b913aac36
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7
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