+
+sub message($$$) {
+ my ($type, $file, $command) = @_;
+ if ($ENV{INSPIRCD_VERBOSE}) {
+ say $command;
+ } else {
+ say console_format "\t<|GREEN $type:|>\t\t$file";
+ }
+}
+
+sub rpath($) {
+ my $message = shift;
+ $message =~ s/-L(\S+)/-Wl,-rpath,$1 -L$1/g unless defined $ENV{INSPIRCD_DISABLE_RPATH};
+ return $message;
+}
+
+sub do_core_link {
+ my $execstr = "$ENV{CXX} -o $out $ENV{CORELDFLAGS} @_ $ENV{LDLIBS}";
+ message 'LINK', $out, $execstr;
+ exec $execstr;
+}
+
+sub do_link_dir {
+ my ($dir, $link_flags) = (shift, '');
+ for my $file (<$dir/*.cpp>) {
+ $link_flags .= rpath(get_directive($file, 'LinkerFlags', '')) . ' ';
+ }
+ my $execstr = "$ENV{CXX} -o $out $ENV{PICLDFLAGS} @_ $link_flags";
+ message 'LINK', $out, $execstr;
+ exec $execstr;
+}
+
+sub do_compile {
+ my ($do_compile, $do_link, $file) = @_;
+
+ my $flags = '';
+ my $libs = '';
+ if ($do_compile) {
+ $flags = $ENV{CORECXXFLAGS} . ' ' . get_directive($file, 'CompilerFlags', '');
+
+ if ($file =~ m#(?:^|/)((?:m|core)_[^/. ]+)(?:\.cpp|/.*\.cpp)$#) {
+ $flags .= ' -DMODNAME=\\"'.$1.'\\"';
+ }
+ }
+
+ if ($do_link) {
+ $flags = join ' ', $flags, $ENV{PICLDFLAGS};
+ $libs = rpath(get_directive($file, 'LinkerFlags', ''));
+ } else {
+ $flags .= ' -c';
+ }
+
+ my $execstr = "$ENV{CXX} -o $out $flags $file $libs";
+ message 'BUILD', abs2rel($file, "$ENV{SOURCEPATH}/src"), $execstr;
+ exec $execstr;
+}