aboutsummaryrefslogtreecommitdiff
path: root/02-usart/genmake.pl
diff options
context:
space:
mode:
authorJosh Rahm <joshuarahm@gmail.com>2020-11-16 18:53:44 -0700
committerJosh Rahm <joshuarahm@gmail.com>2020-11-16 19:47:24 -0700
commitcd115ba47253ce8d2680178248116d251abacb23 (patch)
tree31f79d94f51e9c17d9d6ec32e567bbea672671ac /02-usart/genmake.pl
parent9f17335c19a6ae91a450e267b5313148644a7a14 (diff)
downloadstm32l4-cd115ba47253ce8d2680178248116d251abacb23.tar.gz
stm32l4-cd115ba47253ce8d2680178248116d251abacb23.tar.bz2
stm32l4-cd115ba47253ce8d2680178248116d251abacb23.zip
Update the genmake script for tests.
Update the genmake script to do the following: - Fix bug to link the object files from the source. - Test build output goes into a build/ directory. - Test makefile rules now run the test after building.
Diffstat (limited to '02-usart/genmake.pl')
-rwxr-xr-x02-usart/genmake.pl19
1 files changed, 14 insertions, 5 deletions
diff --git a/02-usart/genmake.pl b/02-usart/genmake.pl
index a0e99de..7bf7de5 100755
--- a/02-usart/genmake.pl
+++ b/02-usart/genmake.pl
@@ -1,5 +1,7 @@
#!/usr/bin/perl
+use File::Basename;
+
# This script is designed to introspect C files and generate a makefile to use.
sub header_deps {
@@ -66,15 +68,22 @@ 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($basename, $directories, $suffix) = fileparse($file, qr/\.[^.]*/);
+
+ my $outdir = $directories . "build/";
+ my $outbinary = $outdir . $basename;
+
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 "${outbinary}: $deps_as_join $obj_files_deps test_harness/test_harness.a\n\t";
+ print '$(CC) $(CFLAGS) -o' . ${outbinary} . ' ' . $c_file . ' ' . $obj_files_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 "$directories$basename:\n\t";
+ print 'mkdir -p ' . $outdir . "\n\t";
+ print 'PREFIX=$(TEST_PREFIX) CFLAGS="$(TEST_CFLAGS)" $(MAKE) ' . $outbinary . "\n\t";
+ print $outbinary . "\n\n";
}
print "test_harness/test_harness.a: test_harness/test_harness.h test_harness/test_harness.c\n\t";