Re: Using make

shakahshakah_at_gmail.com
Date: 03/29/05


Date: 29 Mar 2005 06:53:49 -0800

Chuck Dillon wrote:
> JS wrote:
> > I have a c file called test.c
> >
> > I have then made a Makefile that looks like this:
> >
> > blop : test.c
> > gcc -g -Wall test.c
> >
> > When I type "make test" it compiles the test.c file and generates a
test
> > executable file. But I thought make would only look for the target
(blop),
> > and if no such target is found it would give an error.
> >
> > Why does it compile test.c when I don't have a test target in my
Makefile?
> >
> > JS
>
> A target is one of the words on the left side of the colon. In your
> case the target is blop. Your makefile is telling make that the
> command 'gcc -g -Wall test.c' will make a file called 'blop' and also

> that the file 'blop' depends on the contents of the file 'test.c'.
(If
> you added -o blop to your gcc command it would do what make expects.)
>
> If you do 'make blop', (or just 'make' if the blop clause is the
> first/default clause), make will try to make sure that the file
'blop'
> exists and is newer than the file 'test.c'. If there is no 'blop'
file
> or if 'test.c' if newer than the 'blop' file, make will execute your
> gcc command in an attempt to make 'blop' the file. If 'test.c'
doesn't
> exists make would complain that it doesn't know how to make 'test.c'.
>
> Make does not interpret your gcc command and determine what it
> generates. It assumes the gcc command will create 'blop' since you
> told it that it would.

Why doesn't make complain about "No rule to make target 'test'",
though?
Does make pick up a default ".c => (no extension)" rule?

I tried the OP's makefile on Solaris, got the following:

jc@soyuz:/tmp> cat Makefile
blop: test.c
        gcc -g -Wall test.c

jc@soyuz:/tmp> make
gcc -g -Wall test.c
test.c: In function `main':
test.c:11: warning: implicit declaration of function `open'

jc@soyuz:/tmp> rm a.out
jc@soyuz:/tmp> make test
cc test.c -o test

jc@soyuz:/tmp> rm test
jc@soyuz:/tmp> make bar
make: *** No rule to make target `bar'. Stop.



Relevant Pages

  • Re: Using make
    ... >> executable file. ... >> (blop), and if no such target is found it would give an error. ... > you added -o blop to your gcc command it would do what make expects.) ...
    (comp.unix.programmer)
  • Using make
    ... When I type "make test" it compiles the test.c file and generates a test ... But I thought make would only look for the target (blop), ... Why does it compile test.c when I don't have a test target in my Makefile? ...
    (comp.unix.programmer)
  • Re: Using make
    ... >>A target is one of the words on the left side of the colon. ... It assumes the gcc command will create 'blop' since you ...
    (comp.unix.programmer)
  • Re: Using make
    ... But I thought make would only look for the target (blop), ... > Why does it compile test.c when I don't have a test target in my Makefile? ... gcc command in an attempt to make 'blop' the file. ...
    (comp.unix.programmer)
  • Re: [9fans] plan9 httpd/pegasus on unix?
    ... I've got to maintain a several hundred packages for our emedded target ... > - Makefile dependencies only work with the timestamps on files. ... "make clean" after changing toolchain settings should be obvoius. ... >>> you're running qmail on the host and really can't afford to stop it ...
    (comp.os.plan9)