-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile.windows
112 lines (94 loc) · 3.12 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
#
# ksm - a really simple and fast x64 hypervisor
# Copyright (C) 2016, 2017 Ahmed Samy <[email protected]>
#
# Makefile for MinGW and others.
# To cross-compile, pass C=1:
# make C=1
# to compile under native MinGW:
# mingw32-make
#
# This program is free software; you can redistribute it and/or modify it
# under the terms and conditions of the GNU General Public License,
# version 2, as published by the Free Software Foundation.
#
# This program is distributed in the hope it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along with
# this program; If not, see <http://www.gnu.org/licenses/>.
# See if we are cross compiling.
ifeq ("$(origin C)", "command line")
CROSS_BUILD ?= x86_64-w64-mingw32-
CROSS_INC ?= /usr/x86_64-w64-mingw32/include/ddk
CROSS_LIB ?= /usr/x86_64-w64-mingw32/lib
endif
PREPEND.1 := @
PREPEND := $(PREPEND.$(Q))
CC = $(CROSS_BUILD)gcc
STRIP = $(CROSS_BUILD)strip
OBJCOPY = $(CROSS_BUILD)objcopy --only-keep-debug
# Windows versions:
# 0x0601 = Windows 7
# 0x0602 = Windows 8
# 0x0603 = Windows 8.1
# 0x0A00 = Windows 10
WINVER ?= 0x0A00
DEPFLAGS = -MT $@ -MMD -MP -MF $(DEP_DIR)/$*.d
DBGFLAGS = -DDBG -O2
CFLAGS = -I$(CROSS_INC) $(DBGFLAGS) -D_WIN32_WINNT=$(WINVER) -DENABLE_DBGPRINT \
-std=c99 -Wno-multichar -municode -fno-stack-protector -fms-extensions -fno-stack-check \
-mno-stack-arg-probe -fno-asynchronous-unwind-tables -pipe
AFLAGS = $(CFLAGS) -D__ASSEMBLY__
LDFLAGS = -shared -Wl,--subsystem,native -Wl,--dynamicbase -Wl,--stack=0x6000 \
-Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 \
-Wl,--entry,DriverEntry -Wl,--nxcompat -Wl,--exclude-all-symbols \
-Wl,--enable-stdcall-fixup -nostartfiles -nostdlib
LIBS = -L$(CROSS_LIB) -lntoskrnl -lhal -lmingwex
UM_SRC = um/um.c
UM_BIN = a.out
UM_LIB = -lntdll
SRC = exit.c hotplug.c introspect.c ksm.c sandbox.c mm.c \
main_nt.c epage.c print.c resubv.c vcpu.c
ASM = vmx.S
BIN_DIR ?= bin
OBJ_DIR ?= obj
DEP_DIR ?= dep
DEP = $(SRC:%.c=$(DEP_DIR)/%.d)
OBJ = $(SRC:%.c=$(OBJ_DIR)/%.o)
OBJ += $(ASM:%.S=$(OBJ_DIR)/%.o)
TARGET = $(BIN_DIR)/ksm.sys
SYMBOL = $(BIN_DIR)/ksm.sym
.PHONY: all clean umk dri
.PRECIOUS: $(DEP_DIR)/%.d
all: $(TARGET) $(UM_BIN)
clean:
$(RM) $(UM_BIN) $(TARGET) $(SYMBOL) $(OBJ) $(DEP)
umk: $(UM_BIN)
dri: $(TARGET)
$(TARGET): $(BIN_DIR) $(DEP_DIR) $(OBJ_DIR) $(OBJ) $(DEP)
$(PREPEND)$(CC) $(LDFLAGS) -o $@ $(OBJ) $(LIBS)
$(PREPEND)$(OBJCOPY) $@ $(SYMBOL)
$(PREPEND)$(STRIP) $@
@echo " LD $@"
@echo " All done, install pefile then"
@echo " Run make_nonpageable.py on $@"
$(UM_BIN):
$(PREPEND)$(CC) $(UM_SRC) -o $(UM_BIN) $(UM_LIB)
@echo " LD $@"
$(OBJ_DIR)/%.o: %.c $(DEP_DIR)/%.d
$(PREPEND)$(CC) -c $(CFLAGS) $(DEPFLAGS) -o $@ $<
@echo " CC $@"
$(OBJ_DIR)/%.o: %.S $(DEP_DIR)/%.d
$(PREPEND)$(CC) -c $(AFLAGS) $(DEPFLAGS) -o $@ $<
@echo " AS $@"
-include $(DEP)
$(DEP_DIR)/%.d: ;
$(DEP_DIR):
@mkdir -p $(DEP_DIR)
$(OBJ_DIR):
@mkdir -p $(OBJ_DIR)
$(BIN_DIR):
@mkdir -p $(BIN_DIR)