Emacs xcode-compile

OSX 2010. 6. 1. 17:31

이번에는 Emacs에서 Xcode project를 build하는 것이다.

다음의 emacs lisp 코드를 .emacs 파일안에 넣어놓으면 M-x xcode-compile이 나 F10키로 바로 컴파일이 가능하다.

  1. (defvar xcode-compile-sdks nil)  
  2. (defvar xcode-compile-sdk-history nil)  
  3.   
  4. (dolist (line  
  5.          (split-string  
  6.           (with-temp-buffer  
  7.             (call-process "xcodebuild" nil t nil "-showsdks")  
  8.             (buffer-string))  
  9.           "\n" t)  
  10.          )  
  11.   (let ((comps (split-string line "-sdk " t)))  
  12.     (if (> (length comps) 1)  
  13.         (add-to-list 'xcode-compile-sdks (car (last comps)))  
  14.       )  
  15.     )  
  16.   )  
  17.   
  18. (defun xcode-compile ()  
  19.   (interactive)  
  20.   (let ((command "xcodebuild -activeconfiguration -activetarget"))  
  21.     (setq command  
  22.           (concat  
  23.            command  
  24.            (if xcode-compile-sdks  
  25.                (let ((default-sdk (or (car xcode-compile-sdk-history) (car xcode-compile-sdks))))  
  26.                  (concat  
  27.                   " -sdk "  
  28.                   (completing-read  
  29.                    (format "Compile with sdk (default %s): " default-sdk)  
  30.                    xcode-compile-sdks  
  31.                    nil  
  32.                    t  
  33.                    nil  
  34.                    'xcode-compile-sdk-history  
  35.                    default-sdk  
  36.                    )  
  37.                   )  
  38.                  )  
  39.              )  
  40.            (let ((dir ".") (files nil))  
  41.              (while  
  42.                  (progn  
  43.                    (setq files (directory-files dir nil "\\.xcodeproj\\'"))  
  44.                    (and (not (string-equal "/" (expand-file-name dir))) (null files))  
  45.                    )  
  46.                (setq dir (concat (file-name-as-directory dir) ".."))  
  47.                )  
  48.              (unless (null files) (concat " -project " (file-name-as-directory dir) (car files)))  
  49.              )  
  50.            )  
  51.           )  
  52.     (compile (read-string "Compile command: " (concat command " ")))  
  53.     )  
  54.   )  
  55.   
  56. (define-key global-map [f10] 'xcode-compile)

http://han9kin.doesntexist.com/29#recentTrackback

: