🍞 mbake
A Makefile formatter and linter. It only took 50 years!
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
pip install mbake
Quick Start
mbake format Makefile
mbake format --check Makefile
mbake validate Makefile
mbake init
Usage
Basic Commands
mbake format Makefile
mbake format --check Makefile
mbake format --diff Makefile
mbake validate Makefile
mbake init
mbake config
mbake update
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]
space_around_assignment = true
space_after_colon = true
normalize_line_continuations = true
remove_trailing_whitespace = true
fix_missing_recipe_tabs = true
auto_insert_phony_declarations = false
group_phony_declarations = false
phony_at_top = false
Smart .PHONY Detection
mbake intelligently detects phony targets by analyzing recipe commands:
test:
npm test
clean:
rm -f *.o
deploy:
ssh user@server 'systemctl restart app'
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
CC:=gcc
CFLAGS= -Wall -g
SOURCES=main.c \
utils.c \
helper.c
all: $(TARGET)
$(CC) $(CFLAGS) -o $@ $^
clean:
rm -f *.o
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:
CUSTOM_FORMAT= \
1 \
45678 \
CI/CD Integration
- 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.
git clone https://github.com/ebodshojaei/bake.git
cd mbake
pip install -e ".[dev]"
pytest
License
MIT License - see LICENSE for details.