qsfdeps.pl 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #!/usr/bin/perl
  2. #
  3. # Extract dependency files from a Quartus .qsf file
  4. #
  5. use strict;
  6. my($infile,$project) = @ARGV;
  7. my %fit_deps = ($infile);
  8. my %asm_deps = ();
  9. my %cof_list = ();
  10. my $output_dir = 'output_files';
  11. open(my $in, '<', $infile) or die;
  12. while (defined(my $l = <$in>)) {
  13. chomp $l;
  14. next unless ($l =~ /^\s*set_global_assignment\s+\-name\s+(\w+)\s+\"?(.*?)\"?\s*$/);
  15. my $type = $1;
  16. my $name = $2;
  17. if ($type =~ /^project_output_directory$/i) {
  18. $output_dir = $name;
  19. next;
  20. }
  21. next if ($type !~ /_file$/i || $type =~ /^generate_/i);
  22. $name =~ s/^quartus_\w+://;
  23. if ($name =~ /\.cof$/i) {
  24. $cof_list{$name}++;
  25. } elsif ($type =~ /^(mif|hex)_file$/i) {
  26. $asm_deps{$name}++;
  27. } else {
  28. $fit_deps{$name}++;
  29. }
  30. }
  31. close($in);
  32. sub print_deps($%) {
  33. my($target,%deps) = @_;
  34. print "\n", $target, " :";
  35. foreach my $dep (sort keys(%deps)) {
  36. print " \\\n\t", $dep;
  37. }
  38. print "\n";
  39. }
  40. my $fit_target = "$output_dir/$project.done";
  41. print_deps($fit_target, %fit_deps);
  42. my $asm_target = "$output_dir/$project.asm.done";
  43. $asm_deps{$fit_target}++;
  44. print_deps($asm_target, %asm_deps);
  45. print "\t\$(QCDB) --update_mif $project\n";
  46. print "\t\$(QASM) $project\n";
  47. foreach my $cof (sort keys(%cof_list)) {
  48. print "\t\$(QCPF) --convert $cof\n";
  49. }
  50. print "\ttouch $asm_target\n";
  51. exit 0;