-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMakefile.mingw
118 lines (96 loc) · 2.37 KB
/
Makefile.mingw
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
# -------------------------------
# Mandatory definitions
# -------------------------------
# ARCH=X86|x64
# CHAR=ANSI|Unicode
# OUTDIR=<output_directory>
# -------------------------------
# Optional definitions
# -------------------------------
# CUSTOM_CFLAGS
# CUSTOM_LDFLAGS
# CUSTOM_RCFLAGS
PROJECT = NSutils
BIN = $(PROJECT).dll
OBJ = pluginapi.o gdi.o main.o registry.o strblock.o utils.o handles.o verinfo.o NSutils.res
INC = -I.
LIB = -lkernel32 -luser32 -ladvapi32 -lgdi32 -lole32 -loleaut32 -luuid -lversion
_OBJ = $(patsubst %,$(OUTDIR)/%,$(OBJ))
_BIN = $(patsubst %,$(OUTDIR)/%,$(BIN))
DEF = $(OUTDIR)/lib$(PROJECT).def
STATIC = $(OUTDIR)/lib$(PROJECT).a
#
# https://gcc.gnu.org/onlinedocs/gcc/Option-Summary.html
# http://linux.die.net/man/1/gcc
# http://linux.die.net/man/1/ld
#
# ARCH
ifeq ($(ARCH), X64)
CFLAGS += -DNDEBUG
LDFLAGS += -m64 -Wl,--high-entropy-va -Wl,-e'DllMain'
RCFLAGS += -F pe-x86-64
else
CFLAGS += -march=pentium2 -DNDEBUG
LDFLAGS += -Wl,-e'_DllMain'
RCFLAGS += -F pe-i386
endif
# CHAR
ifeq ($(CHAR), ANSI)
CFLAGS += -DMBCS -D_MBCS
LDFLAGS +=
else
CFLAGS += -municode -DUNICODE -D_UNICODE
LDFLAGS +=
endif
# https://sourceforge.net/p/mingw-w64/wiki2/gnu%20printf/
CFLAGS += -D__USE_MINGW_ANSI_STDIO=0
CFLAGS += \
-mdll \
-s \
-Os \
-fPIE \
-ffunction-sections \
-fdata-sections \
-fno-unwind-tables \
-fno-asynchronous-unwind-tables \
-Wall \
-Wno-unused-function \
$(INC) \
$(CUSTOM_CFLAGS)
LDFLAGS += \
$(CFLAGS) \
-static-libgcc \
-Wl,--gc-sections \
-Wl,--no-seh \
-Wl,--nxcompat \
-Wl,--dynamicbase \
-Wl,--enable-auto-image-base \
-Wl,--enable-stdcall-fixup \
-Wl,--output-def,$(DEF) \
-Wl,--out-implib,$(STATIC) \
$(LIB) \
$(CUSTOM_LDFLAGS)
RCFLAGS += \
$(CUSTOM_RCFLAGS)
.PHONY: clean all-before nsis-sdk all all-after
clean:
@echo.
if exist $(OUTDIR) rd /S /Q $(OUTDIR)
all: all-before nsis-sdk $(_BIN) all-after
all-before:
if not exist $(OUTDIR) mkdir $(OUTDIR)
nsis-sdk:
REM ----- NSIS SDK ------------------------------------------------------------
call py -3 _get_nsis_sdk.py
# Link
$(_BIN): $(_OBJ)
@echo.
gcc $(_OBJ) -o $(_BIN) $(LDFLAGS)
# Compile .c
$(OUTDIR)/%.o: %.c
gcc $(CFLAGS) -o $@ -c $<
$(OUTDIR)/%.o: nsis/pluginapi.c
gcc $(CFLAGS) -o $@ -c $<
# Compile .rc
$(OUTDIR)/%.res: %.rc
windres -o $@ -i $< -O coff --input-format=rc $(RCFLAGS)