5 my $maindir = $ARGV[0] or die;
14 my @files = glob($dir . "/*");
16 my $ext = substr($_, -2);
17 if($ext eq ".c" || $ext eq ".h") {
22 if((/\s*#if[n]{0,1}def ([\w_]+)/ || /\s*#if\s+\(\s+[\(]{0,1}\s*defined\s+\)\s*[\)]{0,1}\s*([\w_]+)/)) {
24 next if ($def =~ /_H_$/ || $def =~ /_H$/) && $def !~ /^HAVE_/;
25 if(!defined($hdefs{$def})) {
29 } elsif (/^\s*(int){0,1}(void]){0,1}\s+main\s*\(/) {
41 push @units, \
@cfiles if(@cfiles);
46 my @a = split /\//, $c;
53 $x = "root" unless defined $x;
60 open($cfg, ">", "config.mak");
61 my @adefs2 = sort {$a cmp $b} @adefs;
63 print { $cfg } "#CFLAGS+=-D" . $_ . "\n";
67 my $h = "#Makefile autogenerated by rofl0rs makefilegen\n\n-include config.mak\n\nall: ";
73 open($mak, ">", "Makefile");
77 my $trg = gettarget
($c);
78 if(!defined($sections{$trg})) {
79 $sectionfiles{$trg} = [];
80 print {$mak} $trg , " ";
83 my $secaref = $sectionfiles{$trg};
89 print { $mak } "\n\n";
90 for(keys %sectionfiles) {
94 print { $mak } $secname, ":\n";
96 my $secaref = $sectionfiles{$secname};
98 push @mains, $_ if defined($hasmain{$_});
99 my $bn = substr($_, 0, -2);
100 $allo .= $bn . ".o ";
101 print { $mak } "\t" . '${CC} -c ' . $bn . '.c ${CFLAGS} -o ' . $bn . ".o\n";
105 my $bn = substr($_, 0, -2);
106 print { $mak } "\t" . '${CC} ' . $allo . ' ${CFLAGS} -o ' . $bn . ".out\n";
109 print { $mak } "\t" . 'ar rcs lib' . $secname . ".a " . $allo . "\n";
113 print { $mak } $f, "\n";