/
configure.pl
executable file
·50 lines (37 loc) · 1.08 KB
/
configure.pl
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
#!/usr/bin/perl
use File::Basename;
# Generates the makefile
my @progs;
my $rules;
for my $dir (grep -d, glob "*") {
my @all_files = grep -f, glob "$dir/*.[ch]";
my @c_files = grep -f, glob "$dir/*.c";
my $prog;
for my $file (@c_files) {
open my $fh, $file or die "Unable to open $file: $!";
my $text = do {local $/; <$fh>};
close $fh;
# find the file with the main function
next unless $text =~ /int \s+ main \s* \(/x;
($prog) = $file =~ m/ (.+) \. \w+ $/x;
push @progs, $prog;
last;
}
die "huh?! no prog" if !defined $prog;
$rules .= "$prog: @all_files\n" .
"\tgcc \${CFLAGS} -o \$\@ @c_files \${LDFLAGS}\n" .
"\tcp -v $prog .\n\n";
}
my @bprogs = map basename($_), @progs;
open my $make, ">", "Makefile" or die "Unable to create Makefile: $!";
print $make <<EOF;
CFLAGS = `pkg-config --cflags gobject-2.0` -g
LDFLAGS = `pkg-config --libs gobject-2.0` -ltap
PROGS = @progs
BPROGS = @bprogs
all: \${PROGS}
clean:
rm -rvf \${PROGS} \${BPROGS}
$rules
EOF
close $make;