#!/usr/bin/perl # # Extract dependency files from a Quartus .qsf file # use strict; my($project,$outfile,@infiles) = @ARGV; my %dep_deps = (); my %map_deps = (); my %asm_deps = (); my %cof_list = (); my $output_dir = 'output_files'; sub read_file($) { my($infile) = @_; $dep_deps{$infile}++; $map_deps{$infile}++; open(my $in, '<', $infile) or die; while (defined(my $l = <$in>)) { chomp $l; if ($l =~ /^\s*include\s+\"?(.*?)\"?\s*$/) { read_file($1); next; } next unless ($l =~ /^\s*set_global_assignment\s+\-name\s+(\w+)\s+\"?(.*?)\"?\s*$/); my $type = lc($1); my $name = $2; if ($type =~ /^project_output_directory$/i) { $output_dir = $name; next; } next if ($type !~ /_file$/i || $type =~ /^generate_/i); $name =~ s/^quartus_\w+://; $name =~ s/\s-.*$//; if ($name =~ /\.cof$/i) { $cof_list{$name}++; } elsif ($type =~ /^(signaltap_file|use_signaltap_file|sld_file)$/i) { # Skip } elsif ($type eq 'source_tcl_script_file' && $name =~ /\.qsf$/i) { read_file($name); } elsif ($type =~ /^(mif|hex)_file$/i) { $asm_deps{$name}++; } else { $map_deps{$name}++; } } close($in); } sub print_deps($$%) { my($out,$target,%deps) = @_; return if (!%deps); print $out "\n", $target, " :"; foreach my $dep (sort keys(%deps)) { print $out " \\\n\t", $dep; } print $out "\n"; } unlink($outfile); foreach my $f (@infiles) { read_file($f); } open(my $out, '>', $outfile) or die; print_deps($out, $outfile, %dep_deps); my $map_target = "$output_dir/$project.map.rpt"; print_deps($out, $map_target, %map_deps); my $asm_target = "$output_dir/$project.mif_update.rpt"; print_deps($out, $asm_target, %asm_deps); close($out); exit 0;