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
|
ifndef DPP_ROOT
$(error DPP_ROOT is undefined)
endif
Q = @
ifeq ($(Q),)
CMAKE_Q = VERBOSE=1
endif
DPP_ROOT ?= .
LOCAL_MINGW64_BUILD_SCRIPT := $(DPP_ROOT)/mingw-w64-build/mingw-w64-build
LOCAL_MINGW64_BUILD_DIR := $(DPP_ROOT)/x86_64-w64-mingw32
LOCAL_MINGW64_CC := $(LOCAL_MINGW64_BUILD_DIR)/bin/x86_64-w64-mingw32-gcc
SIGNTOOL := osslsigncode
SIGNTOOL_PREFIX := codesign
INSTALL = install
CMAKE = cmake
CC = $(LOCAL_MINGW64_CC)
CXX = $(dir $(CC))x86_64-w64-mingw32-g++
DDK_INCLUDE_DIR = $(dir $(CC))../x86_64-w64-mingw32/include/ddk
CFLAGS := -Wall -Wextra -m64 -fPIC \
-ffunction-sections -fdata-sections \
-I$(DPP_ROOT) -I$(DDK_INCLUDE_DIR) \
-D__INTRINSIC_DEFINED_InterlockedBitTestAndSet \
-D__INTRINSIC_DEFINED_InterlockedBitTestAndReset
CXXFLAGS := -fno-exceptions -fno-rtti
EASTL_CXXFLAGS := -I$(DPP_ROOT)/EASTL/include -I$(DPP_ROOT)/EASTL/test/packages/EABase/include/Common \
-DEASTL_THREAD_SUPPORT_AVAILABLE=0 \
-DEASTL_EXCEPTIONS_ENABLED=0 \
-DEASTL_ASSERT_ENABLED=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,--entry,DriverEntry \
-Wl,--gc-sections \
-nostartfiles -nostdlib
DRIVER_LIBS := -lntoskrnl -lhal
USER_LDFLAGS := -Wl,--dynamicbase -Wl,--nxcompat \
-Wl,--gc-sections
DRIVER_ADDITIONAL_DEPS := $(DPP_ROOT)/DriverThread.cpp $(DPP_ROOT)/DriverThread.hpp
DRIVER_ADDITIONAL_OBJS := $(DPP_ROOT)/DriverThread.opp
EASTL_DEPS := $(wildcard $(DPP_ROOT)/EASTL/source/*.cpp) $(wildcard $(DPP_ROOT)/EASTL/include/EASTL/*.h)
EASTL_STATIC_LIB := $(DPP_ROOT)/EASTL-build/libEASTL.a
DRIVER_EASTL_COMPAT_DEPS := $(DPP_ROOT)/EASTL-compat/kcrt.cpp
DRIVER_EASTL_COMPAT := $(DPP_ROOT)/EASTL-compat/kcrt.opp
USER_EASTL_COMPAT_DEPS := $(DPP_ROOT)/EASTL-compat/ucrt.cpp
USER_EASTL_COMPAT := $(DPP_ROOT)/EASTL-compat/ucrt.opp
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 path_exists,$(CC))
$(call path_exists,$(CXX))
$(call path_exists,$(DDK_INCLUDE_DIR))
$(call path_exists,$(DRIVER_ADDITIONAL_OBJS))
$(call path_exists,$(EASTL_STATIC_LIB))
$(call path_exists,$(DRIVER_EASTL_COMPAT))
$(call path_exists,$(USER_EASTL_COMPAT))
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=c99 $(CFLAGS) -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) $(CXXFLAGS) $(EASTL_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) \
-o '$(2)' \
$(1) \
$(DRIVER_LIBS)
@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) \
@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) \
-o '$(2)' \
$(1) \
$(DRIVER_ADDITIONAL_OBJS) \
$(DRIVER_EASTL_COMPAT) \
$(EASTL_STATIC_LIB) \
$(DRIVER_LIBS)
@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) \
$(USER_EASTL_COMPAT) \
$(EASTL_STATIC_LIB)
@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' \
-ac '$(DPP_ROOT)/$(SIGNTOOL_PREFIX)-ca-cert.pem' \
-in "$$target" \
-out "$(DESTDIR)/$$target"; \
done
$(INSTALL) "$(DPP_ROOT)/$(SIGNTOOL_PREFIX)-ca-cert.pem" '$(DESTDIR)/$(SIGNTOOL_PREFIX)-ca-cert.crt'
endef
define CHECK_DPP
$(MAKE) -C $(DPP_ROOT) -f Makefile.deps all
endef
|