1 | # $Id: Makefile-wrapper.gmk 98103 2023-01-17 14:15:46Z vboxsync $
|
---|
2 | ## @file
|
---|
3 | # Makefile template for a wrapper module.
|
---|
4 | #
|
---|
5 |
|
---|
6 | #
|
---|
7 | # Copyright (C) 2006-2023 Oracle and/or its affiliates.
|
---|
8 | #
|
---|
9 | # This file is part of VirtualBox base platform packages, as
|
---|
10 | # available from https://www.virtualbox.org.
|
---|
11 | #
|
---|
12 | # This program is free software; you can redistribute it and/or
|
---|
13 | # modify it under the terms of the GNU General Public License
|
---|
14 | # as published by the Free Software Foundation, in version 3 of the
|
---|
15 | # License.
|
---|
16 | #
|
---|
17 | # This program is distributed in the hope that it will be useful, but
|
---|
18 | # WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
20 | # General Public License for more details.
|
---|
21 | #
|
---|
22 | # You should have received a copy of the GNU General Public License
|
---|
23 | # along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
24 | #
|
---|
25 | # The contents of this file may alternatively be used under the terms
|
---|
26 | # of the Common Development and Distribution License Version 1.0
|
---|
27 | # (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
|
---|
28 | # in the VirtualBox distribution, in which case the provisions of the
|
---|
29 | # CDDL are applicable instead of those of the GPL.
|
---|
30 | #
|
---|
31 | # You may elect to license modified versions of this file under the
|
---|
32 | # terms and conditions of either the GPL or the CDDL or both.
|
---|
33 | #
|
---|
34 | # SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
|
---|
35 | #
|
---|
36 |
|
---|
37 | # Check template parameters.
|
---|
38 | ifndef WRAPPED_MODULE_NAME
|
---|
39 | $(error WRAPPED_MODULE_NAME not defined)
|
---|
40 | endif
|
---|
41 | ifndef VBOXMOD_NAME
|
---|
42 | $(error VBOXMOD_NAME not defined)
|
---|
43 | endif
|
---|
44 |
|
---|
45 |
|
---|
46 | # Linux kbuild sets this to our source directory if we are called from there
|
---|
47 | ifndef VBOX_MODULE_SRC_DIR
|
---|
48 | VBOX_MODULE_SRC_DIR := $(abspath $(dir $(lastword $(MAKEFILE_LIST))))/
|
---|
49 | endif
|
---|
50 | VBOXDRV_DIR := $(abspath $(VBOX_MODULE_SRC_DIR)../vboxdrv/)/
|
---|
51 | VBOX_VMMR0_DIR := $(abspath $(VBOX_MODULE_SRC_DIR)../vbox_vmmr0/)/
|
---|
52 | include $(VBOXDRV_DIR)Makefile-header.gmk
|
---|
53 |
|
---|
54 | # All of these wrappers depend on
|
---|
55 | ifndef KBUILD_EXTRA_SYMBOLS
|
---|
56 | KBUILD_EXTRA_SYMBOLS := $(VBOXDRV_DIR)Module.symvers
|
---|
57 | ifdef WRAPPER_NEED_VMMR0
|
---|
58 | KBUILD_EXTRA_SYMBOLS += $(VBOX_VMMR0_DIR)Module.symvers
|
---|
59 | endif
|
---|
60 | endif
|
---|
61 |
|
---|
62 | VBOXMOD_OBJS = \
|
---|
63 | SUPWrapperMod-linux.o \
|
---|
64 | $(WRAPPED_MODULE_NAME).o
|
---|
65 |
|
---|
66 | VBOXMOD_INCL = \
|
---|
67 | $(VBOXDRV_DIR) \
|
---|
68 | $(VBOXDRV_DIR)include \
|
---|
69 | $(VBOXDRV_DIR)r0drv/linux
|
---|
70 |
|
---|
71 | VBOXMOD_DEFS += \
|
---|
72 | RT_OS_LINUX \
|
---|
73 | IN_RING0 \
|
---|
74 | IN_RT_R0 \
|
---|
75 | IN_SUP_R0 \
|
---|
76 | VBOX \
|
---|
77 | \
|
---|
78 | WRAPPED_MODULE_NAME=\"$(WRAPPED_MODULE_NAME).r0\" \
|
---|
79 | WRAPPED_MODULE_SYMBOL_INCLUDE=\"$(WRAPPED_MODULE_NAME)-symbols.h\"
|
---|
80 | ifdef WRAPPED_MODULE_FLAGS
|
---|
81 | VBOXMOD_DEFS += WRAPPED_MODULE_FLAGS="$(WRAPPED_MODULE_FLAGS)"
|
---|
82 | endif
|
---|
83 | ifdef WRAPPED_MODULE_LINUX_EXPORTS
|
---|
84 | VBOXMOD_DEFS += WRAPPED_MODULE_LINUX_EXPORTS
|
---|
85 | endif
|
---|
86 | ifdef WRAPPED_MODULE_SRV_REQ_HANDLER
|
---|
87 | VBOXMOD_DEFS += WRAPPED_MODULE_SRV_REQ_HANDLER="$(WRAPPED_MODULE_SRV_REQ_HANDLER)"
|
---|
88 | endif
|
---|
89 | ifdef WRAPPED_MODULE_IS_VMMR0
|
---|
90 | VBOXMOD_DEFS += WRAPPED_MODULE_VMMR0_ENTRY_FAST=VMMR0EntryFast
|
---|
91 | VBOXMOD_DEFS += WRAPPED_MODULE_VMMR0_ENTRY_EX=VMMR0EntryEx
|
---|
92 | endif
|
---|
93 | ifdef WRAPPED_MODULE_NO_INIT
|
---|
94 | VBOXMOD_DEFS += WRAPPED_MODULE_INIT=NULL
|
---|
95 | endif
|
---|
96 | ifdef WRAPPED_MODULE_NO_TERM
|
---|
97 | VBOXMOD_DEFS += WRAPPED_MODULE_TERM=NULL
|
---|
98 | endif
|
---|
99 | ifdef WRAPPED_MODULE_LICENSE_PROPRIETARY
|
---|
100 | VBOXMOD_DEFS += WRAPPED_MODULE_LICENSE_PROPRIETARY
|
---|
101 | endif
|
---|
102 |
|
---|
103 | VBOXMOD_CFLAGS = -include $(VBOXDRV_DIR)include/VBox/SUPDrvMangling.h \
|
---|
104 | -fno-omit-frame-pointer -fno-pie -Wno-declaration-after-statement
|
---|
105 |
|
---|
106 | ## @todo cleanup
|
---|
107 |
|
---|
108 | include $(VBOXDRV_DIR)Makefile-footer.gmk
|
---|
109 |
|
---|
110 |
|
---|
111 | #
|
---|
112 | # Custom rules (some of this could later be done before install).
|
---|
113 | #
|
---|
114 | SUPWrapperMod-linux.c \
|
---|
115 | $(VBOX_MODULE_SRC_DIR)SUPWrapperMod-linux.c \
|
---|
116 | $(VBOX_MODULE_SRC_DIR)SUPWrapperMod-linux.o \
|
---|
117 | : $(VBOX_MODULE_SRC_DIR)$(WRAPPED_MODULE_NAME)-symbols.h
|
---|
118 |
|
---|
119 | $(VBOX_MODULE_SRC_DIR)$(WRAPPED_MODULE_NAME)-symbols.h: \
|
---|
120 | $(VBOX_MODULE_SRC_DIR)$(WRAPPED_MODULE_NAME).r0 \
|
---|
121 | $(VBOX_MODULE_SRC_DIR)Makefile-wrapper.gmk \
|
---|
122 | $(VBOX_MODULE_SRC_DIR)Makefile
|
---|
123 | rm -f -- "$@" "$@-tmp1" "$@-tmp2"
|
---|
124 | objdump --syms "$<" > "$@-tmp1"
|
---|
125 | sed -e '/[[:space:]].hidden[[:space:]]/d' \
|
---|
126 | -e '/[[:space:]]\*UND\*[[:space:]]/d' \
|
---|
127 | -e '/[[:space:]]vboxr0mod_/d' \
|
---|
128 | -e '/^[[:xdigit:]][[:xdigit:]]*[[:space:]][gu]/!d' \
|
---|
129 | -e 's/^\([[:xdigit:]]*\)[[:space:]].*000[[:xdigit:]]*[[:space:]]\([_a-zA-Z].*\)$$/SYMBOL_ENTRY(\2)/' \
|
---|
130 | -e '/SYMBOL_ENTRY(ModuleInit)/d' \
|
---|
131 | -e '/SYMBOL_ENTRY(ModuleTerm)/d' \
|
---|
132 | "$@-tmp1" > "$@-tmp2"
|
---|
133 | sort "$@-tmp2" > "$@"
|
---|
134 | rm -f -- "$@-tmp1" "$@-tmp2"
|
---|
135 |
|
---|
136 |
|
---|
137 | $(VBOX_MODULE_SRC_DIR)$(WRAPPED_MODULE_NAME).mangle-symbols: \
|
---|
138 | $(VBOXDRV_DIR)Module.symvers \
|
---|
139 | $(VBOX_MODULE_SRC_DIR)$(WRAPPED_MODULE_NAME)-symbols.h \
|
---|
140 | $(VBOX_MODULE_SRC_DIR)Makefile-wrapper.gmk \
|
---|
141 | $(VBOX_MODULE_SRC_DIR)Makefile
|
---|
142 | sed -e 's/SYMBOL_ENTRY(\([^)]*\))/\/\1 VBoxHost_\1\/d/' \
|
---|
143 | "$(VBOX_MODULE_SRC_DIR)$(WRAPPED_MODULE_NAME)-symbols.h" \
|
---|
144 | > "$@-ignore.sed"
|
---|
145 | sed -e '/[[:space:]]VBoxHost_/!d' \
|
---|
146 | -e 's/^0x[[:xdigit:]]*[[:space:]]VBoxHost_\([^[:space:]]*\)[[:space:]].*$$/\1 VBoxHost_\1/' \
|
---|
147 | -f "$@-ignore.sed" \
|
---|
148 | "$<" \
|
---|
149 | > "$@"
|
---|
150 |
|
---|
151 | $(VBOX_MODULE_SRC_DIR)$(WRAPPED_MODULE_NAME).o: \
|
---|
152 | $(VBOX_MODULE_SRC_DIR)$(WRAPPED_MODULE_NAME).r0 \
|
---|
153 | $(VBOX_MODULE_SRC_DIR)$(WRAPPED_MODULE_NAME).debug \
|
---|
154 | $(VBOX_MODULE_SRC_DIR)$(WRAPPED_MODULE_NAME).mangle-symbols \
|
---|
155 | $(VBOX_MODULE_SRC_DIR)Makefile-wrapper.gmk \
|
---|
156 | $(VBOX_MODULE_SRC_DIR)Makefile \
|
---|
157 | $(if $(CONFIG_UNWINDER_ORC),$(objtool_dep),)
|
---|
158 | rm -f -- "$@" "$@-tmp"
|
---|
159 | eu-unstrip -o "$@-tmp" $(VBOX_MODULE_SRC_DIR)$(WRAPPED_MODULE_NAME).r0 $(VBOX_MODULE_SRC_DIR)$(WRAPPED_MODULE_NAME).debug
|
---|
160 | objcopy --redefine-syms=$(VBOX_MODULE_SRC_DIR)$(WRAPPED_MODULE_NAME).mangle-symbols "$@-tmp" "$@"
|
---|
161 | rm -f -- "$@-tmp"
|
---|
162 | ifdef CONFIG_UNWINDER_ORC # Must generate the ORC sections.
|
---|
163 | $(__objtool_obj) $(objtool_args) $@
|
---|
164 | endif
|
---|
165 | touch $(VBOX_MODULE_SRC_DIR).$(WRAPPED_MODULE_NAME).o.cmd
|
---|
166 |
|
---|