emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: CEDET calls cpp -E -dM -x c++ /dev/null


From: Lennart Borgman
Subject: Re: CEDET calls cpp -E -dM -x c++ /dev/null
Date: Fri, 3 Jul 2009 13:22:44 +0200

On Fri, Jul 3, 2009 at 11:36 AM, Eli Zaretskii<address@hidden> wrote:
>> Date: Fri, 3 Jul 2009 03:13:12 +0200
>> From: Lennart Borgman <address@hidden>
>> Cc: "Eric M. Ludlam" <address@hidden>,
>>       Emacs-Devel devel <address@hidden>
>>
>> (defun semantic-gcc-get-include-paths (lang)
>>   (let* ((gcc-cmd (cond
>>                    ((string= lang "c") "gcc")
>>                    (t (error "Unknown lang: %s" lang))))
>>          (gcc-output (semantic-gcc-query gcc-cmd "-v" "-E" "-x" lang)))
>>     ))
>>
>> However calling (semantic-gcc-get-include-paths "c") does not catch
>> the output I want to gcc-output. I get
>>
>> Result: "gcc.exe: warning: `-x c' after last input file has no effect\n
>
> This is because your forgot to append null-device to the arguments you
> pass to semantic-gcc-get-include-paths.  So the command line ends with
> a "-x c", which, as GCC tells you, is quite pointless without a file
> name after it.

Thanks.


>> Yes, but what about the two different categories of include paths. How
>>  should they be handled? Just use both?
>
> Yes, both.
>
> Btw, as Miles's output shows, there could be more than 2 directories
> in this list, and all of them should be looked in.  AFAIR, the order
> of lookup should be the order in which GCC prints them, because that's
> what GCC does.

What about this version?

(defun semantic-gcc-query (gcc-cmd &rest gcc-option)
  "Return command output.
GCC-CMD is the command to execute and GCC-OPTIONS are the options
to give to the command."
  ;; $ gcc -v
  ;;
  (let ((buff (get-buffer-create " *gcc-query*")))
    (save-excursion
      (set-buffer buff)
      (erase-buffer)
      (condition-case nil
          (apply 'call-process gcc-cmd nil (cons buff t) nil gcc-option)
        (error ;; Some bogus directory for the first time perhaps?
         (let ((default-directory (expand-file-name "~/")))
           (condition-case nil
               (apply 'call-process gcc-cmd nil (cons buff t) nil gcc-option)
             (error ;; gcc doesn't exist???
              nil)))))
      (prog1
          (buffer-string)
        (kill-buffer buff)
        ))))

;;(semantic-gcc-get-include-paths "c")
;;(semantic-gcc-get-include-paths "c++")
(defun semantic-gcc-get-include-paths (lang)
  (let* ((gcc-cmd (cond
                   ((string= lang "c") "gcc")
                   ((string= lang "c++") "c++")
                   (t (error "Unknown lang: %s" lang))))
         (gcc-output (semantic-gcc-query gcc-cmd "-v" "-E" "-x" lang
null-device))
         (lines (split-string gcc-output "\n"))
         (include-marks 0)
         (inc-mark "#include ")
         (inc-mark-len (length "#include "))
         inc-path)
    (message "gcc-output=%s" gcc-output)
    (dolist (line lines)
      (when (> (length line) 1)
        (if (= 0 include-marks)
            (when (and (> (length line) inc-mark-len)
                       (string= inc-mark (substring line 0 inc-mark-len)))
              (setq include-marks (1+ include-marks)))
          (let ((chars (append line nil)))
            (when (= 32 (nth 0 chars))
              (when (if (memq system-type '(windows-nt))
                        (/= ?/ (nth 1 chars))
                      (= ?/ (nth 1 chars)))
                (add-to-list 'inc-path
                             (expand-file-name (substring line 1))
                             t)))))))
    inc-path))




reply via email to

[Prev in Thread] Current Thread [Next in Thread]