1#!/usr/bin/perl
2# Expand the include lines in a Makefile
3# Copyright (C) 2009 Jelmer Vernooij <jelmer@samba.org>
4# Published under the GNU GPLv3 or later
5
6my $depth = 0;
7
8sub process($)
9{
10	my ($f) = @_;
11	$depth++;
12	die("Recursion in $f?") if ($depth > 100);
13	open(IN, $f) or die("Unable to open $f: $!");
14	foreach (<IN>) {
15		my $l = $_;
16		if ($l =~ /^include (.*)$/) {
17			process($1);
18		} else {
19			print $l;
20		}
21	}
22	$depth--;
23}
24
25my $path = shift;
26unless ($path) {
27	print STDERR "Usage: $0 Makefile.in > Makefile-noincludes.in\n";
28	exit(1);
29}
30process($path);
31