qdict: Extract non-QDicts in qdict_array_split()
[qemu-kvm.git] / rules.mak
blob391d6eb8e612e5f7361249fe68040f50eb1c7bcc
2 # Don't use implicit rules or variables
3 # we have explicit rules for everything
4 MAKEFLAGS += -rR
6 # Files with this suffixes are final, don't try to generate them
7 # using implicit rules
8 %.d:
9 %.h:
10 %.c:
11 %.cc:
12 %.cpp:
13 %.m:
14 %.mak:
16 # Flags for C++ compilation
17 QEMU_CXXFLAGS = -D__STDC_LIMIT_MACROS $(filter-out -Wstrict-prototypes -Wmissing-prototypes -Wnested-externs -Wold-style-declaration -Wold-style-definition -Wredundant-decls, $(QEMU_CFLAGS))
19 # Flags for dependency generation
20 QEMU_DGFLAGS += -MMD -MP -MT $@ -MF $(*D)/$(*F).d
22 # Same as -I$(SRC_PATH) -I., but for the nested source/object directories
23 QEMU_INCLUDES += -I$(<D) -I$(@D)
25 %.o: %.c
26 $(call quiet-command,$(CC) $(QEMU_INCLUDES) $(QEMU_CFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) -c -o $@ $<," CC $(TARGET_DIR)$@")
27 %.o: %.rc
28 $(call quiet-command,$(WINDRES) -I. -o $@ $<," RC $(TARGET_DIR)$@")
30 # If we have a CXX we might have some C++ objects, in which case we
31 # must link with the C++ compiler, not the plain C compiler.
32 LINKPROG = $(or $(CXX),$(CC))
34 ifeq ($(LIBTOOL),)
35 LINK = $(call quiet-command,$(LINKPROG) $(QEMU_CFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ \
36 $(sort $(filter %.o, $1)) $(filter-out %.o, $1) $(version-obj-y) \
37 $(LIBS)," LINK $(TARGET_DIR)$@")
38 else
39 LIBTOOL += $(if $(V),,--quiet)
40 %.lo: %.c
41 $(call quiet-command,$(LIBTOOL) --mode=compile --tag=CC $(CC) $(QEMU_INCLUDES) $(QEMU_CFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) -c -o $@ $<," lt CC $@")
42 %.lo: %.rc
43 $(call quiet-command,$(LIBTOOL) --mode=compile --tag=RC $(WINDRES) -I. -o $@ $<,"lt RC $(TARGET_DIR)$@")
44 %.lo: %.dtrace
45 $(call quiet-command,$(LIBTOOL) --mode=compile --tag=CC dtrace -o $@ -G -s $<, " lt GEN $(TARGET_DIR)$@")
47 LINK = $(call quiet-command,\
48 $(if $(filter %.lo %.la,$^),$(LIBTOOL) --mode=link --tag=CC \
49 )$(LINKPROG) $(QEMU_CFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ \
50 $(sort $(filter %.o, $1)) $(filter-out %.o, $1) \
51 $(if $(filter %.lo %.la,$^),$(version-lobj-y),$(version-obj-y)) \
52 $(if $(filter %.lo %.la,$^),$(LIBTOOLFLAGS)) \
53 $(LIBS),$(if $(filter %.lo %.la,$^),"lt LINK ", " LINK ")"$(TARGET_DIR)$@")
54 endif
56 %.asm: %.S
57 $(call quiet-command,$(CPP) $(QEMU_INCLUDES) $(QEMU_CFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) -o $@ $<," CPP $(TARGET_DIR)$@")
59 %.o: %.asm
60 $(call quiet-command,$(AS) $(ASFLAGS) -o $@ $<," AS $(TARGET_DIR)$@")
62 %.o: %.cc
63 $(call quiet-command,$(CXX) $(QEMU_INCLUDES) $(QEMU_CXXFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) -c -o $@ $<," CXX $(TARGET_DIR)$@")
65 %.o: %.cpp
66 $(call quiet-command,$(CXX) $(QEMU_INCLUDES) $(QEMU_CXXFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) -c -o $@ $<," CXX $(TARGET_DIR)$@")
68 %.o: %.m
69 $(call quiet-command,$(OBJCC) $(QEMU_INCLUDES) $(QEMU_CFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) -c -o $@ $<," OBJC $(TARGET_DIR)$@")
71 %.o: %.dtrace
72 $(call quiet-command,dtrace -o $@ -G -s $<, " GEN $(TARGET_DIR)$@")
74 %$(EXESUF): %.o
75 $(call LINK,$^)
77 %.a:
78 $(call quiet-command,rm -f $@ && $(AR) rcs $@ $^," AR $(TARGET_DIR)$@")
80 quiet-command = $(if $(V),$1,$(if $(2),@echo $2 && $1, @$1))
82 # cc-option
83 # Usage: CFLAGS+=$(call cc-option, -falign-functions=0, -malign-functions=0)
85 cc-option = $(if $(shell $(CC) $1 $2 -S -o /dev/null -xc /dev/null \
86 >/dev/null 2>&1 && echo OK), $2, $3)
88 VPATH_SUFFIXES = %.c %.h %.S %.cc %.cpp %.m %.mak %.texi %.sh %.rc
89 set-vpath = $(if $1,$(foreach PATTERN,$(VPATH_SUFFIXES),$(eval vpath $(PATTERN) $1)))
91 # find-in-path
92 # Usage: $(call find-in-path, prog)
93 # Looks in the PATH if the argument contains no slash, else only considers one
94 # specific directory. Returns an # empty string if the program doesn't exist
95 # there.
96 find-in-path = $(if $(find-string /, $1), \
97 $(wildcard $1), \
98 $(wildcard $(patsubst %, %/$1, $(subst :, ,$(PATH)))))
100 # Logical functions (for operating on y/n values like CONFIG_FOO vars)
101 # Inputs to these must be either "y" (true) or "n" or "" (both false)
102 # Output is always either "y" or "n".
103 # Usage: $(call land,$(CONFIG_FOO),$(CONFIG_BAR))
104 # Logical NOT
105 lnot = $(if $(subst n,,$1),n,y)
106 # Logical AND
107 land = $(if $(findstring yy,$1$2),y,n)
108 # Logical OR
109 lor = $(if $(findstring y,$1$2),y,n)
110 # Logical XOR (note that this is the inverse of leqv)
111 lxor = $(if $(filter $(call lnot,$1),$(call lnot,$2)),n,y)
112 # Logical equivalence (note that leqv "","n" is true)
113 leqv = $(if $(filter $(call lnot,$1),$(call lnot,$2)),y,n)
114 # Logical if: like make's $(if) but with an leqv-like test
115 lif = $(if $(subst n,,$1),$2,$3)
117 # String testing functions: inputs to these can be any string;
118 # the output is always either "y" or "n". Leading and trailing whitespace
119 # is ignored when comparing strings.
120 # String equality
121 eq = $(if $(subst $2,,$1)$(subst $1,,$2),n,y)
122 # String inequality
123 ne = $(if $(subst $2,,$1)$(subst $1,,$2),y,n)
124 # Emptiness/non-emptiness tests:
125 isempty = $(if $1,n,y)
126 notempty = $(if $1,y,n)
128 # Generate files with tracetool
129 TRACETOOL=$(PYTHON) $(SRC_PATH)/scripts/tracetool.py
131 # Generate timestamp files for .h include files
133 config-%.h: config-%.h-timestamp
134 @cmp $< $@ >/dev/null 2>&1 || cp $< $@
136 config-%.h-timestamp: config-%.mak
137 $(call quiet-command, sh $(SRC_PATH)/scripts/create_config < $< > $@, " GEN $(TARGET_DIR)config-$*.h")
139 .PHONY: clean-timestamp
140 clean-timestamp:
141 rm -f *.timestamp
142 clean: clean-timestamp
144 # will delete the target of a rule if commands exit with a nonzero exit status
145 .DELETE_ON_ERROR:
147 # magic to descend into other directories
149 obj := .
150 old-nested-dirs :=
152 define push-var
153 $(eval save-$2-$1 = $(value $1))
154 $(eval $1 :=)
155 endef
157 define pop-var
158 $(eval subdir-$2-$1 := $(if $(filter $2,$(save-$2-$1)),$(addprefix $2,$($1))))
159 $(eval $1 = $(value save-$2-$1) $$(subdir-$2-$1))
160 $(eval save-$2-$1 :=)
161 endef
163 define unnest-dir
164 $(foreach var,$(nested-vars),$(call push-var,$(var),$1/))
165 $(eval obj := $(obj)/$1)
166 $(eval include $(SRC_PATH)/$1/Makefile.objs)
167 $(eval obj := $(patsubst %/$1,%,$(obj)))
168 $(foreach var,$(nested-vars),$(call pop-var,$(var),$1/))
169 endef
171 define unnest-vars-1
172 $(eval nested-dirs := $(filter-out \
173 $(old-nested-dirs), \
174 $(sort $(foreach var,$(nested-vars), $(filter %/, $($(var)))))))
175 $(if $(nested-dirs),
176 $(foreach dir,$(nested-dirs),$(call unnest-dir,$(patsubst %/,%,$(dir))))
177 $(eval old-nested-dirs := $(old-nested-dirs) $(nested-dirs))
178 $(call unnest-vars-1))
179 endef
181 define unnest-vars
182 $(call unnest-vars-1)
183 $(foreach var,$(nested-vars),$(eval $(var) := $(filter-out %/, $($(var)))))
184 $(shell mkdir -p $(sort $(foreach var,$(nested-vars),$(dir $($(var))))))
185 $(foreach var,$(nested-vars), $(eval \
186 -include $(addsuffix *.d, $(sort $(dir $($(var)))))))
187 endef