#!/usr/bin/env sh
exec /usr/bin/guile-2.2 -s "$0" "$@"
!#
;;; Lepton EDA netlister
;;; Scheme API
;;; Copyright (C) 2017-2018 Lepton EDA Contributors
;;;
;;; This program is free software; you can redistribute it and/or modify
;;; it under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 2 of the License, or
;;; (at your option) any later version.
;;;
;;; This program is distributed in the hope that it will be useful,
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with this program; if not, write to the Free Software
;;; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA

(load-extension (or (getenv "LIBLEPTON") "/usr/lib/i386-linux-gnu/liblepton")
                "libgeda_init")

;;; At compile time of this program guile won't be aware of these
;;; modules, since it compiles the code before loading the above
;;; extension. Let's make it quiet here.
(define with-toplevel (@@ (geda core toplevel) %with-toplevel))
(define make-toplevel (@@ (geda core toplevel) %make-toplevel))
(define gnetlist-option-ref* (@@ (netlist option) gnetlist-option-ref))

;;; Evaluate Scheme expressions that need to be run before rc
;;; files are loaded.
(for-each (lambda (dir) (add-to-load-path dir))
          (reverse (gnetlist-option-ref* 'load-path)))

;;; Using of primitive-eval() here avoids Scheme errors when this
;;; program is compiled by Guile. See comments above.
(primitive-eval '(use-modules (geda log)
                              (netlist)))

(with-toplevel (make-toplevel)
  (lambda ()
    ;; Init log domain and create log file right away even if
    ;; logging is enabled.
    (init-log "netlist")
    (lepton-netlist-version 'log)
    (main)))
