App-AutoBuild

 view release on metacpan or  search on metacpan

lib/App/AutoBuild.pm  view on Meta::CPAN


		if($self->{'meta'}{$ofile})
		{
			if($self->{'meta'}{$ofile}{'exec'} && $self->{'meta'}{$ofile}{'exec'} eq $exec_str)
			{
				$changed = 0;
				if($self->{'debug'} > 2)
				{
					print "cc $ofile has the same GCC options\n";
				}
			}elsif($self->{'debug'})
			{
				print "cc $ofile has changed GCC options\n";
			}
		}

		for my $f (@check)
		{
			if($self->file_changed($f))
			{
				$changed = 1;
				if($self->{'debug'})
				{
					print "cc $cfile has changed dep $f\n";
				}
			}else
			{
				if($self->{'debug'} > 2)
				{
					print "cc $cfile  no changed dep $f\n";
				}
			}
		}

		if($self->{'clean'})
		{
			$self->unlink_file($ofile);
		}
		elsif($changed)
		{

			if($self->{'verbose'})
			{
				print $exec_str."\n";
			}elsif(!$self->{'quiet'})
			{
				print $job->{'cpp'} ? 'cc++ ' : 'cc   ';
				print "$cfile..\n";
			}

			my $start = time;
			system(@gcc);
			$system_runtime += (time - $start);

			$headers = slurp_depfile($depfile);
			$self->{'meta'}{$cfile}{'headers'} = $headers;

			# remember the new md5sum/mtime
			if($self->file_update($ofile))
			{
				$job->{'updated'} = 1;
			}
			$self->{'meta'}{$ofile}{'exec'} = $exec_str;

			for(@$headers)
			{
				next if(substr($_, 0, 1) eq '/');
				$self->file_changed($_);
			}

		}

		my @needs;

		for my $hfile (@$headers)
		{
			next if(substr($hfile, 0, 1) eq '/');
			# look for a matching c file
			my $c = replace_ext($hfile, 'c');
			# look for a matching cpp file
			$c = replace_ext($hfile, 'cpp') if(!-e $c);
			next unless(-e $c);

			push @needs, $self->add_build_job($c);
		}

		$job->{'needs'} = \@needs;
		$job->{'done'} = 1;

		return 1;
	}

	if($job->{'task'} eq 'ld')
	{
		my $out = $job->{'out'};

		my $any_changed = $self->file_changed($out);

		my $needs = $self->needs_recurse($jid);
		my @ofiles;
		for my $n (@{ $self->needs_recurse($jid) })
		{
			my $oj = $self->{'jobs'}[$n];
			push @ofiles, $oj->{'out'};
			if($oj->{'updated'})
			{
				$any_changed = 1;
				if($self->{'debug'})
				{
					print "ld $out has changed dep ".$oj->{'out'}."\n";
				}
			}
		}

		my @ldflags = @{ $self->{'ldflags'} };
		for my $rule (@{ $self->{'rules'} })
		{
			if($rule->{'file'} && $rule->{'file'} eq $out)
			{
				my $add = $rule->{'add_ldflags'};
				my $del = $rule->{'del_ldflags'};
				if($add)
				{
					for my $f (@$add)
					{
						if(!grep { $_ eq $f } @ldflags)
						{
							push @ldflags, $f;
						}
					}
				}
				if($del)
				{
					@ldflags = grep { my $f = $_; ! grep { $f eq $_ } @$del } @ldflags;
				}
			}
		}

		my $exec = $self->{'cpp_ld'} ? $self->{'cpp'} : $self->{'cc'};
		my @gcc = grep { $_ } (
			$exec,
			@ldflags,
			@ofiles,
			'-o', $out,
		);
		my $exec_str = join(' ', @gcc);

		if(!$self->{'meta'}{$out} || !$self->{'meta'}{$out}{'exec'} || $self->{'meta'}{$out}{'exec'} ne $exec_str)
		{
			$any_changed = 1;
			if($self->{'debug'})
			{
				print "cc $out has changed GCC options\n";
			}
		}else
		{
			if($self->{'debug'} > 2)
			{
				print "cc $out has the same GCC options\n";
			}
		}

		if($self->{'clean'})
		{
			$self->unlink_file($out);



( run in 0.466 second using v1.01-cache-2.11-cpan-e1769b4cff6 )