diff options
-rwxr-xr-x | 02-usart/genmake.pl | 29 |
1 files changed, 21 insertions, 8 deletions
diff --git a/02-usart/genmake.pl b/02-usart/genmake.pl index 7bf7de5..54b1f80 100755 --- a/02-usart/genmake.pl +++ b/02-usart/genmake.pl @@ -1,6 +1,8 @@ #!/usr/bin/perl use File::Basename; +use File::Find; +use Digest::SHA qw(sha1_hex); # This script is designed to introspect C files and generate a makefile to use. @@ -20,8 +22,22 @@ sub header_deps { return @headers; } -my @files = glob('src/*.c'); -my @test_files = glob('tests/*.c'); +my @files; +find(sub { push @files, "src/$_" if $_ =~ /.*\.c/ }, "src/"); + +my @test_files; +find(sub { push @test_files, "tests/$_" if $_ =~ /.*\.c/ }, "tests/"); + +my @header_files; +find(sub { push @header_files, "include/$_" if $_ =~ /.*\.h/ }, "include/" ); + +my $idempotency_hash=sha1_hex("@files @test_files @header_files"); + +if ("$ARGV[0]" eq "hash") { + print "$idempotency_hash\n"; + exit 0 +} + my @obj_files; open(my $fh, '<:encoding(UTF-8)', "Makefile.preamble") @@ -32,13 +48,10 @@ while (<$fh>) { } # Emit a rule that will rerun genmake if the c files do not match. -my $idempotency_cmd = - "ls src/*.c include/*.h tests/*.c | sha1sum | awk '{print \$1}'"; - my $idempotency_cmd_make = - "ls src/*.c include/*.h tests/*.c | sha1sum | awk '{print \$\$1}'"; + "/usr/bin/perl ./genmake.pl hash"; -print "IDEMPOTENCY_HASH=" . `$idempotency_cmd` . "\n"; +print "IDEMPOTENCY_HASH=$idempotency_hash\n"; my $arch_obs_dir = "_\$(PREFIX)_obs"; print "CHEAT_PRE_MAKE := \$(shell mkdir -p $arch_obs_dir)\n"; @@ -92,6 +105,6 @@ print 'cd test_harness; $(MAKE) test_harness.a; cd ..' . "\n\n"; print "FORCE:\n\t\n\n"; print "$arch_obs_dir/main.elf: FORCE $obj_files_deps linker/linker_script.ld\n\t"; print "([ \"\$\$($idempotency_cmd_make)\" != \"\$(IDEMPOTENCY_HASH)\" ] " - . "&& ./genmake.pl > Makefile && make main.elf ) " + . "&& ./genmake.pl > Makefile && make $arch_obs_dir/main.elf ) " . "|| " . "\$(LD) -o $arch_obs_dir/main.elf \$(LD_FLAGS) $obj_files_deps\n\n"; |