From 913708af39ffbb7785e5576f891028a3281e46e6 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Wed, 11 May 2011 11:43:07 -0700 Subject: [PATCH] Don't re-write dup Makefiles all the time. Messes with mtimes & forces camput to re-upload fies. --- build.pl | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/build.pl b/build.pl index bb1fa205a..084388b3c 100755 --- a/build.pl +++ b/build.pl @@ -337,11 +337,11 @@ sub gen_target_makefile { my @go_files = grep { !m!^\.\#! } grep { !/_testmain\.go$/ } grep { /\.go$/ } readdir($dh); closedir($dh); - open(my $mf, ">$target/Makefile") or die; - print $mf "\n\n"; - print $mf "###### NOTE: THIS IS AUTO-GENERATED FROM build.pl IN THE ROOT; DON'T EDIT\n"; - print $mf "\n\n"; - print $mf "include \$(GOROOT)/src/Make.inc\n"; + # Generate the Makefile + my $mfc = "\n\n"; + $mfc .= "###### NOTE: THIS IS AUTO-GENERATED FROM build.pl IN THE ROOT; DON'T EDIT\n"; + $mfc .= "\n\n"; + $mfc .= "include \$(GOROOT)/src/Make.inc\n"; if (@deps) { my $pr = ""; foreach my $dep (@deps) { @@ -350,25 +350,36 @@ sub gen_target_makefile { $pr .= '$(QUOTED_GOROOT)/pkg/$(GOOS)_$(GOARCH)/' . $cam_lib . ".a\\\n\t"; } chop $pr; chop $pr; chop $pr; - print $mf "PREREQ=$pr\n"; + $mfc .= "PREREQ=$pr\n"; } if ($type eq "pkg") { my $targ = $target; $targ =~ s!^lib/go/!!; - print $mf "TARG=$targ\n"; + $mfc .= "TARG=$targ\n"; } else { my $targ = $target; $targ =~ s!^.*/!!; - print $mf "TARG=$targ\n"; + $mfc .= "TARG=$targ\n"; } my @non_test_files = grep { !/_test\.go/ } @go_files; - print $mf "GOFILES=@non_test_files\n"; - print $mf "include \$(GOROOT)/src/Make.$type\n"; - close($mf); + $mfc .= "GOFILES=@non_test_files\n"; + $mfc .= "include \$(GOROOT)/src/Make.$type\n"; + + set_file_contents("$target/Makefile", $mfc); # print "DEPS of $target: @{ $t->{deps} }\n"; } +sub set_file_contents { + my ($fn, $new) = @_; + open(my $fh, $fn) or die; + my $cur = do { local $/; <$fh> }; + return if $new eq $cur; + open(my $fh, ">$fn") or die; + print $fh $new; + close($fh) or die; +} + sub read_targets { my $last; for () {