[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: help with makefile command line
From: |
stan |
Subject: |
Re: help with makefile command line |
Date: |
Fri, 28 Mar 2008 02:11:22 -0500 |
User-agent: |
slrn/0.9.8.0 (Linux) |
Richard G Riley wrote:
> stan <smoore@exis.net> writes:
>
>> Richard G Riley wrote:
>>> "Balaji V. Iyer" <bviyer@ncsu.edu> writes:
>>>
>>>> Hello Everyone,
>>>> I use the compile option extenstively in emacs. When I type "M-x
>>>> compile" the default line is "make -k" Many times I do not have a make
>>>> file thus I would lke the default line to be
>>>>
>>>> "gcc -ansi -O4 -Wall <c_source_file>"
>>>>
>>>> How do I do this?
>>>>
>>>> I tried the following command but it doesn't seem to work (If anyone
>>>> have a better idea please let me know).
>>>>
>>>> (function
>>>> (lambda ()
>>>> (unless (or (file-exists-p "makefile")
>>>> (file-exists-p "Makefile"))
>>>> (setq compile-command
>>>> (concat "gcc -Wall -O3 -o"
>>>> (file-name-sans-extension (file-name-nondirectory
>>>> buffer-file -name))
>>>> " "
>>>> (file-name-nondirectory buffer-file-name))))))
>> <snip>
>>
>> Seems like it might be easier to write a makefile :)
>
> Sorry. I'm not sure I understand. You snipped all my code. Did it not
> work for you? I use it on a daily basis.
Sorry I confused with my snip. I'm not the op. I have my setup working
pretty much the way I want ( is anyone ever really satisfied?)
>
>>
>> Do you really mean that you plan to not use makefiles? If not you
>> might
>
> I do use makefiles. It's in the code I gave to you. If the makefile is
> not there then it uses gcc directly which is what you said you
> wanted. Here it is again:
>
> ,----
>| ;;allow compile window to vanish if no errors.
>| (add-hook 'compilation-finish-functions
>| (lambda (buf str)
>| (if (string-match "exited abnormally" str)
>| (next-error)
>| ;;no errors, make the compilation window go away in a few seconds
>| (run-at-time "2 sec" nil 'delete-windows-on (get-buffer-create
>"*compilation*"))
>| (message "No Compilation Errors!")
>| )
>| ))
>|
>| (defun my-c-init()
>|
>| (line-number-mode 1)
>|
>| (setq compilation-window-height 16)
>| (setq compilation-finish-functions
>| (lambda (buf str)
>| (if (string-match "exited abnormally" str)
>|
>| ;;there were errors
>| (message "compilation errors, F11 to goto next error.")
>|
>| ;;no errors, make the compilation window go away in 0.5 seconds
>| ;; (run-at-time 5.0 nil 'delete-windows-on buf)
>| (message "NO COMPILATION ERRORS!"))))
>|
>|
>| (c-set-style "linux")
>|
>| (setq gdb-show-main t)
>| (setq gdb-many-windows t)
>|
>| (let ((dl '(
>| ([f1] . jump-man-page)
>| ; ([backtab] . semantic-complete-analyze-inline)
>| ;; ([f5] . find-tag-noconfirm)
>| ([f6] . find-tag-repeat)
>| ([f7] . pop-tag-mark)
>| ([f2] . gdb-restore-windows)
>| ([f3] . cscope-find-global-definition-no-prompting)
>| ([f4] . repeat)
>| ([f10] . (lambda()(interactive)(mycompile)))
>| ([f11] . next-error)
>| ([f12] . gdb))))
>| (dolist (i dl)
>|
>| (define-key c-mode-base-map (car i) (cdr i))
>| ;; (define-key c-mode-map (car i) (cdr i))
>| ;; (define-key c++-mode-map (car i) (cdr i))
>| ))
>|
>| (define-key c-mode-map
>| "\C-c\C-f"
>| 'php-search-documentation)
>|
>| (define-key c-mode-map
>| "\C-c\C-m"
>| 'php-browse-manual)
>|
>| (define-key c-mode-map
>| "\C-c\C-c"
>| 'c-browse-faq)
>|
>| (global-unset-key "\M-/")
>| (show-paren-mode 1)
>|
>| )
>|
>| (add-hook 'c-mode-common-hook 'my-c-init)
>|
>| (defun mycompile()
>|
>| (unless (or (file-exists-p "makefile")
>| (file-exists-p "Makefile"))
>| (set (make-local-variable 'compile-command)
>| (let ((file (file-name-nondirectory buffer-file-name)))
>| (format "%s -o %s %s %s %s %s"
>| (or (getenv "CC") "gcc")
>| (file-name-sans-extension file)
>| (or (getenv "GTKFLAGS") "")
>| (or (getenv "CPPFLAGS")"-DDEBUG=9")
>| (or (getenv "CFLAGS") "-std=c99 -pedantic -Wall -Wshadow
>-Wpointer-arith -Wcast-qual -Wcast-align -Wwrite-strings -Wconversion
>-Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations
>-Wredundant-decls -Wnested-externs -Winline -g")
>| file)))
>|
>| )
>| (compile compile-command)
>| )
>|
> `----
>
>
>> just want to change the command on a session basis. You do know that you
>> can backspace over the make -k and simply type g++ -Wall -g file.cpp and
>> that will become the new command until you close emacs. I tend to do
>> that when working on small throwaway programs.
>
> Yes, I do know that. But why would I do that when I can automate it as
> above depending on whether there is a Makefile or not?
Again, our streams got crossed at my snip. Both of our comments should
have been directed to the OP and not each other.
>
>>
>> Another idea, if you don't like what Eli suggested earlier is to come up
>> with a makefile template and use auto insert. I have a template that I
>> only need to basically change the list of files in and it save a lot of
>> time during the compile, run. scream. debug, edit cycle.
>>
>> Finally, you can edit the compile command for all time but it seems like
>> a bad idea.
>
> I'm not sure I understand. I have makefiles for most of my projects. If
> I don't have one it builds a compile and link command based on the c
> file name which is what you requested.
>
> Sorry I can't be more help. Did you try my code?
See above. I didn't snip this time for fear of losing you again :)
Re: help with makefile command line, step, 2008/03/27