[RFC PATCH 1/2] Makefile: cleanup guest/init generation

Andre Przywara
2015-06-23T15:06:12Z

The dependencies and targets for the guest userland binary are
currently not correct, some are redundant.
Fix them by splitting up guest/guest_init.o creation into its two
steps and describe the dependencies properly.
On the way use automatic variables in some rules.

Signed-off-by: Andre Przywara <andre.przywara@arm.com>
---
Makefile | 21 ++++++++++++---------
1 file changed, 12 insertions(+), 9 deletions(-)

diff --git a/Makefile b/Makefile
index 151fa9d..b9480ff 100644
--- a/Makefile
+++ b/Makefile
@@ -337,7 +337,7 @@ ifneq ($(WERROR),0)
CFLAGS += -Werror
endif

-all: $(PROGRAM) $(PROGRAM_ALIAS) $(GUEST_INIT)
+all: $(PROGRAM) $(PROGRAM_ALIAS)

# CFLAGS used when building objects
# This is intentionally not assigned using :=
@@ -352,22 +352,25 @@ c_flags = -Wp,-MD,$(depfile) $(CFLAGS)
STATIC_OBJS = $(patsubst %.o,%.static.o,$(OBJS) $(OBJS_STATOPT))
GUEST_OBJS = guest/guest_init.o

-$(PROGRAM)-static: $(STATIC_OBJS) $(OTHEROBJS) $(GUEST_INIT)
+$(PROGRAM)-static: $(STATIC_OBJS) $(OTHEROBJS) $(GUEST_OBJS)
$(E) " LINK " $@
- $(Q) $(CC) -static $(CFLAGS) $(STATIC_OBJS) $(OTHEROBJS) $(GUEST_OBJS) $(LIBS) $(LIBS_STATOPT) -o $@
+ $(Q) $(CC) -static $(CFLAGS) $^ $(LIBS) $(LIBS_STATOPT) -o $@

-$(PROGRAM): $(OBJS) $(OBJS_DYNOPT) $(OTHEROBJS) $(GUEST_INIT)
+$(PROGRAM): $(OBJS) $(OBJS_DYNOPT) $(OTHEROBJS) $(GUEST_OBJS)
$(E) " LINK " $@
- $(Q) $(CC) $(CFLAGS) $(OBJS) $(OBJS_DYNOPT) $(OTHEROBJS) $(GUEST_OBJS) $(LIBS) $(LIBS_DYNOPT) -o $@
+ $(Q) $(CC) $(CFLAGS) $^ $(LIBS) $(LIBS_DYNOPT) -o $@

$(PROGRAM_ALIAS): $(PROGRAM)
$(E) " LN " $@
- $(Q) ln -f $(PROGRAM) $@
+ $(Q) ln -f $< $@

-$(GUEST_INIT): guest/init.c
+$(GUEST_OBJS): $(GUEST_INIT)
$(E) " LINK " $@
- $(Q) $(CC) -static guest/init.c -o $@
- $(Q) $(LD) $(LDFLAGS) -r -b binary -o guest/guest_init.o $(GUEST_INIT)
+ $(Q) $(LD) $(LDFLAGS) -r -b binary -o $@ $<
+
+$(GUEST_INIT): guest/init.c
+ $(E) " CC " $@
+ $(Q) $(CC) -static $^ -o $@

%.s: %.c
$(Q) $(CC) -o $@ -S $(CFLAGS) -fverbose-asm $<
--
2.3.5