A Python-based Makefile formatter and linter
Project description
🍞 mbake
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mbake-1.4.5.tar.gz.
File metadata
- Download URL: mbake-1.4.5.tar.gz
- Upload date:
- Size: 1.6 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cc0be44d6e07257c138f21c5af255cb6f65554b48f3fe3dae7b211a85c2f9457
|
|
| MD5 |
cb5f29bf7e31a44e06a11be2b40a6dd9
|
|
| BLAKE2b-256 |
a72ff3947481f2d53e9a661f9421a90d93af931ec8ae7f2835bd79d7bd11d03d
|
File details
Details for the file mbake-1.4.5-py3-none-any.whl.
File metadata
- Download URL: mbake-1.4.5-py3-none-any.whl
- Upload date:
- Size: 81.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4286848fc07e81be05ede95f755152bf9eae0780ce9c7d5fd5ed41ea46215eb7
|
|
| MD5 |
20d64a8a403bfa0fb30c1e2913634ef2
|
|
| BLAKE2b-256 |
b625a780c093c8266aebf44b377d4713a48eae1315f5f94ba35581345abb439d
|