diff --git a/modules/lang/fortran/autoload.el b/modules/lang/fortran/autoload.el index 38fa633e2..4df12fd91 100644 --- a/modules/lang/fortran/autoload.el +++ b/modules/lang/fortran/autoload.el @@ -6,22 +6,44 @@ ;;;###autoload (defun +fortran/build () "Compile a Fortran project or file. -If the current file is detected to be within an fpm project, -then building will occur with fpm. Otherwise it will default to gfortran." + +If the current file is detected to be within an fpm project, then +building will occur with fpm. Otherwise it will default to ifort +or gfortran, depending on what feature flags are set." (interactive) - (if (+fortran--fpm-toml) - (+fortran/fpm-build) - (+fortran/gfortran-compile))) + (cond ((+fortran--fpm-toml) (+fortran/fpm-build)) + ((featurep! +intel) (+fortran/ifort-compile)) + (t (+fortran/gfortran-compile)))) ;;;###autoload (defun +fortran/run () "Run a Fortran project or file. -If the current file is detected to be within an fpm project, -then building will occur with fpm. Otherwise it will default to gfortran." + +If the current file is detected to be within an fpm project, then +building will occur with fpm. Otherwise it will default to ifort +or gfortran, depending on what feature flags are set." (interactive) - (if (+fortran--fpm-toml) - (+fortran/fpm-run) - (+fortran/gfortran-run))) + (cond ((+fortran--fpm-toml) (+fortran/fpm-run)) + ((featurep! +intel) (+fortran/ifort-run)) + (t (+fortran/gfortran-run)))) + +;; Intel Fortran +;;;###autoload +(defun +fortran/ifort-compile () + "Compile the current buffer using ifort." + (interactive) + (compile (format "ifort %s" + (buffer-file-name)))) + +;;;###autoload +(defun +fortran/ifort-run () + "Run the current buffer using ifort." + (interactive) + (delete-file "./a.out") + (+fortran/ifort-compile) + (while (not (file-exists-p "./a.out")) + (sleep-for 1)) + (compile "./a.out")) ;; ;;; GFortran diff --git a/modules/lang/fortran/config.el b/modules/lang/fortran/config.el index 95d43bb56..05ee06b1b 100644 --- a/modules/lang/fortran/config.el +++ b/modules/lang/fortran/config.el @@ -8,9 +8,11 @@ :config ;; --- Compilation --- ;; ;; Used by `compile' (SPC c c) - (setq-hook! 'f90-mode-hook - compile-command "gfortran " - compilation-buffer-name-function #'+fortran-compilation-buffer-name-fn) + (let ((cmd (cond ((featurep! +intel) "ifort ") + (t "gfortran ")))) + (setq-hook! 'f90-mode-hook + compile-command cmd + compilation-buffer-name-function #'+fortran-compilation-buffer-name-fn)) (set-popup-rule! "^\\*fortran-compilation" :side 'right :size 0.5 :quit t) ;; --- LSP Configuration --- ;; diff --git a/modules/lang/fortran/doctor.el b/modules/lang/fortran/doctor.el index 0d2de77e9..56373395e 100644 --- a/modules/lang/fortran/doctor.el +++ b/modules/lang/fortran/doctor.el @@ -5,7 +5,12 @@ (featurep! :tools lsp)) "This module requires (:tools lsp)") -(when (not (executable-find "gfortran")) +(when (and (featurep! +intel) + (not (executable-find "ifort"))) + (warn! "Couldn't find Intel ifort - compilation will not work.")) + +(when (and (not (featurep! +intel)) + (not (executable-find "gfortran"))) (warn! "Couldn't find gfortran - compilation will not work.")) (unless (executable-find "fpm")