forked from negrutiu/nsis-nscurl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile.mingw
112 lines (91 loc) · 2.39 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
# -------------------------------
# Mandatory definitions
# -------------------------------
# ARCH=X86|x64
# CHAR=ANSI|Unicode
# OUTDIR=<output_directory>
# -------------------------------
# Optional definitions
# -------------------------------
# CUSTOM_CFLAGS
# CUSTOM_LDFLAGS
# CUSTOM_RCFLAGS
PROJECT = NScurl
BIN = $(PROJECT).dll
OBJ = pluginapi.o main.o utils.o crypto.o curl.o queue.o gui.o resource.res
INC = -I. -Ilibcurl-devel/include -Ilibcurl-devel/include/openssl
LIB = -lcurl -lssl -lcrypto -lnghttp2_static -lzlibstatic -ladvapi32 -lkernel32 -luser32 -lversion -lws2_32 -lcrypt32 -lmsvcrt -lgcc
_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 -Llibcurl-devel/mingw-curl_openssl-Release-x64-Legacy/lib
LDFLAGS += -Wl,-e'DllMain' -Wl,--high-entropy-va
RCFLAGS += -F pe-x86-64
else
CFLAGS += -DNDEBUG -Llibcurl-devel/mingw-curl_openssl-Release-Win32-Legacy/lib -march=pentium2
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 \
$(INC) \
$(CUSTOM_CFLAGS)
LDFLAGS += \
$(CFLAGS) \
-static \
-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 all all-after
clean:
@echo.
if exist $(OUTDIR) rd /S /Q $(OUTDIR)
all: all-before $(_BIN) all-after
all-before:
if not exist $(OUTDIR) mkdir $(OUTDIR)
# 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)