target-ppc: Fix invalid SPR read/write warnings
[qemu/agraf.git] / rules.mak
blob44997458da40573eb765704d0235f75a65759e48
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 %.m:
12 %.mak:
14 # Flags for dependency generation
15 QEMU_DGFLAGS += -MMD -MP -MT $@ -MF $(*D)/$(*F).d
17 # Same as -I$(SRC_PATH) -I., but for the nested source/object directories
18 QEMU_INCLUDES += -I$(<D) -I$(@D)
20 %.o: %.c
21 $(call quiet-command,$(CC) $(QEMU_INCLUDES) $(QEMU_CFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) -c -o $@ $<," CC $(TARGET_DIR)$@")
22 %.o: %.rc
23 $(call quiet-command,$(WINDRES) -I. -o $@ $<," RC $(TARGET_DIR)$@")
25 ifeq ($(LIBTOOL),)
26 LINK = $(call quiet-command,$(CC) $(QEMU_CFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ \
27 $(sort $(filter %.o, $1)) $(filter-out %.o, $1) $(version-obj-y) \
28 $(LIBS)," LINK $(TARGET_DIR)$@")
29 else
30 LIBTOOL += $(if $(V),,--quiet)
31 %.lo: %.c
32 $(call quiet-command,$(LIBTOOL) --mode=compile --tag=CC $(CC) $(QEMU_INCLUDES) $(QEMU_CFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) -c -o $@ $<," lt CC $@")
33 %.lo: %.rc
34 $(call quiet-command,$(LIBTOOL) --mode=compile --tag=RC $(WINDRES) -I. -o $@ $<,"lt RC $(TARGET_DIR)$@")
35 %.lo: %.dtrace
36 $(call quiet-command,$(LIBTOOL) --mode=compile --tag=CC dtrace -o $@ -G -s $<, " lt GEN $(TARGET_DIR)$@")
38 LINK = $(call quiet-command,\
39 $(if $(filter %.lo %.la,$^),$(LIBTOOL) --mode=link --tag=CC \
40 )$(CC) $(QEMU_CFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ \
41 $(sort $(filter %.o, $1)) $(filter-out %.o, $1) \
42 $(if $(filter %.lo %.la,$^),$(version-lobj-y),$(version-obj-y)) \
43 $(if $(filter %.lo %.la,$^),$(LIBTOOLFLAGS)) \
44 $(LIBS),$(if $(filter %.lo %.la,$^),"lt LINK ", " LINK ")"$(TARGET_DIR)$@")
45 endif
47 %.asm: %.S
48 $(call quiet-command,$(CPP) $(QEMU_INCLUDES) $(QEMU_CFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) -o $@ $<," CPP $(TARGET_DIR)$@")
50 %.o: %.asm
51 $(call quiet-command,$(AS) $(ASFLAGS) -o $@ $<," AS $(TARGET_DIR)$@")
53 %.o: %.m
54 $(call quiet-command,$(OBJCC) $(QEMU_INCLUDES) $(QEMU_CFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) -c -o $@ $<," OBJC $(TARGET_DIR)$@")
56 %.o: %.dtrace
57 $(call quiet-command,dtrace -o $@ -G -s $<, " GEN $(TARGET_DIR)$@")
59 %$(EXESUF): %.o
60 $(call LINK,$^)
62 %.a:
63 $(call quiet-command,rm -f $@ && $(AR) rcs $@ $^," AR $(TARGET_DIR)$@")
65 quiet-command = $(if $(V),$1,$(if $(2),@echo $2 && $1, @$1))
67 # cc-option
68 # Usage: CFLAGS+=$(call cc-option, -falign-functions=0, -malign-functions=0)
70 cc-option = $(if $(shell $(CC) $1 $2 -S -o /dev/null -xc /dev/null \
71 >/dev/null 2>&1 && echo OK), $2, $3)
73 VPATH_SUFFIXES = %.c %.h %.S %.m %.mak %.texi %.sh %.rc
74 set-vpath = $(if $1,$(foreach PATTERN,$(VPATH_SUFFIXES),$(eval vpath $(PATTERN) $1)))
76 # find-in-path
77 # Usage: $(call find-in-path, prog)
78 # Looks in the PATH if the argument contains no slash, else only considers one
79 # specific directory. Returns an # empty string if the program doesn't exist
80 # there.
81 find-in-path = $(if $(find-string /, $1), \
82 $(wildcard $1), \
83 $(wildcard $(patsubst %, %/$1, $(subst :, ,$(PATH)))))
85 # Generate files with tracetool
86 TRACETOOL=$(PYTHON) $(SRC_PATH)/scripts/tracetool.py
88 # Generate timestamp files for .h include files
90 config-%.h: config-%.h-timestamp
91 @cmp $< $@ >/dev/null 2>&1 || cp $< $@
93 config-%.h-timestamp: config-%.mak
94 $(call quiet-command, sh $(SRC_PATH)/scripts/create_config < $< > $@, " GEN $(TARGET_DIR)config-$*.h")
96 .PHONY: clean-timestamp
97 clean-timestamp:
98 rm -f *.timestamp
99 clean: clean-timestamp
101 # will delete the target of a rule if commands exit with a nonzero exit status
102 .DELETE_ON_ERROR:
104 # magic to descend into other directories
106 obj := .
107 old-nested-dirs :=
109 define push-var
110 $(eval save-$2-$1 = $(value $1))
111 $(eval $1 :=)
112 endef
114 define pop-var
115 $(eval subdir-$2-$1 := $(if $(filter $2,$(save-$2-$1)),$(addprefix $2,$($1))))
116 $(eval $1 = $(value save-$2-$1) $$(subdir-$2-$1))
117 $(eval save-$2-$1 :=)
118 endef
120 define unnest-dir
121 $(foreach var,$(nested-vars),$(call push-var,$(var),$1/))
122 $(eval obj := $(obj)/$1)
123 $(eval include $(SRC_PATH)/$1/Makefile.objs)
124 $(eval obj := $(patsubst %/$1,%,$(obj)))
125 $(foreach var,$(nested-vars),$(call pop-var,$(var),$1/))
126 endef
128 define unnest-vars-1
129 $(eval nested-dirs := $(filter-out \
130 $(old-nested-dirs), \
131 $(sort $(foreach var,$(nested-vars), $(filter %/, $($(var)))))))
132 $(if $(nested-dirs),
133 $(foreach dir,$(nested-dirs),$(call unnest-dir,$(patsubst %/,%,$(dir))))
134 $(eval old-nested-dirs := $(old-nested-dirs) $(nested-dirs))
135 $(call unnest-vars-1))
136 endef
138 define unnest-vars
139 $(call unnest-vars-1)
140 $(foreach var,$(nested-vars),$(eval $(var) := $(filter-out %/, $($(var)))))
141 $(shell mkdir -p $(sort $(foreach var,$(nested-vars),$(dir $($(var))))))
142 $(foreach var,$(nested-vars), $(eval \
143 -include $(addsuffix *.d, $(sort $(dir $($(var)))))))
144 endef