hardcoded python path in garchive and tragesym
[geda-gaf.git] / gschem / scheme / generate_netlist.scm
bloba020f68b6a72e9b2c7fbd984a934980b59f88bc9
1 ;;; ---------------------------------------------------------------------
2 ;;;    Written by Martin Lehmann
3 ;;; ---------------------------------------------------------------------
5 ;;; This file contents two functions to the hot-keys
6 ;;; g-n and g-e, which stand for (g)enerate (n)etlist and - (e)ntity.
7 ;;; 
9 ;; The generate-mode will be gave to the gnetlist environment, with help
10 ;; of the -c parameter of gEDA gnetlist.
11 ;; The same is doing with all toplevel attributes of a component (or schematic).
12 ;; they are defined in the variable top-attribs.
14 ;; generate-mode sets :
15 ;;   1 - generate netlist of current schematic
16 ;;   2 - generate entity of selected component, or of toplevel, when non selected
18 ;; get-selected-filename: - returns the whole filename of 
19 ;;                          the current-gschem-schematic
21 ;; get-selected-component-attributes: - returns all toplevel attributes
22 ;;                                      of the current entity
24 ;; This function only put together the gnetlist command for the
25 ;; generating-netlist-call.
27 (define generate-netlist
28   (lambda ()
29     (let* ((command "")
30            (source-file (get-selected-filename))
31            (source-file-length (string-length source-file))
32            
33            ;;generate a sensible output-filename (<old-path>/<old-basefilename>.vhdl)
34            (target-file (string-append
35                          (substring source-file 
36                                     (+ (string-rindex source-file #\/ 0 
37                                                       (string-length source-file)) 1)
38                                     (- (string-length source-file) 4))
39                          ".vhdl")))
41       ;;generating the complex gnetlist command
42       (display (getenv 'PWD))
43       (set! command "gnetlist")
44       (set! command (string-append command " -o " vhdl-path "/" target-file))
45       (set! command (string-append command " -g vams " source-file))
46       (display "\ngenerating netlist from current schematic\n")
47       (display command)
48       (newline)
49       (system command)
51       ;; this part is not really important
52       ;;(set! command (string-append "dtpad " vhdl-path "/" 
53       ;;                           (string-append (substring target-file 0 
54       ;;                                                     (string-rindex 
55       ;;                                              target-file #\. 0)) 
56       ;;                          "_arc.vhdl")
57       ;;   " &"))
58       ;;(system command)
59 )))
61 ;; Makes the same like generate-netlist, but its activate a 
62 ;; generating-entity-call.
64 (define generate-entity
65  (lambda ()
66    (let* ((command "")
67           (guile-comm  "")
68           (top-attribs (get-selected-component-attributes))
69           
70           ;; search the right schematic-file for gnetlist call
71           ;; Is necessary, when the selected component contents a
72           ;; underlying schematic (hierachical schematic)
73           (source-file (which-source-file top-attribs))
75           ;; generates the target-file, like <source-filebasename>.vhdl
76           (target-file (string-append
77                         (substring source-file
78                                    (if (string-rindex source-file #\/ 0 
79                                                      (string-length source-file))
80                                        (+ (string-rindex source-file #\/ 0 
81                                                      (string-length source-file)) 1)
82                                        0)
83                                    (- (string-length source-file) 4))
84                         ".vhdl")))
87      ;; put the whole gnetlist command together
88      (set! guile-comm 
89            (string-append guile-comm "\"(define top-attribs " "'" 
90                           (list2string top-attribs) ") (define generate-mode '2)\"")) 
91      (set! command (string-append "gnetlist -c " guile-comm 
92                                   " -o " vhdl-path "/" target-file
93                                   " -g vams " (get-selected-filename)))
94      (display command)
95      (newline)
96      (system command)
97      
98      ;; not important
99      ;;(set! command (string-append "dtpad " vhdl-path "/" target-file " &"))
100      ;;(if (null? top-attribs)
101      ;;  (system command))
106 ;; HELP FUNCTIONS
108 ;; generates a string from a list. 
109 (define list2string 
110   (lambda (list)
111     (let ((string "("))
112       (for-each (lambda (element)
113                   (set! string (string-append string element " ")))
114                 list)
115       (set! string (string-append string ")"))
116       (append string))))
119 ;; search the right source-file, when selected component contents a
120 ;; underlying schematic. which is saved in the source-attribute of
121 ;; this component
122 (define which-source-file
123   (lambda (top-attribs)
124     (if (not (null? top-attribs))
125         (if (string-prefix=? "source=" (car top-attribs))
126             (begin
127               (append (substring (car top-attribs) 7 
128                                  (string-length (car top-attribs)))))
129             (which-source-file (cdr top-attribs)))
130         (append (get-selected-filename)))))
133 ;; define the default vhdl-path, where netlist- and entity-files are
134 ;; saved to.
135 (define vhdl-path ".")
137 (display "loaded generate-netlist.scm\n")