tap: properly initialize vhostfds
[qemu/ar7.git] / rules.mak
blobb21383beba39163cb927a0115d4262661fb4cfc1
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 Makefile: $(version-obj-y)
27 ifeq ($(LIBTOOL),)
28 LIBTOOL = /bin/false
29 LINK = $(call quiet-command,$(CC) $(QEMU_CFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ \
30 $(sort $(filter %.o, $1)) $(filter-out %.o, $1) $(version-obj-y) \
31 $(LIBS)," LINK $(TARGET_DIR)$@")
32 else
33 Makefile: $(version-lobj-y)
34 LIBTOOL += $(if $(V),,--quiet)
35 %.lo: %.c
36 $(call quiet-command,$(LIBTOOL) --mode=compile --tag=CC $(CC) $(QEMU_INCLUDES) $(QEMU_CFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) -c -o $@ $<," lt CC $@")
37 %.lo: %.rc
38 $(call quiet-command,$(LIBTOOL) --mode=compile --tag=RC $(WINDRES) -I. -o $@ $<,"lt RC $(TARGET_DIR)$@")
39 %.lo: %.dtrace
40 $(call quiet-command,$(LIBTOOL) --mode=compile --tag=CC dtrace -o $@ -G -s $<, " lt GEN $(TARGET_DIR)$@")
42 LINK = $(call quiet-command,\
43 $(if $(filter %.lo %.la,$^),$(LIBTOOL) --mode=link --tag=CC \
44 )$(CC) $(QEMU_CFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ \
45 $(sort $(filter %.o, $1)) $(filter-out %.o, $1) \
46 $(if $(filter %.lo %.la,$^),$(version-lobj-y),$(version-obj-y)) \
47 $(if $(filter %.lo %.la,$^),$(LIBTOOLFLAGS)) \
48 $(LIBS),$(if $(filter %.lo %.la,$^),"lt LINK ", " LINK ")"$(TARGET_DIR)$@")
49 endif
51 %.asm: %.S
52 $(call quiet-command,$(CPP) $(QEMU_INCLUDES) $(QEMU_CFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) -o $@ $<," CPP $(TARGET_DIR)$@")
54 %.o: %.asm
55 $(call quiet-command,$(AS) $(ASFLAGS) -o $@ $<," AS $(TARGET_DIR)$@")
57 %.o: %.m
58 $(call quiet-command,$(OBJCC) $(QEMU_INCLUDES) $(QEMU_CFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) -c -o $@ $<," OBJC $(TARGET_DIR)$@")
60 %.o: %.dtrace
61 $(call quiet-command,dtrace -o $@ -G -s $<, " GEN $(TARGET_DIR)$@")
63 %$(EXESUF): %.o
64 $(call LINK,$^)
66 %.a:
67 $(call quiet-command,rm -f $@ && $(AR) rcs $@ $^," AR $(TARGET_DIR)$@")
69 quiet-command = $(if $(V),$1,$(if $(2),@echo $2 && $1, @$1))
71 # cc-option
72 # Usage: CFLAGS+=$(call cc-option, -falign-functions=0, -malign-functions=0)
74 cc-option = $(if $(shell $(CC) $1 $2 -S -o /dev/null -xc /dev/null \
75 >/dev/null 2>&1 && echo OK), $2, $3)
77 VPATH_SUFFIXES = %.c %.h %.S %.m %.mak %.texi %.sh
78 set-vpath = $(if $1,$(foreach PATTERN,$(VPATH_SUFFIXES),$(eval vpath $(PATTERN) $1)))
80 # find-in-path
81 # Usage: $(call find-in-path, prog)
82 # Looks in the PATH if the argument contains no slash, else only considers one
83 # specific directory. Returns an # empty string if the program doesn't exist
84 # there.
85 find-in-path = $(if $(find-string /, $1), \
86 $(wildcard $1), \
87 $(wildcard $(patsubst %, %/$1, $(subst :, ,$(PATH)))))
89 # Generate files with tracetool
90 TRACETOOL=$(PYTHON) $(SRC_PATH)/scripts/tracetool.py
92 # Generate timestamp files for .h include files
94 config-%.h: config-%.h-timestamp
95 @cmp $< $@ >/dev/null 2>&1 || cp $< $@
97 config-%.h-timestamp: config-%.mak
98 $(call quiet-command, sh $(SRC_PATH)/scripts/create_config < $< > $@, " GEN $(TARGET_DIR)config-$*.h")
100 .PHONY: clean-timestamp
101 clean-timestamp:
102 rm -f *.timestamp
103 clean: clean-timestamp
105 # will delete the target of a rule if commands exit with a nonzero exit status
106 .DELETE_ON_ERROR:
108 # magic to descend into other directories
110 obj := .
111 old-nested-dirs :=
113 define push-var
114 $(eval save-$2-$1 = $(value $1))
115 $(eval $1 :=)
116 endef
118 define pop-var
119 $(eval subdir-$2-$1 := $(if $(filter $2,$(save-$2-$1)),$(addprefix $2,$($1))))
120 $(eval $1 = $(value save-$2-$1) $$(subdir-$2-$1))
121 $(eval save-$2-$1 :=)
122 endef
124 define unnest-dir
125 $(foreach var,$(nested-vars),$(call push-var,$(var),$1/))
126 $(eval obj := $(obj)/$1)
127 $(eval include $(SRC_PATH)/$1/Makefile.objs)
128 $(eval obj := $(patsubst %/$1,%,$(obj)))
129 $(foreach var,$(nested-vars),$(call pop-var,$(var),$1/))
130 endef
132 define unnest-vars-1
133 $(eval nested-dirs := $(filter-out \
134 $(old-nested-dirs), \
135 $(sort $(foreach var,$(nested-vars), $(filter %/, $($(var)))))))
136 $(if $(nested-dirs),
137 $(foreach dir,$(nested-dirs),$(call unnest-dir,$(patsubst %/,%,$(dir))))
138 $(eval old-nested-dirs := $(old-nested-dirs) $(nested-dirs))
139 $(call unnest-vars-1))
140 endef
142 define unnest-vars
143 $(call unnest-vars-1)
144 $(foreach var,$(nested-vars),$(eval $(var) := $(filter-out %/, $($(var)))))
145 $(shell mkdir -p $(sort $(foreach var,$(nested-vars),$(dir $($(var))))))
146 $(foreach var,$(nested-vars), $(eval \
147 -include $(addsuffix *.d, $(sort $(dir $($(var)))))))
148 endef