win32 cross compile fix
[qemu] / Makefile.target
1 include config.mak
2
3 TARGET_PATH=$(SRC_PATH)/target-$(TARGET_ARCH)
4 VPATH=$(SRC_PATH):$(TARGET_PATH):$(SRC_PATH)/hw
5 DEFINES=-I. -I$(TARGET_PATH) -I$(SRC_PATH)
6 ifdef CONFIG_USER_ONLY
7 VPATH+=:$(SRC_PATH)/linux-user
8 DEFINES+=-I$(SRC_PATH)/linux-user -I$(SRC_PATH)/linux-user/$(TARGET_ARCH)
9 endif
10 CFLAGS=-Wall -O2 -g
11 LDFLAGS=-g
12 LIBS=
13 HELPER_CFLAGS=$(CFLAGS)
14 DYNGEN=../dyngen$(EXESUF)
15 # user emulator name
16 QEMU_USER=qemu-$(TARGET_ARCH)
17 # system emulator name
18 ifdef CONFIG_SOFTMMU
19 QEMU_SYSTEM=qemu$(EXESUF)
20 else
21 QEMU_SYSTEM=qemu-fast
22 endif
23
24 ifdef CONFIG_USER_ONLY
25 PROGS=$(QEMU_USER)
26 else
27 ifeq ($(TARGET_ARCH), i386)
28
29 ifeq ($(ARCH), i386)
30 PROGS+=$(QEMU_SYSTEM)
31 ifndef CONFIG_SOFTMMU
32 CONFIG_STATIC=y
33 endif
34 else
35 # the system emulator using soft mmu is portable
36 ifdef CONFIG_SOFTMMU
37 PROGS+=$(QEMU_SYSTEM)
38 endif
39 endif # ARCH != i386
40
41 endif # TARGET_ARCH = i386
42
43 ifeq ($(TARGET_ARCH), ppc)
44
45 ifeq ($(ARCH), ppc)
46 PROGS+=$(QEMU_SYSTEM)
47 endif
48
49 ifeq ($(ARCH), i386)
50 ifdef CONFIG_SOFTMMU
51 PROGS+=$(QEMU_SYSTEM)
52 endif
53 endif # ARCH = i386
54
55 endif # TARGET_ARCH = ppc
56 endif # !CONFIG_USER_ONLY
57
58 ifdef CONFIG_STATIC
59 LDFLAGS+=-static
60 endif
61
62 ifeq ($(ARCH),i386)
63 CFLAGS+=-fomit-frame-pointer
64 OP_CFLAGS=$(CFLAGS) -mpreferred-stack-boundary=2
65 ifeq ($(HAVE_GCC3_OPTIONS),yes)
66 OP_CFLAGS+= -falign-functions=0
67 else
68 OP_CFLAGS+= -malign-functions=0
69 endif
70
71 ifdef TARGET_GPROF
72 USE_I386_LD=y
73 endif
74 ifdef CONFIG_STATIC
75 USE_I386_LD=y
76 endif
77 ifdef USE_I386_LD
78 LDFLAGS+=-Wl,-T,$(SRC_PATH)/i386.ld
79 else
80 # WARNING: this LDFLAGS is _very_ tricky : qemu is an ELF shared object
81 # that the kernel ELF loader considers as an executable. I think this
82 # is the simplest way to make it self virtualizable!
83 LDFLAGS+=-Wl,-shared
84 endif
85 endif
86
87 ifeq ($(ARCH),amd64)
88 OP_CFLAGS=$(CFLAGS) -falign-functions=0
89 LDFLAGS+=-Wl,-T,$(SRC_PATH)/amd64.ld
90 endif
91
92 ifeq ($(ARCH),ppc)
93 OP_CFLAGS=$(CFLAGS)
94 LDFLAGS+=-Wl,-T,$(SRC_PATH)/ppc.ld
95 endif
96
97 ifeq ($(ARCH),s390)
98 OP_CFLAGS=$(CFLAGS)
99 LDFLAGS+=-Wl,-T,$(SRC_PATH)/s390.ld
100 endif
101
102 ifeq ($(ARCH),sparc)
103 CFLAGS+=-m32 -ffixed-g1 -ffixed-g2 -ffixed-g3 -ffixed-g6
104 LDFLAGS+=-m32
105 OP_CFLAGS=$(CFLAGS) -fno-delayed-branch -ffixed-i0
106 HELPER_CFLAGS=$(CFLAGS) -ffixed-i0 -mflat
107 # -static is used to avoid g1/g3 usage by the dynamic linker
108 LDFLAGS+=-Wl,-T,$(SRC_PATH)/sparc.ld -static
109 endif
110
111 ifeq ($(ARCH),sparc64)
112 CFLAGS+=-m64 -ffixed-g1 -ffixed-g2 -ffixed-g3 -ffixed-g6
113 LDFLAGS+=-m64
114 OP_CFLAGS=$(CFLAGS) -fno-delayed-branch -ffixed-i0
115 endif
116
117 ifeq ($(ARCH),alpha)
118 # -msmall-data is not used because we want two-instruction relocations
119 # for the constant constructions
120 OP_CFLAGS=-Wall -O2 -g
121 # Ensure there's only a single GP
122 CFLAGS += -msmall-data
123 LDFLAGS+=-Wl,-T,$(SRC_PATH)/alpha.ld
124 endif
125
126 ifeq ($(ARCH),ia64)
127 OP_CFLAGS=$(CFLAGS)
128 endif
129
130 ifeq ($(ARCH),arm)
131 OP_CFLAGS=$(CFLAGS) -mno-sched-prolog
132 LDFLAGS+=-Wl,-T,$(SRC_PATH)/arm.ld
133 endif
134
135 ifeq ($(ARCH),m68k)
136 OP_CFLAGS=$(CFLAGS) -fomit-frame-pointer
137 LDFLAGS+=-Wl,-T,m68k.ld
138 endif
139
140 ifeq ($(HAVE_GCC3_OPTIONS),yes)
141 # very important to generate a return at the end of every operation
142 OP_CFLAGS+=-fno-reorder-blocks -fno-optimize-sibling-calls
143 endif
144
145 #########################################################
146
147 DEFINES+=-D_GNU_SOURCE
148 LIBS+=-lm
149 ifdef CONFIG_WIN32
150 LIBS+=-lwinmm
151 endif
152
153 # profiling code
154 ifdef TARGET_GPROF
155 LDFLAGS+=-p
156 main.o: CFLAGS+=-p
157 endif
158
159 OBJS= elfload.o main.o syscall.o mmap.o signal.o path.o osdep.o thunk.o 
160 ifeq ($(TARGET_ARCH), i386)
161 OBJS+= vm86.o
162 endif
163 ifeq ($(TARGET_ARCH), arm)
164 OBJS+=nwfpe/softfloat.o nwfpe/fpa11.o nwfpe/fpa11_cpdo.o \
165 nwfpe/fpa11_cpdt.o nwfpe/fpa11_cprt.o nwfpe/fpopcode.o nwfpe/single_cpdo.o \
166  nwfpe/double_cpdo.o nwfpe/extended_cpdo.o
167 endif
168 SRCS:= $(OBJS:.o=.c)
169 OBJS+= libqemu.a
170
171 # cpu emulator library
172 LIBOBJS=exec.o translate-all.o cpu-exec.o\
173         translate.o op.o
174
175 ifeq ($(TARGET_ARCH), i386)
176 LIBOBJS+=helper.o helper2.o
177 ifeq ($(ARCH), i386)
178 LIBOBJS+=translate-copy.o
179 endif
180 endif
181
182 ifeq ($(TARGET_ARCH), ppc)
183 LIBOBJS+= op_helper.o helper.o
184 endif
185
186 # NOTE: the disassembler code is only needed for debugging
187 LIBOBJS+=disas.o 
188 ifeq ($(findstring i386, $(TARGET_ARCH) $(ARCH)),i386)
189 USE_I386_DIS=y
190 endif
191 ifeq ($(findstring amd64, $(TARGET_ARCH) $(ARCH)),amd64)
192 USE_I386_DIS=y
193 endif
194 ifdef USE_I386_DIS
195 LIBOBJS+=i386-dis.o
196 endif
197 ifeq ($(findstring alpha, $(TARGET_ARCH) $(ARCH)),alpha)
198 LIBOBJS+=alpha-dis.o
199 endif
200 ifeq ($(findstring ppc, $(TARGET_ARCH) $(ARCH)),ppc)
201 LIBOBJS+=ppc-dis.o
202 endif
203 ifeq ($(findstring sparc, $(TARGET_ARCH) $(ARCH)),sparc)
204 LIBOBJS+=sparc-dis.o
205 endif
206 ifeq ($(findstring arm, $(TARGET_ARCH) $(ARCH)),arm)
207 LIBOBJS+=arm-dis.o
208 endif
209
210 ifeq ($(ARCH),ia64)
211 OBJS += ia64-syscall.o
212 endif
213
214 all: $(PROGS)
215
216 $(QEMU_USER): $(OBJS)
217         $(CC) $(LDFLAGS) -o $@ $^  $(LIBS)
218 ifeq ($(ARCH),alpha)
219 # Mark as 32 bit binary, i. e. it will be mapped into the low 31 bit of
220 # the address space (31 bit so sign extending doesn't matter)
221         echo -ne '\001\000\000\000' | dd of=qemu bs=1 seek=48 count=4 conv=notrunc
222 endif
223
224 # must use static linking to avoid leaving stuff in virtual address space
225 VL_OBJS=vl.o osdep.o block.o monitor.o \
226         ide.o ne2000.o pckbd.o vga.o sb16.o dma.o oss.o \
227         fdc.o mc146818rtc.o serial.o i8259.o i8254.o pc.o
228 ifdef CONFIG_GDBSTUB
229 VL_OBJS+=gdbstub.o 
230 endif
231 ifeq ($(TARGET_ARCH), ppc)
232 VL_OBJS+= hw.o
233 endif
234 ifdef CONFIG_SDL
235 VL_OBJS+=sdl.o
236 ifdef CONFIG_STATIC
237 SDL_LIBS:=$(SDL_STATIC_LIBS)
238 endif
239 endif
240
241 VL_LDFLAGS=
242 # specific flags are needed for non soft mmu emulator
243 ifdef CONFIG_STATIC
244 VL_LDFLAGS+=-static
245 endif
246 ifndef CONFIG_SOFTMMU
247 VL_LDFLAGS+=-Wl,-T,$(SRC_PATH)/i386-vl.ld 
248 endif
249 ifndef CONFIG_WIN32
250 VL_LIBS=-lutil
251 endif
252
253 $(QEMU_SYSTEM): $(VL_OBJS) libqemu.a
254         $(CC) $(VL_LDFLAGS) -o $@ $^ $(LIBS) $(SDL_LIBS) $(VL_LIBS)
255
256 sdl.o: sdl.c
257         $(CC) $(CFLAGS) $(DEFINES) $(SDL_CFLAGS) -c -o $@ $<
258
259 depend: $(SRCS)
260         $(CC) -MM $(CFLAGS) $(DEFINES) $^ 1>.depend
261
262 # libqemu 
263
264 libqemu.a: $(LIBOBJS)
265         rm -f $@
266         $(AR) rcs $@ $(LIBOBJS)
267
268 translate.o: translate.c gen-op.h opc.h cpu.h
269
270 translate-all.o: translate-all.c op.h opc.h cpu.h
271
272 op.h: op.o $(DYNGEN)
273         $(DYNGEN) -o $@ $<
274
275 opc.h: op.o $(DYNGEN)
276         $(DYNGEN) -c -o $@ $<
277
278 gen-op.h: op.o $(DYNGEN)
279         $(DYNGEN) -g -o $@ $<
280
281 op.o: op.c
282         $(CC) $(OP_CFLAGS) $(DEFINES) -c -o $@ $<
283
284 helper.o: helper.c
285         $(CC) $(HELPER_CFLAGS) $(DEFINES) -c -o $@ $<
286
287 ifeq ($(TARGET_ARCH), i386)
288 op.o: op.c opreg_template.h ops_template.h ops_template_mem.h ops_mem.h
289 endif
290
291 ifeq ($(TARGET_ARCH), arm)
292 op.o: op.c op_template.h
293 endif
294
295 ifeq ($(TARGET_ARCH), sparc)
296 op.o: op.c op_template.h
297 endif
298
299 ifeq ($(TARGET_ARCH), ppc)
300 op.o: op.c op_template.h op_mem.h
301 op_helper.o: op_helper_mem.h
302 endif
303
304 %.o: %.c
305         $(CC) $(CFLAGS) $(DEFINES) -c -o $@ $<
306
307 %.o: %.S
308         $(CC) $(DEFINES) -c -o $@ $<
309
310 clean:
311         rm -f *.o  *.a *~ $(PROGS) gen-op.h opc.h op.h nwfpe/*.o
312
313 install: all 
314 ifneq ($(PROGS),)
315         install -m 755 -s $(PROGS) "$(bindir)"
316 endif
317
318 ifneq ($(wildcard .depend),)
319 include .depend
320 endif