-
Notifications
You must be signed in to change notification settings - Fork 30
/
makefile
147 lines (120 loc) · 4.23 KB
/
makefile
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
.PHONY: \
all \
build \
clean \
environment \
environment_clean \
environment_mkdir \
linux_loader \
linux_loader_clean \
windows_loader \
windows_loader_clean \
uefi_loader \
uefi_loader_clean \
hypervisor \
hypervisor_clean \
detect_visual_studio_root \
detect_windows_kits_root \
detect_windows_kits_version
all: build
mode ?= debug
CONFIGURATION ?= $(mode)
MAKEFILE_DIRECTORY := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
include environment.config
TARGET_TYPE := $(SELECTED_ARCHITECTURE)
ifeq ($(OS), Windows_NT)
C_DIRECTORY := C:
else
C_DIRECTORY := /mnt/c
endif
DETECT_ENVIRONMENTS :=
DETECTED_VISUAL_STUDIO_ROOT :=
DETECTED_WINDOWS_KITS_ROOT :=
DETECTED_WINDOWS_KITS_VERSION :=
ifneq ($(filter $(BUILD_DRIVERS), windows uefi), )
ifeq ($(VISUAL_STUDIO_ROOT), )
DETECT_ENVIRONMENTS += detect_visual_studio_root
DETECTED_VISUAL_STUDIO_ROOT := $(shell \
find "$(C_DIRECTORY)/Program Files (x86)/Microsoft Visual Studio" \
-name cstddef | sort | tail -n 1 | \
xargs -d '\n' dirname | xargs -d '\n' dirname \
)
endif
ifeq ($(WINDOWS_KITS_ROOT), )
DETECT_ENVIRONMENTS += detect_windows_kits_root
MAJOR_WINDOWS_KITS_VERSION := $(shell \
find "$(C_DIRECTORY)/Program Files (x86)/Windows Kits" \
-maxdepth 1 | awk -F / '{print $$NF}' | grep -o '[0-9\.]*' | \
sort -n | tail -n 1 \
)
DETECTED_WINDOWS_KITS_ROOT := \
$(C_DIRECTORY)/Program Files (x86)/Windows Kits/$(MAJOR_WINDOWS_KITS_VERSION)
endif
ifeq ($(WINDOWS_KITS_VERSION), )
DETECT_ENVIRONMENTS += detect_windows_kits_version
DETECTED_WINDOWS_KITS_VERSION := $(shell \
find "$(C_DIRECTORY)/Program Files (x86)/Windows Kits" \
-name wdm.h | xargs -d '\n' dirname | xargs -d '\n' dirname | \
awk -F / '{print $$NF}' | grep -o '[0-9\.]*' | sort -n | tail -n 1 \
)
endif
endif
build: $(patsubst %, %_loader, $(BUILD_DRIVERS)) hypervisor environment
clean: linux_loader_clean windows_loader_clean uefi_loader_clean hypervisor_clean environment_clean
linux_loader: | hypervisor
@echo "Building linux loader..." && \
$(MAKE) LINUX_KERNEL=$(LINUX_KERNEL) CONFIGURATION=$(CONFIGURATION) TARGET_TYPE=$(TARGET_TYPE) -s -C linux_loader && \
echo "Built linux loader."
linux_loader_clean:
@echo "Cleaning linux loader..." && \
$(MAKE) LINUX_KERNEL=$(LINUX_KERNEL) CONFIGURATION=$(CONFIGURATION) TARGET_TYPE=$(TARGET_TYPE) -s -C linux_loader clean && \
rm -rf out && \
echo "Cleaned linux loader."
windows_loader: | hypervisor
@$(MAKE) -s -C windows_loader
windows_loader_clean:
@$(MAKE) -s -C windows_loader clean
uefi_loader: | hypervisor
@$(MAKE) -s -C uefi_loader
uefi_loader_clean:
@$(MAKE) -s -C uefi_loader clean
hypervisor: | environment.config environment
@$(MAKE) -s -C hypervisor
hypervisor_clean:
@$(MAKE) -s -C hypervisor clean
environment_mkdir:
@mkdir -p environment
environment: $(DETECT_ENVIRONMENTS) \
$(patsubst environment_templates/%, environment/%, $(shell find "environment_templates" -type f))
environment/%: environment_templates/% environment.config | environment_mkdir
@rm -f $@ && \
echo "Building $@..." && \
cp $< environment && \
sed -i 's@{{project_root}}@$(MAKEFILE_DIRECTORY)@g' $@ && \
sed -i 's/{{ssh_target}}/$(SSH_TARGET)/g' $@ && \
sed -i 's/{{ssh_port}}/$(SSH_PORT)/g' $@ && \
sed -i 's/{{ssh_password}}/$(SSH_PASSWORD)/g' $@ && \
sed -i 's/{{gdb_server_address}}/$(GDB_SERVER_ADDRESS)/g' $@ && \
sed -i 's/{{selected_architecture}}/$(SELECTED_ARCHITECTURE)/g' $@ && \
echo "Built $@."
environment_clean:
@rm -rf environment
ifneq ($(DETECTED_VISUAL_STUDIO_ROOT), )
detect_visual_studio_root:
@echo "Detected Visual Studio Root: '$(DETECTED_VISUAL_STUDIO_ROOT)'." && \
echo VISUAL_STUDIO_ROOT := "\"$(DETECTED_VISUAL_STUDIO_ROOT)\"" >> environment.config
else
detect_visual_studio_root:
endif
ifneq ($(DETECTED_WINDOWS_KITS_ROOT), )
detect_windows_kits_root:
@echo "Detected Windows Kits Root: '$(DETECTED_WINDOWS_KITS_ROOT)'." && \
echo WINDOWS_KITS_ROOT := "\"$(DETECTED_WINDOWS_KITS_ROOT)\"" >> environment.config
else
detect_windows_kits_root:
endif
ifneq ($(DETECTED_WINDOWS_KITS_VERSION), )
detect_windows_kits_version:
@echo "Detected Windows Kits version: '$(DETECTED_WINDOWS_KITS_VERSION)'." && \
echo WINDOWS_KITS_VERSION := "$(DETECTED_WINDOWS_KITS_VERSION)" >> environment.config
endif