Re: Make: puzzeling make behaviour ?

Henrik Carlqvist <[email protected]>
Newsgroups gmane.comp.gnu.utils
Organization SunSITE.dk - Supporting Open source
Message-ID <[email protected]>
B Thomas <[email protected]> wrote:

> I changed the build rule to 
> 
> build:  $(PROGRAMS)
>  	$(CC) $(CFLAGS) $(LDFLAGS) -o "$<" "$<".c
> 
> Shouldn't this work ? However I still have
> the same problem. 

The problem remains because make thinks like this:

1) It wants to create a file named "build". To create the file "build" it
thinks it has a command line which you have specified.

2) Before it can create "build" it will have to create $(PROGRAMS). There
is no rule that specifies how to create $(PROGRAMS) so it uses a built in
rule.

> This make file rule or something else results in :
> gcc -I/home/bt/include   -L/usr/X11R6/lib -lX11 -lGL -lGLU -lm
> -L/home/bt/lib -lgltk  Hello_World.c   -o Hello_World

So make has a built in rule on how to build a program from a C source. If
you still want to call your target "build" the right way to do this would
be something like:

build:  $(PROGRAMS)

%: %.c
	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $<


Above "build" depends on $(PROGRAMS) and a custom rule has been specified
how programs are built from C source. The fact that no file named "build"
is created is no problem. This is how Makefiles are usually written.
However, the de-facto standard for the default rule is usually "all"
instead of "build", but you are free to call the rule whatever you want.

> Output of nm/ar  commands is as follows :

Your output from nm and ar looks fine, once you get the right command done
by make the library will probably be usable.

regards Henrik
-- 
The address in the header is only to prevent spam. My real address is:
hc1(at)poolhem.se Examples of addresses which go to spammers:
root@localhost postmaster@localhost
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.