help-make
[Top][All Lists]
Advanced

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

Re: Hierarchical building


From: Paul Smith
Subject: Re: Hierarchical building
Date: Thu, 02 Dec 2021 13:14:53 -0500
User-agent: Evolution 3.36.5-0ubuntu1

On Thu, 2021-12-02 at 17:12 +0000, Ian Molton wrote:
> So presumably the "right" approach is to use submakefiles somehow,
> but that brings a whole slew of questions about what is defined
> where, and what applies to what, and I'm just finding myself
> completely lost - for example -
> 
> I tried to make a rule that would work for objects located in
> subfolders. This is the closest I got, and it worked fine:
> 
> $(OBJS): %.o: %.c
>         mkdir -p .deps/$(@D)
>         $(CC) $(CFLAGS) -c -o $@ $<

Your basic problem is you're trying to use static pattern rules.  A
static pattern rule is actually an explicit rule, so the above means
you've created an explicit rule for every object in OBJS.

Then if you later write:

> $(OBJS): %.o: %.s
>         mkdir -p .deps/$(@D)
>         $(CC) $(ASFLAGS) -c -o $@ $<

Now you're creating a different explicit rule for those same objects,
with a different recipe and prerequisite.

That can't work.

You need to use normal implicit rules via a pattern rule:

%.o: %.c
        mkdir -p .deps/$(@D)
        $(CC) $(CFLAGS) -c -o $@ $<

%.o: %.s
        mkdir -p .deps/$(@D)
        $(CC) $(ASFLAGS) -c -o $@ $<

Now make will build the .o from a .c file if one exists, else if no .c
file exists it will build the .o from a .s file.




reply via email to

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