forked from rofl0r/rcb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rcb2make.pl
executable file
·74 lines (54 loc) · 1.22 KB
/
rcb2make.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env perl
# program to automatically generate an optimized Makefile from an rcb file
# it is optimized because it only compiles *used* stuff
# use like this: cat myprog.rcb | rcb2make myprog > Makefile
use strict;
use warnings;
my $progname = $ARGV[0] or
die ("pass name of executable the makefile has to build");
my @libs;
my @c;
while(<STDIN>) {
chomp;
if(/^DEP ([\w_\-\/\.]+)$/) {
push @c, $1;
} elsif (/^LINK ([\w_\-\/\.]+)$/) {
push @libs, $1;
}
}
sub make_list {
my @a = @_;
my $res = "";
for(@a) {
$res .= " \\\n" . $_;
}
return $res;
}
my $mak_template = << 'EOF';
prefix = /usr/local
bindir = $(prefix)/bin
PROG = #PROG#
SRCS = #SRCS#
LIBS = #LIBS#
OBJS = $(SRCS:.c=.o)
CFLAGS += -Wall -D_GNU_SOURCE
-include config.mak
all: $(PROG)
install: $(PROG)
install -d $(DESTDIR)/$(bindir)
install -D -m 755 $(PROG) $(DESTDIR)/$(bindir)/
clean:
rm -f $(PROG)
rm -f $(OBJS)
%.o: %.c
$(CC) $(CPPFLAGS) $(CFLAGS) $(INC) $(PIC) -c -o $@ $<
$(PROG): $(OBJS)
$(CC) $(LDFLAGS) $(OBJS) $(LIBS) -o $@
.PHONY: all clean install
EOF
$mak_template =~ s/#PROG#/$progname/;
my $lc = make_list(@c);
$mak_template =~ s/#SRCS#/$lc/;
my $ll = make_list(@libs);
$mak_template =~ s/#LIBS#/$ll/;
print $mak_template;