compile common code once
[qemu] / Makefile
1 # Makefile for QEMU.
2
3 include config-host.mak
4
5 .PHONY: all clean distclean dvi info install install-doc tar tarbin \
6         speed test test2 html dvi info
7
8 BASE_CFLAGS=
9 BASE_LDFLAGS=
10
11 BASE_CFLAGS += $(OS_CFLAGS) $(ARCH_CFLAGS)
12 BASE_LDFLAGS += $(OS_LDFLAGS) $(ARCH_LDFLAGS)
13
14 CPPFLAGS += -I. -I$(SRC_PATH) -MMD -MP
15 CPPFLAGS += -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE
16 CPPFLAGS += -DQEMU_TOOL
17 LIBS=
18 ifdef CONFIG_STATIC
19 BASE_LDFLAGS += -static
20 endif
21 ifdef BUILD_DOCS
22 DOCS=qemu-doc.html qemu-tech.html qemu.1 qemu-img.1
23 else
24 DOCS=
25 endif
26
27 LIBS+=$(AIOLIBS)
28
29 all: libqemu_common.a $(TOOLS) $(DOCS) recurse-all 
30
31 subdir-%: dyngen$(EXESUF)
32         $(MAKE) -C $(subst subdir-,,$@) all
33
34 recurse-all: $(patsubst %,subdir-%, $(TARGET_DIRS))
35
36 ######################################################################
37 # libqemu_common.a: target indepedent part of system emulation. The
38 # long term path is to suppress *all* target specific code in case of
39 # system emulation, i.e. a single QEMU executable should support all
40 # CPUs and machines.
41
42 OBJS+=cutils.o readline.o console.o 
43 #OBJS+=block.o block-raw.o
44 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 block-parallels.o
45
46 ifdef CONFIG_WIN32
47 OBJS+=tap-win32.o
48 endif
49
50 AUDIO_OBJS = audio.o noaudio.o wavaudio.o mixeng.o
51 ifdef CONFIG_SDL
52 AUDIO_OBJS += sdlaudio.o
53 endif
54 ifdef CONFIG_OSS
55 AUDIO_OBJS += ossaudio.o
56 endif
57 ifdef CONFIG_COREAUDIO
58 AUDIO_OBJS += coreaudio.o
59 endif
60 ifdef CONFIG_ALSA
61 AUDIO_OBJS += alsaaudio.o
62 endif
63 ifdef CONFIG_DSOUND
64 AUDIO_OBJS += dsoundaudio.o
65 endif
66 ifdef CONFIG_FMOD
67 AUDIO_OBJS += fmodaudio.o
68 audio/audio.o audio/fmodaudio.o: CPPFLAGS := -I$(CONFIG_FMOD_INC) $(CPPFLAGS)
69 endif
70 AUDIO_OBJS+= wavcapture.o
71 OBJS+=$(addprefix audio/, $(AUDIO_OBJS))
72
73 ifdef CONFIG_SDL
74 OBJS+=sdl.o x_keymap.o
75 endif
76 OBJS+=vnc.o d3des.o
77
78 ifdef CONFIG_COCOA
79 OBJS+=cocoa.o
80 endif
81
82 ifdef CONFIG_SLIRP
83 CPPFLAGS+=-I$(SRC_PATH)/slirp
84 SLIRP_OBJS=cksum.o if.o ip_icmp.o ip_input.o ip_output.o \
85 slirp.o mbuf.o misc.o sbuf.o socket.o tcp_input.o tcp_output.o \
86 tcp_subr.o tcp_timer.o udp.o bootp.o debug.o tftp.o
87 OBJS+=$(addprefix slirp/, $(SLIRP_OBJS))
88 endif
89
90 cocoa.o: cocoa.m
91         $(CC) $(CFLAGS) $(CPPFLAGS) $(BASE_CFLAGS) -c -o $@ $<
92
93 sdl.o: sdl.c keymaps.c sdl_keysym.h
94         $(CC) $(CFLAGS) $(CPPFLAGS) $(SDL_CFLAGS) $(BASE_CFLAGS) -c -o $@ $<
95
96 vnc.o: vnc.c keymaps.c sdl_keysym.h vnchextile.h d3des.c d3des.h
97         $(CC) $(CFLAGS) $(CPPFLAGS) $(BASE_CFLAGS) -c -o $@ $<
98
99 audio/sdlaudio.o: audio/sdlaudio.c
100         $(CC) $(CFLAGS) $(CPPFLAGS) $(SDL_CFLAGS) $(BASE_CFLAGS) -c -o $@ $<
101
102 libqemu_common.a: $(OBJS)
103         rm -f $@ 
104         $(AR) rcs $@ $(OBJS)
105
106 ######################################################################
107
108 qemu-img$(EXESUF): qemu-img.o block.o block-raw.o libqemu_common.a
109         $(CC) $(LDFLAGS) $(BASE_LDFLAGS) -o $@ $^ -lz $(LIBS)
110
111 %.o: %.c
112         $(CC) $(CFLAGS) $(CPPFLAGS) $(BASE_CFLAGS) -c -o $@ $<
113
114 # dyngen host tool
115 dyngen$(EXESUF): dyngen.c
116         $(HOST_CC) $(CFLAGS) $(CPPFLAGS) $(BASE_CFLAGS) -o $@ $^
117
118 clean:
119 # avoid old build problems by removing potentially incorrect old files
120         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
121         rm -f *.o *.d *.a $(TOOLS) dyngen$(EXESUF) TAGS cscope.* *.pod *~ */*~
122         rm -f slirp/*.o slirp/*.d audio/*.o audio/*.d
123         $(MAKE) -C tests clean
124         for d in $(TARGET_DIRS); do \
125         $(MAKE) -C $$d $@ || exit 1 ; \
126         done
127
128 distclean: clean
129         rm -f config-host.mak config-host.h $(DOCS)
130         rm -f qemu-{doc,tech}.{info,aux,cp,dvi,fn,info,ky,log,pg,toc,tp,vr}
131         for d in $(TARGET_DIRS); do \
132         rm -rf $$d || exit 1 ; \
133         done
134
135 KEYMAPS=da     en-gb  et  fr     fr-ch  is  lt  modifiers  no  pt-br  sv \
136 ar      de     en-us  fi  fr-be  hr     it  lv  nl         pl  ru     th \
137 common  de-ch  es     fo  fr-ca  hu     ja  mk  nl-be      pt  sl     tr
138
139 install-doc: $(DOCS)
140         mkdir -p "$(DESTDIR)$(docdir)"
141         $(INSTALL) -m 644 qemu-doc.html  qemu-tech.html "$(DESTDIR)$(docdir)"
142 ifndef CONFIG_WIN32
143         mkdir -p "$(DESTDIR)$(mandir)/man1"
144         $(INSTALL) qemu.1 qemu-img.1 "$(DESTDIR)$(mandir)/man1"
145 endif
146
147 install: all $(if $(BUILD_DOCS),install-doc)
148         mkdir -p "$(DESTDIR)$(bindir)"
149 ifneq ($(TOOLS),)
150         $(INSTALL) -m 755 -s $(TOOLS) "$(DESTDIR)$(bindir)"
151 endif
152         mkdir -p "$(DESTDIR)$(datadir)"
153         for x in bios.bin vgabios.bin vgabios-cirrus.bin ppc_rom.bin \
154                 video.x openbios-sparc32 pxe-ne2k_pci.bin \
155                 pxe-rtl8139.bin pxe-pcnet.bin; do \
156                 $(INSTALL) -m 644 $(SRC_PATH)/pc-bios/$$x "$(DESTDIR)$(datadir)"; \
157         done
158 ifndef CONFIG_WIN32
159         mkdir -p "$(DESTDIR)$(datadir)/keymaps"
160         for x in $(KEYMAPS); do \
161                 $(INSTALL) -m 644 $(SRC_PATH)/keymaps/$$x "$(DESTDIR)$(datadir)/keymaps"; \
162         done
163 endif
164         for d in $(TARGET_DIRS); do \
165         $(MAKE) -C $$d $@ || exit 1 ; \
166         done
167
168 # various test targets
169 test speed test2: all
170         $(MAKE) -C tests $@
171
172 TAGS:
173         etags *.[ch] tests/*.[ch]
174
175 cscope:
176         rm -f ./cscope.*
177         find . -name "*.[ch]" -print > ./cscope.files
178         cscope -b
179
180 # documentation
181 %.html: %.texi
182         texi2html -monolithic -number $<
183
184 %.info: %.texi
185         makeinfo $< -o $@
186
187 %.dvi: %.texi
188         texi2dvi $<
189
190 qemu.1: qemu-doc.texi
191         $(SRC_PATH)/texi2pod.pl $< qemu.pod
192         pod2man --section=1 --center=" " --release=" " qemu.pod > $@
193
194 qemu-img.1: qemu-img.texi
195         $(SRC_PATH)/texi2pod.pl $< qemu-img.pod
196         pod2man --section=1 --center=" " --release=" " qemu-img.pod > $@
197
198 info: qemu-doc.info qemu-tech.info
199
200 dvi: qemu-doc.dvi qemu-tech.dvi
201
202 html: qemu-doc.html qemu-tech.html
203
204 VERSION ?= $(shell cat VERSION)
205 FILE = qemu-$(VERSION)
206
207 # tar release (use 'make -k tar' on a checkouted tree)
208 tar:
209         rm -rf /tmp/$(FILE)
210         cp -r . /tmp/$(FILE)
211         ( cd /tmp ; tar zcvf ~/$(FILE).tar.gz $(FILE) --exclude CVS )
212         rm -rf /tmp/$(FILE)
213
214 # generate a binary distribution
215 tarbin:
216         ( cd / ; tar zcvf ~/qemu-$(VERSION)-$(ARCH).tar.gz \
217         $(bindir)/qemu \
218         $(bindir)/qemu-system-ppc \
219         $(bindir)/qemu-system-ppc64 \
220         $(bindir)/qemu-system-ppcemb \
221         $(bindir)/qemu-system-sparc \
222         $(bindir)/qemu-system-x86_64 \
223         $(bindir)/qemu-system-mips \
224         $(bindir)/qemu-system-mipsel \
225         $(bindir)/qemu-system-mips64 \
226         $(bindir)/qemu-system-mips64el \
227         $(bindir)/qemu-system-arm \
228         $(bindir)/qemu-system-m68k \
229         $(bindir)/qemu-system-sh4 \
230         $(bindir)/qemu-i386 \
231         $(bindir)/qemu-arm \
232         $(bindir)/qemu-armeb \
233         $(bindir)/qemu-sparc \
234         $(bindir)/qemu-ppc \
235         $(bindir)/qemu-ppc64 \
236         $(bindir)/qemu-mips \
237         $(bindir)/qemu-mipsel \
238         $(bindir)/qemu-mipsn32 \
239         $(bindir)/qemu-mipsn32el \
240         $(bindir)/qemu-mips64 \
241         $(bindir)/qemu-mips64el \
242         $(bindir)/qemu-alpha \
243         $(bindir)/qemu-m68k \
244         $(bindir)/qemu-sh4 \
245         $(bindir)/qemu-img \
246         $(datadir)/bios.bin \
247         $(datadir)/vgabios.bin \
248         $(datadir)/vgabios-cirrus.bin \
249         $(datadir)/ppc_rom.bin \
250         $(datadir)/video.x \
251         $(datadir)/openbios-sparc32 \
252         $(datadir)/pxe-ne2k_pci.bin \
253         $(datadir)/pxe-rtl8139.bin \
254         $(datadir)/pxe-pcnet.bin \
255         $(docdir)/qemu-doc.html \
256         $(docdir)/qemu-tech.html \
257         $(mandir)/man1/qemu.1 $(mandir)/man1/qemu-img.1 )
258
259 ifneq ($(wildcard .depend),)
260 include .depend
261 endif
262
263 # Include automatically generated dependency files
264 -include $(wildcard *.d audio/*.d slirp/*.d)