changeset:   1613:92d4cc1e1b86
branch:      org.emacs.ada-mode
tag:         tip
user:        Simon Wright <simonjwright@users.sourceforge.net>
date:        Mon Apr 25 11:18:55 2016 +0100
files:       ada-gnat-xref.el gnat-core.el
description:
Support cross-compilation.

For the moment, the necessary settings can't be extracted using
gpr_query; instead, set them in an ada-mode project file, for example

gpr_file=io_expander.gpr
target=arm-eabi-
runtime=ravenscar-sfp-stm32f4

  * ada-gnat-xref.el (ada-gnat-xref-all): use "${target}gnat find".
      Don't strip any path information from $gpr_file.

  * gnat-core.el (gnat-run-gnat): use ${target}gnat.
      Locate the actual ${target}gnat executable (problem with
      exec-path not staying set, may be OS X-specific).
      If COMMAND is "list", add --RTS=${runtime}.
      Don't strip any path information from $gpr_file.


diff --git a/ada-gnat-xref.el b/ada-gnat-xref.el
--- a/ada-gnat-xref.el
+++ b/ada-gnat-xref.el
@@ -145,7 +145,11 @@
   ;; is asynchronous, and automatically runs the compilation error
   ;; filter.
 
-  (let* ((cmd (format "gnat find -a -r %s:%s:%d:%d" identifier file line col)))
+  (let* ((cmd (format "%sgnat find -a -r %s:%s:%d:%d"
+                      (if (ada-prj-get 'target)
+                          (ada-prj-get 'target)
+                        "")
+                      identifier file line col)))
 
     (with-current-buffer (gnat-run-buffer); for default-directory
       (let ((compilation-environment (ada-prj-get 'proc_env))
@@ -154,7 +158,7 @@
 	    ;; need to set compilation-error-regexp-alist
 	    )
 	(when (ada-prj-get 'gpr_file)
-	  (setq cmd (concat cmd " -P" (file-name-nondirectory (ada-prj-get 'gpr_file)))))
+	  (setq cmd (concat cmd " -P" (ada-prj-get 'gpr_file))))
 
 	(compilation-start cmd
 			   'compilation-mode
diff --git a/gnat-core.el b/gnat-core.el
--- a/gnat-core.el
+++ b/gnat-core.el
@@ -286,10 +286,21 @@
 Assumes current buffer is (gnat-run-buffer)"
   (let* ((project-file-switch
 	  (when (ada-prj-get 'gpr_file)
-	    (concat "-P" (file-name-nondirectory (ada-prj-get 'gpr_file)))))
-	 (cmd (append (list command) (list project-file-switch) switches-args)))
+	    (concat "-P" (ada-prj-get 'gpr_file))))
+         (target-gnat (concat (ada-prj-get 'target) "gnat"))
+         ;; OS X problem with exec-path; find full name now
+         (target-gnat-exec (locate-file
+                            target-gnat
+                            (split-string (getenv "PATH") path-separator)))
+         ;; gnat list understands --RTS without a fully qualified
+         ;; path, gnat find (in particular) doesn't (but it doesn't
+         ;; need to, it uses the GPR)
+         (runtime
+          (when (and (ada-prj-get 'runtime) (string= command "list"))
+            (list (concat "--RTS=" (ada-prj-get 'runtime)))))
+	 (cmd (append (list command) (list project-file-switch) runtime switches-args)))
 
-    (gnat-run "gnat" cmd nil expected-status)
+    (gnat-run target-gnat-exec cmd nil expected-status)
     ))
 
 (defun gnat-run-no-prj (command &optional dir)

