2
0

qsfdeps.pl 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. } elsif ($l =~ /^\s*\#nodeps:\s*\"?(.*?)\"?\s*$/) {
  23. delete $asm_deps{$1};
  24. delete $map_deps{$1};
  25. delete $cof_list{$1};
  26. next;
  27. }
  28. next unless ($l =~ /^\s*set_global_assignment\s+\-name\s+(\w+)\s+\"?(.*?)\"?\s*$/);
  29. my $type = lc($1);
  30. my $name = $2;
  31. if ($type =~ /^project_output_directory$/i) {
  32. $output_dir = $name;
  33. next;
  34. }
  35. next if ($type !~ /_file$/i || $type =~ /^generate_/i);
  36. $name =~ s/^quartus_\w+://;
  37. $name =~ s/\s-.*$//;
  38. if ($name =~ /\.cof$/i) {
  39. $cof_list{$name}++;
  40. } elsif ($type =~ /^(signaltap_file|use_signaltap_file|sld_file|cdf_file)$/i) {
  41. # Skip
  42. } elsif ($type eq 'source_tcl_script_file' &&
  43. $name =~ /\.qsf$/i) {
  44. read_file($name);
  45. } elsif ($type =~ /^(mif|hex)_file$/i) {
  46. $asm_deps{$name}++;
  47. } else {
  48. $map_deps{$name}++;
  49. }
  50. }
  51. close($in);
  52. }
  53. sub print_deps($$%) {
  54. my($out,$prefix,%deps) = @_;
  55. print $out "\n", $prefix;
  56. foreach my $dep (sort keys(%deps)) {
  57. print $out " \\\n\t", $dep;
  58. }
  59. print $out "\n";
  60. }
  61. unlink($outfile);
  62. foreach my $f (@infiles) {
  63. read_file($f);
  64. }
  65. open(my $out, '>', $outfile) or die;
  66. print_deps($out, "${outfile} :", %dep_deps);
  67. print_deps($out, "${project}_asm_deps := ", %asm_deps);
  68. print $out "\n$output_dir/$project.mif_update.rpt: \$(${project}_asm_deps)\n";
  69. print $out "\nall_asm_deps += \$(${project}_asm_deps)\n";
  70. print_deps($out, "${project}_map_deps := ", %map_deps);
  71. print $out "\n$output_dir/$project.map.rpt: \$(${project}_map_deps)\n";
  72. print $out "\nall_map_deps += \$(${project}_map_deps)\n";
  73. close($out);
  74. exit 0;