feat(fortran): name executable after the file name

Previously the output was always the default `a.out`. Note that this is
only for the single-file non-fpm case, where the user just wants to
compile and run a one-off Fortran program.
This commit is contained in:
Colin Woodbury 2022-05-24 13:55:11 -07:00 committed by Henrik Lissner
parent e4184c6bc3
commit 1dfdfd53c6

View file

@ -27,23 +27,31 @@ or gfortran, depending on what feature flags are set."
((featurep! +intel) (+fortran/ifort-run)) ((featurep! +intel) (+fortran/ifort-run))
(t (+fortran/gfortran-run)))) (t (+fortran/gfortran-run))))
;; Intel Fortran (defun +fortran--exec-name ()
"The name of the output executable."
(file-name-sans-extension buffer-file-name))
;;
;;; Intel Fortran
;;;###autoload ;;;###autoload
(defun +fortran/ifort-compile () (defun +fortran/ifort-compile ()
"Compile the current buffer using ifort." "Compile the current buffer using ifort."
(interactive) (interactive)
(compile (format "ifort %S" (compile (format "ifort %S -o %S"
(buffer-file-name)))) (buffer-file-name)
(+fortran--exec-name))))
;;;###autoload ;;;###autoload
(defun +fortran/ifort-run () (defun +fortran/ifort-run ()
"Run the current buffer using ifort." "Run the current buffer using ifort."
(interactive) (interactive)
(delete-file "./a.out") (let ((exec (+fortran--exec-name)))
(+fortran/ifort-compile) (delete-file exec)
(while (not (file-exists-p "./a.out")) (+fortran/ifort-compile)
(sleep-for 1)) (while (not (file-exists-p exec))
(compile "./a.out")) (sleep-for 1))
(compile (format "%S" exec))))
;; ;;
;;; GFortran ;;; GFortran
@ -63,20 +71,21 @@ or gfortran, depending on what feature flags are set."
(defun +fortran/gfortran-compile () (defun +fortran/gfortran-compile ()
"Compile the current buffer using gfortran." "Compile the current buffer using gfortran."
(interactive) (interactive)
(compile (format "gfortran %s %S" (compile (format "gfortran %s %S -o %S"
(+fortran--std) (+fortran--std)
buffer-file-name))) buffer-file-name
(+fortran--exec-name))))
;;;###autoload ;;;###autoload
(defun +fortran/gfortran-run () (defun +fortran/gfortran-run ()
"Run the current buffer using gfortran." "Run the current buffer using gfortran."
(interactive) (interactive)
(delete-file "./a.out") (let ((exec (+fortran--exec-name)))
(+fortran/gfortran-compile) (delete-file exec)
(while (not (file-exists-p "./a.out")) (+fortran/gfortran-compile)
(sleep-for 1)) (while (not (file-exists-p exec))
(compile "./a.out")) (sleep-for 1))
(compile (format "%S" exec))))
;; ;;
;;; FPM ;;; FPM