#!/usr/bin/perl use strict; use warnings; use POSIX qw(getcwd); sub find_output($); sub gendep($); sub dep_cpp($$); sub dep_dir($); sub run(); my %f2dep; run; exit 0; sub run() { my $build = $ENV{BUILDPATH}; mkdir $build; chdir $build or die "Could not open build directory: $!"; mkdir 'bin'; mkdir 'obj'; mkdir 'modules'; symlink "$ENV{SOURCEPATH}/include", 'include'; $build = getcwd(); open MAKE, '>real.mk' or die "Could not write real.mk: $!"; chdir "$ENV{SOURCEPATH}/src"; print MAKE <, , "socketengines/$ENV{SOCKETENGINE}.cpp", "threadengines/threadengine_pthread.cpp") { my $out = find_output $file; dep_cpp $file, $out; push @core_deps, $out; } my @modlist; for my $file (, ) { my $out = find_output $file; dep_cpp $file, $out; push @modlist, $out; } opendir my $moddir, 'modules'; for my $dir (readdir $moddir) { next unless $dir =~ /^m_/ && -d "modules/$dir"; if (dep_dir "modules/$dir") { mkdir "$build/obj/$dir"; push @modlist, "modules/$dir.so"; } } my $core_mk = join ' ', @core_deps; my $mods = join ' ', @modlist; print MAKE <) { if (/^\s*#\s*include\s*"([^"]+)"/) { my $inc = $1; next if $inc eq 'inspircd_version.h' && $f eq '../include/inspircd.h'; my $found = 0; for my $loc ("$basedir/$inc", "../include/$inc") { next unless -e $loc; $found++; $dep{$_}++ for split / /, gendep $loc; $loc =~ s#^\.\./##; $dep{$loc}++; } if ($found == 0 && $inc ne 'inspircd_win32wrapper.h') { print STDERR "WARNING: could not find header $inc for $f\n"; } elsif ($found > 1 && $basedir ne '../include') { print STDERR "WARNING: ambiguous include $inc in $f\n"; } } } close $in; $f2dep{$f} = join ' ', sort keys %dep; $f2dep{$f}; } sub dep_cpp($$) { my($file, $out) = @_; gendep $file; print MAKE "$out: $file $f2dep{$file}\n"; print MAKE "\t@\$(SOURCEPATH)/make/unit-cc.pl \$(VERBOSE) \$< \$\@\n"; } sub dep_dir($) { my($dir) = @_; my @ofiles; opendir DIR, $dir; for my $file (readdir DIR) { next unless $file =~ /(.*)\.cpp$/; my $ofile = find_output "$dir/$file"; dep_cpp "$dir/$file", $ofile; push @ofiles, $ofile; } closedir DIR; if (@ofiles) { my $ofiles = join ' ', @ofiles; print MAKE "$dir.so: $ofiles\n\t\$(RUNCC) \$(PICLDFLAGS) -o \$\@ \$^\n"; return 1; } else { return 0; } }