1 ;;; gEDA - GPL Electronic Design Automation
2 ;;; gnetlist - gEDA Netlist
3 ;;; Copyright (C) 2011 Dan White <dan@whiteaudio.com>
5 ;;; This program is free software; you can redistribute it and/or modify
6 ;;; it under the terms of the GNU General Public License as published by
7 ;;; the Free Software Foundation; either version 2 of the License, or
8 ;;; (at your option) any later version.
10 ;;; This program is distributed in the hope that it will be useful,
11 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 ;;; GNU General Public License for more details.
15 ;;; You should have received a copy of the GNU General Public License
16 ;;; along with this program; if not, write to the Free Software
17 ;;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 ;; --------------------------------------------------------------------------
21 ;; Backend to determine the dependencies of a given schematic.
23 ;; Output is Makefile lines relevant to the input schematic(s):
25 ;; foo.sch: subsheetA.sch subsheetB.sch
26 ;; foo.cir: foo.sch subsheetA.cir subsheetB.cir
28 ;; See the following for the intended usage:
29 ;; http://www.gnu.org/software/make/manual/make.html#Automatic-Prerequisites
31 ;; --------------------------------------------------------------------------
35 (use-modules (ice-9 regex))
36 (use-modules (srfi srfi-1))
40 ; Split a filename into 3 parts:
45 ; base_nam3-#.ext -> [[:alnum:]_]+-[:digit:]+.ext
46 (define makedepend-scheme
47 "([[:alnum:]_]+)-([[:digit:]]+).([[:alpha:]]+)$")
49 (define (makedepend:split-filename makedepend-scheme name)
50 (let* ((match (string-match makedepend-scheme name))
51 (base (match:substring match 1))
52 (page (match:substring match 2))
53 (ext (match:substring match 3))
62 ;; Returns a list of all values found for the given attribute name
63 ;; over all packages in the input files.
65 (define (makedepend:get-all-attr-values attribute packages)
66 ;split individual values (gschem wants a single comma-sep list for source=)
67 (append-map (lambda (str) (string-split str #\,))
68 ;ignore non-existent values
70 ;collect values from all packages into a list
72 ;get all values for a given refdes
73 (lambda (x) (gnetlist:get-all-package-attributes x attribute))
79 (define (makedepend:output-make-command input-files sources files port)
80 (let* (;lazy version, use first filename only for naming scheme
81 (scheme-split (makedepend:split-filename makedepend-scheme (car input-files)))
82 (base (first scheme-split))
83 (page (second scheme-split))
84 (ext (third scheme-split))
88 (format port "~a: ~a\n"
89 (string-join input-files " ")
90 (string-join sources " "))
93 (format port "~a.cir: ~a ~a\n"
95 (string-join input-files " ")
96 (string-join files " "))
102 (define (makedepend output-filename)
103 (let* ((port (open-output-file output-filename))
104 (source-attrs (makedepend:get-all-attr-values "source" packages))
105 (file-attrs (makedepend:get-all-attr-values "file" packages))
106 (input-files (gnetlist:get-input-files))
108 (makedepend:output-make-command input-files source-attrs file-attrs port)
109 (close-output-port port)