forked from utoni/mingw-w64-dpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile.inc
279 lines (253 loc) · 8.92 KB
/
Makefile.inc
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
ifndef DPP_ROOT
$(error DPP_ROOT is undefined)
endif
ifdef BUILD_NATIVE
$(error BUILD_NATIVE is defined, include Makefile.native.inc)
endif
NAME_SUFFIX :=
Q = @
ifeq ($(Q),)
CMAKE_Q = VERBOSE=1
endif
DPP_ROOT = $(realpath .)
ifeq ($(LOCAL_MINGW64_CC),)
LOCAL_MINGW64_BUILD_SCRIPT := $(DPP_ROOT)/mingw-w64-build/mingw-w64-build
LOCAL_MINGW64_BUILD_DIR := $(DPP_ROOT)/mingw-w64-sysroot/x86_64
LOCAL_MINGW64_CC := $(LOCAL_MINGW64_BUILD_DIR)/bin/x86_64-w64-mingw32-gcc
LOCAL_MINGW64_CXX := $(LOCAL_MINGW64_BUILD_DIR)/bin/x86_64-w64-mingw32-g++
LOCAL_MINGW64_AR := $(LOCAL_MINGW64_BUILD_DIR)/bin/x86_64-w64-mingw32-ar
LOCAL_MINGW64_RC := $(LOCAL_MINGW64_BUILD_DIR)/bin/x86_64-w64-mingw32-windres
else
ifeq ($(LOCAL_MINGW64_CXX),)
$(error LOCAL_MINGW64_CC was set, missing required LOCAL_MINGW64_CXX)
endif
ifeq ($(LOCAL_MINGW64_RC),)
$(error LOCAL_MINGW64_CC was set, missing required LOCAL_MINGW64_RC)
endif
endif
ifeq ($(SIGNTOOL),)
SIGNTOOL := osslsigncode
endif
ifeq ($(SIGNTOOL_PREFIX),)
SIGNTOOL_PREFIX := codesign
endif
DDK_GLOBAL_DEPS := deps $(LOCAL_MINGW64_BUILD_SCRIPT) $(LOCAL_MINGW64_BUILD_DIR) $(LOCAL_MINGW64_CC) $(LOCAL_MINGW64_CXX) $(LOCAL_MINGW64_AR) $(LOCAL_MINGW64_RC)
INSTALL = install
SED = sed
CMAKE = cmake
CC = $(LOCAL_MINGW64_CC)
CXX = $(LOCAL_MINGW64_CXX)
AR = $(LOCAL_MINGW64_AR)
RC = $(LOCAL_MINGW64_RC)
DDK_INCLUDE_DIR = $(dir $(CC))../x86_64-w64-mingw32/include/ddk
CFLAGS := -Wall -Wextra -Wno-sign-compare -Wno-strict-aliasing \
-m64 -fPIC -fvisibility=hidden \
-fno-builtin -ffreestanding \
-fno-stack-protector -mno-stack-arg-probe \
-I$(DPP_ROOT)/CRT -I$(DDK_INCLUDE_DIR) \
-D__INTRINSIC_DEFINED_InterlockedBitTestAndSet \
-D__INTRINSIC_DEFINED_InterlockedBitTestAndReset
ifneq ($(WERROR),)
CFLAGS += -Werror
endif
#PRINT_LDSCRIPT = -Wl,--verbose
CXXFLAGS := -fno-exceptions -fno-rtti -fuse-cxa-atexit
EASTL_CXXFLAGS := -I$(DPP_ROOT)/EASTL/include -I$(DPP_ROOT)/EASTL/test/packages/EABase/include/Common \
-DEASTL_USER_CONFIG_HEADER="<eastl_user_config.hpp>" \
-DEASTL_EABASE_DISABLED=1 \
-DEASTL_THREAD_SUPPORT_AVAILABLE=0 \
-DEASTL_EXCEPTIONS_ENABLED=0 \
-DEASTL_ASSERT_ENABLED=0 \
-DEASTL_EASTDC_VSNPRINTF=0 \
-DEA_COMPILER_NO_EXCEPTIONS=1 \
-DEA_COMPILER_MANAGED_CPP=1 \
-Wno-unknown-pragmas \
-Wno-deprecated-copy
DRIVER_LDFLAGS := -shared \
-Wl,--subsystem,native \
-Wl,--image-base,0x140000000 \
-Wl,--dynamicbase -Wl,--nxcompat \
-Wl,--file-alignment,0x200 \
-Wl,--section-alignment,0x1000 \
-Wl,--stack,0x100000 \
-Wl,--gc-sections \
-Wl,--exclude-all-symbols \
-Wl,--entry,_CRT_DriverEntry \
$(PRINT_LDSCRIPT) \
-nostartfiles -nodefaultlibs -nostdlib
DRIVER_LIBS := -lntoskrnl -lhal
USER_LDFLAGS := -Wl,--dynamicbase -Wl,--nxcompat -Wl,--gc-sections
USER_LIBS :=
EASTL_BUILDDIR := EASTL-build
EASTL_STATIC_LIB := $(DPP_ROOT)/$(EASTL_BUILDDIR)/libEASTL.a
LIBCRT_BUILD_DIR := $(DPP_ROOT)/CRT-build
LIBCRT_OBJECTS := \
$(LIBCRT_BUILD_DIR)/kcrt$(NAME_SUFFIX).o \
$(LIBCRT_BUILD_DIR)/ntdll_zw_functions$(NAME_SUFFIX).o
LIBCXXRT_OBJECTS := \
$(LIBCRT_BUILD_DIR)/eastl_compat$(NAME_SUFFIX).opp \
$(LIBCRT_BUILD_DIR)/kcrt$(NAME_SUFFIX).opp \
$(LIBCRT_BUILD_DIR)/DriverThread$(NAME_SUFFIX).opp
LIBUSERCRT_OBJECTS := $(LIBCRT_BUILD_DIR)/ucrt$(NAME_SUFFIX).opp $(LIBCRT_BUILD_DIR)/eastl_compat$(NAME_SUFFIX).opp
LIBCRT_STATIC_LIB := $(LIBCRT_BUILD_DIR)/libcrt.a
LIBCXXRT_STATIC_LIB := $(LIBCRT_BUILD_DIR)/libcxxrt.a
LIBUSERCRT_STATIC_LIB := $(LIBCRT_BUILD_DIR)/libusercrt.a
is_set = \
$(if $1,, \
$(error ERROR: $(if $2,$2)))
path_exists = \
$(if $(realpath $1),, \
$(error ERROR: $1 does not exist, run `make -C $(DPP_ROOT) deps` first.))
define CHECK_REQUIRED_PATHS
$(call is_set,$(CC),Makefile argument CC missing)
$(call is_set,$(CXX),Makefile argument CXX missing)
$(call is_set,$(RC),Makefile argument RC missing)
$(call is_set,$(AR),Makefile argument AR missing)
$(call is_set,$(DDK_INCLUDE_DIR),Makefile argument DDK_INCLUDE_DIR missing)
$(call is_set,$(EASTL_STATIC_LIB),Makefile argument EASTL_STATIC_LIB missing)
$(call is_set,$(LIBCRT_STATIC_LIB),Makefile argument LIBCRT_STATIC_LIB missing)
$(call is_set,$(LIBCXXRT_STATIC_LIB),Makefile argument LIBCXXRT_STATIC_LIB missing)
$(call is_set,$(LIBUSERCRT_STATIC_LIB),Makefile argument LIBUSERCRT_STATIC_LIB missing)
$(call path_exists,$(CC))
$(call path_exists,$(CXX))
$(call path_exists,$(RC))
$(call path_exists,$(AR))
$(call path_exists,$(DDK_INCLUDE_DIR))
$(call path_exists,$(EASTL_STATIC_LIB))
$(call path_exists,$(LIBCRT_STATIC_LIB))
$(call path_exists,$(LIBCXXRT_STATIC_LIB))
$(call path_exists,$(LIBUSERCRT_STATIC_LIB))
endef
define BUILD_C_OBJECT
$(call CHECK_REQUIRED_PATHS)
$(call is_set,$(1),First argument: Source file missing)
$(call is_set,$(2),Second argument: Output object file missing)
$(Q)$(CC) -std=gnu99 $(CFLAGS) $(CUSTOM_CFLAGS) $(CFLAGS_$(2)) -c $(1) -o $(2)
@echo 'CC $(2)'
endef
define BUILD_CPP_OBJECT
$(call CHECK_REQUIRED_PATHS)
$(call is_set,$(1),First argument: Source file missing)
$(call is_set,$(2),Second argument: Output object file missing)
$(Q)$(CXX) $(CFLAGS) $(CUSTOM_CFLAGS) $(CFLAGS_$(2)) $(CXXFLAGS) $(EASTL_CXXFLAGS) $(CUSTOM_CXXFLAGS) -c $(1) -o $(2)
@echo 'CXX $@'
endef
define LINK_C_KERNEL_TARGET
$(call CHECK_REQUIRED_PATHS)
$(call is_set,$(1),First argument: Object files missing)
$(call is_set,$(2),Second argument: Output object file missing)
$(Q)$(CC) \
$(CFLAGS) \
$(DRIVER_LDFLAGS) \
-Wl,-Map='$(2).map' \
-o '$(2)' \
$(1) \
$(LIBCRT_STATIC_LIB) \
$(DRIVER_LIBS) \
$(LDFLAGS_$(2))
@echo 'LD $(2)'
endef
define LINK_C_USER_TARGET
$(call CHECK_REQUIRED_PATHS)
$(call is_set,$(1),First argument: Object files missing)
$(call is_set,$(2),Second argument: Output object file missing)
$(Q)$(CC) \
$(CFLAGS) \
-o '$(2)' \
$(1) \
$(EASTL_STATIC_LIB) \
$(LIBUSERCRT_STATIC_LIB) \
$(LDFLAGS_$(2))
@echo 'LD $(2)'
endef
define LINK_CPP_KERNEL_TARGET
$(call CHECK_REQUIRED_PATHS)
$(call is_set,$(1),First argument: Object files missing)
$(call is_set,$(2),Second argument: Output object file missing)
$(Q)$(CXX) \
$(CFLAGS) \
$(CXXFLAGS) \
$(EASTL_CXXFLAGS) \
$(DRIVER_LDFLAGS) \
-Wl,-Map='$(2).map' \
-o '$(2)' \
$(1) \
$(EASTL_STATIC_LIB) \
$(LIBCRT_STATIC_LIB) \
$(LIBCXXRT_STATIC_LIB) \
$(DRIVER_LIBS) \
$(LDFLAGS_$(2))
@echo 'LD $(2)'
endef
define LINK_CPP_USER_TARGET
$(call CHECK_REQUIRED_PATHS)
$(call is_set,$(1),First argument: Object files missing)
$(call is_set,$(2),Second argument: Output object file missing)
$(Q)$(CXX) \
$(CFLAGS) \
$(CXXFLAGS) \
$(EASTL_CXXFLAGS) \
$(USER_LDFLAGS) \
-o '$(2)' \
$(1) \
$(EASTL_STATIC_LIB) \
$(LIBUSERCRT_STATIC_LIB) \
$(USER_LIBS) \
$(LDFLAGS_$(2))
@echo 'LD $(2)'
endef
define INSTALL_EXEC
$(call is_set,$(1),First argument: Executables to install missing)
$(call is_set,$(DESTDIR),DESTDIR missing)
$(INSTALL) -d '$(DESTDIR)/'
for target in $(1); do \
$(INSTALL) -s --strip-program='$(dir $(CC))/x86_64-w64-mingw32-strip' "$$target" '$(DESTDIR)'; \
done
endef
define INSTALL_EXEC_SIGN
$(call is_set,$(1),First argument: Executables to install missing)
$(call is_set,$(DESTDIR),DESTDIR missing)
$(MAKE) -C '$(DPP_ROOT)' -f Makefile.deps $(SIGNTOOL_PREFIX)
$(INSTALL) -d '$(DESTDIR)/'
test -x '$(shell which $(SIGNTOOL))' || { \
printf '\n *** %s ***\n\n' "$(SIGNTOOL) does not exist / not in your PATH / not executable."; \
false; \
}
for target in $(1); do \
rm -f "$(DESTDIR)/$$target"; \
$(dir $(CC))/x86_64-w64-mingw32-strip -s "$$target"; \
$(SIGNTOOL) sign -pkcs12 '$(DPP_ROOT)/$(SIGNTOOL_PREFIX)-code.p12' \
-in "$$target" \
-out "$(DESTDIR)/$$target"; \
$(INSTALL) "$(DPP_ROOT)/sign-driver-on-windows.bat.in" "$(DESTDIR)/$$(basename $$target .sys)-sign-driver-on-windows.bat"; \
$(SED) -i -e "s/{{\s*DRIVER_NAME\s*}}/$$target/g" "$(DESTDIR)/$$(basename $$target .sys)-sign-driver-on-windows.bat"; \
done
$(INSTALL) "$(DPP_ROOT)/$(SIGNTOOL_PREFIX)-ca-cert.pem" '$(DESTDIR)/$(SIGNTOOL_PREFIX)-ca-cert.crt'
$(INSTALL) "$(DPP_ROOT)/create_codesign_ca.bat" '$(DESTDIR)/create-codesign-ca-on-windows.bat'
endef
define INSTALL_HEADERS
$(call is_set,$(1),First argument: Header subdirectory missing)
$(call is_set,$(2),Second argument: Header files missing)
$(call is_set,$(3),Third argument: Output directory missing)
for header in $(2); do \
mkdir -p '$(3)/include/$(1)/'; \
$(INSTALL) -m0644 "$$header" '$(3)/include/$(1)/'; \
done
endef
define PACKAGE
$(call is_set,$(1),First argument: Library name missing)
$(call is_set,$(2),Second argument: Object files missing)
$(call is_set,$(3),Third argument: Output directory missing)
mkdir -p '$(3)/lib'
$(AR) -rsv '$(3)/lib/lib$(1).a' $(2)
tar --no-acls --no-selinux --no-xattrs --transform 's,^$(3),deps,' -cvjf '$(1).dpp' '$(3)'
endef
define HELP_MAKE_OPTIONS
@echo 'Common make options for Makefile.inc:'
@echo -e '\tBUILD_NATIVE = no'
@echo -e '\tCC = $(CC)'
@echo -e '\tCXX = $(CXX)'
@echo -e '\tRC = $(RC)'
@echo -e '\tDDK_INCLUDE_DIR = $(DDK_INCLUDE_DIR)'
@echo -e '\tDPP_ROOT = $(DPP_ROOT)'
endef