[RFC,kvm-unit-tests,5/8] Makefile: add explicit mkdir for .o targets

Submitted by alex.bennee@linaro.org on April 6, 2017, 7:07 p.m.

Details

Message ID 20170406190727.5624-6-alex.bennee@linaro.org
State New
Headers show

Commit Message

alex.bennee@linaro.org April 6, 2017, 7:07 p.m.
This is fairly direct way of ensuring the target build directories are
created before we build a binary blob. mkdir -p fails gracefully if
the directory is already there.

Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
---
 Makefile | 5 +++++
 1 file changed, 5 insertions(+)

Comments

Andrew Jones April 7, 2017, 2:42 p.m.
On Thu, Apr 06, 2017 at 08:07:24PM +0100, Alex Bennée wrote:
> This is fairly direct way of ensuring the target build directories are
> created before we build a binary blob. mkdir -p fails gracefully if
> the directory is already there.
> 
> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
> ---
>  Makefile | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/Makefile b/Makefile
> index 781186e..56598df 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -79,8 +79,13 @@ $(LIBFDT_archive): $(addprefix $(LIBFDT_objdir)/,$(LIBFDT_OBJS))
>  	$(AR) rcs $@ $^
>  
>  %.o: %.S
> +	mkdir -p $(dir $@)
>  	$(CC) $(CFLAGS) -c -nostdlib -o $@ $<
>  
> +%.o: %.c
> +	mkdir -p $(dir $@)
> +	$(CC) $(CFLAGS) -c -o $@ $<

This rule will override any arch makefile %.o rule.  I don't think we want
to do that.  And I guess that means we should move the '%.o: %.S' rule up
above the include $(TEST_DIR)/Makefile so we don't override those either.

> +
>  -include */.*.d */*/.*.d
>  
>  all: $(shell git -C $(SRCDIR) rev-parse --verify --short=8 HEAD >build-head 2>/dev/null)
> -- 
> 2.11.0
>

I'd prefer we just have a couple places where we do mkdir:  one in the
common Makefile for common dirs (BUILD_DIRS) and one in the arch makefile
for arch dirs (ARCH_BUILD_DIRS).

The example linked below looks like something we might be able to apply.

https://www.gnu.org/software/make/manual/html_node/Prerequisite-Types.html#Prerequisite-Types

Thanks,
drew
Paolo Bonzini April 27, 2017, 3:57 p.m.
On 06/04/2017 21:07, Alex Bennée wrote:
> This is fairly direct way of ensuring the target build directories are
> created before we build a binary blob. mkdir -p fails gracefully if
> the directory is already there.
> 
> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
> ---
>  Makefile | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/Makefile b/Makefile
> index 781186e..56598df 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -79,8 +79,13 @@ $(LIBFDT_archive): $(addprefix $(LIBFDT_objdir)/,$(LIBFDT_OBJS))
>  	$(AR) rcs $@ $^
>  
>  %.o: %.S
> +	mkdir -p $(dir $@)

Should this use @ for cleanliness?

Paolo

>  	$(CC) $(CFLAGS) -c -nostdlib -o $@ $<
>  
> +%.o: %.c
> +	mkdir -p $(dir $@)
> +	$(CC) $(CFLAGS) -c -o $@ $<
> +
>  -include */.*.d */*/.*.d
>  
>  all: $(shell git -C $(SRCDIR) rev-parse --verify --short=8 HEAD >build-head 2>/dev/null)
>
alex.bennee@linaro.org May 11, 2017, 3:30 p.m.
Paolo Bonzini <pbonzini@redhat.com> writes:

> On 06/04/2017 21:07, Alex Bennée wrote:
>> This is fairly direct way of ensuring the target build directories are
>> created before we build a binary blob. mkdir -p fails gracefully if
>> the directory is already there.
>>
>> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
>> ---
>>  Makefile | 5 +++++
>>  1 file changed, 5 insertions(+)
>>
>> diff --git a/Makefile b/Makefile
>> index 781186e..56598df 100644
>> --- a/Makefile
>> +++ b/Makefile
>> @@ -79,8 +79,13 @@ $(LIBFDT_archive): $(addprefix $(LIBFDT_objdir)/,$(LIBFDT_OBJS))
>>  	$(AR) rcs $@ $^
>>
>>  %.o: %.S
>> +	mkdir -p $(dir $@)
>
> Should this use @ for cleanliness?

I'm not sure I follow. Did you mean use $(@D) directly?

>
> Paolo
>
>>  	$(CC) $(CFLAGS) -c -nostdlib -o $@ $<
>>
>> +%.o: %.c
>> +	mkdir -p $(dir $@)
>> +	$(CC) $(CFLAGS) -c -o $@ $<
>> +
>>  -include */.*.d */*/.*.d
>>
>>  all: $(shell git -C $(SRCDIR) rev-parse --verify --short=8 HEAD >build-head 2>/dev/null)
>>


--
Alex Bennée
Paolo Bonzini May 12, 2017, 10:36 a.m.
On 11/05/2017 17:30, Alex Bennée wrote:
>>>
>>>  %.o: %.S
>>> +	mkdir -p $(dir $@)
>> Should this use @ for cleanliness?
> > I'm not sure I follow. Did you mean use $(@D) directly?

That too, but I was thinking of using "@mkdir" to avoid spamming the
output with mkdir commands.

Paolo
alex.bennee@linaro.org May 12, 2017, 11:14 a.m.
Paolo Bonzini <pbonzini@redhat.com> writes:

> On 11/05/2017 17:30, Alex Bennée wrote:
>>>>
>>>>  %.o: %.S
>>>> +	mkdir -p $(dir $@)
>>> Should this use @ for cleanliness?
>> > I'm not sure I follow. Did you mean use $(@D) directly?
>
> That too, but I was thinking of using "@mkdir" to avoid spamming the
> output with mkdir commands.

Gotcha.

>
> Paolo


--
Alex Bennée

Patch hide | download patch | download mbox

diff --git a/Makefile b/Makefile
index 781186e..56598df 100644
--- a/Makefile
+++ b/Makefile
@@ -79,8 +79,13 @@  $(LIBFDT_archive): $(addprefix $(LIBFDT_objdir)/,$(LIBFDT_OBJS))
 	$(AR) rcs $@ $^
 
 %.o: %.S
+	mkdir -p $(dir $@)
 	$(CC) $(CFLAGS) -c -nostdlib -o $@ $<
 
+%.o: %.c
+	mkdir -p $(dir $@)
+	$(CC) $(CFLAGS) -c -o $@ $<
+
 -include */.*.d */*/.*.d
 
 all: $(shell git -C $(SRCDIR) rev-parse --verify --short=8 HEAD >build-head 2>/dev/null)