summaryrefslogtreecommitdiffstats
path: root/smoke/tqt/generate_makefile_am.pl
blob: 8f528bd85b4ad51485565bf268c6952cf0b6a510 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/perl -w

use File::Basename;
use File::Copy qw|cp|;
use File::Compare;
use Cwd;

my $here = getcwd;
my $outdir = $here;
my $tempfile = "$outdir/.Makefile.am.tmpfile";

# Update list of source files in $outdir/Makefile.am
open( MAKEFILE, "<$outdir/Makefile.am" ) or die;
my $makeFileData = '';
my $found = 0;
while (<MAKEFILE>) {
	if (/^libsmoketqt_la_SOURCES/)
	{
		$found = 1;
		$makeFileData .= "libsmoketqt_la_SOURCES = smokedata.cpp";
	}
	$makeFileData .= $_ if (!$found);
}
close MAKEFILE;

die "libsmoketqt_la_SOURCES not found" if (!$found);

open( MAKEFILE, ">$tempfile" ) or die;
print MAKEFILE $makeFileData;

my $count = 0;
opendir (FILES, $outdir) or die;
foreach $filename (readdir(FILES)) {
	if ( $filename =~ /^x_.*\.cpp$/ ) {
		if ( $count++ == 7 ) {
			$count = 0;
			print MAKEFILE " \\\n";
		}
		print MAKEFILE " $filename";
	}
}

print MAKEFILE "\n";
close MAKEFILE;
closedir FILES;

if (compare("$tempfile", "$outdir/Makefile.am")) {
    cp("$tempfile", "$outdir/Makefile.am");
    print STDERR "Makefile.am updated.\n";
}
else {
    print STDERR "Makefile.am unchanged.\n";
}
unlink $tempfile;

exit 0;