-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfigure
executable file
·75 lines (51 loc) · 985 Bytes
/
configure
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
#!/usr/bin/perl
$target = 'build/repl';
@libraries = ( '' );
$compiler='clang++';
$ext='cpp';
sub list_local_includes($)
{
$file = $_[0];
@includes = ();
open FILE, $file;
@lines = <FILE>;
foreach (@lines)
{
if (/^\s*#include\s*"(.*)"\s$/)
{
push(@includes, $1);
}
}
return @includes;
}
`flex -o scanner.cpp scanner.l`;
opendir(LOCALDIR, ".");
@files = grep(/\.$ext$/, readdir(LOCALDIR));
closedir(LOCALDIR);
@rules=();
foreach (@files)
{
$file = $_;
s/\.$ext$//;
s/^\s*//;
$obj = "build/$_.o";
@includes = list_local_includes($file);
$rule = "\n$obj: $file @includes\n";
$rule.= "\t$compiler -c $file -o $obj \${CFLAGS}\n\n";
push @objs, $obj;
push @rules, $rule;
}
open MAKEFILE, ">", ".makefile";
$result = <<EOF
CFLAGS=-g -DDEBUG_COMPILER
LIBS=-lfl
OBJS=@objs
$target: \${OBJS}
\t$compiler -o $target @objs \${LIBS}
\t\@rm -f scanner.cpp
@rules
clean:
\trm -f build/*.o $target scanner.cpp a.out
EOF
;
print MAKEFILE $result;