diff mbox

build: Use separate makefile for "trace/"

Message ID 20121211214412.32738.80113.stgit@fimbulvetr.bsc.es
State New
Headers show

Commit Message

Lluís Vilanova Dec. 11, 2012, 9:44 p.m. UTC
Signed-off-by: Lluís Vilanova <vilanova@ac.upc.edu>
---
 .gitignore                          |    6 +--
 Makefile                            |    8 ++-
 Makefile.objs                       |   64 +---------------------------
 scripts/tracetool/backend/dtrace.py |    2 -
 trace/Makefile.objs                 |   81 +++++++++++++++++++++++++++++++++++
 5 files changed, 92 insertions(+), 69 deletions(-)
 create mode 100644 trace/Makefile.objs

Comments

Paolo Bonzini Dec. 12, 2012, 8:43 a.m. UTC | #1
Il 11/12/2012 22:44, Lluís Vilanova ha scritto:
> Signed-off-by: Lluís Vilanova <vilanova@ac.upc.edu>
> ---
>  .gitignore                          |    6 +--
>  Makefile                            |    8 ++-
>  Makefile.objs                       |   64 +---------------------------
>  scripts/tracetool/backend/dtrace.py |    2 -
>  trace/Makefile.objs                 |   81 +++++++++++++++++++++++++++++++++++
>  5 files changed, 92 insertions(+), 69 deletions(-)
>  create mode 100644 trace/Makefile.objs
> 
> diff --git a/.gitignore b/.gitignore
> index bd6ba1c..b67a37e 100644
> --- a/.gitignore
> +++ b/.gitignore
> @@ -3,9 +3,9 @@ config-all-devices.*
>  config-host.*
>  config-target.*
>  trace.h
> -trace.c
> -trace-dtrace.h
> -trace-dtrace.dtrace
> +trace/generated.c
> +trace/generated-dtrace.h
> +trace/generated-dtrace.dtrace
>  *-timestamp
>  *-softmmu
>  *-darwin-user
> diff --git a/Makefile b/Makefile
> index e9d6848..9dbcca3 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -33,10 +33,10 @@ endif
>  
>  GENERATED_HEADERS = config-host.h trace.h qemu-options.def
>  ifeq ($(TRACE_BACKEND),dtrace)
> -GENERATED_HEADERS += trace-dtrace.h
> +GENERATED_HEADERS += trace/generated-dtrace.h
>  endif
>  GENERATED_HEADERS += qmp-commands.h qapi-types.h qapi-visit.h
> -GENERATED_SOURCES += qmp-marshal.c qapi-types.c qapi-visit.c trace.c
> +GENERATED_SOURCES += qmp-marshal.c qapi-types.c qapi-visit.c trace/generated.c
>  
>  # Don't try to regenerate Makefile or configure
>  # We don't generate any of them
> @@ -252,9 +252,9 @@ clean:
>  	rm -f *.a *.lo $(TOOLS) $(HELPERS-y) qemu-ga TAGS cscope.* *.pod *~ */*~
>  	rm -Rf .libs
>  	rm -f qemu-img-cmds.h
> -	rm -f trace-dtrace.dtrace trace-dtrace.dtrace-timestamp
>  	@# May not be present in GENERATED_HEADERS
> -	rm -f trace-dtrace.h trace-dtrace.h-timestamp
> +	rm -f trace/generated-dtrace.dtrace trace/generated-dtrace.dtrace-timestamp
> +	rm -f trace/generated-dtrace.h trace/generated-dtrace.h-timestamp
>  	rm -f $(foreach f,$(GENERATED_HEADERS),$(f) $(f)-timestamp)
>  	rm -f $(foreach f,$(GENERATED_SOURCES),$(f) $(f)-timestamp)
>  	rm -rf qapi-generated
> diff --git a/Makefile.objs b/Makefile.objs
> index 3c7abca..24832a2 100644
> --- a/Makefile.objs
> +++ b/Makefile.objs
> @@ -147,66 +147,7 @@ libdis-$(CONFIG_LM32_DIS) += lm32-dis.o
>  ######################################################################
>  # trace
>  
> -ifeq ($(TRACE_BACKEND),dtrace)
> -TRACE_H_EXTRA_DEPS=trace-dtrace.h
> -endif
> -trace.h: trace.h-timestamp $(TRACE_H_EXTRA_DEPS)
> -trace.h-timestamp: $(SRC_PATH)/trace-events $(BUILD_DIR)/config-host.mak
> -	$(call quiet-command,$(TRACETOOL) \
> -		--format=h \
> -		--backend=$(TRACE_BACKEND) \
> -		< $< > $@,"  GEN   trace.h")
> -	@cmp -s $@ trace.h || cp $@ trace.h
> -
> -trace.c: trace.c-timestamp
> -trace.c-timestamp: $(SRC_PATH)/trace-events $(BUILD_DIR)/config-host.mak
> -	$(call quiet-command,$(TRACETOOL) \
> -		--format=c \
> -		--backend=$(TRACE_BACKEND) \
> -		< $< > $@,"  GEN   trace.c")
> -	@cmp -s $@ trace.c || cp $@ trace.c
> -
> -trace.o: trace.c $(GENERATED_HEADERS)
> -
> -trace-dtrace.h: trace-dtrace.dtrace
> -	$(call quiet-command,dtrace -o $@ -h -s $<, "  GEN   trace-dtrace.h")
> -
> -# Normal practice is to name DTrace probe file with a '.d' extension
> -# but that gets picked up by QEMU's Makefile as an external dependency
> -# rule file. So we use '.dtrace' instead
> -trace-dtrace.dtrace: trace-dtrace.dtrace-timestamp
> -trace-dtrace.dtrace-timestamp: $(SRC_PATH)/trace-events $(BUILD_DIR)/config-host.mak
> -	$(call quiet-command,$(TRACETOOL) \
> -		--format=d \
> -		--backend=$(TRACE_BACKEND) \
> -		< $< > $@,"  GEN   trace-dtrace.dtrace")
> -	@cmp -s $@ trace-dtrace.dtrace || cp $@ trace-dtrace.dtrace
> -
> -trace-dtrace.o: trace-dtrace.dtrace $(GENERATED_HEADERS)
> -	$(call quiet-command,dtrace -o $@ -G -s $<, "  GEN   trace-dtrace.o")
> -
> -ifeq ($(LIBTOOL),)
> -trace-dtrace.lo: trace-dtrace.dtrace
> -	@echo "missing libtool. please install and rerun configure."; exit 1
> -else
> -trace-dtrace.lo: trace-dtrace.dtrace
> -	$(call quiet-command,$(LIBTOOL) --mode=compile --tag=CC dtrace -o $@ -G -s $<, "  lt GEN trace-dtrace.o")
> -endif
> -
> -trace/simple.o: trace/simple.c $(GENERATED_HEADERS)
> -
> -trace-obj-$(CONFIG_TRACE_DTRACE) += trace-dtrace.o
> -ifneq ($(TRACE_BACKEND),dtrace)
> -trace-obj-y = trace.o
> -endif
> -
> -trace-obj-$(CONFIG_TRACE_DEFAULT) += trace/default.o
> -trace-obj-$(CONFIG_TRACE_SIMPLE) += trace/simple.o
> -trace-obj-$(CONFIG_TRACE_SIMPLE) += qemu-timer-common.o
> -trace-obj-$(CONFIG_TRACE_STDERR) += trace/stderr.o
> -trace-obj-y += trace/control.o
> -
> -$(trace-obj-y): $(GENERATED_HEADERS)
> +trace-obj-y += trace/

Please just put it into oslib-obj-y.

>  ######################################################################
>  # smartcard
> @@ -250,5 +191,6 @@ nested-vars += \
>  	block-obj-y \
>  	user-obj-y \
>  	common-obj-y \
> -	extra-obj-y
> +	extra-obj-y \
> +	trace-obj-y
>  dummy := $(call unnest-vars)
> diff --git a/scripts/tracetool/backend/dtrace.py b/scripts/tracetool/backend/dtrace.py
> index 23c43e2..0cbc68a 100644
> --- a/scripts/tracetool/backend/dtrace.py
> +++ b/scripts/tracetool/backend/dtrace.py
> @@ -37,7 +37,7 @@ def c(events):
>  
>  
>  def h(events):
> -    out('#include "trace-dtrace.h"',
> +    out('#include "trace/generated-dtrace.h"',
>          '')
>  
>      for e in events:
> diff --git a/trace/Makefile.objs b/trace/Makefile.objs
> new file mode 100644
> index 0000000..d7e8cdf
> --- /dev/null
> +++ b/trace/Makefile.objs
> @@ -0,0 +1,81 @@
> +# -*- mode: makefile -*-
> +
> +trace/simple.o: trace/simple.c $(GENERATED_HEADERS)
> +
> +trace-obj-$(CONFIG_TRACE_DEFAULT) += default.o
> +trace-obj-$(CONFIG_TRACE_SIMPLE) += simple.o
> +trace-obj-$(CONFIG_TRACE_SIMPLE) += ../qemu-timer-common.o

Is this line needed?  (Actually, it is obviously unneeded if you use
oslib-obj-y).  I am also worried that it causes duplicate symbols when
you link in both qemu-timer-common.o and trace/../qemu-timer-common.o.
The $(sort) invocation in the LINK macro of rules.mak will not treat
these two paths as duplicate.

> +trace-obj-$(CONFIG_TRACE_STDERR) += stderr.o
> +trace-obj-y += control.o
> +
> +
> +######################################################################
> +# Auto-generated tracing routines
> +
> +# NOTE: "trace.h" is kept in the top-level dir to shorten common include path

Ok, I'll take care of moving it to trace/ later when I do the same for
all other includes.

> +ifeq ($(TRACE_BACKEND),dtrace)
> +TRACE_H_EXTRA_DEPS=trace/generated-dtrace.h
> +endif
> +trace.h: trace.h-timestamp $(TRACE_H_EXTRA_DEPS)
> +trace.h-timestamp: $(SRC_PATH)/trace-events $(BUILD_DIR)/config-host.mak
> +	$(call quiet-command,$(TRACETOOL) \
> +		--format=h \
> +		--backend=$(TRACE_BACKEND) \
> +		< $< > $@,"  GEN   trace.h")
> +	@cmp -s $@ trace.h || cp $@ trace.h
> +
> +
> +trace/generated.c: trace/generated.c-timestamp

Please use $(obj)/generated.c, and similarly for everything else.

> +trace/generated.c-timestamp: $(SRC_PATH)/trace-events $(BUILD_DIR)/config-host.mak
> +	$(call quiet-command,$(TRACETOOL) \
> +		--format=c \
> +		--backend=$(TRACE_BACKEND) \
> +		< $< > $@,"  GEN   trace/generated.c")
> +	@cmp -s $@ trace/generated.c || cp $@ trace/generated.c
> +
> +trace/generated.o: trace/generated.c trace.h
> +
> +
> +ifneq ($(TRACE_BACKEND),dtrace)
> +trace-obj-y += generated.o
> +endif
> +
> +
> +######################################################################
> +# Auto-generated DTrace code
> +
> +# Normal practice is to name DTrace probe file with a '.d' extension
> +# but that gets picked up by QEMU's Makefile as an external dependency
> +# rule file. So we use '.dtrace' instead
> +trace/generated-dtrace.dtrace: trace/generated-dtrace.dtrace-timestamp
> +trace/generated-dtrace.dtrace-timestamp: $(SRC_PATH)/trace-events $(BUILD_DIR)/config-host.mak
> +	$(call quiet-command,$(TRACETOOL) \
> +		--format=d \
> +		--backend=$(TRACE_BACKEND) \
> +		< $< > $@,"  GEN   trace/generated-dtrace.dtrace")
> +	@cmp -s $@ trace/generated-dtrace.dtrace || cp $@ trace/generated-dtrace.dtrace
> +
> +
> +trace/generated-dtrace.h: trace/generated-dtrace.dtrace
> +	$(call quiet-command,dtrace -o $@ -h -s $<, "  GEN   trace/generated-dtrace.h")
> +
> +trace/generated-dtrace.o: trace/generated-dtrace.dtrace $(GENERATED_HEADERS)
> +	$(call quiet-command,dtrace -o $@ -G -s $<, "  GEN   trace/generated-dtrace.o")
> +
> +
> +ifeq ($(LIBTOOL),)
> +trace/generated-dtrace.lo: trace/generated-dtrace.dtrace
> +	@echo "missing libtool. please install and rerun configure."; exit 1
> +else
> +trace/generated-dtrace.lo: trace/generated-dtrace.dtrace
> +	$(call quiet-command,$(LIBTOOL) --mode=compile --tag=CC dtrace -o $@ -G -s $<, "  lt GEN trace/generated-dtrace.lo")
> +endif
> +
> +
> +trace-obj-$(CONFIG_TRACE_DTRACE) += generated-dtrace.o
> +
> +
> +######################################################################
> +# Keep at bottom
> +
> +$(trace-obj-y): $(GENERATED_HEADERS)

This does not do what you think, because trace-obj-y includes a relative
path.  It can be simply

trace/%.o: $(GENERATED_HEADERS)

but it is actually unnecessary because of this in the toplevel:

# Add a dependency on the generated files, so that they are always
# rebuilt before other object files
ifneq ($(filter-out %clean,$(MAKECMDGOALS)),$(if $(MAKECMDGOALS),,fail))
Makefile: $(GENERATED_HEADERS)
endif

Paolo
Lluís Vilanova Dec. 12, 2012, 2:53 p.m. UTC | #2
Paolo Bonzini writes:

> Il 11/12/2012 22:44, Lluís Vilanova ha scritto:
>> Signed-off-by: Lluís Vilanova <vilanova@ac.upc.edu>
>> ---
>> .gitignore                          |    6 +--
>> Makefile                            |    8 ++-
>> Makefile.objs                       |   64 +---------------------------
>> scripts/tracetool/backend/dtrace.py |    2 -
>> trace/Makefile.objs                 |   81 +++++++++++++++++++++++++++++++++++
>> 5 files changed, 92 insertions(+), 69 deletions(-)
>> create mode 100644 trace/Makefile.objs
>> 
>> diff --git a/.gitignore b/.gitignore
>> index bd6ba1c..b67a37e 100644
>> --- a/.gitignore
>> +++ b/.gitignore
>> @@ -3,9 +3,9 @@ config-all-devices.*
>> config-host.*
>> config-target.*
>> trace.h
>> -trace.c
>> -trace-dtrace.h
>> -trace-dtrace.dtrace
>> +trace/generated.c
>> +trace/generated-dtrace.h
>> +trace/generated-dtrace.dtrace
>> *-timestamp
>> *-softmmu
>> *-darwin-user
>> diff --git a/Makefile b/Makefile
>> index e9d6848..9dbcca3 100644
>> --- a/Makefile
>> +++ b/Makefile
>> @@ -33,10 +33,10 @@ endif
>> 
>> GENERATED_HEADERS = config-host.h trace.h qemu-options.def
>> ifeq ($(TRACE_BACKEND),dtrace)
>> -GENERATED_HEADERS += trace-dtrace.h
>> +GENERATED_HEADERS += trace/generated-dtrace.h
>> endif
>> GENERATED_HEADERS += qmp-commands.h qapi-types.h qapi-visit.h
>> -GENERATED_SOURCES += qmp-marshal.c qapi-types.c qapi-visit.c trace.c
>> +GENERATED_SOURCES += qmp-marshal.c qapi-types.c qapi-visit.c trace/generated.c
>> 
>> # Don't try to regenerate Makefile or configure
>> # We don't generate any of them
>> @@ -252,9 +252,9 @@ clean:
>> rm -f *.a *.lo $(TOOLS) $(HELPERS-y) qemu-ga TAGS cscope.* *.pod *~ */*~
>> rm -Rf .libs
>> rm -f qemu-img-cmds.h
>> -	rm -f trace-dtrace.dtrace trace-dtrace.dtrace-timestamp
>> @# May not be present in GENERATED_HEADERS
>> -	rm -f trace-dtrace.h trace-dtrace.h-timestamp
>> +	rm -f trace/generated-dtrace.dtrace trace/generated-dtrace.dtrace-timestamp
>> +	rm -f trace/generated-dtrace.h trace/generated-dtrace.h-timestamp
>> rm -f $(foreach f,$(GENERATED_HEADERS),$(f) $(f)-timestamp)
>> rm -f $(foreach f,$(GENERATED_SOURCES),$(f) $(f)-timestamp)
>> rm -rf qapi-generated
>> diff --git a/Makefile.objs b/Makefile.objs
>> index 3c7abca..24832a2 100644
>> --- a/Makefile.objs
>> +++ b/Makefile.objs
>> @@ -147,66 +147,7 @@ libdis-$(CONFIG_LM32_DIS) += lm32-dis.o
>> ######################################################################
>> # trace
>> 
>> -ifeq ($(TRACE_BACKEND),dtrace)
>> -TRACE_H_EXTRA_DEPS=trace-dtrace.h
>> -endif
>> -trace.h: trace.h-timestamp $(TRACE_H_EXTRA_DEPS)
>> -trace.h-timestamp: $(SRC_PATH)/trace-events $(BUILD_DIR)/config-host.mak
>> -	$(call quiet-command,$(TRACETOOL) \
>> -		--format=h \
>> -		--backend=$(TRACE_BACKEND) \
>> -		< $< > $@,"  GEN   trace.h")
>> -	@cmp -s $@ trace.h || cp $@ trace.h
>> -
>> -trace.c: trace.c-timestamp
>> -trace.c-timestamp: $(SRC_PATH)/trace-events $(BUILD_DIR)/config-host.mak
>> -	$(call quiet-command,$(TRACETOOL) \
>> -		--format=c \
>> -		--backend=$(TRACE_BACKEND) \
>> -		< $< > $@,"  GEN   trace.c")
>> -	@cmp -s $@ trace.c || cp $@ trace.c
>> -
>> -trace.o: trace.c $(GENERATED_HEADERS)
>> -
>> -trace-dtrace.h: trace-dtrace.dtrace
>> -	$(call quiet-command,dtrace -o $@ -h -s $<, "  GEN   trace-dtrace.h")
>> -
>> -# Normal practice is to name DTrace probe file with a '.d' extension
>> -# but that gets picked up by QEMU's Makefile as an external dependency
>> -# rule file. So we use '.dtrace' instead
>> -trace-dtrace.dtrace: trace-dtrace.dtrace-timestamp
>> -trace-dtrace.dtrace-timestamp: $(SRC_PATH)/trace-events $(BUILD_DIR)/config-host.mak
>> -	$(call quiet-command,$(TRACETOOL) \
>> -		--format=d \
>> -		--backend=$(TRACE_BACKEND) \
>> -		< $< > $@,"  GEN   trace-dtrace.dtrace")
>> -	@cmp -s $@ trace-dtrace.dtrace || cp $@ trace-dtrace.dtrace
>> -
>> -trace-dtrace.o: trace-dtrace.dtrace $(GENERATED_HEADERS)
>> -	$(call quiet-command,dtrace -o $@ -G -s $<, "  GEN   trace-dtrace.o")
>> -
>> -ifeq ($(LIBTOOL),)
>> -trace-dtrace.lo: trace-dtrace.dtrace
>> -	@echo "missing libtool. please install and rerun configure."; exit 1
>> -else
>> -trace-dtrace.lo: trace-dtrace.dtrace
>> -	$(call quiet-command,$(LIBTOOL) --mode=compile --tag=CC dtrace -o $@ -G -s $<, "  lt GEN trace-dtrace.o")
>> -endif
>> -
>> -trace/simple.o: trace/simple.c $(GENERATED_HEADERS)
>> -
>> -trace-obj-$(CONFIG_TRACE_DTRACE) += trace-dtrace.o
>> -ifneq ($(TRACE_BACKEND),dtrace)
>> -trace-obj-y = trace.o
>> -endif
>> -
>> -trace-obj-$(CONFIG_TRACE_DEFAULT) += trace/default.o
>> -trace-obj-$(CONFIG_TRACE_SIMPLE) += trace/simple.o
>> -trace-obj-$(CONFIG_TRACE_SIMPLE) += qemu-timer-common.o
>> -trace-obj-$(CONFIG_TRACE_STDERR) += trace/stderr.o
>> -trace-obj-y += trace/control.o
>> -
>> -$(trace-obj-y): $(GENERATED_HEADERS)
>> +trace-obj-y += trace/

> Please just put it into oslib-obj-y.

You mean line "trace-obj-y += trace/"?


>> ######################################################################
>> # smartcard
>> @@ -250,5 +191,6 @@ nested-vars += \
>> block-obj-y \
>> user-obj-y \
>> common-obj-y \
>> -	extra-obj-y
>> +	extra-obj-y \
>> +	trace-obj-y
>> dummy := $(call unnest-vars)
>> diff --git a/scripts/tracetool/backend/dtrace.py b/scripts/tracetool/backend/dtrace.py
>> index 23c43e2..0cbc68a 100644
>> --- a/scripts/tracetool/backend/dtrace.py
>> +++ b/scripts/tracetool/backend/dtrace.py
>> @@ -37,7 +37,7 @@ def c(events):
>> 
>> 
>> def h(events):
>> -    out('#include "trace-dtrace.h"',
>> +    out('#include "trace/generated-dtrace.h"',
>> '')
>> 
>> for e in events:
>> diff --git a/trace/Makefile.objs b/trace/Makefile.objs
>> new file mode 100644
>> index 0000000..d7e8cdf
>> --- /dev/null
>> +++ b/trace/Makefile.objs
>> @@ -0,0 +1,81 @@
>> +# -*- mode: makefile -*-
>> +
>> +trace/simple.o: trace/simple.c $(GENERATED_HEADERS)
>> +
>> +trace-obj-$(CONFIG_TRACE_DEFAULT) += default.o
>> +trace-obj-$(CONFIG_TRACE_SIMPLE) += simple.o
>> +trace-obj-$(CONFIG_TRACE_SIMPLE) += ../qemu-timer-common.o

> Is this line needed?  (Actually, it is obviously unneeded if you use
> oslib-obj-y).  I am also worried that it causes duplicate symbols when
> you link in both qemu-timer-common.o and trace/../qemu-timer-common.o.
> The $(sort) invocation in the LINK macro of rules.mak will not treat
> these two paths as duplicate.

"trace-obj-y" is required by some binaries other than QEMU itself, as they use
routines that require the tracing infrastructure (e.g., qemu-img, which only
includes "qemu-timer-common.o" as a dependency through "tools-obj-y").

I'm not sure how the subdir magic treats paths, but mapping all paths in final
vars into their respective absolute path should simplify things.

In any case, compiling with backends none, stderr, and stdout turns up no
linking problems.


>> +trace-obj-$(CONFIG_TRACE_STDERR) += stderr.o
>> +trace-obj-y += control.o
>> +
>> +
>> +######################################################################
>> +# Auto-generated tracing routines
>> +
>> +# NOTE: "trace.h" is kept in the top-level dir to shorten common include path

> Ok, I'll take care of moving it to trace/ later when I do the same for
> all other includes.

I'll send a new version generating "trace/generated.h" and having "trace.h" just
include it for now.


>> +ifeq ($(TRACE_BACKEND),dtrace)
>> +TRACE_H_EXTRA_DEPS=trace/generated-dtrace.h
>> +endif
>> +trace.h: trace.h-timestamp $(TRACE_H_EXTRA_DEPS)
>> +trace.h-timestamp: $(SRC_PATH)/trace-events $(BUILD_DIR)/config-host.mak
>> +	$(call quiet-command,$(TRACETOOL) \
>> +		--format=h \
>> +		--backend=$(TRACE_BACKEND) \
>> +		< $< > $@,"  GEN   trace.h")
>> +	@cmp -s $@ trace.h || cp $@ trace.h
>> +
>> +
>> +trace/generated.c: trace/generated.c-timestamp

> Please use $(obj)/generated.c, and similarly for everything else.

Tried it, but "obj" is set to ".", although looking at "rules.mak" that should
not be the case...

Inserting "$(error obj=$(obj))" in "trace/Makefile.objs" shows "./trace", but
echoing "obj" in any of the rules shows ".".


>> +trace/generated.c-timestamp: $(SRC_PATH)/trace-events $(BUILD_DIR)/config-host.mak
>> +	$(call quiet-command,$(TRACETOOL) \
>> +		--format=c \
>> +		--backend=$(TRACE_BACKEND) \
>> +		< $< > $@,"  GEN   trace/generated.c")
>> +	@cmp -s $@ trace/generated.c || cp $@ trace/generated.c
>> +
>> +trace/generated.o: trace/generated.c trace.h
>> +
>> +
>> +ifneq ($(TRACE_BACKEND),dtrace)
>> +trace-obj-y += generated.o
>> +endif
>> +
>> +
>> +######################################################################
>> +# Auto-generated DTrace code
>> +
>> +# Normal practice is to name DTrace probe file with a '.d' extension
>> +# but that gets picked up by QEMU's Makefile as an external dependency
>> +# rule file. So we use '.dtrace' instead
>> +trace/generated-dtrace.dtrace: trace/generated-dtrace.dtrace-timestamp
>> +trace/generated-dtrace.dtrace-timestamp: $(SRC_PATH)/trace-events $(BUILD_DIR)/config-host.mak
>> +	$(call quiet-command,$(TRACETOOL) \
>> +		--format=d \
>> +		--backend=$(TRACE_BACKEND) \
>> +		< $< > $@,"  GEN   trace/generated-dtrace.dtrace")
>> +	@cmp -s $@ trace/generated-dtrace.dtrace || cp $@ trace/generated-dtrace.dtrace
>> +
>> +
>> +trace/generated-dtrace.h: trace/generated-dtrace.dtrace
>> +	$(call quiet-command,dtrace -o $@ -h -s $<, "  GEN   trace/generated-dtrace.h")
>> +
>> +trace/generated-dtrace.o: trace/generated-dtrace.dtrace $(GENERATED_HEADERS)
>> +	$(call quiet-command,dtrace -o $@ -G -s $<, "  GEN   trace/generated-dtrace.o")
>> +
>> +
>> +ifeq ($(LIBTOOL),)
>> +trace/generated-dtrace.lo: trace/generated-dtrace.dtrace
>> +	@echo "missing libtool. please install and rerun configure."; exit 1
>> +else
>> +trace/generated-dtrace.lo: trace/generated-dtrace.dtrace
>> +	$(call quiet-command,$(LIBTOOL) --mode=compile --tag=CC dtrace -o $@ -G -s $<, "  lt GEN trace/generated-dtrace.lo")
>> +endif
>> +
>> +
>> +trace-obj-$(CONFIG_TRACE_DTRACE) += generated-dtrace.o
>> +
>> +
>> +######################################################################
>> +# Keep at bottom
>> +
>> +$(trace-obj-y): $(GENERATED_HEADERS)

> This does not do what you think, because trace-obj-y includes a relative
> path.  It can be simply

> trace/%.o: $(GENERATED_HEADERS)

> but it is actually unnecessary because of this in the toplevel:

> # Add a dependency on the generated files, so that they are always
> # rebuilt before other object files
> ifneq ($(filter-out %clean,$(MAKECMDGOALS)),$(if $(MAKECMDGOALS),,fail))
> Makefile: $(GENERATED_HEADERS)
> endif

Nice, I wasn't aware of this addition. Then I suppose none of the rules need to
depend on GENERATED_HEADERS.


BTW, can I extend the GENERATED_HEADERS variable contents right from
"trace/Makefile.objs" even though it's not explicitly included from the
top-level makefile?


I'm sure this has already been previously discussed to the point of extenuation,
but what are the reasons for not using autotools?


Thanks,
  Lluis
Paolo Bonzini Dec. 13, 2012, 8:44 a.m. UTC | #3
Il 12/12/2012 15:53, Lluís Vilanova ha scritto:
> Paolo Bonzini writes:
> 
>> Il 11/12/2012 22:44, Lluís Vilanova ha scritto:
>>> Signed-off-by: Lluís Vilanova <vilanova@ac.upc.edu>
>>> ---
>>> .gitignore                          |    6 +--
>>> Makefile                            |    8 ++-
>>> Makefile.objs                       |   64 +---------------------------
>>> scripts/tracetool/backend/dtrace.py |    2 -
>>> trace/Makefile.objs                 |   81 +++++++++++++++++++++++++++++++++++
>>> 5 files changed, 92 insertions(+), 69 deletions(-)
>>> create mode 100644 trace/Makefile.objs
>>>
>>> diff --git a/.gitignore b/.gitignore
>>> index bd6ba1c..b67a37e 100644
>>> --- a/.gitignore
>>> +++ b/.gitignore
>>> @@ -3,9 +3,9 @@ config-all-devices.*
>>> config-host.*
>>> config-target.*
>>> trace.h
>>> -trace.c
>>> -trace-dtrace.h
>>> -trace-dtrace.dtrace
>>> +trace/generated.c
>>> +trace/generated-dtrace.h
>>> +trace/generated-dtrace.dtrace
>>> *-timestamp
>>> *-softmmu
>>> *-darwin-user
>>> diff --git a/Makefile b/Makefile
>>> index e9d6848..9dbcca3 100644
>>> --- a/Makefile
>>> +++ b/Makefile
>>> @@ -33,10 +33,10 @@ endif
>>>
>>> GENERATED_HEADERS = config-host.h trace.h qemu-options.def
>>> ifeq ($(TRACE_BACKEND),dtrace)
>>> -GENERATED_HEADERS += trace-dtrace.h
>>> +GENERATED_HEADERS += trace/generated-dtrace.h
>>> endif
>>> GENERATED_HEADERS += qmp-commands.h qapi-types.h qapi-visit.h
>>> -GENERATED_SOURCES += qmp-marshal.c qapi-types.c qapi-visit.c trace.c
>>> +GENERATED_SOURCES += qmp-marshal.c qapi-types.c qapi-visit.c trace/generated.c
>>>
>>> # Don't try to regenerate Makefile or configure
>>> # We don't generate any of them
>>> @@ -252,9 +252,9 @@ clean:
>>> rm -f *.a *.lo $(TOOLS) $(HELPERS-y) qemu-ga TAGS cscope.* *.pod *~ */*~
>>> rm -Rf .libs
>>> rm -f qemu-img-cmds.h
>>> -	rm -f trace-dtrace.dtrace trace-dtrace.dtrace-timestamp
>>> @# May not be present in GENERATED_HEADERS
>>> -	rm -f trace-dtrace.h trace-dtrace.h-timestamp
>>> +	rm -f trace/generated-dtrace.dtrace trace/generated-dtrace.dtrace-timestamp
>>> +	rm -f trace/generated-dtrace.h trace/generated-dtrace.h-timestamp
>>> rm -f $(foreach f,$(GENERATED_HEADERS),$(f) $(f)-timestamp)
>>> rm -f $(foreach f,$(GENERATED_SOURCES),$(f) $(f)-timestamp)
>>> rm -rf qapi-generated
>>> diff --git a/Makefile.objs b/Makefile.objs
>>> index 3c7abca..24832a2 100644
>>> --- a/Makefile.objs
>>> +++ b/Makefile.objs
>>> @@ -147,66 +147,7 @@ libdis-$(CONFIG_LM32_DIS) += lm32-dis.o
>>> ######################################################################
>>> # trace
>>>
>>> -ifeq ($(TRACE_BACKEND),dtrace)
>>> -TRACE_H_EXTRA_DEPS=trace-dtrace.h
>>> -endif
>>> -trace.h: trace.h-timestamp $(TRACE_H_EXTRA_DEPS)
>>> -trace.h-timestamp: $(SRC_PATH)/trace-events $(BUILD_DIR)/config-host.mak
>>> -	$(call quiet-command,$(TRACETOOL) \
>>> -		--format=h \
>>> -		--backend=$(TRACE_BACKEND) \
>>> -		< $< > $@,"  GEN   trace.h")
>>> -	@cmp -s $@ trace.h || cp $@ trace.h
>>> -
>>> -trace.c: trace.c-timestamp
>>> -trace.c-timestamp: $(SRC_PATH)/trace-events $(BUILD_DIR)/config-host.mak
>>> -	$(call quiet-command,$(TRACETOOL) \
>>> -		--format=c \
>>> -		--backend=$(TRACE_BACKEND) \
>>> -		< $< > $@,"  GEN   trace.c")
>>> -	@cmp -s $@ trace.c || cp $@ trace.c
>>> -
>>> -trace.o: trace.c $(GENERATED_HEADERS)
>>> -
>>> -trace-dtrace.h: trace-dtrace.dtrace
>>> -	$(call quiet-command,dtrace -o $@ -h -s $<, "  GEN   trace-dtrace.h")
>>> -
>>> -# Normal practice is to name DTrace probe file with a '.d' extension
>>> -# but that gets picked up by QEMU's Makefile as an external dependency
>>> -# rule file. So we use '.dtrace' instead
>>> -trace-dtrace.dtrace: trace-dtrace.dtrace-timestamp
>>> -trace-dtrace.dtrace-timestamp: $(SRC_PATH)/trace-events $(BUILD_DIR)/config-host.mak
>>> -	$(call quiet-command,$(TRACETOOL) \
>>> -		--format=d \
>>> -		--backend=$(TRACE_BACKEND) \
>>> -		< $< > $@,"  GEN   trace-dtrace.dtrace")
>>> -	@cmp -s $@ trace-dtrace.dtrace || cp $@ trace-dtrace.dtrace
>>> -
>>> -trace-dtrace.o: trace-dtrace.dtrace $(GENERATED_HEADERS)
>>> -	$(call quiet-command,dtrace -o $@ -G -s $<, "  GEN   trace-dtrace.o")
>>> -
>>> -ifeq ($(LIBTOOL),)
>>> -trace-dtrace.lo: trace-dtrace.dtrace
>>> -	@echo "missing libtool. please install and rerun configure."; exit 1
>>> -else
>>> -trace-dtrace.lo: trace-dtrace.dtrace
>>> -	$(call quiet-command,$(LIBTOOL) --mode=compile --tag=CC dtrace -o $@ -G -s $<, "  lt GEN trace-dtrace.o")
>>> -endif
>>> -
>>> -trace/simple.o: trace/simple.c $(GENERATED_HEADERS)
>>> -
>>> -trace-obj-$(CONFIG_TRACE_DTRACE) += trace-dtrace.o
>>> -ifneq ($(TRACE_BACKEND),dtrace)
>>> -trace-obj-y = trace.o
>>> -endif
>>> -
>>> -trace-obj-$(CONFIG_TRACE_DEFAULT) += trace/default.o
>>> -trace-obj-$(CONFIG_TRACE_SIMPLE) += trace/simple.o
>>> -trace-obj-$(CONFIG_TRACE_SIMPLE) += qemu-timer-common.o
>>> -trace-obj-$(CONFIG_TRACE_STDERR) += trace/stderr.o
>>> -trace-obj-y += trace/control.o
>>> -
>>> -$(trace-obj-y): $(GENERATED_HEADERS)
>>> +trace-obj-y += trace/
> 
>> Please just put it into oslib-obj-y.
> 
> You mean line "trace-obj-y += trace/"?

Yeah, make it

oslib-obj-y += trace/

and get rid of trace-obj-y.

> 
>>> ######################################################################
>>> # smartcard
>>> @@ -250,5 +191,6 @@ nested-vars += \
>>> block-obj-y \
>>> user-obj-y \
>>> common-obj-y \
>>> -	extra-obj-y
>>> +	extra-obj-y \
>>> +	trace-obj-y
>>> dummy := $(call unnest-vars)
>>> diff --git a/scripts/tracetool/backend/dtrace.py b/scripts/tracetool/backend/dtrace.py
>>> index 23c43e2..0cbc68a 100644
>>> --- a/scripts/tracetool/backend/dtrace.py
>>> +++ b/scripts/tracetool/backend/dtrace.py
>>> @@ -37,7 +37,7 @@ def c(events):
>>>
>>>
>>> def h(events):
>>> -    out('#include "trace-dtrace.h"',
>>> +    out('#include "trace/generated-dtrace.h"',
>>> '')
>>>
>>> for e in events:
>>> diff --git a/trace/Makefile.objs b/trace/Makefile.objs
>>> new file mode 100644
>>> index 0000000..d7e8cdf
>>> --- /dev/null
>>> +++ b/trace/Makefile.objs
>>> @@ -0,0 +1,81 @@
>>> +# -*- mode: makefile -*-
>>> +
>>> +trace/simple.o: trace/simple.c $(GENERATED_HEADERS)
>>> +
>>> +trace-obj-$(CONFIG_TRACE_DEFAULT) += default.o
>>> +trace-obj-$(CONFIG_TRACE_SIMPLE) += simple.o
>>> +trace-obj-$(CONFIG_TRACE_SIMPLE) += ../qemu-timer-common.o
> 
>> Is this line needed?  (Actually, it is obviously unneeded if you use
>> oslib-obj-y).  I am also worried that it causes duplicate symbols when
>> you link in both qemu-timer-common.o and trace/../qemu-timer-common.o.
>> The $(sort) invocation in the LINK macro of rules.mak will not treat
>> these two paths as duplicate.
> 
> "trace-obj-y" is required by some binaries other than QEMU itself, as they use
> routines that require the tracing infrastructure (e.g., qemu-img, which only
> includes "qemu-timer-common.o" as a dependency through "tools-obj-y").

Yes, but they all use oslib-obj-y too.  qemu-timer-common.o is part of
oslib-obj-y.

> I'm not sure how the subdir magic treats paths, but mapping all paths in final
> vars into their respective absolute path should simplify things.

Difficult to do in make. :(

> In any case, compiling with backends none, stderr, and stdout turns up no
> linking problems.

And simple too?  (I suppose stdout is a typo for simple).

> 
>>> +trace-obj-$(CONFIG_TRACE_STDERR) += stderr.o
>>> +trace-obj-y += control.o
>>> +
>>> +
>>> +######################################################################
>>> +# Auto-generated tracing routines
>>> +
>>> +# NOTE: "trace.h" is kept in the top-level dir to shorten common include path
> 
>> Ok, I'll take care of moving it to trace/ later when I do the same for
>> all other includes.
> 
> I'll send a new version generating "trace/generated.h" and having "trace.h" just
> include it for now.

Ok, thanks.

> 
>>> +ifeq ($(TRACE_BACKEND),dtrace)
>>> +TRACE_H_EXTRA_DEPS=trace/generated-dtrace.h
>>> +endif
>>> +trace.h: trace.h-timestamp $(TRACE_H_EXTRA_DEPS)
>>> +trace.h-timestamp: $(SRC_PATH)/trace-events $(BUILD_DIR)/config-host.mak
>>> +	$(call quiet-command,$(TRACETOOL) \
>>> +		--format=h \
>>> +		--backend=$(TRACE_BACKEND) \
>>> +		< $< > $@,"  GEN   trace.h")
>>> +	@cmp -s $@ trace.h || cp $@ trace.h
>>> +
>>> +
>>> +trace/generated.c: trace/generated.c-timestamp
> 
>> Please use $(obj)/generated.c, and similarly for everything else.
> 
> Tried it, but "obj" is set to ".", although looking at "rules.mak" that should
> not be the case...
> 
> Inserting "$(error obj=$(obj))" in "trace/Makefile.objs" shows "./trace", but
> echoing "obj" in any of the rules shows ".".

In the rules it is, because the rules expand variables later when the
command runs.  But in the targets it should be evaluated correctly,
because the targets expand variables earlier when they are read.  As
long as you use $@ and $< and $^ in the rules, you're safe.  Anyway,
this can be done later.

> BTW, can I extend the GENERATED_HEADERS variable contents right from
> "trace/Makefile.objs" even though it's not explicitly included from the
> top-level makefile?

Hmm, risky. :)  Need to look at the actual patch, let's do one thing at
a time.

> I'm sure this has already been previously discussed to the point of extenuation,
> but what are the reasons for not using autotools?

Autoconf -> no point, but someone needs to do the work.

Automake -> the build system is just too different.

Libtool -> using it already. :)

Paolo
Lluís Vilanova Dec. 13, 2012, 2:38 p.m. UTC | #4
Paolo Bonzini writes:
[...]
>>>> -
>>>> -$(trace-obj-y): $(GENERATED_HEADERS)
>>>> +trace-obj-y += trace/
>> 
>>> Please just put it into oslib-obj-y.
>> 
>> You mean line "trace-obj-y += trace/"?

> Yeah, make it

> oslib-obj-y += trace/

> and get rid of trace-obj-y.

Mmm, but according to Makefile.objs:

  oslib-obj-y is code depending on the OS (win32 vs posix)


[...]
>> "trace-obj-y" is required by some binaries other than QEMU itself, as they use
>> routines that require the tracing infrastructure (e.g., qemu-img, which only
>> includes "qemu-timer-common.o" as a dependency through "tools-obj-y").

> Yes, but they all use oslib-obj-y too.  qemu-timer-common.o is part of
> oslib-obj-y.

Removed. Still, see above.


>> I'm not sure how the subdir magic treats paths, but mapping all paths in final
>> vars into their respective absolute path should simplify things.

> Difficult to do in make. :(

Among many other things, AFAIR the linux kernel build system uses absolute
paths, but I think it also uses make to get into each subdirectory (as opposed
to QEMU), which I simplifies coding such a build system.


>> In any case, compiling with backends none, stderr, and stdout turns up no
>> linking problems.

> And simple too?  (I suppose stdout is a typo for simple).

Yes, sorry.


>>>> +ifeq ($(TRACE_BACKEND),dtrace)
>>>> +TRACE_H_EXTRA_DEPS=trace/generated-dtrace.h
>>>> +endif
>>>> +trace.h: trace.h-timestamp $(TRACE_H_EXTRA_DEPS)
>>>> +trace.h-timestamp: $(SRC_PATH)/trace-events $(BUILD_DIR)/config-host.mak
>>>> +	$(call quiet-command,$(TRACETOOL) \
>>>> +		--format=h \
>>>> +		--backend=$(TRACE_BACKEND) \
>>>> +		< $< > $@,"  GEN   trace.h")
>>>> +	@cmp -s $@ trace.h || cp $@ trace.h
>>>> +
>>>> +
>>>> +trace/generated.c: trace/generated.c-timestamp
>> 
>>> Please use $(obj)/generated.c, and similarly for everything else.
>> 
>> Tried it, but "obj" is set to ".", although looking at "rules.mak" that should
>> not be the case...
>> 
>> Inserting "$(error obj=$(obj))" in "trace/Makefile.objs" shows "./trace", but
>> echoing "obj" in any of the rules shows ".".

> In the rules it is, because the rules expand variables later when the
> command runs.  But in the targets it should be evaluated correctly,
> because the targets expand variables earlier when they are read.  As
> long as you use $@ and $< and $^ in the rules, you're safe.  Anyway,
> this can be done later.

Ok, done. But this behaviour easily leads to errors. It might be safer to switch
into a per-directory call to $(MAKE), although this would for sure be a
completely different patch.


>> BTW, can I extend the GENERATED_HEADERS variable contents right from
>> "trace/Makefile.objs" even though it's not explicitly included from the
>> top-level makefile?

> Hmm, risky. :)  Need to look at the actual patch, let's do one thing at
> a time.

For now I'll leave it just as it is.


>> I'm sure this has already been previously discussed to the point of extenuation,
>> but what are the reasons for not using autotools?

> Autoconf -> no point, but someone needs to do the work.

> Automake -> the build system is just too different.

> Libtool -> using it already. :)


Ok, so it's not something against the suite per-se, but about porting work.

The thing I like about automake is that it provides a clear set of vars to
manage the per-dir builds, thanks to using a per-dir $(MAKE); but I'm not sure
how the per-target build would be managed (except by having a separate
configure+make for each of them).

This could also be provided by having the QEMU build infrastructure use $(MAKE)
to enter into each directory, and having it produce an ar file (or a set of them)
with a "standard" name as a result (using libtool).

But I'm not sure how well would that work when building in Windows (is libtool
available there?).


Thanks,
  Lluis
Paolo Bonzini Dec. 14, 2012, 8:14 a.m. UTC | #5
> > Yeah, make it
> 
> > oslib-obj-y += trace/
> 
> > and get rid of trace-obj-y.
> 
> Mmm, but according to Makefile.objs:
> 
>   oslib-obj-y is code depending on the OS (win32 vs posix)

True... I'd like to simplify this jungle sooner or later though.

We can keep trace-obj-y, but please do leave out qemu-timer-common.o

> > > I'm not sure how the subdir magic treats paths, but mapping all paths
> > > in final vars into their respective absolute path should simplify things.
> 
> > Difficult to do in make. :(
> 
> Among many other things, AFAIR the linux kernel build system uses absolute
> paths, but I think it also uses make to get into each subdirectory (as opposed
> to QEMU), which I simplifies coding such a build system.

We already use recursive make to compile each target.  I think the current QEMU
build system is a good balance between non-recursive and recursive make.

> > I'm sure this has already been previously discussed to the point of extenuation,
> > but what are the reasons for not using autotools?
> 
> > Autoconf -> no point, but someone needs to do the work.
> 
> > Automake -> the build system is just too different.
> 
> > Libtool -> using it already. :)
> 
> 
> Ok, so it's not something against the suite per-se, but about porting work.
> 
> The thing I like about automake is that it provides a clear set of vars to
> manage the per-dir builds, thanks to using a per-dir $(MAKE); but I'm
> not sure how the per-target build would be managed (except by having a
> separate configure+make for each of them).

Yes, that would be it.  Even an autoconf conversion probably would have
to use separate configure scripts for the global project and for each
target.

> This could also be provided by having the QEMU build infrastructure use $(MAKE)
> to enter into each directory, and having it produce an ar file (or a
> set of them) with a "standard" name as a result (using libtool).

Doesn't need to use libtool.  Static libraries are just fine.  The problem
is that ar doesn't work well with constructors, which we use for module.c.
It is what QEMU used to use, but Andreas moved away a couple of years ago
and I think it is an improvement.

> But I'm not sure how well would that work when building in Windows
> (is libtool available there?).

Yes.

Paolo
Lluís Vilanova Dec. 14, 2012, 1:46 p.m. UTC | #6
Paolo Bonzini writes:

>> > Yeah, make it
>> 
>> > oslib-obj-y += trace/
>> 
>> > and get rid of trace-obj-y.
>> 
>> Mmm, but according to Makefile.objs:
>> 
>> oslib-obj-y is code depending on the OS (win32 vs posix)

> True... I'd like to simplify this jungle sooner or later though.

> We can keep trace-obj-y, but please do leave out qemu-timer-common.o

Done, I'll send v2 later today.


[...]
>> > I'm sure this has already been previously discussed to the point of extenuation,
>> > but what are the reasons for not using autotools?
>> 
>> > Autoconf -> no point, but someone needs to do the work.
>> 
>> > Automake -> the build system is just too different.
>> 
>> > Libtool -> using it already. :)
>> 
>> 
>> Ok, so it's not something against the suite per-se, but about porting work.
>> 
>> The thing I like about automake is that it provides a clear set of vars to
>> manage the per-dir builds, thanks to using a per-dir $(MAKE); but I'm
>> not sure how the per-target build would be managed (except by having a
>> separate configure+make for each of them).

> Yes, that would be it.

I'd certainly love to see something along those lines for the sake of makefile
simplicity.


> Even an autoconf conversion probably would have to use separate configure
> scripts for the global project and for each target.

If you're willing to pay for a complete recompilation for each target you can
just have a single configure file.


>> This could also be provided by having the QEMU build infrastructure use $(MAKE)
>> to enter into each directory, and having it produce an ar file (or a
>> set of them) with a "standard" name as a result (using libtool).

> Doesn't need to use libtool.  Static libraries are just fine.  The problem
> is that ar doesn't work well with constructors, which we use for module.c.
> It is what QEMU used to use, but Andreas moved away a couple of years ago
> and I think it is an improvement.

Ah, I know that one in gcc :)

  -Wl,--whole-archive foo.a -Wl,--no-whole-archive


Thanks,
  Lluis
Paolo Bonzini Dec. 14, 2012, 1:50 p.m. UTC | #7
Il 14/12/2012 14:46, Lluís Vilanova ha scritto:
>>> The thing I like about automake is that it provides a clear set of vars to
>>> manage the per-dir builds, thanks to using a per-dir $(MAKE); but I'm
>>> not sure how the per-target build would be managed (except by having a
>>> separate configure+make for each of them).
>>> Yes, that would be it.
> 
> I'd certainly love to see something along those lines for the sake of makefile
> simplicity.

QEMU is complex enough that I'm not really sure what Automake would buy.

>> > Even an autoconf conversion probably would have to use separate configure
>> > scripts for the global project and for each target.
> If you're willing to pay for a complete recompilation for each target you can
> just have a single configure file.

That's not the problem.  The problem is that Autoconf does not lend well
to the style of the QEMU build system, with many subparts that are
enabled/disabled at configure time.

> Ah, I know that one in gcc 
> 
>   -Wl,--whole-archive foo.a -Wl,--no-whole-archive

Really in ld (that's what -Wl does) and not very portable...

Paolo
Lluís Vilanova Dec. 14, 2012, 3:04 p.m. UTC | #8
Paolo Bonzini writes:

> Il 14/12/2012 14:46, Lluís Vilanova ha scritto:
>>>> The thing I like about automake is that it provides a clear set of vars to
>>>> manage the per-dir builds, thanks to using a per-dir $(MAKE); but I'm
>>>> not sure how the per-target build would be managed (except by having a
>>>> separate configure+make for each of them).
>>>> Yes, that would be it.
>> 
>> I'd certainly love to see something along those lines for the sake of makefile
>> simplicity.

> QEMU is complex enough that I'm not really sure what Automake would buy.

I'm just talking about having a build system (automake or not) that uses some
"standard" set of vars to establish what to do, plus per-directory make to
simplify management of per-directory vars (if ever needed).


>>> > Even an autoconf conversion probably would have to use separate configure
>>> > scripts for the global project and for each target.
>> If you're willing to pay for a complete recompilation for each target you can
>> just have a single configure file.

> That's not the problem.  The problem is that Autoconf does not lend well
> to the style of the QEMU build system, with many subparts that are
> enabled/disabled at configure time.

Well, for that you have conditional compilation. The linux style (obj-y) is
easier to understand, but AFAIR automake provided broader features.


>> Ah, I know that one in gcc 
>> 
>> -Wl,--whole-archive foo.a -Wl,--no-whole-archive

> Really in ld (that's what -Wl does) and not very portable...

I know, but I had no idea about the portability issues.


Again, don't take it as an intent to start some autotools flame, I was just
curious :)


Lluis
diff mbox

Patch

diff --git a/.gitignore b/.gitignore
index bd6ba1c..b67a37e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,9 +3,9 @@  config-all-devices.*
 config-host.*
 config-target.*
 trace.h
-trace.c
-trace-dtrace.h
-trace-dtrace.dtrace
+trace/generated.c
+trace/generated-dtrace.h
+trace/generated-dtrace.dtrace
 *-timestamp
 *-softmmu
 *-darwin-user
diff --git a/Makefile b/Makefile
index e9d6848..9dbcca3 100644
--- a/Makefile
+++ b/Makefile
@@ -33,10 +33,10 @@  endif
 
 GENERATED_HEADERS = config-host.h trace.h qemu-options.def
 ifeq ($(TRACE_BACKEND),dtrace)
-GENERATED_HEADERS += trace-dtrace.h
+GENERATED_HEADERS += trace/generated-dtrace.h
 endif
 GENERATED_HEADERS += qmp-commands.h qapi-types.h qapi-visit.h
-GENERATED_SOURCES += qmp-marshal.c qapi-types.c qapi-visit.c trace.c
+GENERATED_SOURCES += qmp-marshal.c qapi-types.c qapi-visit.c trace/generated.c
 
 # Don't try to regenerate Makefile or configure
 # We don't generate any of them
@@ -252,9 +252,9 @@  clean:
 	rm -f *.a *.lo $(TOOLS) $(HELPERS-y) qemu-ga TAGS cscope.* *.pod *~ */*~
 	rm -Rf .libs
 	rm -f qemu-img-cmds.h
-	rm -f trace-dtrace.dtrace trace-dtrace.dtrace-timestamp
 	@# May not be present in GENERATED_HEADERS
-	rm -f trace-dtrace.h trace-dtrace.h-timestamp
+	rm -f trace/generated-dtrace.dtrace trace/generated-dtrace.dtrace-timestamp
+	rm -f trace/generated-dtrace.h trace/generated-dtrace.h-timestamp
 	rm -f $(foreach f,$(GENERATED_HEADERS),$(f) $(f)-timestamp)
 	rm -f $(foreach f,$(GENERATED_SOURCES),$(f) $(f)-timestamp)
 	rm -rf qapi-generated
diff --git a/Makefile.objs b/Makefile.objs
index 3c7abca..24832a2 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -147,66 +147,7 @@  libdis-$(CONFIG_LM32_DIS) += lm32-dis.o
 ######################################################################
 # trace
 
-ifeq ($(TRACE_BACKEND),dtrace)
-TRACE_H_EXTRA_DEPS=trace-dtrace.h
-endif
-trace.h: trace.h-timestamp $(TRACE_H_EXTRA_DEPS)
-trace.h-timestamp: $(SRC_PATH)/trace-events $(BUILD_DIR)/config-host.mak
-	$(call quiet-command,$(TRACETOOL) \
-		--format=h \
-		--backend=$(TRACE_BACKEND) \
-		< $< > $@,"  GEN   trace.h")
-	@cmp -s $@ trace.h || cp $@ trace.h
-
-trace.c: trace.c-timestamp
-trace.c-timestamp: $(SRC_PATH)/trace-events $(BUILD_DIR)/config-host.mak
-	$(call quiet-command,$(TRACETOOL) \
-		--format=c \
-		--backend=$(TRACE_BACKEND) \
-		< $< > $@,"  GEN   trace.c")
-	@cmp -s $@ trace.c || cp $@ trace.c
-
-trace.o: trace.c $(GENERATED_HEADERS)
-
-trace-dtrace.h: trace-dtrace.dtrace
-	$(call quiet-command,dtrace -o $@ -h -s $<, "  GEN   trace-dtrace.h")
-
-# Normal practice is to name DTrace probe file with a '.d' extension
-# but that gets picked up by QEMU's Makefile as an external dependency
-# rule file. So we use '.dtrace' instead
-trace-dtrace.dtrace: trace-dtrace.dtrace-timestamp
-trace-dtrace.dtrace-timestamp: $(SRC_PATH)/trace-events $(BUILD_DIR)/config-host.mak
-	$(call quiet-command,$(TRACETOOL) \
-		--format=d \
-		--backend=$(TRACE_BACKEND) \
-		< $< > $@,"  GEN   trace-dtrace.dtrace")
-	@cmp -s $@ trace-dtrace.dtrace || cp $@ trace-dtrace.dtrace
-
-trace-dtrace.o: trace-dtrace.dtrace $(GENERATED_HEADERS)
-	$(call quiet-command,dtrace -o $@ -G -s $<, "  GEN   trace-dtrace.o")
-
-ifeq ($(LIBTOOL),)
-trace-dtrace.lo: trace-dtrace.dtrace
-	@echo "missing libtool. please install and rerun configure."; exit 1
-else
-trace-dtrace.lo: trace-dtrace.dtrace
-	$(call quiet-command,$(LIBTOOL) --mode=compile --tag=CC dtrace -o $@ -G -s $<, "  lt GEN trace-dtrace.o")
-endif
-
-trace/simple.o: trace/simple.c $(GENERATED_HEADERS)
-
-trace-obj-$(CONFIG_TRACE_DTRACE) += trace-dtrace.o
-ifneq ($(TRACE_BACKEND),dtrace)
-trace-obj-y = trace.o
-endif
-
-trace-obj-$(CONFIG_TRACE_DEFAULT) += trace/default.o
-trace-obj-$(CONFIG_TRACE_SIMPLE) += trace/simple.o
-trace-obj-$(CONFIG_TRACE_SIMPLE) += qemu-timer-common.o
-trace-obj-$(CONFIG_TRACE_STDERR) += trace/stderr.o
-trace-obj-y += trace/control.o
-
-$(trace-obj-y): $(GENERATED_HEADERS)
+trace-obj-y += trace/
 
 ######################################################################
 # smartcard
@@ -250,5 +191,6 @@  nested-vars += \
 	block-obj-y \
 	user-obj-y \
 	common-obj-y \
-	extra-obj-y
+	extra-obj-y \
+	trace-obj-y
 dummy := $(call unnest-vars)
diff --git a/scripts/tracetool/backend/dtrace.py b/scripts/tracetool/backend/dtrace.py
index 23c43e2..0cbc68a 100644
--- a/scripts/tracetool/backend/dtrace.py
+++ b/scripts/tracetool/backend/dtrace.py
@@ -37,7 +37,7 @@  def c(events):
 
 
 def h(events):
-    out('#include "trace-dtrace.h"',
+    out('#include "trace/generated-dtrace.h"',
         '')
 
     for e in events:
diff --git a/trace/Makefile.objs b/trace/Makefile.objs
new file mode 100644
index 0000000..d7e8cdf
--- /dev/null
+++ b/trace/Makefile.objs
@@ -0,0 +1,81 @@ 
+# -*- mode: makefile -*-
+
+trace/simple.o: trace/simple.c $(GENERATED_HEADERS)
+
+trace-obj-$(CONFIG_TRACE_DEFAULT) += default.o
+trace-obj-$(CONFIG_TRACE_SIMPLE) += simple.o
+trace-obj-$(CONFIG_TRACE_SIMPLE) += ../qemu-timer-common.o
+trace-obj-$(CONFIG_TRACE_STDERR) += stderr.o
+trace-obj-y += control.o
+
+
+######################################################################
+# Auto-generated tracing routines
+
+# NOTE: "trace.h" is kept in the top-level dir to shorten common include path
+ifeq ($(TRACE_BACKEND),dtrace)
+TRACE_H_EXTRA_DEPS=trace/generated-dtrace.h
+endif
+trace.h: trace.h-timestamp $(TRACE_H_EXTRA_DEPS)
+trace.h-timestamp: $(SRC_PATH)/trace-events $(BUILD_DIR)/config-host.mak
+	$(call quiet-command,$(TRACETOOL) \
+		--format=h \
+		--backend=$(TRACE_BACKEND) \
+		< $< > $@,"  GEN   trace.h")
+	@cmp -s $@ trace.h || cp $@ trace.h
+
+
+trace/generated.c: trace/generated.c-timestamp
+trace/generated.c-timestamp: $(SRC_PATH)/trace-events $(BUILD_DIR)/config-host.mak
+	$(call quiet-command,$(TRACETOOL) \
+		--format=c \
+		--backend=$(TRACE_BACKEND) \
+		< $< > $@,"  GEN   trace/generated.c")
+	@cmp -s $@ trace/generated.c || cp $@ trace/generated.c
+
+trace/generated.o: trace/generated.c trace.h
+
+
+ifneq ($(TRACE_BACKEND),dtrace)
+trace-obj-y += generated.o
+endif
+
+
+######################################################################
+# Auto-generated DTrace code
+
+# Normal practice is to name DTrace probe file with a '.d' extension
+# but that gets picked up by QEMU's Makefile as an external dependency
+# rule file. So we use '.dtrace' instead
+trace/generated-dtrace.dtrace: trace/generated-dtrace.dtrace-timestamp
+trace/generated-dtrace.dtrace-timestamp: $(SRC_PATH)/trace-events $(BUILD_DIR)/config-host.mak
+	$(call quiet-command,$(TRACETOOL) \
+		--format=d \
+		--backend=$(TRACE_BACKEND) \
+		< $< > $@,"  GEN   trace/generated-dtrace.dtrace")
+	@cmp -s $@ trace/generated-dtrace.dtrace || cp $@ trace/generated-dtrace.dtrace
+
+
+trace/generated-dtrace.h: trace/generated-dtrace.dtrace
+	$(call quiet-command,dtrace -o $@ -h -s $<, "  GEN   trace/generated-dtrace.h")
+
+trace/generated-dtrace.o: trace/generated-dtrace.dtrace $(GENERATED_HEADERS)
+	$(call quiet-command,dtrace -o $@ -G -s $<, "  GEN   trace/generated-dtrace.o")
+
+
+ifeq ($(LIBTOOL),)
+trace/generated-dtrace.lo: trace/generated-dtrace.dtrace
+	@echo "missing libtool. please install and rerun configure."; exit 1
+else
+trace/generated-dtrace.lo: trace/generated-dtrace.dtrace
+	$(call quiet-command,$(LIBTOOL) --mode=compile --tag=CC dtrace -o $@ -G -s $<, "  lt GEN trace/generated-dtrace.lo")
+endif
+
+
+trace-obj-$(CONFIG_TRACE_DTRACE) += generated-dtrace.o
+
+
+######################################################################
+# Keep at bottom
+
+$(trace-obj-y): $(GENERATED_HEADERS)