hw/sd/pl181: Replace fprintf(stderr, "*\n") with error_report()
[qemu/ar7.git] / Makefile
blob8373ddccc93766de7d22544cfeaae01ef99d908d
1 # Makefile for QEMU.
3 ifneq ($(words $(subst :, ,$(CURDIR))), 1)
4 $(error main directory cannot contain spaces nor colons)
5 endif
7 # Always point to the root of the build tree (needs GNU make).
8 BUILD_DIR=$(CURDIR)
10 # Before including a proper config-host.mak, assume we are in the source tree
11 SRC_PATH=.
13 UNCHECKED_GOALS := %clean TAGS cscope ctags dist \
14 help check-help print-% \
15 docker docker-% vm-help vm-test vm-build-%
17 # All following code might depend on configuration variables
18 ifneq ($(wildcard config-host.mak),)
19 # Put the all: rule here so that config-host.mak can contain dependencies.
20 all:
21 include config-host.mak
23 git-submodule-update:
25 .PHONY: git-submodule-update
27 git_module_status := $(shell \
28 cd '$(SRC_PATH)' && \
29 GIT="$(GIT)" ./scripts/git-submodule.sh status $(GIT_SUBMODULES); \
30 echo $$?; \
33 ifeq (1,$(git_module_status))
34 ifeq (no,$(GIT_UPDATE))
35 git-submodule-update:
36 $(call quiet-command, \
37 echo && \
38 echo "GIT submodule checkout is out of date. Please run" && \
39 echo " scripts/git-submodule.sh update $(GIT_SUBMODULES)" && \
40 echo "from the source directory checkout $(SRC_PATH)" && \
41 echo && \
42 exit 1)
43 else
44 git-submodule-update:
45 $(call quiet-command, \
46 (cd $(SRC_PATH) && GIT="$(GIT)" ./scripts/git-submodule.sh update $(GIT_SUBMODULES)), \
47 "GIT","$(GIT_SUBMODULES)")
48 endif
49 endif
51 export NINJA=./ninjatool
53 # Running meson regenerates both build.ninja and ninjatool, and that is
54 # enough to prime the rest of the build.
55 ninjatool: build.ninja
57 # Only needed in case Makefile.ninja does not exist.
58 .PHONY: ninja-clean ninja-distclean clean-ctlist
59 clean-ctlist:
60 ninja-clean::
61 ninja-distclean::
62 build.ninja: config-host.mak
64 Makefile.ninja: build.ninja ninjatool
65 ./ninjatool -t ninja2make --omit clean dist uninstall < $< > $@
66 -include Makefile.ninja
68 ${ninja-targets-c_COMPILER} ${ninja-targets-cpp_COMPILER}: .var.command += -MP
70 # If MESON is empty, the rule will be re-evaluated after Makefiles are
71 # reread (and MESON won't be empty anymore).
72 ifneq ($(MESON),)
73 Makefile.mtest: build.ninja scripts/mtest2make.py
74 $(MESON) introspect --tests | $(PYTHON) scripts/mtest2make.py > $@
75 -include Makefile.mtest
76 endif
78 .git-submodule-status: git-submodule-update config-host.mak
80 # Check that we're not trying to do an out-of-tree build from
81 # a tree that's been used for an in-tree build.
82 ifneq ($(realpath $(SRC_PATH)),$(realpath .))
83 ifneq ($(wildcard $(SRC_PATH)/config-host.mak),)
84 $(error This is an out of tree build but your source tree ($(SRC_PATH)) \
85 seems to have been used for an in-tree build. You can fix this by running \
86 "$(MAKE) distclean && rm -rf *-linux-user *-softmmu" in your source tree)
87 endif
88 endif
90 CONFIG_SOFTMMU := $(if $(filter %-softmmu,$(TARGET_DIRS)),y)
91 CONFIG_USER_ONLY := $(if $(filter %-user,$(TARGET_DIRS)),y)
92 CONFIG_XEN := $(CONFIG_XEN_BACKEND)
93 CONFIG_ALL=y
94 -include config-all-devices.mak
95 -include config-all-disas.mak
97 config-host.mak: $(SRC_PATH)/configure $(SRC_PATH)/pc-bios $(SRC_PATH)/VERSION
98 @echo $@ is out-of-date, running configure
99 @if test -f meson-private/coredata.dat; then \
100 ./config.status --skip-meson; \
101 else \
102 ./config.status; \
105 # Force configure to re-run if the API symbols are updated
106 ifeq ($(CONFIG_PLUGIN),y)
107 config-host.mak: $(SRC_PATH)/plugins/qemu-plugins.symbols
108 endif
110 else
111 config-host.mak:
112 ifneq ($(filter-out $(UNCHECKED_GOALS),$(MAKECMDGOALS)),$(if $(MAKECMDGOALS),,fail))
113 @echo "Please call configure before running make!"
114 @exit 1
115 endif
116 endif
118 include $(SRC_PATH)/rules.mak
120 # lor is defined in rules.mak
121 CONFIG_BLOCK := $(call lor,$(CONFIG_SOFTMMU),$(CONFIG_TOOLS))
123 generated-files-y += .git-submodule-status
125 # Don't try to regenerate Makefile or configure
126 # We don't generate any of them
127 Makefile: ;
128 configure: ;
130 .PHONY: all clean cscope distclean install \
131 recurse-all dist msi FORCE
133 $(call set-vpath, $(SRC_PATH))
135 LIBS+=-lz $(LIBS_TOOLS)
137 SUBDIR_MAKEFLAGS=$(if $(V),,--no-print-directory --quiet) BUILD_DIR=$(BUILD_DIR)
139 ifneq ($(wildcard config-host.mak),)
140 include $(SRC_PATH)/Makefile.objs
141 endif
143 include $(SRC_PATH)/tests/Makefile.include
145 all: recurse-all
146 Makefile: $(addsuffix /all, $(SUBDIRS))
148 # LIBFDT_lib="": avoid breaking existing trees with objects requiring -fPIC
149 DTC_MAKE_ARGS=-I$(SRC_PATH)/dtc VPATH=$(SRC_PATH)/dtc -C dtc V="$(V)" LIBFDT_lib=""
150 DTC_CFLAGS=$(CFLAGS) $(QEMU_CFLAGS)
151 DTC_CPPFLAGS=-I$(SRC_PATH)/dtc/libfdt
153 .PHONY: dtc/all
154 dtc/all: .git-submodule-status dtc/libfdt
155 $(call quiet-command,$(MAKE) $(DTC_MAKE_ARGS) CPPFLAGS="$(DTC_CPPFLAGS)" CFLAGS="$(DTC_CFLAGS)" LDFLAGS="$(QEMU_LDFLAGS)" ARFLAGS="$(ARFLAGS)" CC="$(CC)" AR="$(AR)" LD="$(LD)" $(SUBDIR_MAKEFLAGS) libfdt,)
157 dtc/%: .git-submodule-status
158 @mkdir -p $@
160 # Overriding CFLAGS causes us to lose defines added in the sub-makefile.
161 # Not overriding CFLAGS leads to mis-matches between compilation modes.
162 # Therefore we replicate some of the logic in the sub-makefile.
163 # Remove all the extra -Warning flags that QEMU uses that Capstone doesn't;
164 # no need to annoy QEMU developers with such things.
165 CAP_CFLAGS = $(patsubst -W%,,$(CFLAGS) $(QEMU_CFLAGS))
166 CAP_CFLAGS += -DCAPSTONE_USE_SYS_DYN_MEM
167 CAP_CFLAGS += -DCAPSTONE_HAS_ARM
168 CAP_CFLAGS += -DCAPSTONE_HAS_ARM64
169 CAP_CFLAGS += -DCAPSTONE_HAS_POWERPC
170 CAP_CFLAGS += -DCAPSTONE_HAS_X86
172 .PHONY: capstone/all
173 capstone/all: .git-submodule-status
174 $(call quiet-command,$(MAKE) -C $(SRC_PATH)/capstone CAPSTONE_SHARED=no BUILDDIR="$(BUILD_DIR)/capstone" CC="$(CC)" AR="$(AR)" LD="$(LD)" RANLIB="$(RANLIB)" CFLAGS="$(CAP_CFLAGS)" $(SUBDIR_MAKEFLAGS) $(BUILD_DIR)/capstone/$(LIBCAPSTONE))
176 .PHONY: slirp/all
177 slirp/all: .git-submodule-status
178 $(call quiet-command,$(MAKE) -C $(SRC_PATH)/slirp \
179 BUILD_DIR="$(BUILD_DIR)/slirp" \
180 PKG_CONFIG="$(PKG_CONFIG)" \
181 CC="$(CC)" AR="$(AR)" LD="$(LD)" RANLIB="$(RANLIB)" \
182 CFLAGS="$(QEMU_CFLAGS) $(CFLAGS)" LDFLAGS="$(QEMU_LDFLAGS)")
184 ROM_DIRS = $(addprefix pc-bios/, $(ROMS))
185 ROM_DIRS_RULES=$(foreach t, all clean, $(addsuffix /$(t), $(ROM_DIRS)))
186 # Only keep -O and -g cflags
187 .PHONY: $(ROM_DIRS_RULES)
188 $(ROM_DIRS_RULES):
189 $(call quiet-command,$(MAKE) $(SUBDIR_MAKEFLAGS) -C $(dir $@) V="$(V)" TARGET_DIR="$(dir $@)" CFLAGS="$(filter -O% -g%,$(CFLAGS))" $(notdir $@),)
191 .PHONY: recurse-all recurse-clean
192 recurse-all: $(ROM_DIRS)
193 recurse-clean: $(addsuffix /clean, $(ROM_DIRS))
195 ######################################################################
197 clean: recurse-clean ninja-clean clean-ctlist
198 -test -f ninjatool && ./ninjatool $(if $(V),-v,) -t clean
199 # avoid old build problems by removing potentially incorrect old files
200 rm -f config.mak op-i386.h opc-i386.h gen-op-i386.h op-arm.h opc-arm.h gen-op-arm.h
201 find . \( -name '*.so' -o -name '*.dll' -o -name '*.[oda]' \) -type f \
202 ! -path ./roms/edk2/ArmPkg/Library/GccLto/liblto-aarch64.a \
203 ! -path ./roms/edk2/ArmPkg/Library/GccLto/liblto-arm.a \
204 ! -path ./roms/edk2/BaseTools/Source/Python/UPT/Dll/sqlite3.dll \
205 -exec rm {} +
206 rm -f TAGS cscope.* *.pod *~ */*~
207 rm -f fsdev/*.pod scsi/*.pod
208 rm -f $(foreach f,$(generated-files-y),$(f) $(f)-timestamp)
210 VERSION = $(shell cat $(SRC_PATH)/VERSION)
212 dist: qemu-$(VERSION).tar.bz2
214 qemu-%.tar.bz2:
215 $(SRC_PATH)/scripts/make-release "$(SRC_PATH)" "$(patsubst qemu-%.tar.bz2,%,$@)"
217 distclean: clean ninja-distclean
218 -test -f ninjatool && ./ninjatool $(if $(V),-v,) -t clean -g
219 rm -f config-host.mak config-host.h*
220 rm -f tests/tcg/config-*.mak
221 rm -f config-all-disas.mak config.status
222 rm -f tests/qemu-iotests/common.env
223 rm -f roms/seabios/config.mak roms/vgabios/config.mak
224 rm -f qemu-plugins-ld.symbols qemu-plugins-ld64.symbols
225 rm -f *-config-target.h *-config-devices.mak *-config-devices.h
226 rm -rf meson-private meson-logs meson-info compile_commands.json
227 rm -f Makefile.ninja ninjatool ninjatool.stamp Makefile.mtest
228 rm -f config.log
229 rm -f linux-headers/asm
230 rm -Rf .sdk
232 KEYMAPS=da en-gb et fr fr-ch is lt no pt-br sv \
233 ar de en-us fi fr-be hr it lv nl pl ru th \
234 de-ch es fo fr-ca hu ja mk pt sl tr \
235 bepo cz
237 ifdef INSTALL_BLOBS
238 BLOBS=bios.bin bios-256k.bin bios-microvm.bin sgabios.bin vgabios.bin vgabios-cirrus.bin \
239 vgabios-stdvga.bin vgabios-vmware.bin vgabios-qxl.bin vgabios-virtio.bin \
240 vgabios-ramfb.bin vgabios-bochs-display.bin vgabios-ati.bin \
241 openbios-sparc32 openbios-sparc64 openbios-ppc QEMU,tcx.bin QEMU,cgthree.bin \
242 pxe-e1000.rom pxe-eepro100.rom pxe-ne2k_pci.rom \
243 pxe-pcnet.rom pxe-rtl8139.rom pxe-virtio.rom \
244 efi-e1000.rom efi-eepro100.rom efi-ne2k_pci.rom \
245 efi-pcnet.rom efi-rtl8139.rom efi-virtio.rom \
246 efi-e1000e.rom efi-vmxnet3.rom \
247 qemu-nsis.bmp \
248 bamboo.dtb canyonlands.dtb petalogix-s3adsp1800.dtb petalogix-ml605.dtb \
249 multiboot.bin linuxboot.bin linuxboot_dma.bin kvmvapic.bin pvh.bin \
250 s390-ccw.img s390-netboot.img \
251 slof.bin skiboot.lid \
252 palcode-clipper \
253 u-boot.e500 u-boot-sam460-20100605.bin \
254 qemu_vga.ndrv \
255 edk2-licenses.txt \
256 hppa-firmware.img \
257 opensbi-riscv32-sifive_u-fw_jump.bin opensbi-riscv32-virt-fw_jump.bin \
258 opensbi-riscv64-sifive_u-fw_jump.bin opensbi-riscv64-virt-fw_jump.bin
259 else
260 BLOBS=
261 endif
263 install-datadir:
264 $(INSTALL_DIR) "$(DESTDIR)$(qemu_datadir)"
266 install-localstatedir:
267 ifdef CONFIG_POSIX
268 ifeq ($(CONFIG_GUEST_AGENT),y)
269 $(INSTALL_DIR) "$(DESTDIR)$(qemu_localstatedir)"/run
270 endif
271 endif
273 ICON_SIZES=16x16 24x24 32x32 48x48 64x64 128x128 256x256 512x512
275 # Needed by "meson install"
276 export DESTDIR
277 install: all install-datadir install-localstatedir
278 ifdef CONFIG_TRACE_SYSTEMTAP
279 $(INSTALL_PROG) "scripts/qemu-trace-stap" $(DESTDIR)$(bindir)
280 endif
281 ifneq ($(BLOBS),)
282 set -e; for x in $(BLOBS); do \
283 $(INSTALL_DATA) $(SRC_PATH)/pc-bios/$$x "$(DESTDIR)$(qemu_datadir)"; \
284 done
285 endif
286 for s in $(ICON_SIZES); do \
287 mkdir -p "$(DESTDIR)$(qemu_icondir)/hicolor/$${s}/apps"; \
288 $(INSTALL_DATA) $(SRC_PATH)/ui/icons/qemu_$${s}.png \
289 "$(DESTDIR)$(qemu_icondir)/hicolor/$${s}/apps/qemu.png"; \
290 done; \
291 mkdir -p "$(DESTDIR)$(qemu_icondir)/hicolor/32x32/apps"; \
292 $(INSTALL_DATA) $(SRC_PATH)/ui/icons/qemu_32x32.bmp \
293 "$(DESTDIR)$(qemu_icondir)/hicolor/32x32/apps/qemu.bmp"; \
294 mkdir -p "$(DESTDIR)$(qemu_icondir)/hicolor/scalable/apps"; \
295 $(INSTALL_DATA) $(SRC_PATH)/ui/icons/qemu.svg \
296 "$(DESTDIR)$(qemu_icondir)/hicolor/scalable/apps/qemu.svg"
297 mkdir -p "$(DESTDIR)$(qemu_desktopdir)"
298 $(INSTALL_DATA) $(SRC_PATH)/ui/qemu.desktop \
299 "$(DESTDIR)$(qemu_desktopdir)/qemu.desktop"
300 $(INSTALL_DIR) "$(DESTDIR)$(qemu_datadir)/keymaps"
301 set -e; for x in $(KEYMAPS); do \
302 $(INSTALL_DATA) $(SRC_PATH)/pc-bios/keymaps/$$x "$(DESTDIR)$(qemu_datadir)/keymaps"; \
303 done
305 ifdef CONFIG_WIN32
307 INSTALLER = qemu-setup-$(VERSION)$(EXESUF)
309 nsisflags = -V2 -NOCD
311 ifneq ($(wildcard $(SRC_PATH)/dll),)
312 ifeq ($(ARCH),x86_64)
313 # 64 bit executables
314 DLL_PATH = $(SRC_PATH)/dll/w64
315 nsisflags += -DW64
316 else
317 # 32 bit executables
318 DLL_PATH = $(SRC_PATH)/dll/w32
319 endif
320 endif
322 .PHONY: installer
323 installer: $(INSTALLER)
325 INSTDIR=/tmp/qemu-nsis
327 $(INSTALLER): $(SRC_PATH)/qemu.nsi
328 $(MAKE) install DESTDIR=${INSTDIR}
329 ifdef SIGNCODE
330 (cd ${INSTDIR}/${bindir}; \
331 for i in *.exe; do \
332 $(SIGNCODE) $${i}; \
333 done \
335 endif # SIGNCODE
336 (cd ${INSTDIR}/${bindir}; \
337 for i in qemu-system-*.exe; do \
338 arch=$${i%.exe}; \
339 arch=$${arch#qemu-system-}; \
340 echo Section \"$$arch\" Section_$$arch; \
341 echo SetOutPath \"\$$INSTDIR\"; \
342 echo File \"\$${BINDIR}\\$$i\"; \
343 echo SectionEnd; \
344 done \
345 ) >${INSTDIR}/${bindir}/system-emulations.nsh
346 makensis $(nsisflags) \
347 $(if $(BUILD_DOCS),-DCONFIG_DOCUMENTATION="y") \
348 $(if $(CONFIG_GTK),-DCONFIG_GTK="y") \
349 -DBINDIR="${INSTDIR}/${bindir}" \
350 $(if $(DLL_PATH),-DDLLDIR="$(DLL_PATH)") \
351 -DSRCDIR="$(SRC_PATH)" \
352 -DOUTFILE="$(INSTALLER)" \
353 -DDISPLAYVERSION="$(VERSION)" \
354 $(SRC_PATH)/qemu.nsi
355 rm -r ${INSTDIR}
356 ifdef SIGNCODE
357 $(SIGNCODE) $(INSTALLER)
358 endif # SIGNCODE
359 endif # CONFIG_WIN
361 # Add a dependency on the generated files, so that they are always
362 # rebuilt before other object files
363 ifneq ($(wildcard config-host.mak),)
364 ifneq ($(filter-out $(UNCHECKED_GOALS),$(MAKECMDGOALS)),$(if $(MAKECMDGOALS),,fail))
365 Makefile: $(generated-files-y)
366 endif
367 endif
369 # Include automatically generated dependency files
370 # Dependencies in Makefile.objs files come from our recursive subdir rules
371 -include $(wildcard *.d tests/*.d)
373 include $(SRC_PATH)/tests/docker/Makefile.include
374 include $(SRC_PATH)/tests/vm/Makefile.include
376 print-help-run = printf " %-30s - %s\\n" "$1" "$2"
377 print-help = $(quiet-@)$(call print-help-run,$1,$2)
379 .PHONY: help
380 help:
381 @echo 'Generic targets:'
382 $(call print-help,all,Build all)
383 $(call print-help,dir/file.o,Build specified target only)
384 $(call print-help,install,Install QEMU, documentation and tools)
385 $(call print-help,ctags/TAGS,Generate tags file for editors)
386 $(call print-help,cscope,Generate cscope index)
387 $(call print-help,sparse,Run sparse on the QEMU source)
388 @echo ''
389 @echo 'Cleaning targets:'
390 $(call print-help,clean,Remove most generated files but keep the config)
391 $(call print-help,distclean,Remove all generated files)
392 $(call print-help,dist,Build a distributable tarball)
393 @echo ''
394 @echo 'Test targets:'
395 $(call print-help,check,Run all tests (check-help for details))
396 $(call print-help,docker,Help about targets running tests inside containers)
397 $(call print-help,vm-help,Help about targets running tests inside VM)
398 @echo ''
399 @echo 'Documentation targets:'
400 $(call print-help,html info pdf txt man,Build documentation in specified format)
401 @echo ''
402 ifdef CONFIG_WIN32
403 @echo 'Windows targets:'
404 $(call print-help,installer,Build NSIS-based installer for QEMU)
405 ifdef QEMU_GA_MSI_ENABLED
406 $(call print-help,msi,Build MSI-based installer for qemu-ga)
407 endif
408 @echo ''
409 endif
410 $(call print-help,$(MAKE) [targets],(quiet build, default))
411 $(call print-help,$(MAKE) V=1 [targets],(verbose build))