summaryrefslogtreecommitdiffstats
path: root/include/Makefile.kmk
blob: e89b6c3d6efd83037e77d3900db6c9c7f5e40b30 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
# $Id: Makefile.kmk $
## @file
# Some hacks to allow syntax and prerequisite include checking of headers.
# This makefile doesn't and shouldn't build successfully.
#

#
# Copyright (C) 2006-2023 Oracle and/or its affiliates.
#
# This file is part of VirtualBox base platform packages, as
# available from https://www.virtualbox.org.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation, in version 3 of the
# License.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <https://www.gnu.org/licenses>.
#
# SPDX-License-Identifier: GPL-3.0-only
#

SUB_DEPTH = ..
include $(KBUILD_PATH)/subheader.kmk

LIBRARIES += SyntaxVBoxIncludeR3 SyntaxVBoxIncludeR0

# Omit headers that are using C++ features and upsets gcc.
VBOX_HDRS_CPP_FEATURES := \
	VBox/vmm/hm.h \
	VBox/vmm/hm_vmx.h \
	VBox/vmm/pdmaudioinline.h \
	VBox/vmm/pdmaudiohostenuminline.h \
	VBox/HostServices/GuestControlSvc.h \
	VBox/HostServices/DragAndDropSvc.h \
	VBox/HostServices/Service.h \
	VBox/GuestHost/GuestControl.h \
	VBox/GuestHost/DragAndDrop.h \
	VBox/GuestHost/SharedClipboard-transfers.h \
	VBox/dbus.h \
	VBox/xrandr.h \
	VBox/VBoxCrHgsmi.h \
	VBox/VBoxGuestLibSharedFoldersInline.h \
	VBox/VBoxPktDmp.h \
	VBox/VBoxUhgsmi.h \
	iprt/cpp/%

# Omit headers that are C++ and ring-3.
VBOX_HDRS_R3_CPP := \
	VBox/dbggui.h \
	VBox/settings.h \
	VBox/com/Guid.h \
	VBox/vmm/vmmr3vtable.h \
	iprt/cpp/% \
	VBox/com/% \
	$(subst $(PATH_SUB_CURRENT)/,,$(wildcard $(PATH_SUB_CURRENT)/iprt/*_cpp.h))

# Ring-3 only headers.
VBOX_HDRS_R3_ONLY := \
	VBox/vrdpapi.h \
	VBox/vrdpusb.h \
	VBox/VBoxHDD.h \
	VBox/VBoxHDD-Plugin.h \
	VBox/VBoxCrHgsmi.h \
	VBox/VBoxUhgsmi.h \
	VBox/VBoxNetCfg-win.h \
	VBox/VBoxDrvCfg-win.h \
	VBox/dbus.h \
	VBox/xrandr.h \
	$(if-expr "$(KBUILD_TARGET)" == "win",VBox/usblib.h,) \
	VBox/usblib-win.h \
	VBox/vd.h \
	VBox/vd-cache-backend.h \
	VBox/vd-ifs.h \
	VBox/vd-ifs-internal.h \
	VBox/vd-image-backend.h \
	VBox/vd-plugin.h \
	VBox/vd-filter-backend.h \
	VBox/vddbg.h \
	VBox/vmm/uvm.h \
	VBox/vmm/dbgfflowtrace.h \
	VBox/vscsi.h \
	VBox/ExtPack/% \
	VBox/GuestHost/SharedClipboard-transfers.h \
	VBox/GuestHost/SharedClipboard-win.h \
	VBox/GuestHost/SharedClipboard-x11.h \
	VBox/GuestHost/DragAndDrop.h \
	VBox/HostServices/Service.h \
	iprt/win/% \
	iprt/alloca.h \
	iprt/tcp.h \
	iprt/localipc.h \
	iprt/linux/sysfs.h \
	iprt/socket.h \
	iprt/udp.h \
	iprt/fuzz.h \
	iprt/linux/symvers.h

# Ring-0 driver only headers.
VBOX_HDRS_R0DRV_ONLY := \
	VBox/VBoxGuestLibSharedFolders.h \
	VBox/VBoxGuestLibSharedFoldersInline.h \
	iprt/linux/version.h

# GCC only headers.
VBOX_HDRS_GCC_ONLY := \
	iprt/nocrt/fenv.h \
	iprt/nocrt/math.h

# Headers to omit all together.
VBOX_HDRS_OMIT := \
	VBox/HostServices/glext.h \
	VBox/HostServices/glxext.h \
	VBox/HostServices/wglext.h \
	VBox/VBoxGL2D.h \
	$(if-expr "$(KBUILD_TARGET)" != "linux", \
	VBox/GuestHost/SharedClipboard-x11.h \
	,) \
	$(if-expr "$(KBUILD_TARGET)" != "solaris", \
	VBox/usblib-solaris.h \
	,) \
	VBox/VDEPlug.h \
	VBox/VDEPlugSymDefs.h \
	VBox/VBoxNetCmn-win.h \
	$(if-expr "$(KBUILD_TARGET)" != "win", \
	VBox/com/microatl.h \
	VBox/GuestHost/SharedClipboard-win.h \
	VBox/usblib-win.h \
	VBox/VBoxDrvCfg-win.h \
	VBox/VBoxNetCfg-win.h \
	iprt/sanitized/intrin.h \
	,$(VBOX_HDRS_GCC_ONLY)) \
	\
	VBox/dbus-calls.h \
	VBox/xrandr-calls.h \
	VBox/VBoxKeyboard.h \
	VBox/vmm/pdmpcidevint.h \
	VBox/vmm/vmmr3vtable-def.h \
	iprt/runtime-loader.h \
	iprt/mangling.h \
	$(subst $(PATH_SUB_CURRENT)/,,$(wildcard $(PATH_SUB_CURRENT)/iprt/asm*watcom*.h)) \
	iprt/asn1-generator% \
	iprt/win/% \
	iprt/nt/% \
	\
	$(foreach os,$(filter-out $(KBUILD_TARGET),$(KBUILD_OSES)),iprt/$(os)/% VBox/$(os)/%) \
	$(foreach arch,$(KBUILD_ARCHES),iprt/nocrt/$(arch)/%)

# AMD64 only headers.
ifneq ($(KBUILD_TARGET_ARCH),amd64)
 VBOX_HDRS_OMIT += \
 	VBox/vmm/cpumctx.h \
 	VBox/vmm/cpumctx-v1_6.h \
 	VBox/vmm/dbgfcorefmt.h
endif
# ARM only headers.
ifn1of ($(KBUILD_TARGET_ARCH), arm32 arm64)
 VBOX_HDRS_OMIT += \
 	iprt/asm-arm.h
endif


# We omit a few headers which have platform specific issues or are templates.
VBOX_HDRS_ALL := $(filter-out $(VBOX_HDRS_OMIT), \
	$(subst $(PATH_SUB_CURRENT)/,,$(wildcard \
	$(PATH_SUB_CURRENT)/VBox/*.h \
	$(PATH_SUB_CURRENT)/VBox/*/*.h \
	$(PATH_SUB_CURRENT)/iprt/*.h \
	$(PATH_SUB_CURRENT)/iprt/*/*.h \
	)))

# ring-3, ring-0 and raw-mode context specific exclusions.
VBOX_HDRS_ALL_R3      := $(filter-out $(VBOX_HDRS_R0DRV_ONLY), $(VBOX_HDRS_ALL))
if "$(intersects $(KBUILD_TARGET_ARCH),$(VBOX_SUPPORTED_HOST_ARCHS))" == ""
 ifeq ($(KBUILD_TARGET),win)
  VBOX_HDRS_ALL_R3    := $(filter-out VBox/com/VirtualBox.h VBox/com/listeners.h VBox/settings.h,$(VBOX_HDRS_ALL_R3))
 else
  VBOX_HDRS_ALL_R3    := $(filter-out VBox/com/% VBox/settings.h,$(VBOX_HDRS_ALL_R3))
 endif
endif
VBOX_HDRS_ALL_R3_C    := $(filter-out $(VBOX_HDRS_CPP_FEATURES) $(VBOX_HDRS_R3_CPP), $(VBOX_HDRS_ALL_R3))
VBOX_HDRS_ALL_R0      := $(filter-out $(VBOX_HDRS_R3_CPP) $(VBOX_HDRS_R3_ONLY) $(VBOX_HDRS_R0DRV_ONLY), $(VBOX_HDRS_ALL))
VBOX_HDRS_ALL_R0_C    := $(filter-out $(VBOX_HDRS_CPP_FEATURES), $(VBOX_HDRS_ALL_R0))
VBOX_HDRS_ALL_R0DRV   := $(filter-out $(VBOX_HDRS_R3_CPP) $(VBOX_HDRS_R3_ONLY), $(VBOX_HDRS_ALL))
VBOX_HDRS_ALL_R0DRV_C := $(filter-out $(VBOX_HDRS_CPP_FEATURES), $(VBOX_HDRS_ALL_R0DRV))
VBOX_HDRS_ALL_RC      := $(filter-out \
	VBox/VBoxGuestLib.h \
	VBox/vmm/gvm.h \
	iprt/thread.h \
	iprt/mem.h \
	iprt/memsafer.h \
	iprt/alloc.h \
	iprt/vector.h \
	$(VBOX_HDRS_R3_CPP) \
	$(VBOX_HDRS_R3_ONLY) \
	$(VBOX_HDRS_R0DRV_ONLY) \
	, $(VBOX_HDRS_ALL))
VBOX_HDRS_ALL_RC_C := $(filter-out $(VBOX_HDRS_CPP_FEATURES), $(VBOX_HDRS_ALL_RC))
#$(error $(subst $(SP),$(NLTAB),$(strip $(sort $(VBOX_HDRS_ALL_RC_C)))))

if1of ($(KBUILD_TARGET_ARCH), $(VBOX_SUPPORTED_HOST_ARCHS))
 SyntaxVBoxIncludeR3_TEMPLATE = VBoxMainExe
 SyntaxVBoxIncludeR3_DEFS = VBOX_WITH_HGCM
else
 SyntaxVBoxIncludeR3_TEMPLATE = VBoxR3Exe
 SyntaxVBoxIncludeR3_SDKS.win = ReorderCompilerIncs $(VBOX_WINPSDK) $(VBOX_WINDDK)
endif
SyntaxVBoxIncludeR3_DEFS += USING_VMM_COMMON_DEFS
SyntaxVBoxIncludeR3_CDEFS = IPRT_WITHOUT_NAMED_UNIONS_AND_STRUCTS
SyntaxVBoxIncludeR3_SOURCES := \
	$(addprefix $(PATH_OBJ)/include/c/,  $(addsuffix .c,  $(basename $(VBOX_HDRS_ALL_R3_C)))) \
	$(addprefix $(PATH_OBJ)/include/cpp/,$(addsuffix .cpp,$(basename $(VBOX_HDRS_ALL_R3))))
SyntaxVBoxIncludeR3_CLEAN = $(SyntaxVBoxIncludeR3_SOURCES)
#$(error $(subst $(SP),$(NLTAB),$(strip $(sort $(SyntaxVBoxIncludeR3_SOURCES)))))

SyntaxVBoxIncludeR0_TEMPLATE = VBoxR0
SyntaxVBoxIncludeR0_DEFS = VBOX_WITH_HGCM USING_VMM_COMMON_DEFS
SyntaxVBoxIncludeR0_CDEFS = IPRT_WITHOUT_NAMED_UNIONS_AND_STRUCTS
SyntaxVBoxIncludeR0_SOURCES := \
	$(addprefix $(PATH_OBJ)/include/c/,  $(addsuffix .c,  $(basename $(VBOX_HDRS_ALL_R0_C)))) \
	$(addprefix $(PATH_OBJ)/include/cpp/,$(addsuffix .cpp,$(basename $(VBOX_HDRS_ALL_R0))))
SyntaxVBoxIncludeR0_CLEAN = $(SyntaxVBoxIncludeR0_SOURCES)

if1of ($(KBUILD_TARGET), darwin os2 solaris win)
 LIBRARIES += SyntaxVBoxIncludeR0Drv
 SyntaxVBoxIncludeR0Drv_TEMPLATE = VBoxR0DrvLib
 SyntaxVBoxIncludeR0Drv_SDKS.win = ReorderCompilerIncs $(VBOX_WINDDK) $(VBOX_WINPSDK_INCS)
 SyntaxVBoxIncludeR0Drv_DEFS = VBOX_WITH_HGCM USING_VMM_COMMON_DEFS
 SyntaxVBoxIncludeR0Drv_CDEFS = IPRT_WITHOUT_NAMED_UNIONS_AND_STRUCTS
 SyntaxVBoxIncludeR0Drv_SOURCES := \
 	$(addprefix $(PATH_OBJ)/include/c/,  $(addsuffix .c,  $(basename $(VBOX_HDRS_ALL_R0DRV_C)))) \
 	$(addprefix $(PATH_OBJ)/include/cpp/,$(addsuffix .cpp,$(basename $(VBOX_HDRS_ALL_R0DRV))))
 SyntaxVBoxIncludeR0Drv_CLEAN = $(SyntaxVBoxIncludeR0Drv_SOURCES)
endif

ifdef VBOX_WITH_RAW_MODE
 LIBRARIES += SyntaxVBoxIncludeRC
 SyntaxVBoxIncludeRC_TEMPLATE = VBoxRc
 SyntaxVBoxIncludeRC_DEFS = VBOX_WITH_HGCM USING_VMM_COMMON_DEFS
 SyntaxVBoxIncludeRC_CDEFS = IPRT_WITHOUT_NAMED_UNIONS_AND_STRUCTS
 SyntaxVBoxIncludeRC_SOURCES := \
 	$(addprefix $(PATH_OBJ)/include/c/,  $(addsuffix .c,  $(basename $(VBOX_HDRS_ALL_RC_C)))) \
 	$(addprefix $(PATH_OBJ)/include/cpp/,$(addsuffix .cpp,$(basename $(VBOX_HDRS_ALL_RC))))
 SyntaxVBoxIncludeRC_CLEAN = $(SyntaxVBoxIncludeRC_SOURCES)
endif


# Headers that must only be included once.
VBOX_HDRS_ONLY_ONCE := \
	iprt/bldprog-strtab-template.cpp.h


# Generate the files we compile.
define def_hdr
 $(eval functioname := $(translate $(basename $(hdr)),-./,___))

 $$(PATH_OBJ)/include/c/$(basename $(hdr)).c: | $$$$(dir $$$$@)
	$(QUIET)$$(APPEND) -t -n $$@ \
		'#include <$(hdr)>' \
		$(if-expr $(intersects $(hdr),$(VBOX_HDRS_ONLY_ONCE)),, '#include <$(hdr)>') \
		'extern int $(functioname)_c(void);' \
		'int $(functioname)_c(void) { return 0;}'

 $$(PATH_OBJ)/include/cpp/$(basename $(hdr)).cpp: | $$$$(dir $$$$@)
	$(QUIET)$$(APPEND) -t -n $$@ \
		'#include <$(hdr)>' \
		$(if-expr $(intersects $(hdr),$(VBOX_HDRS_ONLY_ONCE)),, '#include <$(hdr)>') \
		'extern int $(functioname)_cpp(void);' \
		'int $(functioname)_cpp(void) { return 0;}'

endef

$(foreach hdr,$(VBOX_HDRS_ALL), $(eval $(def_hdr)))

# Tell kBuild to generate rules for making the directories for the generated files.
VBOX_HDR_DIRS := $(sort $(dir $(VBOX_HDRS_ALL)))
BLDDIRS += $(addprefix $(PATH_OBJ)/include/c/,$(VBOX_HDR_DIRS)) $(addprefix $(PATH_OBJ)/include/cpp/,$(VBOX_HDR_DIRS))


include $(FILE_KBUILD_SUB_FOOTER)