Root/
| 1 | #!/usr/bin/perl |
| 2 | # |
| 3 | # fpdoc - Generate a PDF with the footprints used in a specific project |
| 4 | # |
| 5 | # Written 2011 by Werner Almesberger |
| 6 | # Copyright 2011 Werner Almesberger |
| 7 | # |
| 8 | # This program is free software; you can redistribute it and/or modify |
| 9 | # it under the terms of the GNU General Public License as published by |
| 10 | # the Free Software Foundation; either version 2 of the License, or |
| 11 | # (at your option) any later version. |
| 12 | # |
| 13 | |
| 14 | |
| 15 | sub usage |
| 16 | { |
| 17 | print STDERR "usage: $0 [-a module ...] pro-file pdf-file\n\n"; |
| 18 | print STDERR " -a module add the specified module\n"; |
| 19 | exit(1); |
| 20 | } |
| 21 | |
| 22 | |
| 23 | while ($ARGV[0] eq "-a") { |
| 24 | shift(@ARGV); |
| 25 | &usage unless @ARGV; |
| 26 | $need{shift @ARGV} = 1; |
| 27 | } |
| 28 | |
| 29 | &usage if $ARGV[0] =~ /^-/; |
| 30 | &usage unless @ARGV == 2; |
| 31 | |
| 32 | $pro = $ARGV[0]; |
| 33 | $out = $ARGV[1]; |
| 34 | |
| 35 | ($base = $pro) =~ s|\.pro$||; |
| 36 | |
| 37 | $pos = "${base}Front.pos"; |
| 38 | $cmp = "$base.cmp"; |
| 39 | |
| 40 | my $on = 0; |
| 41 | open(FILE, $pro) || die "$pro: $!"; |
| 42 | while (<FILE>) { |
| 43 | chop; |
| 44 | if (m|^\[pcbnew/libraries\]|) { |
| 45 | $on = 1; |
| 46 | next; |
| 47 | } |
| 48 | $on = 0 if /^\[/; |
| 49 | next unless $on; |
| 50 | next unless /LibName\d+=/; |
| 51 | my $mod = "$'.mod"; |
| 52 | my $fpd = "$'.fpd"; |
| 53 | open(MOD, $mod) || die "$mod: $!"; |
| 54 | while (<MOD>) { |
| 55 | chop; |
| 56 | next unless /^\$MODULE\s+/; |
| 57 | $fpd{$'} = $fpd; |
| 58 | } |
| 59 | close MOD; |
| 60 | } |
| 61 | close FILE; |
| 62 | |
| 63 | push(@INC, split(":", $ENV{"PATH"})); |
| 64 | do "pos2fab" || die "pos2fab: $!"; |
| 65 | |
| 66 | # |
| 67 | # We iterate over the items in the .pos file so that we skip NC and virtual |
| 68 | # components. |
| 69 | # |
| 70 | |
| 71 | for (@order) { |
| 72 | $need{$fp{$_}} = 1 if defined $fp{$_}; |
| 73 | } |
| 74 | |
| 75 | for (keys %need) { |
| 76 | die "don't have $_" unless defined $fpd{$_}; |
| 77 | } |
| 78 | |
| 79 | exec "fpd2pdf", "-o", $out, map { "$fpd{$_}:$_" } sort keys %need; |
| 80 |
Branches:
master
