#!/usr/bin/env perl use strict; use warnings; open my $fh, ">", "deps.mk"; print $fh "# This file is generated by makedeps.\n"; while (my $f = glob("c/*.cpp")) { open my $gh, "<", $f; $f =~ s,^c/,,; $f =~ s/\.cpp$//; if ($f eq "main") { print $fh "b/\$(EXE):"; } else { print $fh "b/$f.obj:"; } while ($_ = <$gh>) { next if /^$/; goto n if not /#/; print $fh " c/$1" if /^#include\s+"([^"]+)"/; } n: print $fh "\n"; }