-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig
executable file
·82 lines (66 loc) · 1.79 KB
/
config
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/perl
&main;
sub main
{
my $make_file = "./Makefile";
my $mk = "./mk";
if ( ! -e $mk)
{
print STDERR "ERROR: can't find mk file. Aborted\n";
exit -1;
}
print "writing Makefile...\n=================== NEW MAKEFILE ===================\n";
open (MAKEFILE, ">", $make_file);
open (MK, "<", $mk);
print MAKEFILE "CC=gcc\n";
print MAKEFILE "CFLAGS=-I.\n";
print MAKEFILE "\$DEPS=\n";
print MAKEFILE "\n";
print MAKEFILE "all: ";
my @prefixs;
my $tgt_hash = {};
while(<MK>)
{
chomp;
my @files;
next if ($_ =~ "#" );
$_ =~ s/\s//g;
@files = split (',', $_);
foreach my $file (@files)
{
if ($file =~ "(.*)\.c")
{
my $prefix = "exe_".$1;
my $file_name = $1;
if ($file =~ "(.*)_src")
{
$prefix = "exe_".$1;
}
if (! defined ($$tgt_hash{$prefix}) || $$tgt_hash{$prefix} eq "")
{
$$tgt_hash{$prefix} = $file_name.".o";
}
else
{
$$tgt_hash{$prefix} .= " ".$file_name.".o";
}
}
}
}
foreach my $key ( keys %$tgt_hash )
{
print MAKEFILE $key." ";
}
print MAKEFILE "\n\n";
print MAKEFILE "%.o: %.c \$(DEPS)\n\t\$(CC) -c -o \$@ \$< \$(CFLAGS)\n";
print MAKEFILE "\n";
foreach my $key ( keys %$tgt_hash )
{
print MAKEFILE "$key: $$tgt_hash{$key}\n\t\$(CC) -o \$@ \$^ \$(CFLAGS)\n\n";
}
print MAKEFILE "\nclean:\n";
print MAKEFILE "\trm -rf ./*.o ./exe_*\n";
close(MK);
close(MAKEFILE);
system ("cat $make_file");
}