3 TARGET_BASE_ARCH:=$(TARGET_ARCH)
4 ifeq ($(TARGET_ARCH), x86_64)
7 ifeq ($(TARGET_ARCH), mips64)
10 ifeq ($(TARGET_ARCH), ppc64)
13 ifeq ($(TARGET_ARCH), ppcemb)
16 ifeq ($(TARGET_ARCH), sparc64)
17 TARGET_BASE_ARCH:=sparc
19 TARGET_PATH=$(SRC_PATH)/target-$(TARGET_BASE_ARCH)
20 VPATH=$(SRC_PATH):$(TARGET_PATH):$(SRC_PATH)/hw:$(SRC_PATH)/audio
21 CPPFLAGS=-I. -I.. -I$(TARGET_PATH) -I$(SRC_PATH)
22 ifdef CONFIG_DARWIN_USER
23 VPATH+=:$(SRC_PATH)/darwin-user
24 CPPFLAGS+=-I$(SRC_PATH)/darwin-user -I$(SRC_PATH)/darwin-user/$(TARGET_ARCH)
26 ifdef CONFIG_LINUX_USER
27 VPATH+=:$(SRC_PATH)/linux-user
28 CPPFLAGS+=-I$(SRC_PATH)/linux-user -I$(SRC_PATH)/linux-user/$(TARGET_ARCH)
34 HELPER_CFLAGS=$(CFLAGS)
35 DYNGEN=../dyngen$(EXESUF)
37 TARGET_ARCH2=$(TARGET_ARCH)
38 ifeq ($(TARGET_ARCH),arm)
39 ifeq ($(TARGET_WORDS_BIGENDIAN),yes)
43 ifeq ($(TARGET_ARCH),sh4)
44 ifeq ($(TARGET_WORDS_BIGENDIAN),yes)
48 ifeq ($(TARGET_ARCH),mips)
49 ifneq ($(TARGET_WORDS_BIGENDIAN),yes)
53 ifeq ($(TARGET_ARCH),mips64)
54 ifneq ($(TARGET_WORDS_BIGENDIAN),yes)
58 QEMU_USER=qemu-$(TARGET_ARCH2)
59 # system emulator name
61 ifeq ($(TARGET_ARCH), i386)
62 QEMU_SYSTEM=qemu$(EXESUF)
64 QEMU_SYSTEM=qemu-system-$(TARGET_ARCH2)$(EXESUF)
70 ifdef CONFIG_USER_ONLY
77 endif # !CONFIG_USER_ONLY
83 # We require -O2 to avoid the stack setup prologue in EXIT_TB
84 OP_CFLAGS := -Wall -O2 -g -fno-strict-aliasing
87 # Usage: OP_CFLAGS+=$(call cc-option, -falign-functions=0, -malign-functions=0)
89 cc-option = $(shell if $(CC) $(OP_CFLAGS) $(1) -S -o /dev/null -xc /dev/null \
90 > /dev/null 2>&1; then echo "$(1)"; else echo "$(2)"; fi ;)
92 OP_CFLAGS+=$(call cc-option, -fno-reorder-blocks, "")
93 OP_CFLAGS+=$(call cc-option, -fno-gcse, "")
94 OP_CFLAGS+=$(call cc-option, -fno-tree-ch, "")
95 OP_CFLAGS+=$(call cc-option, -fno-optimize-sibling-calls, "")
96 OP_CFLAGS+=$(call cc-option, -fno-crossjumping, "")
97 OP_CFLAGS+=$(call cc-option, -fno-align-labels, "")
98 OP_CFLAGS+=$(call cc-option, -fno-align-jumps, "")
99 OP_CFLAGS+=$(call cc-option, -fno-align-functions, $(call cc-option, -malign-functions=0, ""))
102 HELPER_CFLAGS+=-fomit-frame-pointer
103 OP_CFLAGS+=-mpreferred-stack-boundary=2 -fomit-frame-pointer
111 BASE_LDFLAGS+=-Wl,-T,$(SRC_PATH)/$(ARCH).ld
113 ifdef CONFIG_LINUX_USER
114 # WARNING: this LDFLAGS is _very_ tricky : qemu is an ELF shared object
115 # that the kernel ELF loader considers as an executable. I think this
116 # is the simplest way to make it self virtualizable!
117 BASE_LDFLAGS+=-Wl,-shared
122 ifeq ($(ARCH),x86_64)
123 BASE_LDFLAGS+=-Wl,-T,$(SRC_PATH)/$(ARCH).ld
127 CPPFLAGS+= -D__powerpc__
128 ifdef CONFIG_LINUX_USER
129 BASE_LDFLAGS+=-Wl,-T,$(SRC_PATH)/$(ARCH).ld
134 BASE_LDFLAGS+=-Wl,-T,$(SRC_PATH)/$(ARCH).ld
138 BASE_CFLAGS+=-ffixed-g2 -ffixed-g3
139 OP_CFLAGS+=-fno-delayed-branch -ffixed-i0
140 ifeq ($(CONFIG_SOLARIS),yes)
141 OP_CFLAGS+=-fno-omit-frame-pointer
143 BASE_CFLAGS+=-ffixed-g1 -ffixed-g6
144 HELPER_CFLAGS=$(CFLAGS) -ffixed-i0 -mflat
145 # -static is used to avoid g1/g3 usage by the dynamic linker
146 BASE_LDFLAGS+=-Wl,-T,$(SRC_PATH)/$(ARCH).ld -static
150 ifeq ($(ARCH),sparc64)
151 BASE_CFLAGS+=-ffixed-g1 -ffixed-g4 -ffixed-g5 -ffixed-g7
152 OP_CFLAGS+=-mcpu=ultrasparc -m64 -fno-delayed-branch -ffixed-i0
153 ifneq ($(CONFIG_SOLARIS),yes)
154 BASE_LDFLAGS+=-Wl,-T,$(SRC_PATH)/$(ARCH).ld
155 OP_CFLAGS+=-ffixed-g1 -ffixed-g4 -ffixed-g5 -ffixed-g7
160 # -msmall-data is not used for OP_CFLAGS because we want two-instruction
161 # relocations for the constant constructions
162 # Ensure there's only a single GP
163 BASE_CFLAGS+=-msmall-data
164 BASE_LDFLAGS+=-Wl,-T,$(SRC_PATH)/$(ARCH).ld
168 BASE_CFLAGS+=-mno-sdata
169 OP_CFLAGS+=-mno-sdata
170 BASE_LDFLAGS+=-Wl,-G0 -Wl,-T,$(SRC_PATH)/$(ARCH).ld
174 OP_CFLAGS+=-mno-sched-prolog -fno-omit-frame-pointer
175 BASE_LDFLAGS+=-Wl,-T,$(SRC_PATH)/$(ARCH).ld
179 OP_CFLAGS+=-fomit-frame-pointer
180 BASE_LDFLAGS+=-Wl,-T,$(SRC_PATH)/$(ARCH).ld
184 ifeq ($(WORDS_BIGENDIAN),yes)
185 BASE_LDFLAGS+=-Wl,-T,$(SRC_PATH)/$(ARCH).ld
187 BASE_LDFLAGS+=-Wl,-T,$(SRC_PATH)/$(ARCH)el.ld
191 ifeq ($(ARCH),mips64)
192 ifeq ($(WORDS_BIGENDIAN),yes)
193 BASE_LDFLAGS+=-Wl,-T,$(SRC_PATH)/$(ARCH).ld
195 BASE_LDFLAGS+=-Wl,-T,$(SRC_PATH)/$(ARCH)el.ld
199 ifeq ($(CONFIG_DARWIN),yes)
203 ifdef CONFIG_DARWIN_USER
204 # Leave some space for the regular program loading zone
205 BASE_LDFLAGS+=-Wl,-segaddr,__STD_PROG_ZONE,0x1000 -image_base 0x0e000000
208 BASE_CFLAGS+=$(OS_CFLAGS) $(ARCH_CFLAGS)
209 BASE_LDFLAGS+=$(OS_LDFLAGS) $(ARCH_LDFLAGS)
210 OP_CFLAGS+=$(OS_CFLAGS) $(ARCH_CFLAGS)
211 OP_LDFLAGS+=$(OS_LDFLAGS) $(ARCH_LDFLAGS)
213 #########################################################
215 CPPFLAGS+=-D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE
217 ifndef CONFIG_USER_ONLY
221 LIBS+=-lwinmm -lws2_32 -liphlpapi
224 LIBS+=-lsocket -lnsl -lresolv
225 ifdef NEEDS_LIBSUNMATH
227 LDFLAGS+=-L/opt/SUNWspro/prod/lib -R/opt/SUNWspro/prod/lib
228 OP_CFLAGS+=-I/opt/SUNWspro/prod/include/cc
229 BASE_CFLAGS+=-I/opt/SUNWspro/prod/include/cc
236 main.o: BASE_CFLAGS+=-p
239 ifdef CONFIG_LINUX_USER
240 OBJS= main.o syscall.o mmap.o signal.o path.o osdep.o thunk.o \
241 elfload.o linuxload.o
243 ifdef TARGET_HAS_BFLT
247 ifeq ($(TARGET_ARCH), i386)
250 ifeq ($(TARGET_ARCH), arm)
251 OBJS+=nwfpe/fpa11.o nwfpe/fpa11_cpdo.o \
252 nwfpe/fpa11_cpdt.o nwfpe/fpa11_cprt.o nwfpe/fpopcode.o nwfpe/single_cpdo.o \
253 nwfpe/double_cpdo.o nwfpe/extended_cpdo.o arm-semi.o
255 ifeq ($(TARGET_ARCH), m68k)
256 OBJS+= m68k-sim.o m68k-semi.o
258 endif #CONFIG_LINUX_USER
260 ifdef CONFIG_DARWIN_USER
261 OBJS= main.o commpage.o machload.o mmap.o osdep.o signal.o syscall.o thunk.o
267 # cpu emulator library
268 LIBOBJS=exec.o kqemu.o translate-op.o translate-all.o cpu-exec.o\
270 ifdef CONFIG_SOFTFLOAT
271 LIBOBJS+=fpu/softfloat.o
273 LIBOBJS+=fpu/softfloat-native.o
275 CPPFLAGS+=-I$(SRC_PATH)/fpu
277 ifeq ($(TARGET_ARCH), i386)
278 LIBOBJS+=helper.o helper2.o
280 LIBOBJS+=translate-copy.o
284 ifeq ($(TARGET_ARCH), x86_64)
285 LIBOBJS+=helper.o helper2.o
288 ifeq ($(TARGET_BASE_ARCH), ppc)
289 LIBOBJS+= op_helper.o helper.o
292 ifeq ($(TARGET_BASE_ARCH), mips)
293 LIBOBJS+= op_helper.o helper.o
296 ifeq ($(TARGET_BASE_ARCH), sparc)
297 LIBOBJS+= op_helper.o helper.o
300 ifeq ($(TARGET_BASE_ARCH), arm)
301 LIBOBJS+= op_helper.o helper.o
304 ifeq ($(TARGET_BASE_ARCH), sh4)
305 LIBOBJS+= op_helper.o helper.o
308 ifeq ($(TARGET_BASE_ARCH), m68k)
312 ifeq ($(TARGET_BASE_ARCH), alpha)
313 LIBOBJS+= op_helper.o helper.o alpha_palcode.o
316 # NOTE: the disassembler code is only needed for debugging
318 ifeq ($(findstring i386, $(TARGET_ARCH) $(ARCH)),i386)
321 ifeq ($(findstring x86_64, $(TARGET_ARCH) $(ARCH)),x86_64)
327 ifeq ($(findstring alpha, $(TARGET_ARCH) $(ARCH)),alpha)
330 ifeq ($(findstring ppc, $(TARGET_BASE_ARCH) $(ARCH)),ppc)
333 ifeq ($(findstring mips, $(TARGET_BASE_ARCH) $(ARCH)),mips)
336 ifeq ($(findstring sparc, $(TARGET_BASE_ARCH) $(ARCH)),sparc)
339 ifeq ($(findstring arm, $(TARGET_ARCH) $(ARCH)),arm)
342 ifeq ($(findstring m68k, $(TARGET_ARCH) $(ARCH)),m68k)
345 ifeq ($(findstring sh4, $(TARGET_ARCH) $(ARCH)),sh4)
355 $(QEMU_USER): $(OBJS)
356 $(CC) $(LDFLAGS) $(BASE_LDFLAGS) -o $@ $^ $(LIBS)
358 # Mark as 32 bit binary, i. e. it will be mapped into the low 31 bit of
359 # the address space (31 bit so sign extending doesn't matter)
360 echo -ne '\001\000\000\000' | dd of=qemu bs=1 seek=48 count=4 conv=notrunc
363 # must use static linking to avoid leaving stuff in virtual address space
364 VL_OBJS=vl.o osdep.o readline.o monitor.o pci.o console.o loader.o isa_mmio.o
366 VL_OBJS+=block.o block-raw.o
367 VL_OBJS+=block-cow.o block-qcow.o aes.o block-vmdk.o block-cloop.o block-dmg.o block-bochs.o block-vpc.o block-vvfat.o block-qcow2.o
373 SOUND_HW = sb16.o es1370.o
374 AUDIODRV = audio.o noaudio.o wavaudio.o
376 AUDIODRV += sdlaudio.o
379 AUDIODRV += ossaudio.o
381 ifdef CONFIG_COREAUDIO
382 AUDIODRV += coreaudio.o
385 AUDIODRV += alsaaudio.o
389 AUDIODRV += dsoundaudio.o
390 LIBS += -lole32 -ldxguid
393 AUDIODRV += fmodaudio.o
394 audio.o fmodaudio.o: CPPFLAGS := -I$(CONFIG_FMOD_INC) $(CPPFLAGS)
395 LIBS += $(CONFIG_FMOD_LIB)
398 SOUND_HW += fmopl.o adlib.o
400 AUDIODRV+= wavcapture.o
403 VL_OBJS+= scsi-disk.o cdrom.o lsi53c895a.o
406 VL_OBJS+= usb.o usb-hub.o usb-linux.o usb-hid.o usb-ohci.o usb-msd.o
409 VL_OBJS += eeprom93xx.o
412 VL_OBJS += eepro100.o
417 ifeq ($(TARGET_BASE_ARCH), i386)
419 VL_OBJS+= ide.o pckbd.o ps2.o vga.o $(SOUND_HW) dma.o $(AUDIODRV)
420 VL_OBJS+= fdc.o mc146818rtc.o serial.o i8259.o i8254.o pcspk.o pc.o
421 VL_OBJS+= cirrus_vga.o mixeng.o apic.o parallel.o acpi.o piix_pci.o
422 VL_OBJS+= usb-uhci.o smbus_eeprom.o vmmouse.o vmware_vga.o
423 CPPFLAGS += -DHAS_AUDIO
425 ifeq ($(TARGET_BASE_ARCH), ppc)
426 VL_OBJS+= ppc.o ide.o pckbd.o ps2.o vga.o $(SOUND_HW) dma.o $(AUDIODRV)
427 VL_OBJS+= mc146818rtc.o serial.o i8259.o i8254.o fdc.o m48t59.o pflash_cfi02.o
428 VL_OBJS+= ppc_prep.o ppc_chrp.o cuda.o adb.o openpic.o heathrow_pic.o mixeng.o
429 VL_OBJS+= grackle_pci.o prep_pci.o unin_pci.o ppc405_uc.o ppc405_boards.o
430 CPPFLAGS += -DHAS_AUDIO
432 ifeq ($(TARGET_BASE_ARCH), mips)
433 VL_OBJS+= mips_r4k.o mips_malta.o mips_pica61.o
434 VL_OBJS+= mips_timer.o mips_int.o dma.o vga.o serial.o i8254.o i8259.o
435 VL_OBJS+= ide.o gt64xxx.o pckbd.o ps2.o fdc.o mc146818rtc.o usb-uhci.o acpi.o ds1225y.o
436 VL_OBJS+= piix_pci.o parallel.o mixeng.o cirrus_vga.o $(SOUND_HW) $(AUDIODRV)
437 CPPFLAGS += -DHAS_AUDIO
439 ifeq ($(TARGET_BASE_ARCH), sparc)
440 ifeq ($(TARGET_ARCH), sparc64)
441 VL_OBJS+= sun4u.o ide.o pckbd.o ps2.o vga.o apb_pci.o
442 VL_OBJS+= fdc.o mc146818rtc.o serial.o m48t59.o
443 VL_OBJS+= cirrus_vga.o parallel.o
445 VL_OBJS+= sun4m.o tcx.o pcnet.o iommu.o m48t59.o slavio_intctl.o
446 VL_OBJS+= slavio_timer.o slavio_serial.o slavio_misc.o fdc.o esp.o sparc32_dma.o
450 ifeq ($(TARGET_BASE_ARCH), arm)
451 VL_OBJS+= integratorcp.o versatilepb.o ps2.o smc91c111.o arm_pic.o arm_timer.o
452 VL_OBJS+= arm_boot.o pl011.o pl050.o pl080.o pl110.o pl181.o pl190.o
453 VL_OBJS+= versatile_pci.o sd.o
454 VL_OBJS+= arm_gic.o realview.o arm_sysctl.o
457 ifeq ($(TARGET_BASE_ARCH), sh4)
458 VL_OBJS+= shix.o sh7750.o sh7750_regnames.o tc58128.o
464 VL_OBJS+=sdl.o x_keymap.o
469 COCOA_LIBS=-F/System/Library/Frameworks -framework Cocoa -framework IOKit
470 ifdef CONFIG_COREAUDIO
471 COCOA_LIBS+=-framework CoreAudio
475 CPPFLAGS+=-I$(SRC_PATH)/slirp
476 SLIRP_OBJS=cksum.o if.o ip_icmp.o ip_input.o ip_output.o \
477 slirp.o mbuf.o misc.o sbuf.o socket.o tcp_input.o tcp_output.o \
478 tcp_subr.o tcp_timer.o udp.o bootp.o debug.o tftp.o
479 VL_OBJS+=$(addprefix slirp/, $(SLIRP_OBJS))
484 # specific flags are needed for non soft mmu emulator
488 ifndef CONFIG_SOFTMMU
489 VL_LDFLAGS+=-Wl,-T,$(SRC_PATH)/i386-vl.ld
493 ifndef CONFIG_SOLARIS
499 vl.o: BASE_CFLAGS+=-p
504 VL_LDFLAGS+=-Wl,-G0 -Wl,-T,$(SRC_PATH)/ia64.ld
507 ifeq ($(ARCH),sparc64)
509 ifneq ($(CONFIG_SOLARIS),yes)
510 VL_LDFLAGS+=-Wl,-T,$(SRC_PATH)/$(ARCH).ld
515 SDL_LIBS := $(filter-out -mwindows, $(SDL_LIBS)) -mconsole
518 $(QEMU_SYSTEM): $(VL_OBJS) libqemu.a
519 $(CC) $(VL_LDFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS) $(SDL_LIBS) $(COCOA_LIBS) $(VL_LIBS)
522 $(CC) $(CFLAGS) $(CPPFLAGS) $(BASE_CFLAGS) -c -o $@ $<
524 sdl.o: sdl.c keymaps.c sdl_keysym.h
525 $(CC) $(CFLAGS) $(CPPFLAGS) $(SDL_CFLAGS) $(BASE_CFLAGS) -c -o $@ $<
527 vnc.o: vnc.c keymaps.c sdl_keysym.h vnchextile.h
528 $(CC) $(CFLAGS) $(CPPFLAGS) $(BASE_CFLAGS) -c -o $@ $<
530 sdlaudio.o: sdlaudio.c
531 $(CC) $(CFLAGS) $(CPPFLAGS) $(SDL_CFLAGS) $(BASE_CFLAGS) -c -o $@ $<
534 $(CC) -MM $(CFLAGS) $(CPPFLAGS) $(BASE_CFLAGS) $^ 1>.depend
536 vldepend: $(VL_OBJS:.o=.c)
537 $(CC) -MM $(CFLAGS) $(CPPFLAGS) $(BASE_CFLAGS) $^ 1>.depend
541 libqemu.a: $(LIBOBJS)
543 $(AR) rcs $@ $(LIBOBJS)
545 translate.o: translate.c gen-op.h opc.h cpu.h
547 translate-all.o: translate-all.c opc.h cpu.h
549 translate-op.o: translate-all.c op.h opc.h cpu.h
554 opc.h: op.o $(DYNGEN)
555 $(DYNGEN) -c -o $@ $<
557 gen-op.h: op.o $(DYNGEN)
558 $(DYNGEN) -g -o $@ $<
561 $(CC) $(OP_CFLAGS) $(CPPFLAGS) -c -o $@ $<
563 # HELPER_CFLAGS is used for all the code compiled with static register
565 ifeq ($(TARGET_BASE_ARCH), i386)
566 # XXX: rename helper.c to op_helper.c
568 $(CC) $(HELPER_CFLAGS) $(CPPFLAGS) $(BASE_CFLAGS) -c -o $@ $<
570 op_helper.o: op_helper.c
571 $(CC) $(HELPER_CFLAGS) $(CPPFLAGS) $(BASE_CFLAGS) -c -o $@ $<
574 cpu-exec.o: cpu-exec.c
575 $(CC) $(HELPER_CFLAGS) $(CPPFLAGS) $(BASE_CFLAGS) -c -o $@ $<
577 # Note: this is a workaround. The real fix is to avoid compiling
578 # cpu_signal_handler() in cpu-exec.c.
580 $(CC) $(HELPER_CFLAGS) $(CPPFLAGS) $(BASE_CFLAGS) -c -o $@ $<
582 ifeq ($(TARGET_BASE_ARCH), i386)
583 op.o: op.c opreg_template.h ops_template.h ops_template_mem.h ops_mem.h ops_sse.h
586 ifeq ($(TARGET_ARCH), arm)
587 op.o: op.c op_template.h
588 pl110.o: pl110_template.h
591 ifeq ($(TARGET_BASE_ARCH), sparc)
592 op.o: op.c op_template.h op_mem.h fop_template.h fbranch_template.h
593 magic_load.o: elf_op.h
596 ifeq ($(TARGET_BASE_ARCH), ppc)
597 op.o: op.c op_template.h op_mem.h
598 op_helper.o: op_helper_mem.h
599 translate.o: translate.c translate_init.c
602 ifeq ($(TARGET_BASE_ARCH), mips)
603 helper.o: cpu.h exec-all.h
604 op.o: op_template.c fop_template.c op_mem.c exec.h
605 op_helper.o: op_helper_mem.c exec.h softmmu_template.h
606 translate.o: translate_init.c exec-all.h disas.h
609 loader.o: loader.c elf_ops.h
611 ifeq ($(TARGET_ARCH), sh4)
612 op.o: op.c op_mem.c cpu.h
613 op_helper.o: op_helper.c exec.h cpu.h
614 helper.o: helper.c exec.h cpu.h
615 sh7750.o: sh7750.c sh7750_regs.h sh7750_regnames.h cpu.h
616 shix.o: shix.c sh7750_regs.h sh7750_regnames.h
617 sh7750_regnames.o: sh7750_regnames.c sh7750_regnames.h sh7750_regs.h
621 ifeq ($(TARGET_BASE_ARCH), alpha)
622 op.o: op.c op_template.h op_mem.h
623 op_helper.o: op_helper_mem.h
626 $(OBJS) $(LIBOBJS) $(VL_OBJS): config.h ../config-host.h
629 $(CC) $(CFLAGS) $(CPPFLAGS) $(BASE_CFLAGS) -c -o $@ $<
632 $(CC) $(CPPFLAGS) -c -o $@ $<
635 rm -f *.o *.a *~ $(PROGS) gen-op.h opc.h op.h nwfpe/*.o slirp/*.o fpu/*.o
639 $(INSTALL) -m 755 -s $(PROGS) "$(DESTDIR)$(bindir)"
642 ifneq ($(wildcard .depend),)
647 audio.o sdlaudio.o dsoundaudio.o ossaudio.o wavaudio.o noaudio.o \
648 fmodaudio.o alsaaudio.o mixeng.o sb16.o es1370.o gus.o adlib.o: \
649 CFLAGS := $(CFLAGS) -Wall -Werror -W -Wsign-compare