diff --git a/t/80_vppreproc.t b/t/80_vppreproc.t index dd7e689..eecbcac 100755 --- a/t/80_vppreproc.t +++ b/t/80_vppreproc.t @@ -9,13 +9,13 @@ use IO::File; use strict; use Test::More; -BEGIN { plan tests => 15 } +BEGIN { plan tests => 24 } BEGIN { require "./t/test_utils.pl"; } print "Checking vppreproc...\n"; -vppreproc ("t/80_vppreproc_none.out", "test_dir/vppreproc_none.v", ""); -vppreproc ("t/80_vppreproc_cmped.out", "test_dir/vppreproc_cmped.v", "--nocomment --pedantic"); +vppreproc ("t/80_vppreproc_none.out", "test_dir/vppreproc_none.v", ""); +vppreproc ("t/80_vppreproc_cmped.out", "test_dir/vppreproc_cmped.v", "--nocomment --pedantic"); vppreproc ("t/80_vppreproc_simple.out", "test_dir/vppreproc_simple.v", "--simple"); vppreproc ("t/80_vppreproc_defines.out", "test_dir/vppreproc_defines.v", "--dump-defines"); vppreproc ("t/80_vppreproc_rel_file.out", "test_dir/vppreproc_rel_file.v", "-f verilog/t_80_foo.f"); @@ -28,12 +28,57 @@ sub vppreproc { my $cmd = "${PERL} ./vppreproc ${flags} -y verilog inc2.v > $out"; if (0 == run_system_no_die ($cmd)) { - pass("run command"); - ok(-r $out, "vppreproc output from: $cmd"); - ok(files_identical ($out, $checkname), "diff"); + pass("run command"); + ok(-r $out, "vppreproc output from: $cmd"); + ok(files_identical ($out, $checkname), "diff"); } else { - fail ("run command"); - fail ("no output file created"); - fail ("no output file to compare"); + fail("run command"); + fail("no output file created"); + fail("no output file to compare"); } } + + + +# Test -MMD -MP +vppreproc_d("t/80_vppreproc_v_hier_top_mmd_mp.d", "-MMD -MP"); +vppreproc_d("t/80_vppreproc_v_hier_top_mmd.d", "-MMD"); +vppreproc_d_o(); + +sub vppreproc_d { + my $checkname = shift; + my $flags = shift; + my $defaultcfg = "verilog/v_hier_top.v verilog/v_sv_intf.v +incdir+verilog"; + my $cmd = "${PERL} ./vppreproc $flags $defaultcfg"; + my $dotd = "verilog/v_hier_top.v.d"; + if (0 == run_system_no_die($cmd)) { + pass("run command"); + ok(-r $dotd, "vppreproc .d from: $cmd"); + ok(files_identical ($dotd, $checkname), "diff"); + } else { + fail("run command"); + fail("no output file created"); + fail("no output file to compare"); + } + system("/bin/rm -f verilog/v_hier_top.v.d verilog/v_sv_intf.v.d"); +} + +sub vppreproc_d_o { + my $obasename = "res"; + my $checkname = "t/80_vppreproc_v_res.d"; + my $defaultcfg = "verilog/v_hier_top.v verilog/v_sv_intf.v +incdir+verilog"; + my $cmd = "${PERL} ./vppreproc -MMD -o test_dir/$obasename.vpp $defaultcfg"; + my $dotd = "test_dir/$obasename.d"; + + system("/bin/rm -f $dotd"); + if (0 == run_system_no_die($cmd)) { + pass("run command"); + ok(-r $dotd, "vppreproc .d from: $cmd"); + ok(files_identical($dotd, $checkname), "diff"); + } else { + fail("run command"); + fail("no output file created"); + fail("no output file to compare"); + } +} + diff --git a/t/80_vppreproc_v_hier_top_mmd.d b/t/80_vppreproc_v_hier_top_mmd.d new file mode 100644 index 0000000..893b8d9 --- /dev/null +++ b/t/80_vppreproc_v_hier_top_mmd.d @@ -0,0 +1,3 @@ +# Generated by vppreproc + +verilog/v_hier_top.v.d: verilog/v_hier_top.v verilog/v_hier_inc.vh diff --git a/t/80_vppreproc_v_hier_top_mmd_mp.d b/t/80_vppreproc_v_hier_top_mmd_mp.d new file mode 100644 index 0000000..5755164 --- /dev/null +++ b/t/80_vppreproc_v_hier_top_mmd_mp.d @@ -0,0 +1,5 @@ +# Generated by vppreproc + +verilog/v_hier_top.v.d: verilog/v_hier_top.v verilog/v_hier_inc.vh + +verilog/v_hier_inc.vh: diff --git a/t/80_vppreproc_v_res.d b/t/80_vppreproc_v_res.d new file mode 100644 index 0000000..60e60e2 --- /dev/null +++ b/t/80_vppreproc_v_res.d @@ -0,0 +1,4 @@ +# Generated by vppreproc + +test_dir/res.vpp: verilog/v_hier_top.v verilog/v_hier_inc.vh +test_dir/res.vpp: verilog/v_sv_intf.v verilog/v_sv_pkg.v diff --git a/vppreproc b/vppreproc index a1f6a05..aeb8886 100755 --- a/vppreproc +++ b/vppreproc @@ -10,6 +10,7 @@ use lib "$RealBin"; use Getopt::Long; use IO::File; use Pod::Usage; +use File::Basename; use Verilog::Preproc; use Verilog::Getopt; @@ -25,6 +26,8 @@ $Debug = 0; my $opt_output_filename = undef; my $opt_blank=1; my $opt_dump_defines; +my $opt_mmd; +my $opt_mp; my @opt_files; my @opt_pp_flags; @@ -45,6 +48,8 @@ if (! GetOptions ( "blank!" => \$opt_blank, "comment!" => sub { push @opt_pp_flags, (keep_comments=>$_[1]); }, "dump-defines!" => \$opt_dump_defines, + "MMD!" => \$opt_mmd, + "MP!" => \$opt_mp, "line!" => sub { push @opt_pp_flags, (line_directives=>$_[1]); }, "P!" => sub { $opt_blank=0; push @opt_pp_flags, (line_directives=>$_[1]); }, "pedantic!" => sub { push @opt_pp_flags, (pedantic=>$_[1]); }, @@ -92,6 +97,54 @@ if ($opt_dump_defines) { printf "`define %s%s %s\n", $name,$par,$value; } } + +# MMD MP option +# produces a list of makefile dependency rules suitable for use by a make utility +if ($opt_mmd) { + my $fh = IO::File->new; + if ($opt_output_filename) { + # Create a single .d + my ($filename, $dirs, $suffix) = File::Basename::fileparse($opt_output_filename, qr/\.[^.]*/); + my $opt_output_filename_d = File::Spec->canonpath("$dirs$filename.d"); # .d file + $fh->open(">$opt_output_filename_d") or die "%Error: $! $opt_output_filename_d\n"; + printf $fh "# Generated by vppreproc\n\n" + } else { + # Create a .d for each input file + } + my %includes = %{$Opt->{includes}}; + foreach my $target (sort (keys %includes)) { + my $dep_file; # MMD target + # Setup dep file + if ($opt_output_filename) { + $dep_file = $opt_output_filename; + } else { + $dep_file = "$target.d"; + $fh->open(">$dep_file") or die "%Error: $! $dep_file\n"; + printf $fh "# Generated by vppreproc\n\n" + } + # Create mmd dep + printf $fh "$dep_file: $target"; + my @deps = (sort (keys %{$includes{$target}})); + foreach my $dep (@deps) { + $dep = File::Spec->canonpath($Opt->file_path($dep)); + printf $fh " $dep"; + } + printf $fh "\n"; + # Create phony dependency targets (MP) + if ($opt_mp) { + foreach my $dep (@deps) { + $dep = File::Spec->canonpath($Opt->file_path($dep)); + printf $fh "\n$dep:\n"; + } + } + if (!$opt_output_filename){ + $fh->close; + } + } + if ($opt_output_filename) { + $fh->close; + } +} exit(0); @@ -201,6 +254,14 @@ Use the given filename for output instead of stdout. Suppress normal output, and instead print a list of all defines existing at the end of processing the input file. +=item --MMD + +Create .d dependency files, similar to "gcc -MMD" behavior. + +=item --MP + +Create phony dependency targets, similar to "gcc -MP" behavior. + =item --noblank Removes empty lines from the output. Should be used with --noline, as if