f2cl-asdf.lisp 1.44 KB
Newer Older
1 2 3 4 5 6
(defpackage :f2cl-asdf
  (:use :cl :asdf :uiop :asdf/component)
  (:export #:fortran-file #:f2cl-system #:f2cl-options))

(in-package :f2cl-asdf)

7 8 9 10 11 12 13
;; Source files for f2cl itself.
(defclass cl-source-file.l (cl-source-file)
  ((type :initform "l"))
  (:documentation "Component class for a Common Lisp source file using type \"l\""))

(setf (find-class 'asdf::cl-source-file.l) (find-class 'cl-source-file.l))

14 15 16
(defclass f2cl-system (system)
  ((f2cl-options
    :initarg :f2cl-options :type list :reader f2cl-options)
17 18 19 20 21 22
   ;; Note that the below only works on ASDF 3.3 and later:
   ;; a bug in the reset-system protocol prevents usefully overriding
   ;; the :initform (or :default-initargs) of slots defined by class SYSTEM.
   ;; Therefore, until everyone uses ASDF 3.3 (say in 2019?),
   ;; all f2cl-system's must explicitly use:
   ;;   :default-component-class fortran-file
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
   (asdf/component:default-component-class :initform 'fortran-file)))

(defclass fortran-file (cl-source-file)
  ((f2cl-options
    :initarg :f2cl-options :initform nil :type list :reader f2cl-options))
  (:default-initargs :type "f"))

(defmethod perform ((o compile-op) (c fortran-file))
  (let ((file (component-pathname c)))
    (apply 'symbol-call :f2cl :f2cl-compile file
           :output-file (first (output-files o c))
           (append (f2cl-options c) (f2cl-options (component-system c))))))

(defmethod perform ((o load-op) (c fortran-file))
  (load (first (input-files o c))))