-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Makefile.windows
268 lines (238 loc) · 9.4 KB
/
Makefile.windows
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
# Generic makefile for Windows build
#
# For "API" documentation check Makefile.generic
#
# Variables supposed to be in component's Makefile.builder:
# WIN_COMPILER - "WDK", "mingw", "msbuild" (default) or "custom"
# WIN_BUILD_CMD - build command for "custom" WIN_COMPILER
# WIN_SLN_DIR - directory with *.sln file for msbuild (default "vs2013")
# WIN_SLN_NAME - *.sln file for msbuild (default "$(COMPONENT).sln")
# WIN_SOURCE_SUBDIRS - list of directories to process
# WIN_PREBUILD_CMD - commands to run before build process
# WIN_POSTBUILD_CMD - commands to run after build process
# (after WIN_PACKAGE_CMD)
# WIN_SIGN_CMD - command to sign executables
# the default script signs all dll, exe, msi, sys and cat files
# WIN_PACKAGE_CMD - command to generate .msm/msi files
# the default script builds all .wxs files with Wix,
# and .wxb files as Wix bundles (producing .exe)
# WIN_PACKAGE_EXT - desired extension of the installer output
# "msi" (final installer package) or "msm" (merge module, default)
# WIN_OUTPUT_LIBS - directory with output libraries (both *.lib and *.dll),
# relative to $(PACKAGE)
# WIN_OUTPUT_HEADERS - directory with includes for $(WIN_OUTPUT_LIBS),
# relative to $(PACKAGE)
# WIN_BUILD_DEPS - components needed to compile/link this one, headers will be
# available in $(QUBES_INCLUDES), libraries in $(QUBES_LIBS)
#
# For dummy *_CMD use "true"
#
PATHCONV := $(WINDOWS_PLUGIN_DIR)/scripts/convert-path.sh
WINDOWS_SCRIPTS := $(shell $(PATHCONV) $(WINDOWS_PLUGIN_DIR))/scripts
### Variables required Makefile.generic
# Use directory list as PACKAGE_LIST
PACKAGE_LIST = $(WIN_SOURCE_SUBDIRS)
DIST_BUILD_DIR = .
### Settings: defaults, to be overriden by Makefile.builder
WIN_COMPILER ?= msbuild
WIN_SIGN_CMD ?= call $(WINDOWS_SCRIPTS)/sign.bat
WIN_PACKAGE_CMD ?= call $(WINDOWS_SCRIPTS)/wix.bat $(WIN_PACKAGE_EXT)
WIN_PREBUILD_CMD ?= true
WIN_POSTBUILD_CMD ?= true
WIN_PACKAGE_EXT ?= msm
### Settings: defaults, to be overriden by builder.conf
DDK_PATH ?= C:\\WinDDK\\7600.16385.1
WDK8_PATH ?= c:\Program Files (x86)\Windows Kits\8.1
WDK10_PATH ?= c:\Program Files (x86)\Windows Kits\10
VS_PATH ?= c:\\Program\ Files\ \(x86\)\\Microsoft\ Visual\ Studio\ 12.0
# Build type: fre (release), chk (debug)
WIN_BUILD_TYPE ?= fre
WIN_CERT_FILENAME ?=
WIN_CERT_PASSWORD ?=
# MS Cross Signing Certificate .cer (if you have a proper authenticode cert)
WIN_CERT_CROSS_CERT_FILENAME ?=
# public certificate .cer (if you _don't_ have a proper authenticode cert)
WIN_CERT_PUBLIC_FILENAME ?=
### Local variables
# Build environment
ifneq (,$(findstring x64,$(DIST)))
DDK_ARCH = x64
DIST_TMP = $(subst x64,,$(DIST))
else ifneq (,$(findstring x86,$(DIST)))
DDK_ARCH = x86
DIST_TMP = $(subst x86,,$(DIST))
else
$(error unsupported architecture: $(DIST))
endif
ifeq ($(DIST_TMP),win7)
DDK_DIST = WIN7
else ifeq ($(DIST_TMP),winVista)
DDK_DIST = WLH
else ifeq ($(DIST_TMP),win2k)
DDK_DIST = W2K
$(error Windows 2000 not supported)
else ifeq ($(DIST_TMP),winXP)
DDK_DIST = WXP
else
$(error $(DIST_TMP) not supported)
endif
# Code signing certificate
ifneq (,$(WIN_CERT_FILENAME))
CERT_FILENAME = $(abspath $(WIN_CERT_FILENAME))
export CERT_FILENAME
endif
CERT_PASSWORD = $(WIN_CERT_PASSWORD)
export CERT_PASSWORD
CERT_PASSWORD_FLAG = -p "$(CERT_PASSWORD)"
ifneq (,$(WIN_CERT_CROSS_CERT_FILENAME))
CERT_CROSS_CERT_FILENAME = $(abspath $(WIN_CERT_CROSS_CERT_FILENAME))
export CERT_CROSS_CERT_FILENAME
endif
ifneq (,$(WIN_CERT_PUBLIC_FILENAME))
CERT_PUBLIC_FILENAME = $(abspath $(WIN_CERT_PUBLIC_FILENAME))
export CERT_PUBLIC_FILENAME
endif
# Misc variables
ifeq ($(WIN_COMPILER),WDK)
SETENV_ARGS = $(DDK_PATH) $(WIN_BUILD_TYPE) $(DDK_ARCH) $(DDK_DIST)
SETENV_CMD = $(DDK_PATH)\\bin\\setenv.bat $(SETENV_ARGS)
PREBUILD_ACTUAL_CMD := set MAKEFLAGS=
PREBUILD_ACTUAL_CMD += && pushd . && $(WIN_PREBUILD_CMD) && popd
PREBUILD_ACTUAL_CMD += && pushd . && $(SETENV_CMD) && popd
else ifeq ($(WIN_COMPILER),custom)
PREBUILD_ACTUAL_CMD := set MAKEFLAGS=
PREBUILD_ACTUAL_CMD += && pushd . && $(WIN_PREBUILD_CMD) && popd
else ifeq ($(WIN_COMPILER),msbuild)
WIN_SLN_DIR ?= vs2013
WIN_SLN_NAME ?= "$(COMPONENT).sln"
ifeq ($(DDK_ARCH),x64)
MSBUILD_ARCH = x64
else
MSBUILD_ARCH = Win32
endif
ifeq ($(WIN_BUILD_TYPE),fre)
MSBUILD_CONFIG = Release
else
MSBUILD_CONFIG = Debug
endif
SETENV_CMD = "$(VS_PATH)\\VC\\Auxiliary\\Build\\vcvarsall.bat" x86
PREBUILD_ACTUAL_CMD := set MAKEFLAGS=
PREBUILD_ACTUAL_CMD += && pushd . && $(WIN_PREBUILD_CMD) && popd
PREBUILD_ACTUAL_CMD += && pushd . && $(SETENV_CMD) && popd
else
PREBUILD_ACTUAL_CMD := set MAKEFLAGS=
PREBUILD_ACTUAL_CMD += && $(WIN_PREBUILD_CMD)
endif
# Set this way to have them converted to windows paths by msys
QUBES_INCLUDES = $(shell mkdir -p $(CHROOT_DIR)/build-deps/include && cd $(CHROOT_DIR)/build-deps/include && pwd -W)
QUBES_LIBS = $(shell mkdir -p $(CHROOT_DIR)/build-deps/libs && cd $(CHROOT_DIR)/build-deps/libs && pwd -W)
# Workaround for msys path conversion
TMP := $(shell cd $(TMP) && pwd -W | sed 's:/:\\\\:g')
TEMP := $(TMP)
SIGNTOOL := "$(shell find "$(WDK10_PATH)" "$(WDK8_PATH)" "$(DDK_PATH)" -path "*/$(DDK_ARCH)/signtool.exe" 2>/dev/null |head -1)"
MAKECERT := "$(shell find "$(WDK10_PATH)" "$(WDK8_PATH)" "$(DDK_PATH)" -path "*/$(DDK_ARCH)/makecert.exe" 2>/dev/null |head -1)"
### Targets required by Makefile.generic to build packages
dist-prepare-chroot: $(CHROOT_DIR)/.be-prepared
@mkdir -p $(CHROOT_DIR)
# script that prepares windows BE creates a file containing important variables:
# mingw base path, python2 path, modified search PATH containing mingw/msys/other dependencies, Wix toolset path and python3 executable path
$(eval BE_MARKER := $(CHROOT_DIR)/.be-prepared)
$(eval MINGW_DIR := $(shell sed -n '1p' $(BE_MARKER)))
$(eval PYTHON_DIR := $(shell sed -n '2p' $(BE_MARKER)))
$(eval WIN_PATH := $(shell sed -n '3p' $(BE_MARKER)))
$(eval WIX := $(shell sed -n '4p' $(BE_MARKER)))
$(eval PYTHON3 := $(shell sed -n '5p' $(BE_MARKER)))
ifneq ($(CERT_FILENAME),)
@if [ ! -r "$(CERT_FILENAME)" ]; then \
$(MAKECERT) -r -pe -ss PrivateCertStore -a sha256 -n "CN=Qubes Test Cert" "$(CERT_PUBLIC_FILENAME)"; \
certutil -exportpfx -user -privatekey $(CERT_PASSWORD_FLAG) PrivateCertStore "Qubes Test Cert" "$(CERT_FILENAME)"; \
fi
endif
$(CHROOT_DIR)/.be-prepared:
# Prepare windows BE
@export VERBOSE=$(VERBOSE); powershell -executionpolicy bypass $(WINDOWS_PLUGIN_DIR)/scripts/prepare-be.ps1
ifeq ($(WIN_COMPILER),WDK)
dist-prep:
# Running OACR will prevent removing old sources
@cmd //C "$(SETENV_CMD) && oacr stop"
else
dist-prep:
@true
endif
dist-build-dep:
@rm -rf $(CHROOT_DIR)/build-deps/libs
@rm -rf $(CHROOT_DIR)/build-deps/include
@mkdir -p $(CHROOT_DIR)/build-deps/libs
@mkdir -p $(CHROOT_DIR)/build-deps/include
@for dep in $(WIN_BUILD_DEPS); do \
if [ -d $(BUILDER_REPO_DIR)/$$dep/libs ]; then \
cp -t $(CHROOT_DIR)/build-deps/libs $(BUILDER_REPO_DIR)/$$dep/libs/*; \
fi; \
if [ -d $(BUILDER_REPO_DIR)/$$dep/include ]; then \
cp -t $(CHROOT_DIR)/build-deps/include $(BUILDER_REPO_DIR)/$$dep/include/*; \
fi; \
done
dist-package: SCRIPT_TMP=$(TEMP)/build-$(COMPONENT).bat
dist-package:
ifndef PACKAGE
$(error "PACKAGE need to be set!")
endif
@rm -f $(CHROOT_DIR)/$(DIST_SRC)/$(PACKAGE)/*.msi
ifneq (,$(WIN_CERT_FILENAME))
@echo > $(CHROOT_DIR)/$(DIST_SRC)/$(PACKAGE)/sign_config.bat
else
@rm -f $(CHROOT_DIR)/$(DIST_SRC)/$(PACKAGE)/sign_config.bat
endif
ifeq ($(WIN_COMPILER),WDK)
@cd $(CHROOT_DIR)/$(DIST_SRC)/$(PACKAGE) && \
cmd //C '$(PREBUILD_ACTUAL_CMD) && \
build -cZg && \
$(WIN_SIGN_CMD) && \
$(WIN_PACKAGE_CMD) && \
$(WIN_POSTBUILD_CMD)'
else ifeq ($(WIN_COMPILER),msbuild)
printf %s '$(PREBUILD_ACTUAL_CMD) && ' >$(SCRIPT_TMP)
printf %s 'cd $(WIN_SLN_DIR) && ' >>$(SCRIPT_TMP)
printf %s 'msbuild.exe /m:1 /p:Configuration="$(MSBUILD_CONFIG)" /p:Platform="$(MSBUILD_ARCH)" /t:"Build" $(WIN_SLN_NAME) && ' >>$(SCRIPT_TMP)
printf %s 'cd .. && ' >>$(SCRIPT_TMP)
printf %s '$(WIN_SIGN_CMD) && ' >>$(SCRIPT_TMP)
printf %s '$(WIN_PACKAGE_CMD) && ' >>$(SCRIPT_TMP)
printf %s '$(WIN_POSTBUILD_CMD)' >> $(SCRIPT_TMP)
cd $(CHROOT_DIR)/$(DIST_SRC)/$(PACKAGE) && $(SCRIPT_TMP)
else ifeq ($(WIN_COMPILER),custom)
@cd $(CHROOT_DIR)/$(DIST_SRC)/$(PACKAGE) && \
cmd //C "$(PREBUILD_ACTUAL_CMD) && \
$(WIN_BUILD_CMD) && \
$(WIN_SIGN_CMD) && \
$(WIN_PACKAGE_CMD) && \
$(WIN_POSTBUILD_CMD)"
else
@cd $(CHROOT_DIR)/$(DIST_SRC)/$(PACKAGE) && $(PREBUILD_ACTUAL_CMD)
@cd $(CHROOT_DIR)/$(DIST_SRC)/$(PACKAGE) && PATH="$(WIN_PATH)" make all
@cd $(CHROOT_DIR)/$(DIST_SRC)/$(PACKAGE) && PATH="$(WIN_PATH)" $(WIN_PACKAGE_CMD)
endif
dist-copy-out:
@echo "--> Done:" >&3
@rm -rf "$(BUILDER_REPO_DIR)/$(COMPONENT)"
ifneq ($(WIN_PACKAGE_CMD),true)
@shopt -s nullglob;\
for pkg in $(CHROOT_DIR)/$(DIST_SRC)/$(PACKAGE)/*.ms[im] $(CHROOT_DIR)/$(DIST_SRC)/$(PACKAGE)/*.exe; do\
echo " `basename $$pkg`" >&3 ;\
mv -t $(ORIG_SRC)/$(PACKAGE) $$pkg;\
done
endif
ifneq (,$(WIN_OUTPUT_LIBS))
@mkdir -p $(BUILDER_REPO_DIR)/$(COMPONENT)/libs
@for file in $(CHROOT_DIR)/$(DIST_SRC)/$(PACKAGE)/$(WIN_OUTPUT_LIBS)/*/*; do\
echo " libs/`basename $$file`" >&3 ;\
mv -t $(BUILDER_REPO_DIR)/$(COMPONENT)/libs/ $$file || exit 1;\
done
endif
ifneq (,$(WIN_OUTPUT_HEADERS))
@mkdir -p $(BUILDER_REPO_DIR)/$(COMPONENT)/include
@for file in $(CHROOT_DIR)/$(DIST_SRC)/$(PACKAGE)/$(WIN_OUTPUT_HEADERS)/*.h; do\
echo " include/`basename $$file`" >&3 ;\
mv -t $(BUILDER_REPO_DIR)/$(COMPONENT)/include/ $$file || exit 1;\
done
endif
### Additional targets