Makefile enhancements
cover Makefile enhancements
Minor makefile cleanups; the most significant is the last patch which updates the makefile to generate Linux-style simpified output by default.
Avi Kivity (5):
Drop OP_CFLAGS
Consolidate compiler invocations
Introduce rules.mak
Consolidate linker rules
Make make output quieter
Makefile | 25 ++++++---------- Makefile.target | 85 ++++++++++-------------------------------------------- rules.mak | 16 ++++++++++ 3 files changed, 42 insertions(+), 84 deletions(-) create mode 100644 rules.mak
PATCH 1/5 Drop OP_CFLAGS
OP_CFLAGS is no longer used, except for machine.c, where it is not needed.
--- Makefile.target | 52 +++++----------------------------------------------- 1 files changed, 5 insertions(+), 47 deletions(-)
Makefile.target +5 -47
@@ -71,90 +71,49 @@ endif PROGS=$(QEMU_PROG) -# We require -O2 to avoid the stack setup prologue in EXIT_TB -OP_CFLAGS := -O2 -g -fno-strict-aliasing -OP_CFLAGS += -Wall -Wundef -Wendif-labels -Wwrite-strings -Wmissing-prototypes -Wstrict-prototypes -Wredundant-decls - # cc-option -# Usage: OP_CFLAGS+=$(call cc-option, -falign-functions=0, -malign-functions=0) - -cc-option = $(shell if $(CC) $(OP_CFLAGS) $(1) -S -o /dev/null -xc /dev/null \ - > /dev/null 2>&1; then echo "$(1)"; else echo "$(2)"; fi ;) +# Usage: CFLAGS+=$(call cc-option, $(CFLAGS), -falign-functions=0, -malign-functions=0) -OP_CFLAGS+=$(call cc-option, -fno-reorder-blocks, "") -OP_CFLAGS+=$(call cc-option, -fno-gcse, "") -OP_CFLAGS+=$(call cc-option, -fno-tree-ch, "") -OP_CFLAGS+=$(call cc-option, -fno-optimize-sibling-calls, "") -OP_CFLAGS+=$(call cc-option, -fno-crossjumping, "") -OP_CFLAGS+=$(call cc-option, -fno-align-labels, "") -OP_CFLAGS+=$(call cc-option, -fno-align-jumps, "") -OP_CFLAGS+=$(call cc-option, -fno-align-functions, $(call cc-option, -malign-functions=0, "")) -OP_CFLAGS+=$(call cc-option, -fno-section-anchors, "") +cc-option = $(shell if $(CC) $(1) $(2) -S -o /dev/null -xc /dev/null \ + > /dev/null 2>&1; then echo "$(2)"; else echo "$(3)"; fi ;) HELPER_CFLAGS= ifeq ($(ARCH),i386) HELPER_CFLAGS+=-fomit-frame-pointer -OP_CFLAGS+=-mpreferred-stack-boundary=2 -fomit-frame-pointer endif ifeq ($(ARCH),sparc) CFLAGS+=-ffixed-g2 -ffixed-g3 - OP_CFLAGS+=-fno-delayed-branch -ffixed-i0 - ifeq ($(CONFIG_SOLARIS),yes) - OP_CFLAGS+=-fno-omit-frame-pointer - else + ifneq ($(CONFIG_SOLARIS),yes) CFLAGS+=-ffixed-g1 -ffixed-g6 HELPER_CFLAGS+=-ffixed-i0 endif endif ifeq ($(ARCH),sparc64) - OP_CFLAGS+=-mcpu=ultrasparc -m64 -fno-delayed-branch -ffixed-i0 ifneq ($(CONFIG_SOLARIS),yes) CFLAGS+=-ffixed-g5 -ffixed-g6 -ffixed-g7 - OP_CFLAGS+=-ffixed-g5 -ffixed-g6 -ffixed-g7 else CFLAGS+=-ffixed-g1 -ffixed-g4 -ffixed-g5 -ffixed-g7 endif endif ifeq ($(ARCH),alpha) -# -msmall-data is not used for OP_CFLAGS because we want two-instruction -# relocations for the constant constructions # Ensure there's only a single GP CFLAGS+=-msmall-data endif ifeq ($(ARCH),hppa) -OP_CFLAGS=-O1 -fno-delayed-branch BASE_LDFLAGS+=-Wl,-T,$(SRC_PATH)/$(ARCH).ld endif ifeq ($(ARCH),ia64) CFLAGS+=-mno-sdata -OP_CFLAGS+=-mno-sdata -endif - -ifeq ($(ARCH),arm) -OP_CFLAGS+=-mno-sched-prolog -fno-omit-frame-pointer -endif - -ifeq ($(ARCH),m68k) -OP_CFLAGS+=-fomit-frame-pointer -endif - -ifeq ($(ARCH),mips) -OP_CFLAGS+=-mabi=32 -G0 -fno-PIC -mno-abicalls -fomit-frame-pointer -fno-delayed-branch -Wa,-O0 -endif - -ifeq ($(ARCH),mips64) -OP_CFLAGS+=-mabi=n32 -G0 -fno-PIC -mno-abicalls -fomit-frame-pointer -fno-delayed-branch -Wa,-O0 endif CFLAGS+=$(OS_CFLAGS) $(ARCH_CFLAGS) LDFLAGS+=$(OS_LDFLAGS) $(ARCH_LDFLAGS) -OP_CFLAGS+=$(OS_CFLAGS) $(ARCH_CFLAGS) CPPFLAGS+=-D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE LIBS+=-lm
@@ -166,7 +125,6 @@ LIBS+=-lsocket -lnsl -lresolv ifdef NEEDS_LIBSUNMATH LIBS+=-lsunmath LDFLAGS+=-L/opt/SUNWspro/prod/lib -R/opt/SUNWspro/prod/lib -OP_CFLAGS+=-I/opt/SUNWspro/prod/include/cc CFLAGS+=-I/opt/SUNWspro/prod/include/cc endif endif
@@ -262,7 +220,7 @@ translate-all.o: translate-all.c cpu.h tcg/tcg.o: cpu.h machine.o: machine.c - $(CC) $(OP_CFLAGS) $(CPPFLAGS) -c -o $@ $< + $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $< # HELPER_CFLAGS is used for all the code compiled with static register # variables
Signature · 1 line
1.6.0.6
PATCH 2/5 Consolidate compiler invocations
In reply to Avi KivityInstead of specifying the compilation command over and over, use a single rule and adjust it as necessary using target specific target overrides.
--- Makefile | 17 ++++++++--------- Makefile.target | 18 +++++------------- 2 files changed, 13 insertions(+), 22 deletions(-)
Makefile +8 -9
@@ -158,22 +158,18 @@ endif LIBS+=$(VDE_LIBS) cocoa.o: cocoa.m - $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $< sdl.o: sdl.c keymaps.c sdl_keysym.h - $(CC) $(CFLAGS) $(CPPFLAGS) $(SDL_CFLAGS) -c -o $@ $< + +sdl.o audio/sdlaudio.o: CFLAGS += $(SDL_CFLAGS) vnc.o: vnc.c keymaps.c sdl_keysym.h vnchextile.h d3des.c d3des.h - $(CC) $(CFLAGS) $(CPPFLAGS) $(CONFIG_VNC_TLS_CFLAGS) -c -o $@ $< -curses.o: curses.c keymaps.c curses_keys.h - $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $< +vnc.o: CFLAGS += $(CONFIG_VNC_TLS_CFLAGS) -bt-host.o: bt-host.c - $(CC) $(CFLAGS) $(CPPFLAGS) $(CONFIG_BLUEZ_CFLAGS) -c -o $@ $< +curses.o: curses.c keymaps.c curses_keys.h -audio/sdlaudio.o: audio/sdlaudio.c - $(CC) $(CFLAGS) $(CPPFLAGS) $(SDL_CFLAGS) -c -o $@ $< +bt-host.o: CFLAGS += $(CONFIG_BLUEZ_CFLAGS) libqemu_common.a: $(OBJS) rm -f $@
@@ -195,6 +191,9 @@ qemu-img$(EXESUF): qemu-img.o qemu-tool.o osdep.o $(BLOCK_OBJS) %.o: %.c $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $< +%.o: %.m + $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $< + qemu-nbd$(EXESUF): qemu-nbd.o qemu-tool.o osdep.o $(BLOCK_OBJS) $(CC) $(LDFLAGS) -o $@ $^ -lz $(LIBS)
Makefile.target +5 -13
@@ -219,16 +219,11 @@ translate-all.o: translate-all.c cpu.h tcg/tcg.o: cpu.h -machine.o: machine.c - $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $< - # HELPER_CFLAGS is used for all the code compiled with static register # variables -op_helper.o: op_helper.c - $(CC) $(HELPER_CFLAGS) $(CPPFLAGS) $(CFLAGS) $(I386_CFLAGS) -c -o $@ $< +op_helper.o: CFLAGS += $(HELPER_CFLAGS) $(I386_CFLAGS) -cpu-exec.o: cpu-exec.c - $(CC) $(HELPER_CFLAGS) $(CPPFLAGS) $(CFLAGS) -c -o $@ $< +cpu-exec.o: CFLAGS += $(HELPER_CFLAGS) ######################################################### # Linux user emulator target
@@ -356,8 +351,7 @@ OBJS+= libqemu.a # Note: this is a workaround. The real fix is to avoid compiling # cpu_signal_handler() in cpu-exec.c. -signal.o: signal.c - $(CC) $(HELPER_CFLAGS) $(CPPFLAGS) $(CFLAGS) -c -o $@ $< +signal.o: CFLAGS += $(HELPER_CFLAGS) $(QEMU_PROG): $(OBJS) ../libqemu_user.a $(CC) $(LDFLAGS) -o $@ $^ $(LIBS)
@@ -392,8 +386,7 @@ endif # Note: this is a workaround. The real fix is to avoid compiling # cpu_signal_handler() in cpu-exec.c. -signal.o: signal.c - $(CC) $(HELPER_CFLAGS) $(CPPFLAGS) $(CFLAGS) -c -o $@ $< +signal.o: CFLAGS += $(HELPER_CFLAGS) $(QEMU_PROG): $(OBJS) $(CC) $(LDFLAGS) -o $@ $^ $(LIBS)
@@ -497,8 +490,7 @@ endif # Note: this is a workaround. The real fix is to avoid compiling # cpu_signal_handler() in cpu-exec.c. -signal.o: signal.c - $(CC) $(HELPER_CFLAGS) $(CPPFLAGS) $(CFLAGS) -c -o $@ $< +signal.o: CFLAGS += $(HELPER_CFLAGS) $(QEMU_PROG): $(OBJS) ../libqemu_user.a $(CC) $(LDFLAGS) -o $@ $^ $(LIBS)
Signature · 1 line
1.6.0.6
PATCH 3/5 Introduce rules.mak
In reply to Avi KivityAdd a file for common makefile rules.
(Don't forget to 'svn add')
--- Makefile | 8 ++------ Makefile.target | 7 +------ rules.mak | 10 ++++++++++ 3 files changed, 13 insertions(+), 12 deletions(-) create mode 100644 rules.mak
Makefile +2 -6
@@ -7,6 +7,8 @@ include config-host.mak VPATH=$(SRC_PATH):$(SRC_PATH)/hw +include rules.mak + CFLAGS += $(OS_CFLAGS) $(ARCH_CFLAGS) LDFLAGS += $(OS_LDFLAGS) $(ARCH_LDFLAGS)
@@ -188,12 +190,6 @@ libqemu_user.a: $(USER_OBJS) qemu-img$(EXESUF): qemu-img.o qemu-tool.o osdep.o $(BLOCK_OBJS) $(CC) $(LDFLAGS) -o $@ $^ -lz $(LIBS) -%.o: %.c - $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $< - -%.o: %.m - $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $< - qemu-nbd$(EXESUF): qemu-nbd.o qemu-tool.o osdep.o $(BLOCK_OBJS) $(CC) $(LDFLAGS) -o $@ $^ -lz $(LIBS)
Makefile.target +1 -6
@@ -1,4 +1,5 @@ include config.mak +include $(SRC_PATH)/rules.mak TARGET_BASE_ARCH:=$(TARGET_ARCH) ifeq ($(TARGET_ARCH), x86_64)
@@ -731,12 +732,6 @@ else $(SHELL) $(SRC_PATH)/feature_to_c.sh $@ $(TARGET_XML_FILES) endif -%.o: %.c - $(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $< - -%.o: %.S - $(CC) $(CPPFLAGS) -c -o $@ $< - clean: rm -f *.o *.a *~ $(PROGS) nwfpe/*.o fpu/*.o rm -f *.d */*.d tcg/*.o
rules.mak new file +10 -0
@@ -0,0 +1,10 @@ + +%.o: %.c + $(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $< + +%.o: %.S + $(CC) $(CPPFLAGS) -c -o $@ $< + +%.o: %.m + $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $< +
Signature · 1 line
1.6.0.6
[Qemu-devel] Re: [PATCH 3/5] Introduce rules.mak
Quoted 17 lines · Avi Kivity
Add a file for common makefile rules.
Signed-off-by Avi Kivity <[email protected]>(Don't forget to 'svn add')
--- Makefile | 8 ++------ Makefile.target | 7 +------ rules.mak | 10 ++++++++++ 3 files changed, 13 insertions(+), 12 deletions(-) create mode 100644 rules.makMakefile +0
-0
Makefile include config-host.mak · line 11
Quoted 5 lines
Makefile +1
-0@@ -7,6 +7,8 @@ include config-host.mak VPATH=$(SRC_PATH):$(SRC_PATH)/hw +include rules.mak
This breaks the build from an external directory. You at least need to do include $(SRC_PATH)/rules.mak
I noticed you didn't cover the ar command, any particular reason?
Regards,
Anthony Liguori
Re: [Qemu-devel] Re: [PATCH 3/5] Introduce rules.mak
Quoted 6 lines · Anthony Liguori
Quoted 4 lines
VPATH=$(SRC_PATH):$(SRC_PATH)/hw
+include rules.mak
This breaks the build from an external directory. You at least need to do include $(SRC_PATH)/rules.mak
Must have thought VPATH would cover it for me. Fixed.
Quoted 2 lines
I noticed you didn't cover the ar command, any particular reason?
Laziness.
Signature · 1 line
error compiling committee.c: too many arguments to function
PATCH 4/5 Consolidate linker rules
In reply to Avi KivityUse generic rules where posssible, and a LINK macro where not.
--- Makefile | 4 ++-- Makefile.target | 10 ++++++---- rules.mak | 4 ++++ 3 files changed, 12 insertions(+), 6 deletions(-)
Makefile +2 -2
@@ -188,10 +188,10 @@ libqemu_user.a: $(USER_OBJS) ###################################################################### qemu-img$(EXESUF): qemu-img.o qemu-tool.o osdep.o $(BLOCK_OBJS) - $(CC) $(LDFLAGS) -o $@ $^ -lz $(LIBS) qemu-nbd$(EXESUF): qemu-nbd.o qemu-tool.o osdep.o $(BLOCK_OBJS) - $(CC) $(LDFLAGS) -o $@ $^ -lz $(LIBS) + +qemu-img$(EXESUF) qemu-nbd$(EXESUF): LIBS += -lz clean: # avoid old build problems by removing potentially incorrect old files
Makefile.target +6 -4
@@ -355,7 +355,7 @@ OBJS+= libqemu.a signal.o: CFLAGS += $(HELPER_CFLAGS) $(QEMU_PROG): $(OBJS) ../libqemu_user.a - $(CC) $(LDFLAGS) -o $@ $^ $(LIBS) + $(LINK) ifeq ($(ARCH),alpha) # Mark as 32 bit binary, i. e. it will be mapped into the low 31 bit of # the address space (31 bit so sign extending doesn't matter)
@@ -390,7 +390,7 @@ endif signal.o: CFLAGS += $(HELPER_CFLAGS) $(QEMU_PROG): $(OBJS) - $(CC) $(LDFLAGS) -o $@ $^ $(LIBS) + $(LINK) endif #CONFIG_DARWIN_USER
@@ -494,7 +494,7 @@ endif signal.o: CFLAGS += $(HELPER_CFLAGS) $(QEMU_PROG): $(OBJS) ../libqemu_user.a - $(CC) $(LDFLAGS) -o $@ $^ $(LIBS) + $(LINK) endif #CONFIG_BSD_USER
@@ -719,8 +719,10 @@ LDFLAGS+=-p main.o: CFLAGS+=-p endif +$(QEMU_PROG): LIBS += $(SDL_LIBS) $(COCOA_LIBS) $(CURSES_LIBS) $(BRLAPI_LIBS) $(VDE_LIBS) + $(QEMU_PROG): $(OBJS) ../libqemu_common.a libqemu.a - $(CC) $(LDFLAGS) -o $@ $^ $(LIBS) $(SDL_LIBS) $(COCOA_LIBS) $(CURSES_LIBS) $(BRLAPI_LIBS) $(VDE_LIBS) + $(LINK) endif # !CONFIG_USER_ONLY
rules.mak +4 -0
@@ -8,3 +8,7 @@ %.o: %.m $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $< +LINK = $(CC) $(LDFLAGS) -o $@ $^ $(LIBS) + +%$(EXESUF): %.o + $(LINK)
Signature · 1 line
1.6.0.6
PATCH 5/5 Make make output quieter
In reply to Avi KivitySpew out less noise when compiling. This helps review make output for information such as compilation warnings, rather than extra long compiler invocations.
The full output can be generated by supplying a 'V=1' parameter to make.
--- Makefile | 2 +- rules.mak | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-)
Makefile +1 -1
@@ -39,7 +39,7 @@ all: $(TOOLS) $(DOCS) recurse-all SUBDIR_RULES=$(patsubst %,subdir-%, $(TARGET_DIRS)) subdir-%: - $(MAKE) -C $(subst subdir-,,$@) all + $(MAKE) -C $(subst subdir-,,$@) V="$(V)" all $(filter %-softmmu,$(SUBDIR_RULES)): libqemu_common.a $(filter %-user,$(SUBDIR_RULES)): libqemu_user.a
rules.mak +6 -4
@@ -1,14 +1,16 @@ %.o: %.c - $(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $< + $(call quiet-command,$(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $<,CC $@) %.o: %.S - $(CC) $(CPPFLAGS) -c -o $@ $< + $(call quiet-command,$(CC) $(CPPFLAGS) -c -o $@ $<,AS $@) %.o: %.m - $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $< + $(call quiet-command,$(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $<,OBJC $@) -LINK = $(CC) $(LDFLAGS) -o $@ $^ $(LIBS) +LINK = $(call quiet-command,$(CC) $(LDFLAGS) -o $@ $^ $(LIBS),LINK $@) %$(EXESUF): %.o $(LINK) + +quiet-command = $(if $(V),$1,@echo $2 && $1)
Signature · 1 line
1.6.0.6
Quoted 3 lines · Avi Kivity
Minor makefile cleanups; the most significant is the last patch which updates the makefile to generate Linux-style simpified output by default.
I like this series especially because I often miss warnings because of the scrolling mess. Does anyone have an objection to it?
Regards,
Anthony Liguori
Quoted 14 lines
Avi Kivity (5):
DropOP_CFLAGS
Consolidate compiler invocations
Introduce rules.mak
Consolidate linker rules
Make make output quieterMakefile | 25 ++++++---------- Makefile.target | 85 ++++++++++-------------------------------------------- rules.mak | 16 ++++++++++ 3 files changed, 42 insertions(+), 84 deletions(-) create mode 100644 rules.mak
Quoted 6 lines · Anthony Liguori
Quoted 2 lines · Avi Kivity
Minor makefile cleanups; the most significant is the last patch which updates the makefile to generate Linux-style simpified output by default.
I like this series especially because I often miss warnings because of the scrolling mess. Does anyone have an objection to it?
I haven't tested it, but looks ok in principle.
Paul