modern-c-makefile
Create, analyze, or improve Makefiles for modern C/C++ projects using best practices from the gnaro project template. Use when working with C/C++ projects that need clean, maintainable build systems for creating new Makefiles, improving existing ones, understanding modern patterns, or setting up comprehensive build workflows with testing and code quality tools.
Best use case
modern-c-makefile is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
Create, analyze, or improve Makefiles for modern C/C++ projects using best practices from the gnaro project template. Use when working with C/C++ projects that need clean, maintainable build systems for creating new Makefiles, improving existing ones, understanding modern patterns, or setting up comprehensive build workflows with testing and code quality tools.
Teams using modern-c-makefile should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/modern-c-makefile/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How modern-c-makefile Compares
| Feature / Agent | modern-c-makefile | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
Create, analyze, or improve Makefiles for modern C/C++ projects using best practices from the gnaro project template. Use when working with C/C++ projects that need clean, maintainable build systems for creating new Makefiles, improving existing ones, understanding modern patterns, or setting up comprehensive build workflows with testing and code quality tools.
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
SKILL.md Source
# Modern C Makefile
## Overview
This skill provides guidance and templates for creating clean, maintainable Makefiles for modern C/C++ projects, based on the best practices demonstrated in the [gnaro project](https://github.com/lucavallin/gnaro). It helps structure build systems that integrate compilation, testing, linting, formatting, and dependency management in a clear and organized way.
## Core Concepts
Understand these key Makefile concepts before implementing:
- **Variables**: Centralize project settings like compiler flags, directories, and tool paths
- **Wildcards**: Use patterns like `*.c` and `**/*.c` to automatically find source files
- **Automatic Variables**: Leverage `$@` (target), `$<` (first dependency), `$*` (stem), `$(@D)` (target directory)
- **Phony Targets**: Declare `.PHONY` targets for actions like `clean`, `format`, `lint` that don't produce files
- **Conditionals**: Use `ifeq`/`else`/`endif` for debug/release builds or platform-specific configurations
- **Pattern Rules**: Create generic rules for compiling `.c` to `.o` files
## Makefile Template
The complete gnaro Makefile template is available in [references/gnaro_makefile.md](references/gnaro_makefile.md). Key sections include:
### Project Structure Variables
```makefile
debug ?= 0
NAME := your-project
SRC_DIR := src
BUILD_DIR := build
INCLUDE_DIR := include
LIB_DIR := lib
TESTS_DIR := tests
BIN_DIR := bin
```
### Automatic Object File Generation
```makefile
OBJS := $(patsubst %.c,%.o, $(wildcard $(SRC_DIR)/*.c) $(wildcard $(LIB_DIR)/**/*.c))
```
### Compiler and Tool Configuration
```makefile
CC := clang
LINTER := clang-tidy
FORMATTER := clang-format
CFLAGS := -std=gnu17 -D _GNU_SOURCE -D __STDC_WANT_LIB_EXT1__ -Wall -Wextra -pedantic
LDFLAGS := -lm
```
### Core Targets
- `$(NAME)`: Build executable with dependencies on format, lint, and object files
- `$(OBJS)`: Pattern rule for compiling object files with directory creation
- `test`: Compile and run CUnit tests
- `lint`: Run static analysis with clang-tidy
- `format`: Apply code formatting with clang-format
- `check`: Run valgrind memory checks
- `setup`: Install development dependencies (Debian/Ubuntu)
- `clean`: Remove build artifacts
- `bear`: Generate compile_commands.json for tooling
## Customization Guide
### Adapting to Your Project
1. **Basic Configuration**:
- Update `NAME` to your project name
- Adjust directory variables to match your project structure
- Modify `CFLAGS` for your C standard and feature requirements
2. **Compiler and Tools**:
- Change `CC`, `LINTER`, `FORMATTER` to match your installed versions
- For GCC projects: `CC := gcc`
- Adjust tool paths for non-Debian systems
3. **Cross-Platform Considerations**:
- Replace apt-based `setup` target with appropriate package manager commands
- Use conditionals for platform-specific configurations:
```makefile
ifeq ($(OS),Windows_NT)
# Windows-specific settings
else ifeq ($(shell uname -s),Darwin)
# macOS-specific settings
else
# Linux-specific settings
endif
```
4. **Adding Features**:
- **Documentation**: Add `docs` target for Doxygen or other documentation generators
- **Packaging**: Add `package` target for creating distributable archives
- **Installation**: Add `install` and `uninstall` targets for system installation
### Common Modifications
**Multiple Executables**:
```makefile
EXECUTABLES := app1 app2
all: $(EXECUTABLES)
app1: $(APP1_OBJS)
$(CC) $(CFLAGS) -o $(BIN_DIR)/$@ $^ $(LDFLAGS)
app2: $(APP2_OBJS)
$(CC) $(CFLAGS) -o $(BIN_DIR)/$@ $^ $(LDFLAGS)
```
**Header Dependency Generation**:
```makefile
DEPFILES := $(OBJS:.o=.d)
-include $(DEPFILES)
%.d: %.c
@$(CC) $(CFLAGS) -MM -MP -MT $*.o -MF $@ $<
```
**Verbose Mode**:
```makefile
V ?= 0
ifeq ($(V),1)
Q :=
else
Q := @
endif
$(OBJS): dir
$(Q)mkdir -p $(BUILD_DIR)/$(@D)
$(Q)$(CC) $(CFLAGS) -o $(BUILD_DIR)/$@ -c $*.c
```
## Usage Examples
### Example 1: Creating a New Makefile
```
User: Create a Makefile for my C project "calculator" with source files in src/, headers in include/, tests in tests/
Assistant: Creates Makefile based on template with customized variables
```
### Example 2: Adding Testing to Existing Makefile
```
User: Add CUnit testing support to my existing Makefile
Assistant: Adds test target and updates dependencies
```
### Example 3: Improving Build Performance
```
User: My Makefile rebuilds everything when headers change
Assistant: Adds automatic dependency generation with -MM flags
```
### Example 4: Cross-Platform Support
```
User: Make my Makefile work on both Linux and macOS
Assistant: Adds OS detection and conditional tool paths
```
## Quick Reference
### Essential Commands
```bash
make # Build project (default target)
make debug=1 # Build with debug symbols, no optimization
make test # Run tests
make lint # Run static analysis
make format # Format code
make check # Run memory checks
make clean # Clean build artifacts
```
### Project Structure Convention
```
project/
├── Makefile
├── src/ # Source files (*.c)
├── include/ # Header files (*.h)
├── lib/ # Third-party libraries
├── tests/ # Test files
├── build/ # Object files (generated)
└── bin/ # Executables (generated)
```
## Resources
This skill includes the following bundled resources:
### references/
Reference documentation for Makefile best practices and templates:
- **[gnaro_makefile.md](references/gnaro_makefile.md)**: Complete Makefile from the gnaro project with detailed analysis and adaptation notes. Use this as the primary reference template.
- **[best_practices.md](references/best_practices.md)**: Comprehensive guide to modern C Makefile design patterns, advanced techniques, and common solutions.
**When to load references:** Read these files when you need detailed analysis of Makefile patterns, adaptation guidance, or advanced techniques beyond what's covered in the main skill.
### assets/
Template files and guides for project setup:
- **[basic_makefile.template](assets/basic_makefile.template)**: Simplified Makefile template ready for customization. Replace `PROJECT_NAME` and adjust directories as needed.
- **[project_structure_example.md](assets/project_structure_example.md)**: Recommended project structure with variations for different project types (single-header libraries, applications with resources, multi-target projects).
- **[cross_platform_guide.md](assets/cross_platform_guide.md)**: Guide for adapting Makefiles to different operating systems (Linux, macOS, Windows) with platform detection, package manager integration, and cross-compilation support.
**When to use assets:** These files provide starting points and templates that can be copied and adapted for specific projects. They're particularly useful when creating new projects or porting existing ones to different platforms.
### scripts/
This skill doesn't include scripts since Makefile creation is primarily about configuration and structure rather than automated processing. However, consider creating custom scripts for:
- Project scaffolding (generating directory structure)
- Dependency management
- Build automation beyond Makefile capabilitiesRelated Skills
makefile-validator
Comprehensive toolkit for validating, linting, and optimizing Makefiles. Use this skill when working with Makefiles (Makefile, makefile, *.mk files), validating build configurations, checking for best practices, identifying security issues, or debugging Makefile problems.
makefile-generator
Comprehensive toolkit for generating best practice Makefiles following current standards and conventions. Use this skill when creating new Makefiles, implementing build automation, or building production-ready build systems.
fullstack-modern
Apply when working with modern fullstack patterns including React/Vue, GraphQL, REST APIs, and headless architectures
dioxus-modern
Modern Dioxus 0.7 + Tailwind CSS development guide. Use when asking about Signals, Stores, ReadSignal props, async patterns, components, or Tailwind integration in Dioxus 0.7.
angular-modernization
Modernizes Angular code such as components and directives to follow best practices using both automatic CLI migrations and Bitwarden-specific patterns. YOU must use this skill when someone requests modernizing Angular code. DO NOT invoke for general Angular discussions unrelated to modernization.
react-modernization
Upgrade React applications to latest versions, migrate from class components to hooks, and adopt concurrent features. Use when modernizing React codebases, migrating to React Hooks, or upgrading to...
modern-web-creator
Creates distinctive, human-quality websites using 2025 design philosophy—anti-design aesthetics, bold minimalism, organic shapes, and intentional imperfection. Specializes in React/TypeScript with Tailwind CSS, shadcn/ui, and custom micro-interactions. Prevents generic AI templates through specific constraints, asymmetric layouts, and brand-aligned creative direction. Use for portfolios, marketing sites, SaaS interfaces, or any project requiring unique visual identity beyond cookie-cutter designs.
modern-python-standards
Strict adherence to modern (3.11+), idiomatic, and type-safe Python development.
modern-python
Modern Python tooling best practices using uv, ruff, ty, and pytest. Mandates the Trail of Bits Python coding standards for project setup, dependency management, linting, type checking, and testing. Based on patterns from trailofbits/cookiecutter-python.
modern-javascript-patterns
Master ES6+ features including async/await, destructuring, spread operators, arrow functions, promises, modules, iterators, generators, and functional programming patterns for writing clean, effici...
modern-java-backend-playbook
Enforces backend Java/Quarkus project standards including architecture layers, design patterns, code reuse, Lombok, TDD, exception handling, and modern Java features. Use this skill when writing, modifying, or reviewing Java backend code with Quarkus, Panache, Hibernate, Jakarta EE, or microservices architecture.
legacy-modernizer
Refactor legacy codebases, migrate outdated frameworks, and implement gradual modernization. Handles technical debt, dependency updates, and backward compatibility.