qsfdeps.pl 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #!/usr/bin/perl
  2. #
  3. # Extract dependency files from a Quartus .qsf file
  4. #
  5. use strict;
  6. my($project,$outfile,@infiles) = @ARGV;
  7. my %dep_deps = ();
  8. my %map_deps = ();
  9. my %asm_deps = ();
  10. my %cof_list = ();
  11. my $output_dir = 'output_files';
  12. sub read_file($) {
  13. my($infile) = @_;
  14. $dep_deps{$infile}++;
  15. $map_deps{$infile}++;
  16. open(my $in, '<', $infile) or die;
  17. while (defined(my $l = <$in>)) {
  18. chomp $l;
  19. if ($l =~ /^\s*include\s+\"?(.*?)\"?\s*$/) {
  20. read_file($1);
  21. next;
  22. }
  23. next unless ($l =~ /^\s*set_global_assignment\s+\-name\s+(\w+)\s+\"?(.*?)\"?\s*$/);
  24. my $type = lc($1);
  25. my $name = $2;
  26. if ($type =~ /^project_output_directory$/i) {
  27. $output_dir = $name;
  28. next;
  29. }
  30. next if ($type !~ /_file$/i || $type =~ /^generate_/i);
  31. $name =~ s/^quartus_\w+://;
  32. $name =~ s/\s-.*$//;
  33. if ($name =~ /\.cof$/i) {
  34. $cof_list{$name}++;
  35. } elsif ($type =~ /^(signaltap_file|use_signaltap_file|sld_file)$/i) {
  36. # Skip
  37. } elsif ($type eq 'source_tcl_script_file' &&
  38. $name =~ /\.qsf$/i) {
  39. read_file($name);
  40. } elsif ($type =~ /^(mif|hex)_file$/i) {
  41. $asm_deps{$name}++;
  42. } else {
  43. $map_deps{$name}++;
  44. }
  45. }
  46. close($in);
  47. }
  48. sub print_deps($$%) {
  49. my($out,$target,%deps) = @_;
  50. return if (!%deps);
  51. print $out "\n", $target, " :";
  52. foreach my $dep (sort keys(%deps)) {
  53. print $out " \\\n\t", $dep;
  54. }
  55. print $out "\n";
  56. }
  57. unlink($outfile);
  58. foreach my $f (@infiles) {
  59. read_file($f);
  60. }
  61. open(my $out, '>', $outfile) or die;
  62. print_deps($out, $outfile, %dep_deps);
  63. my $map_target = "$output_dir/$project.map.rpt";
  64. print_deps($out, $map_target, %map_deps);
  65. my $asm_target = "$output_dir/$project.mif_update.rpt";
  66. print_deps($out, $asm_target, %asm_deps);
  67. close($out);
  68. exit 0;