forked from rbsec/sslscan
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile.mingw
96 lines (75 loc) · 3.47 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
#
# To build a 64-bit executable: make -f Makefile.mingw
# To build a 32-bit executable: make -f Makefile.mingw BUILD_32BIT=1
#
# Enable to echo commands for debugging.
#SHELL = sh -xv
# If we're in Linux, lets see if we can find the path to Mingw automatically...
ARCHITECTURE=
CC_PREFIX=
OPENSSL_TARGET=
ifneq ($(BUILD_32BIT),)
DEFINES=-DBUILD_32BIT=1
endif
ifeq ($(shell uname), Linux)
MINGW32=$(shell which i686-w64-mingw32-gcc)
ifneq ($(MINGW32),)
CC=$(MINGW32)
ARCHITECTURE=32-bit
CC_PREFIX=i686-w64-mingw32-
OPENSSL_TARGET=mingw
endif
MINGW64=$(shell which x86_64-w64-mingw32-gcc)
ifneq ($(MINGW64),)
ifeq ($(BUILD_32BIT),)
CC=$(MINGW64)
ARCHITECTURE=64-bit
CC_PREFIX=x86_64-w64-mingw32-
OPENSSL_TARGET=mingw64
endif
endif
endif
ifndef CC
$(error "Failed to determine the compiler!")
endif
.PHONY: clean
# Enable security options like stack protectors and variable formatting checks.
# Sadly, we can't use -pie, because MinGW produces a broken executable when
# enabled.
SECURITY_OPTIONS=-fstack-protector-all -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security
# Turn on linker optimizations, and DEP support (--nxcompat)
LINK_OPTIONS=-Wl,-O1 -Wl,--discard-all -Wl,--no-undefined -Wl,--dynamicbase -Wl,--nxcompat -static
CFLAGS += -Iopenssl_mingw/include -D__USE_GNU -DOPENSSL_NO_SSL2 -Wno-deprecated-declarations
LDFLAGS += -lws2_32 -lgdi32 -lcrypt32
# Set the version string for the program.
VERSION = "$(shell grep -E -o -m 1 '[0-9]+\.[0-9]+\.[0-9]+(\-[a-z]+[0-9]+)?' Changelog) Windows $(ARCHITECTURE) (Mingw)"
all: sslscan
.openssl_mingw.is.fresh: opensslpull
true
zlibpull:
# If the zlib dir already exists, issue a pull, otherwise clone it from GitHub. Either way, check out the latest tag.
if [ -d zlib_mingw -a -d zlib_mingw/.git ]; then \
cd ./zlib_mingw && git pull && git checkout tags/`git describe --abbrev=0 --tags` ; \
else \
git clone --depth 1 https://github.com/madler/zlib ./zlib_mingw && cd ./zlib_mingw && git checkout tags/`git describe --abbrev=0` ; \
fi
opensslpull:
if [ -d openssl_mingw -a -d openssl_mingw/.git ]; then \
cd ./openssl_mingw && git checkout OpenSSL_1_1_1-stable && git pull | grep -q "Already up-to-date." && [ -e ../.openssl_mingw.is.fresh ] || touch ../.openssl_mingw.is.fresh ; \
else \
git clone --depth 1 -b OpenSSL_1_1_1-stable https://github.com/openssl/openssl ./openssl_mingw && cd ./openssl_mingw && touch ../.openssl_mingw.is.fresh ; \
fi
zlib_mingw/libz.a: zlibpull
cd ./zlib_mingw; make -f win32/Makefile.gcc PREFIX=$(CC_PREFIX)
openssl_mingw/Makefile: .openssl_mingw.is.fresh zlib_mingw/libz.a
cd ./openssl_mingw; ./Configure --cross-compile-prefix=$(CC_PREFIX) --with-zlib-include=`pwd`/../zlib_mingw --with-zlib-lib=`pwd`/../zlib_mingw -fstack-protector-all -D_FORTIFY_SOURCE=2 $(OPENSSL_TARGET) no-shared enable-weak-ssl-ciphers enable-ssl2 zlib
openssl_mingw/libcrypto.a: openssl_mingw/Makefile
$(MAKE) -C openssl_mingw depend CC=$(CC)
$(MAKE) -j 10 -C openssl_mingw all CC=$(CC)
sslscan: openssl_mingw/libcrypto.a sslscan.c
$(CC) $(CFLAGS) -DVERSION=\"$(VERSION)\" $(DEFINES) $(SECURITY_OPTIONS) $(LINK_OPTIONS) -o sslscan.exe sslscan.c openssl_mingw/libssl.a openssl_mingw/libcrypto.a zlib_mingw/libz.a $(LDFLAGS)
$(CC_PREFIX)strip sslscan.exe
clean:
rm -f *.o sslscan.exe .openssl_mingw.is.fresh
if [ -f openssl_mingw/Makefile ]; then $(MAKE) -C openssl_mingw clean; fi
if [ -f zlib_mingw/win32/Makefile.gcc ]; then $(MAKE) -C zlib_mingw -f win32/Makefile.gcc clean; fi