aboutsummaryrefslogtreecommitdiffstats
path: root/hardware/geda/Rakefile
blob: ebff956a67755b116bf2893ec3c56f861c130928 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
require 'rake/clean'

# ==============
# important info
# ==============

target = "simtrace"
version = IO.read("version").chomp
date = Time.now.strftime("%Y-%m-%d")
revision = `git log --pretty=oneline "#{target}.sch" | wc -l`.chomp.to_i

# schema
sch = "#{target}.sch"
# schema with version
vsch = "#{target}_v#{version}.#{revision.to_s.rjust(3,'0')}.sch"


# ================
# helper functions
# ================

def read_sch(path)
  text = IO.read(path)
  elements = []
  element = {}
  block = false
  text.each_line do |line|
    l = line.chomp
    if l=="{" then
      block = true
      element[:block] = {}
    elsif l=="}" then
      block = false
    elsif block then
      # only take attributes
      if l.include?("=") then
        k,v = l.split("=")
        element[:block][k] = v
      end
    elsif !block then
      elements << element unless element.empty?
      element = {}
      element[:line] = l
      element[:type] = l[0,1]
    else
      raise "don't know how to handle line: #{l}"
    end
  end
  return elements
end

# =========
# the tasks
# =========

task :default => [:version,:print,:pdf,:install]

task :version => vsch
CLEAN.include(vsch)
CLOBBER.include("#{target}_*.sch")

task :print => "#{target}.ps"
CLEAN.include("#{target}.ps")

task :pdf => "#{target}.pdf"
CLEAN.include("#{target}.pdf")

task :install => "#{target}.pdf"
  cp "#{target}.pdf","../pcb/schema/#{target}.pdf"
CLOBBER.include("../pcb/schema/#{target}.pdf")


# every component should have: refdes without ?, device, value,
# footprint, manufacturer, documentation, digikey
task :read
  elements = read_sch(sch)
  elements.each do |element|
    if element[:type]=="C" then
      if element[:block] and element[:block]["refdes"] then
        name = element[:block]["refdes"]
        name += " (#{element[:block]['device']})" if element[:block]["device"]
        puts name+" has no ID" if element[:block]["refdes"].include? "?"
        ["device","value","footprint","manufacturer","manufacturer-part","documentation","digikey-part"].each do |attribute|
          puts name+" has no "+attribute unless element[:block][attribute]
        end
      end
    end
  end

# ===============
# file processing
# ===============

file vsch => sch do
  sh "cp #{sch} #{vsch}"
  # on \ is to prevent ruby interpreting it, th other is for sed
  # the version
  sh "sed -i 's/\\(version=\\)\\$Version\\$/\\1#{version}/' #{vsch}"
  # the date
  sh "sed -i 's/\\(date=\\)\\$Date\\$/\\1#{date}/' #{vsch}"
  # the revision
  sh "sed -i 's/\\(revision=\\)\\$Revision\\$/\\1#{revision}/' #{vsch}"
end

file "#{target}.ps" => vsch do
  sh "gschem -p -o #{target}.ps -s /usr/share/gEDA/scheme/print.scm #{vsch} > /dev/null 2>&1"
end

file "#{target}.pdf" => "#{target}.ps" do
  sh "ps2pdf -sPAPERSIZE=a4 #{target}.ps"
end