Introduce rules.mak (Avi Kivity)
[qemu] / Makefile
1 # Makefile for QEMU.
2
3 include config-host.mak
4 include $(SRC_PATH)/rules.mak
5
6 .PHONY: all clean cscope distclean dvi html info install install-doc \
7         recurse-all speed tar tarbin test
8
9 VPATH=$(SRC_PATH):$(SRC_PATH)/hw
10
11
12 CFLAGS += $(OS_CFLAGS) $(ARCH_CFLAGS)
13 LDFLAGS += $(OS_LDFLAGS) $(ARCH_LDFLAGS)
14
15 CPPFLAGS += -I. -I$(SRC_PATH) -MMD -MP -MT $@
16 CPPFLAGS += -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE
17 LIBS=
18 ifdef CONFIG_STATIC
19 LDFLAGS += -static
20 endif
21 ifdef BUILD_DOCS
22 DOCS=qemu-doc.html qemu-tech.html qemu.1 qemu-img.1 qemu-nbd.8
23 else
24 DOCS=
25 endif
26
27 LIBS+=$(AIOLIBS)
28
29 ifdef CONFIG_SOLARIS
30 LIBS+=-lsocket -lnsl -lresolv
31 endif
32
33 ifdef CONFIG_WIN32
34 LIBS+=-lwinmm -lws2_32 -liphlpapi
35 endif
36
37 all: $(TOOLS) $(DOCS) recurse-all
38
39 SUBDIR_RULES=$(patsubst %,subdir-%, $(TARGET_DIRS))
40
41 subdir-%:
42         $(MAKE) -C $(subst subdir-,,$@) all
43
44 $(filter %-softmmu,$(SUBDIR_RULES)): libqemu_common.a
45 $(filter %-user,$(SUBDIR_RULES)): libqemu_user.a
46
47 recurse-all: $(SUBDIR_RULES)
48
49 #######################################################################
50 # BLOCK_OBJS is code used by both qemu system emulation and qemu-img
51
52 BLOCK_OBJS=cutils.o qemu-malloc.o
53 BLOCK_OBJS+=block-cow.o block-qcow.o aes.o block-vmdk.o block-cloop.o
54 BLOCK_OBJS+=block-dmg.o block-bochs.o block-vpc.o block-vvfat.o
55 BLOCK_OBJS+=block-qcow2.o block-parallels.o block-nbd.o
56 BLOCK_OBJS+=nbd.o block.o aio.o
57
58 ifdef CONFIG_WIN32
59 BLOCK_OBJS += block-raw-win32.o
60 else
61 ifdef CONFIG_AIO
62 BLOCK_OBJS += posix-aio-compat.o
63 endif
64 BLOCK_OBJS += block-raw-posix.o
65 endif
66
67 ######################################################################
68 # libqemu_common.a: Target independent part of system emulation. The
69 # long term path is to suppress *all* target specific code in case of
70 # system emulation, i.e. a single QEMU executable should support all
71 # CPUs and machines.
72
73 OBJS=$(BLOCK_OBJS)
74 OBJS+=readline.o console.o
75
76 OBJS+=irq.o
77 OBJS+=i2c.o smbus.o smbus_eeprom.o max7310.o max111x.o wm8750.o
78 OBJS+=ssd0303.o ssd0323.o ads7846.o stellaris_input.o twl92230.o
79 OBJS+=tmp105.o lm832x.o
80 OBJS+=scsi-disk.o cdrom.o
81 OBJS+=scsi-generic.o
82 OBJS+=usb.o usb-hub.o usb-$(HOST_USB).o usb-hid.o usb-msd.o usb-wacom.o
83 OBJS+=usb-serial.o usb-net.o
84 OBJS+=sd.o ssi-sd.o
85 OBJS+=bt.o bt-host.o bt-vhci.o bt-l2cap.o bt-sdp.o bt-hci.o bt-hid.o usb-bt.o
86 OBJS+=buffered_file.o migration.o migration-tcp.o net.o qemu-sockets.o
87 OBJS+=qemu-char.o aio.o net-checksum.o savevm.o cache-utils.o
88
89 ifdef CONFIG_BRLAPI
90 OBJS+= baum.o
91 LIBS+=-lbrlapi
92 endif
93
94 ifdef CONFIG_WIN32
95 OBJS+=tap-win32.o
96 else
97 OBJS+=migration-exec.o
98 endif
99
100 AUDIO_OBJS = audio.o noaudio.o wavaudio.o mixeng.o
101 ifdef CONFIG_SDL
102 AUDIO_OBJS += sdlaudio.o
103 endif
104 ifdef CONFIG_OSS
105 AUDIO_OBJS += ossaudio.o
106 endif
107 ifdef CONFIG_COREAUDIO
108 AUDIO_OBJS += coreaudio.o
109 AUDIO_PT = yes
110 endif
111 ifdef CONFIG_ALSA
112 AUDIO_OBJS += alsaaudio.o
113 endif
114 ifdef CONFIG_DSOUND
115 AUDIO_OBJS += dsoundaudio.o
116 endif
117 ifdef CONFIG_FMOD
118 AUDIO_OBJS += fmodaudio.o
119 audio/audio.o audio/fmodaudio.o: CPPFLAGS := -I$(CONFIG_FMOD_INC) $(CPPFLAGS)
120 endif
121 ifdef CONFIG_ESD
122 AUDIO_PT = yes
123 AUDIO_PT_INT = yes
124 AUDIO_OBJS += esdaudio.o
125 endif
126 ifdef CONFIG_PA
127 AUDIO_PT = yes
128 AUDIO_PT_INT = yes
129 AUDIO_OBJS += paaudio.o
130 endif
131 ifdef AUDIO_PT
132 LDFLAGS += -pthread
133 endif
134 ifdef AUDIO_PT_INT
135 AUDIO_OBJS += audio_pt_int.o
136 endif
137 AUDIO_OBJS+= wavcapture.o
138 OBJS+=$(addprefix audio/, $(AUDIO_OBJS))
139
140 ifdef CONFIG_SDL
141 OBJS+=sdl.o x_keymap.o
142 endif
143 ifdef CONFIG_CURSES
144 OBJS+=curses.o
145 endif
146 OBJS+=vnc.o d3des.o
147
148 ifdef CONFIG_COCOA
149 OBJS+=cocoa.o
150 endif
151
152 ifdef CONFIG_SLIRP
153 CPPFLAGS+=-I$(SRC_PATH)/slirp
154 SLIRP_OBJS=cksum.o if.o ip_icmp.o ip_input.o ip_output.o \
155 slirp.o mbuf.o misc.o sbuf.o socket.o tcp_input.o tcp_output.o \
156 tcp_subr.o tcp_timer.o udp.o bootp.o debug.o tftp.o
157 OBJS+=$(addprefix slirp/, $(SLIRP_OBJS))
158 endif
159
160 LIBS+=$(VDE_LIBS)
161
162 cocoa.o: cocoa.m
163
164 sdl.o: sdl.c keymaps.c sdl_keysym.h
165
166 sdl.o audio/sdlaudio.o: CFLAGS += $(SDL_CFLAGS)
167
168 vnc.o: vnc.c keymaps.c sdl_keysym.h vnchextile.h d3des.c d3des.h
169
170 vnc.o: CFLAGS += $(CONFIG_VNC_TLS_CFLAGS)
171
172 curses.o: curses.c keymaps.c curses_keys.h
173
174 bt-host.o: CFLAGS += $(CONFIG_BLUEZ_CFLAGS)
175
176 libqemu_common.a: $(OBJS)
177         rm -f $@ 
178         $(AR) rcs $@ $(OBJS)
179
180 #######################################################################
181 # USER_OBJS is code used by qemu userspace emulation
182 USER_OBJS=cutils.o  cache-utils.o
183
184 libqemu_user.a: $(USER_OBJS)
185         rm -f $@ 
186         $(AR) rcs $@ $(USER_OBJS)
187
188 ######################################################################
189
190 qemu-img$(EXESUF): qemu-img.o qemu-tool.o osdep.o $(BLOCK_OBJS)
191         $(CC) $(LDFLAGS) -o $@ $^ -lz $(LIBS)
192
193 qemu-nbd$(EXESUF):  qemu-nbd.o qemu-tool.o osdep.o $(BLOCK_OBJS)
194         $(CC) $(LDFLAGS) -o $@ $^ -lz $(LIBS)
195
196 clean:
197 # avoid old build problems by removing potentially incorrect old files
198         rm -f config.mak config.h op-i386.h opc-i386.h gen-op-i386.h op-arm.h opc-arm.h gen-op-arm.h
199         rm -f *.o *.d *.a $(TOOLS) TAGS cscope.* *.pod *~ */*~
200         rm -f slirp/*.o slirp/*.d audio/*.o audio/*.d
201         $(MAKE) -C tests clean
202         for d in $(TARGET_DIRS); do \
203         $(MAKE) -C $$d $@ || exit 1 ; \
204         done
205
206 distclean: clean
207         rm -f config-host.mak config-host.h $(DOCS)
208         rm -f qemu-{doc,tech}.{info,aux,cp,dvi,fn,info,ky,log,pg,toc,tp,vr}
209         for d in $(TARGET_DIRS); do \
210         rm -rf $$d || exit 1 ; \
211         done
212
213 KEYMAPS=da     en-gb  et  fr     fr-ch  is  lt  modifiers  no  pt-br  sv \
214 ar      de     en-us  fi  fr-be  hr     it  lv  nl         pl  ru     th \
215 common  de-ch  es     fo  fr-ca  hu     ja  mk  nl-be      pt  sl     tr
216
217 ifdef INSTALL_BLOBS
218 BLOBS=bios.bin vgabios.bin vgabios-cirrus.bin ppc_rom.bin \
219 video.x openbios-sparc32 openbios-sparc64 openbios-ppc \
220 pxe-ne2k_pci.bin pxe-rtl8139.bin pxe-pcnet.bin pxe-e1000.bin \
221 bamboo.dtb
222 else
223 BLOBS=
224 endif
225
226 install-doc: $(DOCS)
227         mkdir -p "$(DESTDIR)$(docdir)"
228         $(INSTALL) -m 644 qemu-doc.html  qemu-tech.html "$(DESTDIR)$(docdir)"
229 ifndef CONFIG_WIN32
230         mkdir -p "$(DESTDIR)$(mandir)/man1"
231         $(INSTALL) qemu.1 qemu-img.1 "$(DESTDIR)$(mandir)/man1"
232         mkdir -p "$(DESTDIR)$(mandir)/man8"
233         $(INSTALL) qemu-nbd.8 "$(DESTDIR)$(mandir)/man8"
234 endif
235
236 install: all $(if $(BUILD_DOCS),install-doc)
237         mkdir -p "$(DESTDIR)$(bindir)"
238 ifneq ($(TOOLS),)
239         $(INSTALL) -m 755 -s $(TOOLS) "$(DESTDIR)$(bindir)"
240 endif
241 ifneq ($(BLOBS),)
242         mkdir -p "$(DESTDIR)$(datadir)"
243         set -e; for x in $(BLOBS); do \
244                 $(INSTALL) -m 644 $(SRC_PATH)/pc-bios/$$x "$(DESTDIR)$(datadir)"; \
245         done
246 endif
247 ifndef CONFIG_WIN32
248         mkdir -p "$(DESTDIR)$(datadir)/keymaps"
249         set -e; for x in $(KEYMAPS); do \
250                 $(INSTALL) -m 644 $(SRC_PATH)/keymaps/$$x "$(DESTDIR)$(datadir)/keymaps"; \
251         done
252 endif
253         for d in $(TARGET_DIRS); do \
254         $(MAKE) -C $$d $@ || exit 1 ; \
255         done
256
257 # various test targets
258 test speed: all
259         $(MAKE) -C tests $@
260
261 TAGS:
262         etags *.[ch] tests/*.[ch]
263
264 cscope:
265         rm -f ./cscope.*
266         find . -name "*.[ch]" -print | sed 's,^\./,,' > ./cscope.files
267         cscope -b
268
269 # documentation
270 %.html: %.texi
271         texi2html -monolithic -number $<
272
273 %.info: %.texi
274         makeinfo $< -o $@
275
276 %.dvi: %.texi
277         texi2dvi $<
278
279 qemu.1: qemu-doc.texi
280         $(SRC_PATH)/texi2pod.pl $< qemu.pod
281         pod2man --section=1 --center=" " --release=" " qemu.pod > $@
282
283 qemu-img.1: qemu-img.texi
284         $(SRC_PATH)/texi2pod.pl $< qemu-img.pod
285         pod2man --section=1 --center=" " --release=" " qemu-img.pod > $@
286
287 qemu-nbd.8: qemu-nbd.texi
288         $(SRC_PATH)/texi2pod.pl $< qemu-nbd.pod
289         pod2man --section=8 --center=" " --release=" " qemu-nbd.pod > $@
290
291 info: qemu-doc.info qemu-tech.info
292
293 dvi: qemu-doc.dvi qemu-tech.dvi
294
295 html: qemu-doc.html qemu-tech.html
296
297 qemu-doc.dvi qemu-doc.html qemu-doc.info: qemu-img.texi qemu-nbd.texi
298
299 VERSION ?= $(shell cat VERSION)
300 FILE = qemu-$(VERSION)
301
302 # tar release (use 'make -k tar' on a checkouted tree)
303 tar:
304         rm -rf /tmp/$(FILE)
305         cp -r . /tmp/$(FILE)
306         cd /tmp && tar zcvf ~/$(FILE).tar.gz $(FILE) --exclude CVS --exclude .git --exclude .svn
307         rm -rf /tmp/$(FILE)
308
309 # generate a binary distribution
310 tarbin:
311         cd / && tar zcvf ~/qemu-$(VERSION)-$(ARCH).tar.gz \
312         $(bindir)/qemu \
313         $(bindir)/qemu-system-x86_64 \
314         $(bindir)/qemu-system-arm \
315         $(bindir)/qemu-system-cris \
316         $(bindir)/qemu-system-m68k \
317         $(bindir)/qemu-system-mips \
318         $(bindir)/qemu-system-mipsel \
319         $(bindir)/qemu-system-mips64 \
320         $(bindir)/qemu-system-mips64el \
321         $(bindir)/qemu-system-ppc \
322         $(bindir)/qemu-system-ppcemb \
323         $(bindir)/qemu-system-ppc64 \
324         $(bindir)/qemu-system-sh4 \
325         $(bindir)/qemu-system-sh4eb \
326         $(bindir)/qemu-system-sparc \
327         $(bindir)/qemu-i386 \
328         $(bindir)/qemu-x86_64 \
329         $(bindir)/qemu-alpha \
330         $(bindir)/qemu-arm \
331         $(bindir)/qemu-armeb \
332         $(bindir)/qemu-cris \
333         $(bindir)/qemu-m68k \
334         $(bindir)/qemu-mips \
335         $(bindir)/qemu-mipsel \
336         $(bindir)/qemu-ppc \
337         $(bindir)/qemu-ppc64 \
338         $(bindir)/qemu-ppc64abi32 \
339         $(bindir)/qemu-sh4 \
340         $(bindir)/qemu-sh4eb \
341         $(bindir)/qemu-sparc \
342         $(bindir)/qemu-sparc64 \
343         $(bindir)/qemu-sparc32plus \
344         $(bindir)/qemu-img \
345         $(bindir)/qemu-nbd \
346         $(datadir)/bios.bin \
347         $(datadir)/vgabios.bin \
348         $(datadir)/vgabios-cirrus.bin \
349         $(datadir)/ppc_rom.bin \
350         $(datadir)/video.x \
351         $(datadir)/openbios-sparc32 \
352         $(datadir)/openbios-sparc64 \
353         $(datadir)/openbios-ppc \
354         $(datadir)/pxe-ne2k_pci.bin \
355         $(datadir)/pxe-rtl8139.bin \
356         $(datadir)/pxe-pcnet.bin \
357         $(datadir)/pxe-e1000.bin \
358         $(docdir)/qemu-doc.html \
359         $(docdir)/qemu-tech.html \
360         $(mandir)/man1/qemu.1 \
361         $(mandir)/man1/qemu-img.1 \
362         $(mandir)/man8/qemu-nbd.8
363
364 # Include automatically generated dependency files
365 -include $(wildcard *.d audio/*.d slirp/*.d)