Emacs: cleaned cc-set-compiler and set cc-ld* variables as local
parent
d7894f697e
commit
ac4abd5e7f
|
@ -141,9 +141,10 @@ A page boundary is any line whose beginning matches the regexp
|
|||
|
||||
(defun get-closest-pathname (&optional file)
|
||||
"Get pathname of the first instance of FILE towards root.
|
||||
This may not do the correct thing in presence of links. If it
|
||||
does not find FILE, then it shall return the name of FILE in the
|
||||
current directory, suitable for creation"
|
||||
If FILE is unspecified, look for 'Makefile'. If it does not find
|
||||
FILE, then it shall return the name of FILE in the current
|
||||
directory, suitable for creation. This may not do the correct
|
||||
thing in presence of links."
|
||||
(let ((current-dir default-directory) (looping t) (makefile (or file "Makefile")))
|
||||
(while (progn
|
||||
(if (file-exists-p (expand-file-name makefile current-dir))
|
||||
|
|
|
@ -3,12 +3,14 @@
|
|||
;;==============================================================================
|
||||
|
||||
(defcustom cc-ldlibs "-lm -pthread"
|
||||
"[Local variable] Custom linker flags for C/C++ linkage."
|
||||
"Custom linker flags for C/C++ linkage."
|
||||
:safe 'stringp)
|
||||
(make-variable-buffer-local 'cc-ldlibs)
|
||||
|
||||
(defcustom cc-ldflags ""
|
||||
"[Local variable] Custom linker libs for C/C++ linkage."
|
||||
"Custom linker libs for C/C++ linkage."
|
||||
:safe 'stringp)
|
||||
(make-variable-buffer-local 'cc-ldflags)
|
||||
|
||||
(defun cc-set-compiler ()
|
||||
"Set compile command to be nearest Makefile.
|
||||
|
@ -17,23 +19,24 @@ found, then a configurable command line is provided.\n
|
|||
Requires `get-closest-pathname'."
|
||||
(require 'functions)
|
||||
(interactive)
|
||||
(if (get-closest-pathname)
|
||||
(set (make-local-variable 'compile-command) (format "make -k -f %s" (get-closest-pathname)))
|
||||
(set (make-local-variable 'compile-command)
|
||||
(let
|
||||
((is-cpp (equal (symbol-name major-mode) "c++-mode"))
|
||||
(file (file-name-nondirectory buffer-file-name)))
|
||||
(format "%s %s -o %s %s %s %s"
|
||||
(if is-cpp
|
||||
(or (getenv "CXX") "g++")
|
||||
(or (getenv "CC") "gcc"))
|
||||
file
|
||||
(file-name-sans-extension file)
|
||||
(if is-cpp
|
||||
(or (getenv "CPPFLAGS") "-Wall -Wextra -Wshadow -DDEBUG=9 -g3 -O0")
|
||||
(or (getenv "CFLAGS") "-ansi -pedantic -std=c99 -Wall -Wextra -Wshadow -DDEBUG=9 -g3 -O0"))
|
||||
(or (getenv "LDFLAGS") cc-ldflags)
|
||||
(or (getenv "LDLIBS") cc-ldlibs))))))
|
||||
(let ((makefile (get-closest-pathname)))
|
||||
(if makefile
|
||||
(set (make-local-variable 'compile-command) (format "make -k -f %s" makefile))
|
||||
(set (make-local-variable 'compile-command)
|
||||
(let
|
||||
((is-cpp (eq major-mode 'c++-mode))
|
||||
(file (file-name-nondirectory buffer-file-name)))
|
||||
(format "%s %s -o %s %s %s %s"
|
||||
(if is-cpp
|
||||
(or (getenv "CXX") "g++")
|
||||
(or (getenv "CC") "gcc"))
|
||||
file
|
||||
(file-name-sans-extension file)
|
||||
(if is-cpp
|
||||
(or (getenv "CPPFLAGS") "-Wall -Wextra -Wshadow -DDEBUG=9 -g3 -O0")
|
||||
(or (getenv "CFLAGS") "-ansi -pedantic -std=c99 -Wall -Wextra -Wshadow -DDEBUG=9 -g3 -O0"))
|
||||
(or (getenv "LDFLAGS") cc-ldflags)
|
||||
(or (getenv "LDLIBS") cc-ldlibs)))))))
|
||||
|
||||
(defun cc-clean ()
|
||||
"Find Makefile and call the `clean' rule. If no Makefile is
|
||||
|
@ -115,8 +118,9 @@ restored."
|
|||
;; Skel
|
||||
;;==============================================================================
|
||||
|
||||
;; Note that it is possible to extend the skel syntax like this: (setq
|
||||
;; skeleton-further-elements '((q "\"")))
|
||||
;; Note that it is possible to extend the skel syntax with
|
||||
;; `skeleton-further-elements'. For instance:
|
||||
; (setq skeleton-further-elements '((q "\"")))
|
||||
|
||||
(define-skeleton cc-printf
|
||||
"fprintf/printf snippet.
|
||||
|
|
Loading…
Reference in New Issue