xref: /illumos-kvm/Makefile (revision ea8a63a5)
1#
2# Copyright (c) 2019, Joyent, Inc.
3#
4
5include		$(PWD)/../../../build.env
6
7KERNEL_SOURCE =	$(PWD)/../../illumos
8MDB_SOURCE =	$(KERNEL_SOURCE)/usr/src/cmd/mdb
9PROTO_AREA =	$(PWD)/../../../proto
10STRAP_AREA =	$(PWD)/../../../proto.strap
11
12CC =		$(STRAP_AREA)/usr/bin/gcc
13LD =		/usr/bin/ld
14CTFBINDIR =	$(KERNEL_SOURCE)/usr/src/tools/proto/*/opt/onbld/bin/i386
15CTFCONVERT =	$(CTFBINDIR)/ctfconvert
16CSTYLE =	$(KERNEL_SOURCE)/usr/src/tools/scripts/cstyle
17HDRCHK =	tools/hdrchk
18HDRCHK_USRFLAG =	"$(CC)"
19HDRCHK_SYSFLAG =	"$(CC) -D_KERNEL"
20
21ALWAYS_CPPFLAGS = \
22	-D__sun
23
24KERNEL_CPPFLAGS = \
25	$(ALWAYS_CPPFLAGS) \
26	-D_KERNEL \
27	-D_MACHDEP \
28	-Dx86 \
29	-DDEBUG \
30	-DCONFIG_SOLARIS \
31	-D_ASM_INLINES \
32	-DDIS_MEM \
33	-D_KERNEL \
34	-D_SYSCALL32 \
35	-D_DDI_STRICT \
36	-Di86pc \
37	-D_MACHDEP \
38	-DOPTERON_ERRATUM_88 \
39	-DOPTERON_ERRATUM_91 \
40	-DOPTERON_ERRATUM_93 \
41	-DOPTERON_ERRATUM_95 \
42	-DOPTERON_ERRATUM_99 \
43	-DOPTERON_ERRATUM_100 \
44	-DOPTERON_ERRATUM_101 \
45	-DOPTERON_ERRATUM_108 \
46	-DOPTERON_ERRATUM_109 \
47	-DOPTERON_ERRATUM_121 \
48	-DOPTERON_ERRATUM_122 \
49	-DOPTERON_ERRATUM_123 \
50	-DOPTERON_ERRATUM_131 \
51	-DOPTERON_WORKAROUND_6336786 \
52	-DOPTERON_WORKAROUND_6323525 \
53	-DOPTERON_ERRATUM_172 \
54	-DOPTERON_ERRATUM_298 \
55	-DUTS_RELEASE="5.11" \
56	-DUTS_VERSION="joyent.147" \
57	-DUTS_PLATFORM="i86pc" \
58	-nostdinc \
59	-I$(KERNEL_SOURCE)/usr/src/uts/common \
60	-I$(KERNEL_SOURCE)/usr/src/uts/intel \
61	-I$(KERNEL_SOURCE)/usr/src/uts/i86pc
62
63DMOD_CPPFLAGS = \
64	$(ALWAYS_CPPFLAGS) \
65	-D_KERNEL \
66	-DTEXT_DOMAIN="SUNW_OST_OSCMD" \
67	-D_TS_ERRNO \
68	-D_ELF64 \
69	-Ui386 \
70	-U__i386 \
71	-isystem $(PROTO_AREA)/usr/include \
72	-I$(KERNEL_SOURCE)/usr/src/uts/common \
73	-I$(KERNEL_SOURCE)/usr/src/uts/intel \
74	-I$(KERNEL_SOURCE)/usr/src/uts/i86pc \
75	-I$(MDB_SOURCE)/common
76
77LINKMOD_CPPFLAGS = \
78	$(ALWAYS_CPPFLAGS) \
79	-DTEXT_DOMAIN="SUNW_OST_OSCMD" \
80	-D_TS_ERRNO \
81	-isystem $(PROTO_AREA)/usr/include \
82	-I$(KERNEL_SOURCE)/usr/src/cmd/devfsadm/ \
83	-I$(KERNEL_SOURCE)/usr/src/cmd/devfsadm/../../uts/common \
84	-I$(KERNEL_SOURCE)/usr/src/cmd/devfsadm/../modload
85
86ALWAYS_CFLAGS = \
87	-fident \
88	-fno-builtin \
89	-fno-asm \
90	-nodefaultlibs \
91	-Wall \
92	-Wno-unknown-pragmas \
93	-Wno-unused \
94	-Werror \
95	-fno-inline-functions
96
97#
98# Skip dangerous GCC options (not that any specific problems are know of here).
99#
100ifneq ($(PRIMARY_COMPILER_VER),4)
101ALWAYS_CFLAGS += -fno-aggressive-loop-optimizations
102endif
103
104#
105# Replacing -O with -O2 causes the KVM host to panic.  Don't do that.
106#
107KERNEL_CFLAGS = \
108	$(ALWAYS_CFLAGS) \
109	-m64 \
110	-mcmodel=kernel \
111	-g \
112	-O \
113	-fno-inline \
114	-ffreestanding \
115	-fno-strict-aliasing \
116	-Wpointer-arith \
117	-gdwarf-2 \
118	-std=gnu99 \
119	-mno-red-zone
120
121USER_CFLAGS = \
122	-finline \
123	-gdwarf-2 \
124	-std=gnu89 \
125	-Wno-missing-braces \
126	-Wno-sign-compare \
127	-Wno-parentheses \
128	-Wno-uninitialized \
129	-Wno-implicit-function-declaration \
130	-Wno-trigraphs \
131	-Wno-char-subscripts \
132	-Wno-switch
133
134DMOD_CFLAGS = \
135	$(ALWAYS_CFLAGS) \
136	$(USER_CFLAGS) \
137	-m64 \
138	-fno-strict-aliasing \
139	-fno-unit-at-a-time \
140	-fno-optimize-sibling-calls \
141	-O2 \
142	-fno-inline-small-functions \
143	-fno-inline-functions-called-once \
144	-mtune=opteron \
145	-Wno-address \
146	-ffreestanding \
147	-fPIC
148
149LINKMOD_CFLAGS = \
150	$(ALWAYS_CFLAGS) \
151	$(USER_CFLAGS) \
152	-O \
153	-fpic
154
155USER_LDFLAGS = \
156	-Wl,-Bdirect \
157	-Wl,-zfatal-warnings \
158	-Wl,-zassert-deflib \
159	-Wl,-zguidance
160
161DMOD_LDFLAGS = \
162	$(USER_LDFLAGS) \
163	-m64 \
164	-shared \
165	-nodefaultlibs \
166	-std=gnu89 \
167	-Wl,-M$(KERNEL_SOURCE)/usr/src/common/mapfiles/common/map.pagealign \
168	-Wl,-M$(KERNEL_SOURCE)/usr/src/common/mapfiles/common/map.noexdata \
169	-Wl,-ztext \
170	-Wl,-zdefs \
171	-Wl,-zignore \
172	-Wl,-M$(MDB_SOURCE)/common/modules/conf/mapfile-extern \
173	-L$(PROTO_AREA)/lib \
174	-L$(PROTO_AREA)/usr/lib
175
176DMOD_LIBS = \
177	-lc
178
179LINKMOD_LDFLAGS = \
180	$(USER_LDFLAGS) \
181	-shared \
182	-nodefaultlibs \
183	-Wl,-zdefs \
184	-Wl,-ztext \
185	-Wl,-M$(KERNEL_SOURCE)/usr/src/cmd/devfsadm/mapfile-vers \
186	-Wl,-M$(KERNEL_SOURCE)/usr/src/common/mapfiles/common/map.pagealign \
187	-Wl,-M$(KERNEL_SOURCE)/usr/src/common/mapfiles/common/map.noexdata \
188	-h JOY_kvm_link.so \
189	-L$(PROTO_AREA)/lib \
190	-L$(PROTO_AREA)/usr/lib \
191
192LINKMOD_LIBS = \
193	-ldevinfo \
194	-lc
195
196HEADERS=			\
197	kvm.h			\
198	kvm_bitops.h		\
199	kvm_cache_regs.h	\
200	kvm_coalesced_mmio.h	\
201	kvm_cpuid.h		\
202	kvm_emulate.h		\
203	kvm_host.h		\
204	kvm_i8254.h		\
205	kvm_impl.h		\
206	kvm_ioapic.h		\
207	kvm_iodev.h		\
208	kvm_irq.h		\
209	kvm_lapic.h		\
210	kvm_mmu.h		\
211	kvm_msidef.h		\
212	kvm_msr.h		\
213	kvm_paging_tmpl.h	\
214	kvm_timer.h		\
215	kvm_types.h		\
216	kvm_vmx.h		\
217	kvm_x86host.h		\
218	kvm_x86impl.h		\
219	kvm_x86.h
220
221HDRCHK_USRHDRS= 		\
222	kvm.h			\
223	kvm_types.h		\
224	kvm_x86.h
225
226HDRCHK_SYSHDRS=			\
227	kvm_bitops.h		\
228	kvm_cache_regs.h	\
229	kvm_cpuid.h		\
230	kvm_host.h		\
231	kvm_impl.h		\
232	kvm_ioapic.h		\
233	kvm_iodev.h		\
234	kvm_irq.h		\
235	kvm_msidef.h		\
236	kvm_mmu.h		\
237	kvm_timer.h		\
238	kvm_types.h		\
239	kvm_vmx.h		\
240	kvm_x86host.h		\
241	kvm_x86impl.h
242
243KMOD_SRCS =			\
244	kvm.c			\
245	kvm_x86.c		\
246	kvm_emulate.c		\
247	kvm_irq.c		\
248	kvm_i8254.c		\
249	kvm_lapic.c		\
250	kvm_mmu.c		\
251	kvm_iodev.c		\
252	kvm_ioapic.c		\
253	kvm_vmx.c		\
254	kvm_i8259.c		\
255	kvm_coalesced_mmio.c	\
256	kvm_irq_comm.c		\
257	kvm_cache_regs.c
258
259DMOD_SRCS = \
260	kvm_mdb.c
261
262LINKMOD_SRCS = \
263	kvm_link.c
264
265CSTYLE_CHK = \
266	$(KMOD_SRCS:%=%.chk) \
267	$(DMOD_SRCS:%=%.chk) \
268	$(LINKMOD_SRCS:%=%.chk) \
269	$(HEADERS:%=%.chk)
270
271XXX_CHK = \
272	$(KMOD_SRCS:%=%.xxxchk)
273
274USR_HDRCHK =	$(HDRCHK_USRHDRS:%=%.uhdrchk)
275SYS_HDRCHK =	$(HDRCHK_SYSHDRS:%=%.shdrchk)
276
277KMOD_OBJS =	$(KMOD_SRCS:%.c=%.o)
278DMOD_OBJS =	$(DMOD_SRCS:%.c=%.o)
279LINKMOD_OBJS =	$(LINKMOD_SRCS:%.c=%.o)
280
281kvm :	CPPFLAGS =	$(KERNEL_CPPFLAGS)
282kvm :	CFLAGS =	$(KERNEL_CFLAGS)
283
284kvm.so :	CPPFLAGS =	$(DMOD_CPPFLAGS)
285kvm.so :	CFLAGS =	$(DMOD_CFLAGS)
286kvm.so :	LDFLAGS =	$(DMOD_LDFLAGS)
287kvm.so :	LIBS =		$(DMOD_LIBS)
288
289JOY_kvm_link.so :	CPPFLAGS =	$(LINKMOD_CPPFLAGS)
290JOY_kvm_link.so :	CFLAGS =	$(LINKMOD_CFLAGS)
291JOY_kvm_link.so :	LDFLAGS =	$(LINKMOD_LDFLAGS)
292JOY_kvm_link.so :	LIBS =		$(LINKMOD_LIBS)
293
294world: kvm kvm.so JOY_kvm_link.so
295
296kvm: $(KMOD_OBJS)
297	$(LD) -r -o $@ $(KMOD_OBJS)
298	$(CTFCONVERT) -L VERSION -o $@ $@
299
300kvm.so: $(DMOD_OBJS)
301	$(CC) $(LDFLAGS) -o $@ $(DMOD_OBJS) $(LIBS)
302	$(CTFCONVERT) -L VERSION -o $@ $@
303
304JOY_kvm_link.so: $(LINKMOD_OBJS)
305	$(CC) $(LDFLAGS) -o $@ $(LINKMOD_OBJS) $(LIBS)
306	$(CTFCONVERT) -L VERSION -o $@ $@
307
308%.o: %.c $(HEADERS)
309	$(CC) $(CPPFLAGS) $(CFLAGS) -o $@ -c $<
310
311install: world
312	@echo "==> Installing kvm module (to $(DESTDIR)/)"
313	@mkdir -p $(DESTDIR)/usr/kernel/drv/amd64
314	@cp kvm $(DESTDIR)/usr/kernel/drv/amd64/kvm
315	@cp kvm.conf $(DESTDIR)/usr/kernel/drv
316	@mkdir -p $(DESTDIR)/usr/lib/mdb/kvm/amd64
317	@cp kvm.so $(DESTDIR)/usr/lib/mdb/kvm/amd64
318	@mkdir -p $(DESTDIR)/usr/lib/devfsadm/linkmod
319	@cp JOY_kvm_link.so $(DESTDIR)/usr/lib/devfsadm/linkmod
320
321check: $(CSTYLE_CHK) $(XXX_CHK) $(USR_HDRCHK) $(SYS_HDRCHK)
322
323%.chk: %
324	$(CSTYLE) $<
325
326%.xxxchk: %
327	./tools/xxxcheck $<
328
329%.uhdrchk: %
330	$(HDRCHK) $(HDRCHK_USRFLAG) $<
331
332%.shdrchk: %
333	$(HDRCHK) $(HDRCHK_SYSFLAG) $<
334
335update:
336	git pull --rebase
337
338clean:
339	@pfexec rm -f *.o kvm kvm.so JOY_kvm_link.so
340
341.PHONY: manifest
342manifest:
343	cp manifest $(DESTDIR)/$(DESTNAME)
344
345.PHONY: mancheck_conf
346mancheck_conf:
347
348uninstall:
349	@pfexec rem_drv kvm || /bin/true
350	@pfexec rm -f /usr/kernel/drv/kvm* /usr/kernel/drv/amd64/kvm*
351