| 1 |
## mingw/mingw64 Makefile |
| 2 |
# by Michal Trojnara 1998-2026 |
| 3 |
|
| 4 |
# 32-bit Windows |
| 5 |
#win32_arch=win32 |
| 6 |
#win32_targetcpu=i686 |
| 7 |
#win32_mingw=mingw |
| 8 |
|
| 9 |
# 64-bit Windows |
| 10 |
#win32_arch=win64 |
| 11 |
#win32_targetcpu=x86_64 |
| 12 |
#win32_mingw=mingw64 |
| 13 |
|
| 14 |
# Uncomment to enable mimalloc |
| 15 |
#win32_mimalloc_dir := /opt/mimalloc-$(win32_mingw) |
| 16 |
|
| 17 |
bindir = ../bin/$(win32_arch) |
| 18 |
objdir = ../obj/$(win32_arch) |
| 19 |
|
| 20 |
ifeq ($(win32_ssl_dir),) |
| 21 |
win32_ssl_dir := /opt/openssl-$(win32_mingw) |
| 22 |
endif |
| 23 |
win32_cppflags = -I$(win32_ssl_dir)/include |
| 24 |
ifneq ($(win32_mimalloc_dir),) |
| 25 |
win32_cppflags += -I$(win32_mimalloc_dir)/include/mimalloc-2.1 |
| 26 |
endif |
| 27 |
win32_cflags = -g -mthreads -O2 |
| 28 |
win32_cflags += -Wall -Wextra -Wpedantic -Wconversion -std=c99 |
| 29 |
win32_cflags += -DUNICODE -D_UNICODE |
| 30 |
ifneq ($(win32_mimalloc_dir),) |
| 31 |
win32_cflags += -DHAVE_MIMALLOC_H |
| 32 |
endif |
| 33 |
win32_cflags += -fstack-protector-strong -fcf-protection=full -D_FORTIFY_SOURCE=2 |
| 34 |
win32_ldflags = -g -mthreads -pipe |
| 35 |
ifeq ($(win32_arch),win64) |
| 36 |
win32_ldflags += -Wl,--high-entropy-va |
| 37 |
else |
| 38 |
win32_ldflags += -Wl,--large-address-aware |
| 39 |
endif |
| 40 |
win32_ldflags += -Wl,--dynamicbase,--nxcompat,--no-seh,--tsaware,--no-insert-timestamp |
| 41 |
|
| 42 |
# -fstack-protector was broken in x86_64-w64-mingw32-gcc 8.2.0 |
| 43 |
|
| 44 |
# compiling with -D_FORTIFY_SOURCE=2 may require linking with -lssp |
| 45 |
win32_common_libs = -lws2_32 -lkernel32 -lssp |
| 46 |
ifneq ($(win32_mimalloc_dir),) |
| 47 |
win32_common_libs += -L$(win32_mimalloc_dir)/bin -lmimalloc |
| 48 |
endif |
| 49 |
ifneq (,$(wildcard $(win32_ssl_dir)/lib64/libcrypto.dll.a)) |
| 50 |
# use OpenSSL 3.x.x mingw-generated library stubs if available |
| 51 |
win32_ssl_libs = -L$(win32_ssl_dir)/lib64 -lcrypto -lssl |
| 52 |
else ifneq (,$(wildcard $(win32_ssl_dir)/lib/libcrypto.dll.a)) |
| 53 |
# use OpenSSL 1.x.x mingw-generated library stubs if available |
| 54 |
win32_ssl_libs = -L$(win32_ssl_dir)/lib -lcrypto -lssl |
| 55 |
else |
| 56 |
# directly import libeay32.dll and ssleay32.dll otherwise |
| 57 |
win32_ssl_libs = -L$(win32_ssl_dir)/bin -llibeay32 -lssleay32 |
| 58 |
endif |
| 59 |
win32_gui_libs = $(win32_common_libs) -lgdi32 -lpsapi $(win32_ssl_libs) |
| 60 |
win32_cli_libs = $(win32_common_libs) $(win32_ssl_libs) |
| 61 |
|
| 62 |
common_headers = common.h prototypes.h version.h |
| 63 |
win32_common = tls str file client log options protocol network resolver |
| 64 |
win32_common += ssl ctx verify ocsp sthreads fd dhparam cron stunnel |
| 65 |
win32_gui = ui_win_gui resources |
| 66 |
win32_cli = ui_win_cli |
| 67 |
win32_common_objs = $(addsuffix .o, $(addprefix $(objdir)/, $(win32_common))) |
| 68 |
win32_gui_objs = $(addsuffix .o, $(addprefix $(objdir)/, $(win32_gui))) |
| 69 |
win32_cli_objs = $(addsuffix .o, $(addprefix $(objdir)/, $(win32_cli))) |
| 70 |
|
| 71 |
win32_prefix = $(win32_targetcpu)-w64-mingw32- |
| 72 |
win32_cc = $(win32_prefix)gcc |
| 73 |
win32_windres = $(win32_prefix)windres |
| 74 |
|
| 75 |
all: mkdirs $(bindir)/stunnel.exe $(bindir)/tstunnel.exe |
| 76 |
|
| 77 |
mkdirs: |
| 78 |
mkdir -p $(bindir) $(objdir) |
| 79 |
|
| 80 |
$(bindir)/stunnel.exe: $(win32_common_objs) $(win32_gui_objs) |
| 81 |
$(win32_cc) -mwindows $(win32_ldflags) -o $(bindir)/stunnel.exe $(win32_common_objs) $(win32_gui_objs) $(win32_gui_libs) |
| 82 |
|
| 83 |
$(bindir)/tstunnel.exe: $(win32_common_objs) $(win32_cli_objs) |
| 84 |
$(win32_cc) $(win32_ldflags) -o $(bindir)/tstunnel.exe $(win32_common_objs) $(win32_cli_objs) $(win32_cli_libs) |
| 85 |
|
| 86 |
$(objdir)/%.o: $(srcdir)/%.c |
| 87 |
$(win32_cc) -c $(win32_cppflags) $(win32_cflags) -o $@ $< |
| 88 |
|
| 89 |
$(objdir)/%.o: $(common_headers) |
| 90 |
|
| 91 |
$(win32_gui_objs): $(srcdir)/resources.h |
| 92 |
|
| 93 |
$(objdir)/resources.o: $(srcdir)/resources.rc |
| 94 |
$(win32_windres) --include-dir $(srcdir) $< $@ |
| 95 |
|
| 96 |
$(objdir)/resources.o: $(srcdir)/version.h |