Re: Using make
shakahshakah_at_gmail.com
Date: 03/29/05
- Next message: Måns Rullgård: "Re: Base class and OOP in C"
- Previous message: j_mckitrick_at_bigfoot.com: "Base class and OOP in C"
- In reply to: Chuck Dillon: "Re: Using make"
- Next in thread: Chuck Dillon: "Re: Using make"
- Reply: Chuck Dillon: "Re: Using make"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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.
- Next message: Måns Rullgård: "Re: Base class and OOP in C"
- Previous message: j_mckitrick_at_bigfoot.com: "Base class and OOP in C"
- In reply to: Chuck Dillon: "Re: Using make"
- Next in thread: Chuck Dillon: "Re: Using make"
- Reply: Chuck Dillon: "Re: Using make"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|