MyMake Build Tool
Unix Make Reimplementation from Scratch
Overview
A complete reimplementation of the Unix make utility built from scratch in C++. MyMake reads Makefiles, parses target rules and inference patterns, resolves dependency graphs recursively, and executes shell commands through forked child processes — all with support for advanced features like pipes, I/O redirection, macro substitution, and signal handling.
Key Features
- Full Makefile parsing with target rules, inference/pattern rules (%.c → %.o), and macro substitution ($@, $<)
- Recursive dependency graph resolution with circular dependency detection
- Process management via fork/exec with support for sequential commands, pipes, and I/O redirection
- Signal handling: SIGINT for graceful shutdown, SIGALRM for timeout enforcement
- Custom MYPATH environment variable for command resolution (alternative to PATH)
- CLI flags: -f (custom makefile), -p (print rules), -k (continue on error), -d (debug), -t (timeout)
Architecture
The build tool uses a rule-based data model with Target, Rule, and GenericRule structures stored in hash maps. Dependency resolution is recursive with a visited set to prevent cycles. Command execution forks child processes, with nested forks for pipeline chains. The parser handles both $VAR and $(VAR) macro syntax with full substitution before execution. Debug mode outputs indented hierarchical traces showing rule application order.