aboutsummaryrefslogtreecommitdiff
path: root/02-usart/genmake.pl
diff options
context:
space:
mode:
Diffstat (limited to '02-usart/genmake.pl')
-rwxr-xr-x02-usart/genmake.pl22
1 files changed, 20 insertions, 2 deletions
diff --git a/02-usart/genmake.pl b/02-usart/genmake.pl
index 341db3d..a0e99de 100755
--- a/02-usart/genmake.pl
+++ b/02-usart/genmake.pl
@@ -19,6 +19,7 @@ sub header_deps {
}
my @files = glob('src/*.c');
+my @test_files = glob('tests/*.c');
my @obj_files;
open(my $fh, '<:encoding(UTF-8)', "Makefile.preamble")
@@ -30,10 +31,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| sha1sum | awk '{print \$1}'";
+ "ls src/*.c include/*.h tests/*.c | sha1sum | awk '{print \$1}'";
my $idempotency_cmd_make =
- "ls src/*.c include/*.h | sha1sum | awk '{print \$\$1}'";
+ "ls src/*.c include/*.h tests/*.c | sha1sum | awk '{print \$\$1}'";
print "IDEMPOTENCY_HASH=" . `$idempotency_cmd` . "\n";
@@ -62,6 +63,23 @@ foreach $file (@files) {
}
my $obj_files_deps = join(' ', @obj_files);
+
+foreach $file (@test_files) {
+ my $c_file = $file;
+ (my $file_no_ext = $file) =~ s/(.*)\.c/\1/g;
+ my @deps = header_deps($c_file);
+ my $deps_as_join = join(" ", @deps);
+
+ print "_${file_no_ext}: $deps_as_join $obj_files_deps test_harness/test_harness.a\n\t";
+ print '$(CC) $(CFLAGS) -o' . $file_no_ext . ' ' . $c_file . ' ' . $obj_file_deps . " test_harness/test_harness.a\n\n";
+
+ print "${file_no_ext}: $deps_as_join $obj_files_deps test_harness/test_harness.a\n\t";
+ print 'PREFIX=$(TEST_PREFIX) CFLAGS="$(TEST_CFLAGS)" $(MAKE) _' . $file_no_ext . "\n\n";
+}
+
+print "test_harness/test_harness.a: test_harness/test_harness.h test_harness/test_harness.c\n\t";
+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)\" ] "