2 # Don't use implicit rules or variables
3 # we have explicit rules for everything
6 # Files with this suffixes are final, don't try to generate them
15 # Flags for C++ compilation
16 QEMU_CXXFLAGS
= -D__STDC_LIMIT_MACROS
$(filter-out -Wstrict-prototypes
-Wmissing-prototypes
-Wnested-externs
-Wold-style-declaration
-Wold-style-definition
-Wredundant-decls
, $(QEMU_CFLAGS
))
18 # Flags for dependency generation
19 QEMU_DGFLAGS
+= -MMD
-MP
-MT
$@
-MF
$(*D
)/$(*F
).d
21 # Same as -I$(SRC_PATH) -I., but for the nested source/object directories
22 QEMU_INCLUDES
+= -I
$(<D
) -I
$(@D
)
25 $(call quiet-command
,$(CC
) $(QEMU_INCLUDES
) $(QEMU_CFLAGS
) $(QEMU_DGFLAGS
) $(CFLAGS
) -c
-o
$@
$<," CC $(TARGET_DIR)$@")
27 $(call quiet-command
,$(WINDRES
) -I.
-o
$@
$<," RC $(TARGET_DIR)$@")
30 LINK
= $(call quiet-command
,$(CC
) $(QEMU_CFLAGS
) $(CFLAGS
) $(LDFLAGS
) -o
$@ \
31 $(sort $(filter %.o
, $1)) $(filter-out %.o
, $1) $(version-obj-y
) \
32 $(LIBS
)," LINK $(TARGET_DIR)$@")
34 LIBTOOL
+= $(if
$(V
),,--quiet
)
36 $(call quiet-command
,$(LIBTOOL
) --mode
=compile
--tag
=CC
$(CC
) $(QEMU_INCLUDES
) $(QEMU_CFLAGS
) $(QEMU_DGFLAGS
) $(CFLAGS
) -c
-o
$@
$<," lt CC $@")
38 $(call quiet-command
,$(LIBTOOL
) --mode
=compile
--tag
=RC
$(WINDRES
) -I.
-o
$@
$<,"lt RC $(TARGET_DIR)$@")
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)$@")
52 $(call quiet-command
,$(CPP
) $(QEMU_INCLUDES
) $(QEMU_CFLAGS
) $(QEMU_DGFLAGS
) $(CFLAGS
) -o
$@
$<," CPP $(TARGET_DIR)$@")
55 $(call quiet-command
,$(AS
) $(ASFLAGS
) -o
$@
$<," AS $(TARGET_DIR)$@")
58 $(call quiet-command
,$(CXX
) $(QEMU_INCLUDES
) $(QEMU_CXXFLAGS
) $(QEMU_DGFLAGS
) $(CFLAGS
) -c
-o
$@
$<," CXX $(TARGET_DIR)$@")
61 $(call quiet-command
,$(OBJCC
) $(QEMU_INCLUDES
) $(QEMU_CFLAGS
) $(QEMU_DGFLAGS
) $(CFLAGS
) -c
-o
$@
$<," OBJC $(TARGET_DIR)$@")
64 $(call quiet-command
,dtrace
-o
$@
-G
-s
$<, " GEN $(TARGET_DIR)$@")
70 $(call quiet-command
,rm -f
$@
&& $(AR
) rcs
$@
$^
," AR $(TARGET_DIR)$@")
72 quiet-command
= $(if
$(V
),$1,$(if
$(2),@echo
$2 && $1, @
$1))
75 # Usage: CFLAGS+=$(call cc-option, -falign-functions=0, -malign-functions=0)
77 cc-option
= $(if
$(shell $(CC
) $1 $2 -S
-o
/dev
/null
-xc
/dev
/null \
78 >/dev
/null
2>&1 && echo OK
), $2, $3)
80 VPATH_SUFFIXES
= %.c
%.h
%.S
%.
cpp %.m
%.mak
%.texi
%.sh
%.rc
81 set-vpath
= $(if
$1,$(foreach PATTERN
,$(VPATH_SUFFIXES
),$(eval vpath
$(PATTERN
) $1)))
84 # Usage: $(call find-in-path, prog)
85 # Looks in the PATH if the argument contains no slash, else only considers one
86 # specific directory. Returns an # empty string if the program doesn't exist
88 find-in-path
= $(if
$(find-string
/, $1), \
90 $(wildcard $(patsubst %, %/$1, $(subst :, ,$(PATH
)))))
92 # Generate files with tracetool
93 TRACETOOL
=$(PYTHON
) $(SRC_PATH
)/scripts
/tracetool.py
95 # Generate timestamp files for .h include files
97 config-
%.h
: config-
%.h-timestamp
98 @cmp
$< $@
>/dev
/null
2>&1 || cp
$< $@
100 config-
%.h-timestamp
: config-
%.mak
101 $(call quiet-command
, sh
$(SRC_PATH
)/scripts
/create_config
< $< > $@
, " GEN $(TARGET_DIR)config-$*.h")
103 .PHONY
: clean-timestamp
106 clean: clean-timestamp
108 # will delete the target of a rule if commands exit with a nonzero exit status
111 # magic to descend into other directories
117 $(eval save-
$2-$1 = $(value
$1))
122 $(eval subdir-
$2-$1 := $(if
$(filter $2,$(save-
$2-$1)),$(addprefix $2,$($1))))
123 $(eval
$1 = $(value save-
$2-$1) $$(subdir-
$2-$1))
124 $(eval save-
$2-$1 :=)
128 $(foreach var
,$(nested-vars
),$(call push-var
,$(var
),$1/))
129 $(eval obj
:= $(obj
)/$1)
130 $(eval
include $(SRC_PATH
)/$1/Makefile.objs
)
131 $(eval obj
:= $(patsubst %/$1,%,$(obj
)))
132 $(foreach var
,$(nested-vars
),$(call pop-var
,$(var
),$1/))
136 $(eval nested-dirs
:= $(filter-out \
137 $(old-nested-dirs
), \
138 $(sort $(foreach var
,$(nested-vars
), $(filter %/, $($(var
)))))))
140 $(foreach dir,$(nested-dirs
),$(call unnest-dir
,$(patsubst %/,%,$(dir))))
141 $(eval old-nested-dirs
:= $(old-nested-dirs
) $(nested-dirs
))
142 $(call unnest-vars-1
))
146 $(call unnest-vars-1
)
147 $(foreach var
,$(nested-vars
),$(eval
$(var
) := $(filter-out %/, $($(var
)))))
148 $(shell mkdir
-p
$(sort $(foreach var
,$(nested-vars
),$(dir $($(var
))))))
149 $(foreach var
,$(nested-vars
), $(eval \
150 -include $(addsuffix *.d
, $(sort $(dir $($(var
)))))))