ram: account the amount of transferred ram better
[qemu/ar7.git] / rules.mak
blob8448b94cdf0e30d6815918e48bb83e3038c9882c
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_CFLAGS += -I$(<D) -I$(@D)
20 %.o: %.c
21 $(call quiet-command,$(CC) $(QEMU_INCLUDES) $(QEMU_CFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) -c -o $@ $<," CC $(TARGET_DIR)$@")
23 ifeq ($(LIBTOOL),)
24 %.lo: %.c
25 @echo "missing libtool. please install and rerun configure"; exit 1
26 else
27 %.lo: %.c
28 $(call quiet-command,$(LIBTOOL) --mode=compile --quiet --tag=CC $(CC) $(QEMU_INCLUDES) $(QEMU_CFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) -c -o $@ $<," lt CC $@")
29 endif
31 %.o: %.S
32 $(call quiet-command,$(CC) $(QEMU_INCLUDES) $(QEMU_CFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) -c -o $@ $<," AS $(TARGET_DIR)$@")
34 %.o: %.m
35 $(call quiet-command,$(OBJCC) $(QEMU_INCLUDES) $(QEMU_CFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) -c -o $@ $<," OBJC $(TARGET_DIR)$@")
37 LINK = $(call quiet-command,$(CC) $(QEMU_CFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ $(sort $(filter %.o, $1)) $(filter-out %.o, $1) $(LIBS)," LINK $(TARGET_DIR)$@")
39 %$(EXESUF): %.o
40 $(call LINK,$^)
42 %.a:
43 $(call quiet-command,rm -f $@ && $(AR) rcs $@ $^," AR $(TARGET_DIR)$@")
45 quiet-command = $(if $(V),$1,$(if $(2),@echo $2 && $1, @$1))
47 # cc-option
48 # Usage: CFLAGS+=$(call cc-option, -falign-functions=0, -malign-functions=0)
50 cc-option = $(if $(shell $(CC) $1 $2 -S -o /dev/null -xc /dev/null \
51 >/dev/null 2>&1 && echo OK), $2, $3)
53 VPATH_SUFFIXES = %.c %.h %.S %.m %.mak %.texi %.sh
54 set-vpath = $(if $1,$(foreach PATTERN,$(VPATH_SUFFIXES),$(eval vpath $(PATTERN) $1)))
56 # find-in-path
57 # Usage: $(call find-in-path, prog)
58 # Looks in the PATH if the argument contains no slash, else only considers one
59 # specific directory. Returns an # empty string if the program doesn't exist
60 # there.
61 find-in-path = $(if $(find-string /, $1), \
62 $(wildcard $1), \
63 $(wildcard $(patsubst %, %/$1, $(subst :, ,$(PATH)))))
65 # Generate files with tracetool
66 TRACETOOL=$(PYTHON) $(SRC_PATH)/scripts/tracetool.py
68 # Generate timestamp files for .h include files
70 %.h: %.h-timestamp
71 @test -f $@ || cp $< $@
73 %.h-timestamp: %.mak
74 $(call quiet-command, sh $(SRC_PATH)/scripts/create_config < $< > $@, " GEN $(TARGET_DIR)$*.h")
75 @cmp $@ $*.h >/dev/null 2>&1 || cp $@ $*.h
77 # will delete the target of a rule if commands exit with a nonzero exit status
78 .DELETE_ON_ERROR:
80 # magic to descend into other directories
82 obj := .
83 old-nested-dirs :=
85 define push-var
86 $(eval save-$2-$1 = $(value $1))
87 $(eval $1 :=)
88 endef
90 define pop-var
91 $(eval subdir-$2-$1 := $(if $(filter $2,$(save-$2-$1)),$(addprefix $2,$($1))))
92 $(eval $1 = $(value save-$2-$1) $$(subdir-$2-$1))
93 $(eval save-$2-$1 :=)
94 endef
96 define unnest-dir
97 $(foreach var,$(nested-vars),$(call push-var,$(var),$1/))
98 $(eval obj := $(obj)/$1)
99 $(eval include $(SRC_PATH)/$1/Makefile.objs)
100 $(eval obj := $(patsubst %/$1,%,$(obj)))
101 $(foreach var,$(nested-vars),$(call pop-var,$(var),$1/))
102 endef
104 define unnest-vars-1
105 $(eval nested-dirs := $(filter-out \
106 $(old-nested-dirs), \
107 $(sort $(foreach var,$(nested-vars), $(filter %/, $($(var)))))))
108 $(if $(nested-dirs),
109 $(foreach dir,$(nested-dirs),$(call unnest-dir,$(patsubst %/,%,$(dir))))
110 $(eval old-nested-dirs := $(old-nested-dirs) $(nested-dirs))
111 $(call unnest-vars-1))
112 endef
114 define unnest-vars
115 $(call unnest-vars-1)
116 $(foreach var,$(nested-vars),$(eval $(var) := $(filter-out %/, $($(var)))))
117 $(shell mkdir -p $(sort $(foreach var,$(nested-vars),$(dir $($(var))))))
118 $(foreach var,$(nested-vars), $(eval \
119 -include $(addsuffix *.d, $(sort $(dir $($(var)))))))
120 endef