virtiofsd: Disable remote posix locks by default
[qemu.git] / rules.mak
blobc66c8218f025dbc4d6aa20867bf022eaede3c0b3
2 # These are used when we want to do substitutions without confusing Make
3 NULL :=
4 SPACE := $(NULL) #
5 COMMA := ,
7 # Don't use implicit rules or variables
8 # we have explicit rules for everything
9 MAKEFLAGS += -rR
11 # Files with this suffixes are final, don't try to generate them
12 # using implicit rules
13 %/trace-events:
14 %.hx:
15 %.py:
16 %.objs:
17 %.d:
18 %.h:
19 %.c:
20 %.cc:
21 %.cpp:
22 %.m:
23 %.mak:
25 # Flags for dependency generation
26 QEMU_DGFLAGS += -MMD -MP -MT $@ -MF $(@D)/$(*F).d
28 # Compiler searches the source file dir first, but in vpath builds
29 # we need to make it search the build dir too, before any other
30 # explicit search paths. There are two search locations in the build
31 # dir, one absolute and the other relative to the compiler working
32 # directory. These are the same for target-independent files, but
33 # different for target-dependent ones.
34 QEMU_LOCAL_INCLUDES = -iquote $(BUILD_DIR) -iquote $(BUILD_DIR)/$(@D) -iquote $(@D)
36 WL := -Wl,
37 ifdef CONFIG_DARWIN
38 whole-archive = $(WL)-force_load,$1
39 else
40 whole-archive = $(WL)--whole-archive $1 $(WL)--no-whole-archive
41 endif
43 extract-libs = $(strip $(foreach o,$1,$($o-libs)))
45 %.o: %.c
46 @mkdir -p $(dir $@)
47 $(call quiet-command,$(CC) $(QEMU_LOCAL_INCLUDES) $(QEMU_INCLUDES) \
48 $(QEMU_CFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) $($@-cflags) \
49 -c -o $@ $<,"CC","$(TARGET_DIR)$@")
51 # If we have a CXX we might have some C++ objects, in which case we
52 # must link with the C++ compiler, not the plain C compiler.
53 LINKPROG = $(or $(CXX),$(CC))
55 LINK = $(call quiet-command, $(LINKPROG) $(CFLAGS) $(QEMU_LDFLAGS) -o $@ \
56 $(filter-out %.a %.fa,$1) \
57 $(foreach l,$(filter %.fa,$1),$(call whole-archive,$l)) \
58 $(filter %.a,$1) \
59 $(call extract-libs,$1) $(LIBS),"LINK","$(TARGET_DIR)$@")
61 %.o: %.S
62 $(call quiet-command,$(CCAS) $(QEMU_LOCAL_INCLUDES) $(QEMU_INCLUDES) \
63 $(QEMU_CFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) \
64 -c -o $@ $<,"CCAS","$(TARGET_DIR)$@")
66 %.o: %.cc
67 $(call quiet-command,$(CXX) $(QEMU_LOCAL_INCLUDES) $(QEMU_INCLUDES) \
68 $(QEMU_CXXFLAGS) $(QEMU_DGFLAGS) $(CXXFLAGS) $($@-cflags) \
69 -c -o $@ $<,"CXX","$(TARGET_DIR)$@")
71 %.o: %.cpp
72 $(call quiet-command,$(CXX) $(QEMU_LOCAL_INCLUDES) $(QEMU_INCLUDES) \
73 $(QEMU_CXXFLAGS) $(QEMU_DGFLAGS) $(CXXFLAGS) $($@-cflags) \
74 -c -o $@ $<,"CXX","$(TARGET_DIR)$@")
76 %.o: %.m
77 $(call quiet-command,$(OBJCC) $(QEMU_LOCAL_INCLUDES) $(QEMU_INCLUDES) \
78 $(QEMU_CFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) $($@-cflags) \
79 -c -o $@ $<,"OBJC","$(TARGET_DIR)$@")
81 %.o: %.dtrace
82 $(call quiet-command,dtrace -o $@ -G -s $<,"GEN","$(TARGET_DIR)$@")
84 .PHONY: modules
85 modules:
87 %$(EXESUF): %.o
88 $(call LINK,$(filter %.o %.a %.fa, $^))
90 %.a:
91 $(call quiet-command,rm -f $@ && $(AR) rcs $@ $^,"AR","$(TARGET_DIR)$@")
93 # Usage: $(call quiet-command,command and args,"NAME","args to print")
94 # This will run "command and args", and either:
95 # if V=1 just print the whole command and args
96 # otherwise print the 'quiet' output in the format " NAME args to print"
97 # NAME should be a short name of the command, 7 letters or fewer.
98 # If called with only a single argument, will print nothing in quiet mode.
99 quiet-command-run = $(if $(V),,$(if $2,printf " %-7s %s\n" $2 $3 && ))$1
100 quiet-@ = $(if $(V),,@)
101 quiet-command = $(quiet-@)$(call quiet-command-run,$1,$2,$3)
103 # cc-option
104 # Usage: CFLAGS+=$(call cc-option, -falign-functions=0, -malign-functions=0)
106 cc-option = $(if $(shell $(CC) $1 $2 -S -o /dev/null -xc /dev/null \
107 >/dev/null 2>&1 && echo OK), $2, $3)
108 cc-c-option = $(if $(shell $(CC) $1 $2 -c -o /dev/null -xc /dev/null \
109 >/dev/null 2>&1 && echo OK), $2, $3)
111 VPATH_SUFFIXES = %.c %.h %.S %.cc %.cpp %.m %.mak %.texi %.sh %.rc Kconfig% %.json.in
112 set-vpath = $(if $1,$(foreach PATTERN,$(VPATH_SUFFIXES),$(eval vpath $(PATTERN) $1)))
114 # install-prog list, dir
115 define install-prog
116 $(INSTALL_DIR) "$2"
117 $(INSTALL_PROG) $1 "$2"
118 $(if $(STRIP),$(STRIP) $(foreach T,$1,"$2/$(notdir $T)"),)
119 endef
121 # Logical functions (for operating on y/n values like CONFIG_FOO vars)
122 # Inputs to these must be either "y" (true) or "n" or "" (both false)
123 # Output is always either "y" or "n".
124 # Usage: $(call land,$(CONFIG_FOO),$(CONFIG_BAR))
125 # Logical NOT
126 lnot = $(if $(subst n,,$1),n,y)
127 # Logical AND
128 land = $(if $(findstring yy,$1$2),y,n)
129 # Logical OR
130 lor = $(if $(findstring y,$1$2),y,n)
131 # Logical XOR (note that this is the inverse of leqv)
132 lxor = $(if $(filter $(call lnot,$1),$(call lnot,$2)),n,y)
133 # Logical equivalence (note that leqv "","n" is true)
134 leqv = $(if $(filter $(call lnot,$1),$(call lnot,$2)),y,n)
135 # Logical if: like make's $(if) but with an leqv-like test
136 lif = $(if $(subst n,,$1),$2,$3)
138 # String testing functions: inputs to these can be any string;
139 # the output is always either "y" or "n". Leading and trailing whitespace
140 # is ignored when comparing strings.
141 # String equality
142 eq = $(if $(subst $2,,$1)$(subst $1,,$2),n,y)
143 # String inequality
144 ne = $(if $(subst $2,,$1)$(subst $1,,$2),y,n)
145 # Emptiness/non-emptiness tests:
146 isempty = $(if $1,n,y)
147 notempty = $(if $1,y,n)
149 .PHONY: clean-timestamp
150 clean-timestamp:
151 rm -f *.timestamp
152 clean: clean-timestamp
154 # will delete the target of a rule if commands exit with a nonzero exit status
155 .DELETE_ON_ERROR:
157 print-%:
158 @echo '$*=$($*)'