static link
[qemu] / Makefile.target
1 include config.mak
2
3 TARGET_PATH=$(SRC_PATH)/target-$(TARGET_ARCH)
4 VPATH=$(SRC_PATH):$(TARGET_PATH)
5 CFLAGS=-Wall -O2 -g
6 LDFLAGS=-g
7 LIBS=
8 DEFINES=-I. -I$(TARGET_PATH) -I$(SRC_PATH)
9 HELPER_CFLAGS=$(CFLAGS)
10 DYNGEN=../dyngen
11 # user emulator name
12 QEMU_USER=qemu-$(TARGET_ARCH)
13 # system emulator name
14 ifdef CONFIG_SOFTMMU
15 QEMU_SYSTEM=qemu
16 else
17 QEMU_SYSTEM=qemu-fast
18 endif
19
20 ifdef CONFIG_USER_ONLY
21 PROGS=$(QEMU_USER)
22 else
23 ifeq ($(ARCH),i386)
24 ifeq ($(TARGET_ARCH), i386)
25 PROGS+=$(QEMU_SYSTEM)
26 endif
27 endif
28 endif
29
30 ifdef CONFIG_STATIC
31 LDFLAGS+=-static
32 endif
33
34 ifeq ($(ARCH),i386)
35 CFLAGS+=-fomit-frame-pointer
36 OP_CFLAGS=$(CFLAGS) -mpreferred-stack-boundary=2
37 ifeq ($(HAVE_GCC3_OPTIONS),yes)
38 OP_CFLAGS+= -falign-functions=0
39 else
40 OP_CFLAGS+= -malign-functions=0
41 endif
42
43 ifdef TARGET_GPROF
44 USE_I386_LD=y
45 endif
46 ifdef CONFIG_STATIC
47 USE_I386_LD=y
48 endif
49 ifdef USE_I386_LD
50 LDFLAGS+=-Wl,-T,$(SRC_PATH)/i386.ld
51 else
52 # WARNING: this LDFLAGS is _very_ tricky : qemu is an ELF shared object
53 # that the kernel ELF loader considers as an executable. I think this
54 # is the simplest way to make it self virtualizable!
55 LDFLAGS+=-Wl,-shared
56 endif
57 endif
58
59 ifeq ($(ARCH),ppc)
60 OP_CFLAGS=$(CFLAGS)
61 LDFLAGS+=-Wl,-T,$(SRC_PATH)/ppc.ld
62 endif
63
64 ifeq ($(ARCH),s390)
65 OP_CFLAGS=$(CFLAGS)
66 LDFLAGS+=-Wl,-T,$(SRC_PATH)/s390.ld
67 endif
68
69 ifeq ($(ARCH),sparc)
70 CFLAGS+=-m32 -ffixed-g1 -ffixed-g2 -ffixed-g3 -ffixed-g6
71 LDFLAGS+=-m32
72 OP_CFLAGS=$(CFLAGS) -fno-delayed-branch -ffixed-i0
73 HELPER_CFLAGS=$(CFLAGS) -ffixed-i0 -mflat
74 # -static is used to avoid g1/g3 usage by the dynamic linker
75 LDFLAGS+=-Wl,-T,$(SRC_PATH)/sparc.ld -static
76 endif
77
78 ifeq ($(ARCH),sparc64)
79 CFLAGS+=-m64 -ffixed-g1 -ffixed-g2 -ffixed-g3 -ffixed-g6
80 LDFLAGS+=-m64
81 OP_CFLAGS=$(CFLAGS) -fno-delayed-branch -ffixed-i0
82 endif
83
84 ifeq ($(ARCH),alpha)
85 # -msmall-data is not used because we want two-instruction relocations
86 # for the constant constructions
87 OP_CFLAGS=-Wall -O2 -g
88 # Ensure there's only a single GP
89 CFLAGS += -msmall-data
90 LDFLAGS+=-Wl,-T,$(SRC_PATH)/alpha.ld
91 endif
92
93 ifeq ($(ARCH),ia64)
94 OP_CFLAGS=$(CFLAGS)
95 endif
96
97 ifeq ($(ARCH),arm)
98 OP_CFLAGS=$(CFLAGS) -mno-sched-prolog
99 LDFLAGS+=-Wl,-T,$(SRC_PATH)/arm.ld
100 endif
101
102 ifeq ($(ARCH),m68k)
103 OP_CFLAGS=$(CFLAGS) -fomit-frame-pointer
104 LDFLAGS+=-Wl,-T,m68k.ld
105 endif
106
107 ifeq ($(HAVE_GCC3_OPTIONS),yes)
108 # very important to generate a return at the end of every operation
109 OP_CFLAGS+=-fno-reorder-blocks -fno-optimize-sibling-calls
110 endif
111
112 #########################################################
113
114 DEFINES+=-D_GNU_SOURCE
115 LIBS+=-lm
116
117 # profiling code
118 ifdef TARGET_GPROF
119 LDFLAGS+=-p
120 main.o: CFLAGS+=-p
121 endif
122
123 OBJS= elfload.o main.o syscall.o mmap.o signal.o path.o
124 ifeq ($(TARGET_ARCH), i386)
125 OBJS+= vm86.o
126 endif
127 SRCS:= $(OBJS:.o=.c)
128 OBJS+= libqemu.a
129
130 # cpu emulator library
131 LIBOBJS=thunk.o exec.o translate-all.o cpu-exec.o gdbstub.o \
132         translate.o op.o
133
134 ifeq ($(TARGET_ARCH), i386)
135 LIBOBJS+=helper.o helper2.o
136 endif
137
138 # NOTE: the disassembler code is only needed for debugging
139 LIBOBJS+=disas.o 
140 ifeq ($(findstring i386, $(TARGET_ARCH) $(ARCH)),i386)
141 LIBOBJS+=i386-dis.o
142 endif
143 ifeq ($(findstring alpha, $(TARGET_ARCH) $(ARCH)),alpha)
144 LIBOBJS+=alpha-dis.o
145 endif
146 ifeq ($(findstring ppc, $(TARGET_ARCH) $(ARCH)),ppc)
147 LIBOBJS+=ppc-dis.o
148 endif
149 ifeq ($(findstring sparc, $(TARGET_ARCH) $(ARCH)),sparc)
150 LIBOBJS+=sparc-dis.o
151 endif
152 ifeq ($(findstring arm, $(TARGET_ARCH) $(ARCH)),arm)
153 LIBOBJS+=arm-dis.o
154 endif
155
156 ifeq ($(ARCH),ia64)
157 OBJS += ia64-syscall.o
158 endif
159
160 all: $(PROGS)
161
162 $(QEMU_USER): $(OBJS)
163         $(CC) $(LDFLAGS) -o $@ $^  $(LIBS)
164 ifeq ($(ARCH),alpha)
165 # Mark as 32 bit binary, i. e. it will be mapped into the low 31 bit of
166 # the address space (31 bit so sign extending doesn't matter)
167         echo -ne '\001\000\000\000' | dd of=qemu bs=1 seek=48 count=4 conv=notrunc
168 endif
169
170 # must use static linking to avoid leaving stuff in virtual address space
171 VL_OBJS=vl.o block.o vga.o
172 ifdef CONFIG_SDL
173 VL_OBJS+=sdl.o
174 SDL_LIBS+=-L/usr/X11R6/lib -lX11 -lXext -lXv -ldl -lm
175 endif
176
177 $(QEMU_SYSTEM): $(VL_OBJS) libqemu.a
178         $(CC) -static -Wl,-T,$(SRC_PATH)/i386-vl.ld -o $@ $^ $(LIBS) $(SDL_LIBS)
179
180 sdl.o: sdl.c
181         $(CC) $(CFLAGS) $(DEFINES) $(SDL_CFLAGS) -c -o $@ $<
182
183 depend: $(SRCS)
184         $(CC) -MM $(CFLAGS) $(DEFINES) $^ 1>.depend
185
186 # libqemu 
187
188 libqemu.a: $(LIBOBJS)
189         rm -f $@
190         $(AR) rcs $@ $(LIBOBJS)
191
192 translate.o: translate.c gen-op.h opc.h cpu.h
193
194 translate-all.o: translate-all.c op.h opc.h cpu.h
195
196 op.h: op.o $(DYNGEN)
197         $(DYNGEN) -o $@ $<
198
199 opc.h: op.o $(DYNGEN)
200         $(DYNGEN) -c -o $@ $<
201
202 gen-op.h: op.o $(DYNGEN)
203         $(DYNGEN) -g -o $@ $<
204
205 op.o: op.c
206         $(CC) $(OP_CFLAGS) $(DEFINES) -c -o $@ $<
207
208 helper.o: helper.c
209         $(CC) $(HELPER_CFLAGS) $(DEFINES) -c -o $@ $<
210
211 ifeq ($(TARGET_ARCH), i386)
212 op.o: op.c opreg_template.h ops_template.h ops_template_mem.h ops_mem.h
213 endif
214
215 ifeq ($(TARGET_ARCH), arm)
216 op.o: op.c op_template.h
217 endif
218
219 ifeq ($(TARGET_ARCH), sparc)
220 op.o: op.c op_template.h
221 endif
222
223 %.o: %.c
224         $(CC) $(CFLAGS) $(DEFINES) -c -o $@ $<
225
226 clean:
227         rm -f *.o  *.a *~ $(PROGS) gen-op.h opc.h op.h
228
229 install: all 
230         install -m 755 -s $(PROGS) $(prefix)/bin
231
232 ifneq ($(wildcard .depend),)
233 include .depend
234 endif