all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* help with makefile command line
@ 2008-03-25 13:09 Balaji V. Iyer
  2008-03-25 14:04 ` William Xu
                   ` (2 more replies)
  0 siblings, 3 replies; 20+ messages in thread
From: Balaji V. Iyer @ 2008-03-25 13:09 UTC (permalink / raw)
  To: help-gnu-emacs

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))))))
 
 
 
Any help is greatly appreciated.
 
Thanks,
 
-- 
 
Balaji V. Iyer
PhD Student, 
Center for Efficient, Scalable and Reliable Computing,
Department of Electrical and Computer Engineering,
North Carolina State University.






^ permalink raw reply	[flat|nested] 20+ messages in thread

* Help with makefile command line
@ 2008-03-25 13:11 Balaji V. Iyer
  2008-03-26  4:17 ` Mike Mattie
                   ` (2 more replies)
  0 siblings, 3 replies; 20+ messages in thread
From: Balaji V. Iyer @ 2008-03-25 13:11 UTC (permalink / raw)
  To: emacs-devel

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))))))
 
 
 
Any help is greatly appreciated.

Oh, one thing..I am using emacs 21.2.1 on cygwin
 
Thanks,
 
-- 
 
Balaji V. Iyer
PhD Student,
Center for Efficient, Scalable and Reliable Computing, Department of
Electrical and Computer Engineering, North Carolina State University.






^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: help with makefile command line
  2008-03-25 13:09 help " Balaji V. Iyer
@ 2008-03-25 14:04 ` William Xu
  2008-03-26  4:19 ` Eli Zaretskii
  2008-03-26 16:20 ` Nikolaj Schumacher
  2 siblings, 0 replies; 20+ messages in thread
From: William Xu @ 2008-03-25 14:04 UTC (permalink / raw)
  To: help-gnu-emacs

"Balaji V. Iyer" <bviyer@ncsu.edu> writes:

>     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?

You may be interested in buffer-action.el -- Perform
actions(compile/run, etc) in buffer based on mode/filename.  

  http://permalink.gmane.org/gmane.emacs.sources/2826

-- 
William

http://williamxu.net9.org

       点绛唇
                王禹
雨恨云愁,江南依旧称佳丽。
水村渔市,一缕孤烟细。
天际征鸿,遥认行如缀。
平生事,此时凝睇,谁会恁栏意!





^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: Help with makefile command line
  2008-03-25 13:11 Help " Balaji V. Iyer
@ 2008-03-26  4:17 ` Mike Mattie
  2008-03-26  9:05 ` Andreas Schwab
  2008-03-26 13:50 ` Stefan Monnier
  2 siblings, 0 replies; 20+ messages in thread
From: Mike Mattie @ 2008-03-26  4:17 UTC (permalink / raw)
  To: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 1546 bytes --]

On Tue, 25 Mar 2008 09:11:58 -0400
"Balaji V. Iyer" <bviyer@ncsu.edu> wrote:

> 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
   ^^^ defun
>  (lambda ()
>    (unless (or (file-exists-p "makefile")
                                 ^^
                                 strange?
>                (file-exists-p "Makefile"))
>      (setq compile-command
       ^^^
       why modify a variable each time ? pass as an argument function ?
>            (concat "gcc -Wall -O3 -o"
>                    (file-name-sans-extension (file-name-nondirectory
> buffer-file -name))
             ^^
             broken ?

>                    " "
>                    (file-name-nondirectory buffer-file-name))))))
                      ^^^
                      computed twice, should bind.
>  
>  
>  
> Any help is greatly appreciated.

also concatenating arguments means that some external shell is going to have to split the args again,
usually better (no quoting issues), to simply pass off the arguments to exec without invoking the shell
if you can.

Hope that helps a bit.

> Oh, one thing..I am using emacs 21.2.1 on cygwin
>  
> Thanks,
>  

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: help with makefile command line
  2008-03-25 13:09 help " Balaji V. Iyer
  2008-03-25 14:04 ` William Xu
@ 2008-03-26  4:19 ` Eli Zaretskii
  2008-03-26  4:25   ` Mike Mattie
  2008-03-26  4:42   ` Mike Mattie
  2008-03-26 16:20 ` Nikolaj Schumacher
  2 siblings, 2 replies; 20+ messages in thread
From: Eli Zaretskii @ 2008-03-26  4:19 UTC (permalink / raw)
  To: help-gnu-emacs

> From: "Balaji V. Iyer" <bviyer@ncsu.edu>
> Date: Tue, 25 Mar 2008 09:09:56 -0400
> 
>     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

You don't need a Makefile to perform simple tasks, because Make knows
a lot of built in rules out of the box.  For example, to compile a .c
source file foo.c into a program foo, all you need is say "make -k foo", 
and Make will do it even without a Makefile.

> thus I would lke the default line to be
>  
> "gcc -ansi -O4 -Wall <c_source_file>"
>  
> How do I do this?

Customize the variable compile-command.

> 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))))))

Where did you put this and how did you use it?




^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: help with makefile command line
  2008-03-26  4:19 ` Eli Zaretskii
@ 2008-03-26  4:25   ` Mike Mattie
  2008-03-26  4:42   ` Mike Mattie
  1 sibling, 0 replies; 20+ messages in thread
From: Mike Mattie @ 2008-03-26  4:25 UTC (permalink / raw)
  To: help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 1501 bytes --]

On Wed, 26 Mar 2008 06:19:17 +0200
Eli Zaretskii <eliz@gnu.org> wrote:

> > From: "Balaji V. Iyer" <bviyer@ncsu.edu>
> > Date: Tue, 25 Mar 2008 09:09:56 -0400
> > 
> >     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
> 
> You don't need a Makefile to perform simple tasks, because Make knows
> a lot of built in rules out of the box.  For example, to compile a .c
> source file foo.c into a program foo, all you need is say "make -k
> foo", and Make will do it even without a Makefile.
> 
> > thus I would lke the default line to be
> >  
> > "gcc -ansi -O4 -Wall <c_source_file>"
> >  
> > How do I do this?
> 
> Customize the variable compile-command.
> 
> > 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))))))
> 
> Where did you put this and how did you use it?
> 
> 

btw , you don't have to setq. You can bind a value to compile-command with let as well, calling compile within
the let form.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: help with makefile command line
  2008-03-26  4:19 ` Eli Zaretskii
  2008-03-26  4:25   ` Mike Mattie
@ 2008-03-26  4:42   ` Mike Mattie
  2008-03-26  4:57     ` Mike Mattie
  1 sibling, 1 reply; 20+ messages in thread
From: Mike Mattie @ 2008-03-26  4:42 UTC (permalink / raw)
  To: help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 2544 bytes --]

On Wed, 26 Mar 2008 06:19:17 +0200
Eli Zaretskii <eliz@gnu.org> wrote:

> > From: "Balaji V. Iyer" <bviyer@ncsu.edu>
> > Date: Tue, 25 Mar 2008 09:09:56 -0400
> > 
> >     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
> 
> You don't need a Makefile to perform simple tasks, because Make knows
> a lot of built in rules out of the box.  For example, to compile a .c
> source file foo.c into a program foo, all you need is say "make -k
> foo", and Make will do it even without a Makefile.
> 
> > thus I would lke the default line to be
> >  
> > "gcc -ansi -O4 -Wall <c_source_file>"
> >  
> > How do I do this?
> 
> Customize the variable compile-command.
> 
> > 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))))))
> 
> Where did you put this and how did you use it?
> 
> 

(defun string-join (prefix list)
  ;; This is analogous to the perl5 join function.
  ;; given a <prefix> and a <list> of strings join the
  ;; strings with <prefix> as a seperator between the
  ;; list values.
  ;;
  ;; The result is a single string value.
  (apply 'concat
    (car list)
    (if (cdr list) (prefix-strings prefix (cdr list))) ))


(setq my-warnings '("-Wall"))
(setq my-optimization '("-O2"))

(defun create-compile-command ( target source )
  (string-join " " (cons
                     (or (getenv "CC") "gcc")
                     (append my-warnings my-optimization (list "-o" target source)))))

(create-compile-command "foo" "foo.c")

(defun my-compile ()
  (interactive)
  (lexical-let*
    ((source    (file-name-nondirectory buffer-file-name))
     (target    (file-name-sans-extension source)))

    (if (file-readable-p (concat (file-name-directory buffer-file-name) "Makefile"))
      (compile)
      (let
        (compile-command (create-compile-command))
        (compile))) ))

I haven't used compile in a while, but this is a sketch of how I would approach it. Hope it helps.

Cheers,
Mike Mattie

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: help with makefile command line
  2008-03-26  4:42   ` Mike Mattie
@ 2008-03-26  4:57     ` Mike Mattie
  0 siblings, 0 replies; 20+ messages in thread
From: Mike Mattie @ 2008-03-26  4:57 UTC (permalink / raw)
  To: help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 2868 bytes --]

On Tue, 25 Mar 2008 21:42:20 -0700
Mike Mattie <codermattie@gmail.com> wrote:

> On Wed, 26 Mar 2008 06:19:17 +0200
> Eli Zaretskii <eliz@gnu.org> wrote:
> 
> > > From: "Balaji V. Iyer" <bviyer@ncsu.edu>
> > > Date: Tue, 25 Mar 2008 09:09:56 -0400
> > > 
> > >     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
> > 
> > You don't need a Makefile to perform simple tasks, because Make
> > knows a lot of built in rules out of the box.  For example, to
> > compile a .c source file foo.c into a program foo, all you need is
> > say "make -k foo", and Make will do it even without a Makefile.
> > 
> > > thus I would lke the default line to be
> > >  
> > > "gcc -ansi -O4 -Wall <c_source_file>"
> > >  
> > > How do I do this?
> > 
> > Customize the variable compile-command.
> > 
> > > 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))))))
> > 
> > Where did you put this and how did you use it?
> > 
> > 
> 
> (defun string-join (prefix list)
>   ;; This is analogous to the perl5 join function.
>   ;; given a <prefix> and a <list> of strings join the
>   ;; strings with <prefix> as a seperator between the
>   ;; list values.
>   ;;
>   ;; The result is a single string value.
>   (apply 'concat
>     (car list)
>     (if (cdr list) (prefix-strings prefix (cdr list))) ))
> 
> 
> (setq my-warnings '("-Wall"))
> (setq my-optimization '("-O2"))
> 
> (defun create-compile-command ( target source )
>   (string-join " " (cons
>                      (or (getenv "CC") "gcc")
>                      (append my-warnings my-optimization (list "-o"
> target source)))))
> 
> (create-compile-command "foo" "foo.c")
> 
> (defun my-compile ()
>   (interactive)
>   (lexical-let*
>     ((source    (file-name-nondirectory buffer-file-name))
>      (target    (file-name-sans-extension source)))
> 
>     (if (file-readable-p (concat (file-name-directory
> buffer-file-name) "Makefile")) (compile)
>       (let
>         (compile-command (create-compile-command))
>         (compile))) ))
> 
> I haven't used compile in a while, but this is a sketch of how I
> would approach it. Hope it helps.

as cute as elisp is why not create a generic Makefile, and supply a -f argument ?
 
> Cheers,
> Mike Mattie

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: Help with makefile command line
  2008-03-25 13:11 Help " Balaji V. Iyer
  2008-03-26  4:17 ` Mike Mattie
@ 2008-03-26  9:05 ` Andreas Schwab
  2008-03-26 13:50 ` Stefan Monnier
  2 siblings, 0 replies; 20+ messages in thread
From: Andreas Schwab @ 2008-03-26  9:05 UTC (permalink / raw)
  To: Balaji V. Iyer; +Cc: emacs-devel

"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?

Note that you can run make even without a makefile.  There are builtin
default rules that allows you to type "make foo.o" to create foo.o from
foo.c.

Andreas.

-- 
Andreas Schwab, SuSE Labs, schwab@suse.de
SuSE Linux Products GmbH, Maxfeldstraße 5, 90409 Nürnberg, Germany
PGP key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."




^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: Help with makefile command line
  2008-03-25 13:11 Help " Balaji V. Iyer
  2008-03-26  4:17 ` Mike Mattie
  2008-03-26  9:05 ` Andreas Schwab
@ 2008-03-26 13:50 ` Stefan Monnier
  2 siblings, 0 replies; 20+ messages in thread
From: Stefan Monnier @ 2008-03-26 13:50 UTC (permalink / raw)
  To: Balaji V. Iyer; +Cc: emacs-devel

> "gcc -ansi -O4 -Wall <c_source_file>"
 
> How do I do this?
 
C-h v compile-command RET


        Stefan




^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: help with makefile command line
  2008-03-25 13:09 help " Balaji V. Iyer
  2008-03-25 14:04 ` William Xu
  2008-03-26  4:19 ` Eli Zaretskii
@ 2008-03-26 16:20 ` Nikolaj Schumacher
  2 siblings, 0 replies; 20+ messages in thread
From: Nikolaj Schumacher @ 2008-03-26 16:20 UTC (permalink / raw)
  To: Balaji V. Iyer; +Cc: help-gnu-emacs

"Balaji V. Iyer" <bviyer@ncsu.edu> wrote:

> 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))))))

You create an (nameless) function that will set a new `compile-command'.
However, you don't call the function, therefore you don't see any
effect.

If you did
(funcall (lambda () ...
the function would be executed immediately and do what you want.

Certainly you'll want it to execute automatically:
(add-hook 'c-mode-hook (lambda () ...
will automatically call your function when you open a C file.


regards,
Nikolaj Schumacher




^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: help with makefile command line
       [not found] <mailman.9409.1206451688.18990.help-gnu-emacs@gnu.org>
@ 2008-03-27 15:36 ` step
  2008-03-27 17:28 ` Richard G Riley
  1 sibling, 0 replies; 20+ messages in thread
From: step @ 2008-03-27 15:36 UTC (permalink / raw)
  To: help-gnu-emacs

On 3月25日, 下午9时09分, "Balaji V. Iyer" <bvi...@ncsu.edu> wrote:
> 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))))))
>
> Any help is greatly appreciated.
>
> Thanks,
>
> --
>
> Balaji V. Iyer
> PhD Student,
> Center for Efficient, Scalable and Reliable Computing,
> Department of Electrical and Computer Engineering,
> North Carolina State University.

why don't use the smart-compile.el for emacs?


^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: help with makefile command line
       [not found] <mailman.9409.1206451688.18990.help-gnu-emacs@gnu.org>
  2008-03-27 15:36 ` help with makefile command line step
@ 2008-03-27 17:28 ` Richard G Riley
  2008-03-28  2:51   ` stan
  1 sibling, 1 reply; 20+ messages in thread
From: Richard G Riley @ 2008-03-27 17:28 UTC (permalink / raw)
  To: help-gnu-emacs

"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))))))
>  
>  
>  
> Any help is greatly appreciated.
>  
> Thanks,


Here is the section from my .emacs which might be of help to you - see
the f10 binding to mycompile.


,----
| (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)
|   )
| 
`----



^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: help with makefile command line
  2008-03-27 17:28 ` Richard G Riley
@ 2008-03-28  2:51   ` stan
  2008-03-28  3:01     ` Richard G Riley
  2008-03-29 15:33     ` Kevin Rodgers
  0 siblings, 2 replies; 20+ messages in thread
From: stan @ 2008-03-28  2:51 UTC (permalink / raw)
  To: help-gnu-emacs

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 :) 

Do you really mean that you plan to not use makefiles? If not you might
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. 

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.


^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: help with makefile command line
  2008-03-28  2:51   ` stan
@ 2008-03-28  3:01     ` Richard G Riley
  2008-03-28  7:11       ` stan
  2008-03-29 15:33     ` Kevin Rodgers
  1 sibling, 1 reply; 20+ messages in thread
From: Richard G Riley @ 2008-03-28  3:01 UTC (permalink / raw)
  To: help-gnu-emacs

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.

>
> 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?

>
> 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?



^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: help with makefile command line
  2008-03-28  3:01     ` Richard G Riley
@ 2008-03-28  7:11       ` stan
  2008-03-28 12:57         ` Richard G Riley
  0 siblings, 1 reply; 20+ messages in thread
From: stan @ 2008-03-28  7:11 UTC (permalink / raw)
  To: help-gnu-emacs

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 :)


^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: help with makefile command line
  2008-03-28  7:11       ` stan
@ 2008-03-28 12:57         ` Richard G Riley
  2008-03-28 20:33           ` stan
  0 siblings, 1 reply; 20+ messages in thread
From: Richard G Riley @ 2008-03-28 12:57 UTC (permalink / raw)
  To: help-gnu-emacs

stan <smoore@exis.net> writes:

> 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?)

But what has your setup and they way you want it got to do with the OP
wanting auto selection between Makefile and the gcc direct approach?

>>
>> 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.

My comments were directed at you. It was your post I replied to
above. You replied to me. I replied to you.

I am still not sure what points you were trying to make though. Did you
understand the OPs want better now?


>>
>>>
>>> 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 :)


^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: help with makefile command line
  2008-03-28 12:57         ` Richard G Riley
@ 2008-03-28 20:33           ` stan
  2008-03-29 13:18             ` Richard G Riley
  0 siblings, 1 reply; 20+ messages in thread
From: stan @ 2008-03-28 20:33 UTC (permalink / raw)
  To: help-gnu-emacs

Richard G Riley wrote:
> stan <smoore@exis.net> writes:
>
>> 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?)
>
> But what has your setup and they way you want it got to do with the OP
> wanting auto selection between Makefile and the gcc direct approach?

The op originally asked how to replace make -k with gcc -ansi -O4 -Wall
file because he didn't have a makefile. He asked for ideas. 
>>>
>>> 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.
>
> My comments were directed at you. It was your post I replied to
> above. You replied to me. I replied to you.

I wasn't replying to you, as I said the streams got crossed. You might
note the snip started with your reply and left the op attempted
solution.
>
> I am still not sure what points you were trying to make though. Did you
> understand the OPs want better now?

I understood from the beginning. Several options were offered by others
that didn't involve hard coding a choosable make or gcc command. Hard
coding the compiler as the op attempted to do seems to me to have the
disadvantage of hard coding the compiler options also. In a case where
you dont want the hard coded it seems reasonable to change them on a
session basis, or try some other option.

Your code also requires changeing the code to get a different set of
options in the generated makefile. Personally I prefer the insert a
template approach because I prefer simply editing the template when I
update the baseline. I realize that your code generates a baseline
Makfle that can be modified, I'm refering to changes in the baseline.
For example I jump between cygwin and linux with diferent baseline
makefiles and with your method I would add to the headache of
maintaining a .emacs for both systems. Hard coding either a gcc command
or a baseline makefile seems to lose flexibility to me.

For me at least your way seems to involve some extra steps when I update
my standard Makefile. I.e. generate the makefile, run to test. locate
problem, modify code, generate makefile, ... With the insert template
method I simply modify Makefile, run to test, locate problem, modify
Makefile. When satisfied, replace template Makefile. Seems like less
steps and cleaner to me.

What works for me might not be best for others though so I'm a firm
believer in options. The more the merrier most of the time.

I saw the op's issue as how to solve compile without a makefile and you
aparrently see the issue as how to modify .emacs. Different
perspectives, different solution options. That's a good thing.(tm)
>
>>>
>>>>
>>>> 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 :)


^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: help with makefile command line
  2008-03-28 20:33           ` stan
@ 2008-03-29 13:18             ` Richard G Riley
  0 siblings, 0 replies; 20+ messages in thread
From: Richard G Riley @ 2008-03-29 13:18 UTC (permalink / raw)
  To: help-gnu-emacs

stan <smoore@exis.net> writes:

> Richard G Riley wrote:
>> stan <smoore@exis.net> writes:
>>
>>> 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?)
>>
>> But what has your setup and they way you want it got to do with the OP
>> wanting auto selection between Makefile and the gcc direct approach?
>
> The op originally asked how to replace make -k with gcc -ansi -O4 -Wall
> file because he didn't have a makefile. He asked for ideas. 
>>>>
>>>> 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.
>>
>> My comments were directed at you. It was your post I replied to
>> above. You replied to me. I replied to you.
>
> I wasn't replying to you, as I said the streams got crossed. You might
> note the snip started with your reply and left the op attempted
> solution.
>>
>> I am still not sure what points you were trying to make though. Did you
>> understand the OPs want better now?
>
> I understood from the beginning. Several options were offered by others
> that didn't involve hard coding a choosable make or gcc command. Hard

Nothing is hard coded that can not be undone at compile time. You can
choose not to use mycompile ...

> coding the compiler as the op attempted to do seems to me to have the
> disadvantage of hard coding the compiler options also. In a case where

As most makefiles do - but thats a straw man since you can as easily use
system variables in them. As I do.

> you dont want the hard coded it seems reasonable to change them on a
> session basis, or try some other option.
>
> Your code also requires changeing the code to get a different set of
> options in the generated makefile. Personally I prefer the insert a

What generated makefile? It doesn't generate any makefiles.

> template approach because I prefer simply editing the template when I
> update the baseline. I realize that your code generates a baseline
> Makfle that can be modified, I'm refering to changes in the baseline.

No it doesn't.

> For example I jump between cygwin and linux with diferent baseline
> makefiles and with your method I would add to the headache of
> maintaining a .emacs for both systems. Hard coding either a gcc command
> or a baseline makefile seems to lose flexibility to me.

I'm not sure I follow you with this hard coded stuff. Its a baseline. All
functions and utilities are "hard coded" - in this case using a  makefile
on a C project if it exists is hardly hard coding anything. Makefiles
are an integral part of C development.

>
> For me at least your way seems to involve some extra steps when I update
> my standard Makefile. I.e. generate the makefile, run to test. locate

Again. it doesn't generate any makefile.

> problem, modify code, generate makefile, ... With the insert template
> method I simply modify Makefile, run to test, locate problem, modify
> Makefile. When satisfied, replace template Makefile. Seems like less
> steps and cleaner to me.

I hardly ever modify a base makefile. I use a template, add the target
and source files and bang - its there for pretty much ever.

>
> What works for me might not be best for others though so I'm a firm
> believer in options. The more the merrier most of the time.

Yes. I agree.

>
> I saw the op's issue as how to solve compile without a makefile and you
> aparrently see the issue as how to modify .emacs. Different
> perspectives, different solution options. That's a good thing.(tm)

No. I gave a solution that works with or without a makefile. Most
"custom" things in emacs require a modification of a utility el or the
.emacs. I'm somewhat confused as to your understanding of the
function/example I provided.

Anyway, I guess we've done this to death.


^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: help with makefile command line
  2008-03-28  2:51   ` stan
  2008-03-28  3:01     ` Richard G Riley
@ 2008-03-29 15:33     ` Kevin Rodgers
  1 sibling, 0 replies; 20+ messages in thread
From: Kevin Rodgers @ 2008-03-29 15:33 UTC (permalink / raw)
  To: help-gnu-emacs

stan wrote:
> 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 :) 

You don't need to write a Makefile, because make has built-in rules that
handle this.

(add-hook 'c-mode-hook
	  (lambda ()
	    (set (make-local-variable 'compile-command)
		 (format "make %s"
			 (file-name-sans-extension
			  (file-name-nondirectory buffer-file-name))))))

Just set the CC=gcc and CFLAGs="-Wall -O3" environment variables, and voila!

-- 
Kevin Rodgers
Denver, Colorado, USA





^ permalink raw reply	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2008-03-29 15:33 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <mailman.9409.1206451688.18990.help-gnu-emacs@gnu.org>
2008-03-27 15:36 ` help with makefile command line step
2008-03-27 17:28 ` Richard G Riley
2008-03-28  2:51   ` stan
2008-03-28  3:01     ` Richard G Riley
2008-03-28  7:11       ` stan
2008-03-28 12:57         ` Richard G Riley
2008-03-28 20:33           ` stan
2008-03-29 13:18             ` Richard G Riley
2008-03-29 15:33     ` Kevin Rodgers
2008-03-25 13:11 Help " Balaji V. Iyer
2008-03-26  4:17 ` Mike Mattie
2008-03-26  9:05 ` Andreas Schwab
2008-03-26 13:50 ` Stefan Monnier
  -- strict thread matches above, loose matches on Subject: below --
2008-03-25 13:09 help " Balaji V. Iyer
2008-03-25 14:04 ` William Xu
2008-03-26  4:19 ` Eli Zaretskii
2008-03-26  4:25   ` Mike Mattie
2008-03-26  4:42   ` Mike Mattie
2008-03-26  4:57     ` Mike Mattie
2008-03-26 16:20 ` Nikolaj Schumacher

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.