[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: help: make static rules

From: Paul Smith
Subject: Re: help: make static rules
Date: Thu, 28 Feb 2008 07:43:49 -0500

On Thu, 2008-02-28 at 14:05 +0200, Vad N wrote:

> Makefile contain this:
> objects = main.o first.o
> $(objects): %.o: %.c
>               $(CC) -c $(CFLAGS) $< -o $@
> ---------------------------------
> I suppose that main.o and first.o objects file will be created by
> above static rule, becouse i indicated them in object variable,but
> only main.o created. Why?

Unless you specify a target to build on the command line, make will
build the first target it finds in the makefile, then stop.  In this
case, the first target in the makefile is main.o, so that's what it

The normal convention is to make a target "all" be the first target in
the makefile, and list the target(s) you want to build as prerequisites
of that:

        all: $(objects)

Note you don't need the static pattern rule at all here, because make
knows implicitly (with a built in implicit rule) how to build a .o from
a .c).

If you wanted to build a program from those objects then it would be:

        all: myprog

        myprog: $(objects)

 Paul D. Smith <address@hidden>          Find some GNU make tips at:            
 "Please remain calm...I may be mad, but I am a professional." --Mad Scientist

reply via email to

[Prev in Thread] Current Thread [Next in Thread]