Debian Codegraph @

src/mingw.mak

raw
1 # Simple Makefile.w32 for stunnel.exe by Michal Trojnara 1998-2026
2 #
3 # Modified by Brian Hatch ([email protected])
4 # 20101030 pdelaage:
5 # + multi-HOST management (if used on Windows host or Linux Host)
6 # + lack of gnu-win32 (rm) detection
7 # note: rm is used INTERNALLY by gcc for deletion if intermediate files.
8
9 # This makefile is only tested on the mingw compiler. Mingw can successfully
10 # compile both openssl and stunnel. If you want to use another compiler, give
11 # it a shot, and tell us how it went.
12
13 # pdelaage : THIS makefile can be used with mingw-make on Windows or gnu make
14 # on Linux, to produce the Win32 version of stunnel (target is win32). It
15 # requires, on Windows, the use of gnu-win32 tools: rm, mkdir, rmdir that
16 # manages files and dirs BOTH on linux and Windows with / as path separator.
17 # Note: Native windows equivalent, del and mkdir/rmdir, badly manage / and \,
18 # so they cannot be used here.
19 # On Windows host, download:
20 # http://gnuwin32.sourceforge.net/downlinks/coreutils.php
21 # if you have forgotten this, this makefile will remind you...
22
23 # Modify this to point to your actual openssl compile directory
24 # (You did already compile openssl, didn't you???)
25 #SSLDIR=../../openssl-0.9.8zh
26 #SSLDIR=../../openssl-1.0.0t
27 SSLDIR=../../openssl-1.0.1q
28
29 # For 0.9.8 mingw compiled openssl
30 #SSLINC=$(SSLDIR)/outinc
31 #SSLLIBS=-L$(SSLDIR)/out -leay32 -lssl32
32
33 # for 1.0.0/1.0.1 mingw (msys2) compiled
34 SSLINC=$(SSLDIR)/include
35 SSLLIBS=-L$(SSLDIR) -lcrypto.dll -lssl.dll
36
37 # For MSVC compiled openssl
38 #SSLINC=$(SSLDIR)/inc32
39 #SSLLIBS=-L$(SSLDIR)/out32dll -lssleay32 -llibeay32
40
41 # c:\, backslash is not correctly recognized by mingw32-make, produces some
42 # "missing separator" issue.
43 # pdelaage: simple trick to detect if we are using mingw-gcc on a Windows host,
44 # or on a linux host. windir is a system environment variable on windows NT
45 # and above, and then redefine some macros.
46 # note: ifdef is !IFDEF in MS nmake or Borland make.
47 # $(info is !MESSAGE in MS nmake or Borland make.
48
49 ifdef windir
50 $(info host machine is a Windows machine )
51 NULLDEV=NUL
52 MKDIR="C:\Program Files\GnuWin32\bin\mkdir.exe"
53 DELFILES="C:\Program Files\GnuWin32\bin\rm.exe" -f
54 DELDIR="C:\Program Files\GnuWin32\bin\rm.exe" -rf
55 COPYFILES="C:\Program Files\GnuWin32\bin\cp.exe" -f
56 else
57 $(info host machine is a linux machine )
58 NULLDEV=/dev/null
59 MKDIR=mkdir
60 DELFILES=rm -f
61 DELDIR=rm -rf
62 COPYFILES=cp -f
63 endif
64
65 TARGETCPU=MGW32
66 SRC=../src
67 OBJROOT=../obj
68 OBJ=$(OBJROOT)/$(TARGETCPU)
69 BINROOT=../bin
70 BIN=$(BINROOT)/$(TARGETCPU)
71
72 OBJS=$(OBJ)/stunnel.o $(OBJ)/ssl.o $(OBJ)/ctx.o $(OBJ)/verify.o \
73 $(OBJ)/file.o $(OBJ)/client.o $(OBJ)/protocol.o $(OBJ)/sthreads.o \
74 $(OBJ)/log.o $(OBJ)/options.o $(OBJ)/network.o $(OBJ)/resolver.o \
75 $(OBJ)/ui_win_gui.o $(OBJ)/resources.o $(OBJ)/str.o $(OBJ)/tls.o \
76 $(OBJ)/fd.o $(OBJ)/dhparam.o $(OBJ)/ocsp.o $(OBJ)/cron.o
77
78 TOBJS=$(OBJ)/stunnel.o $(OBJ)/ssl.o $(OBJ)/ctx.o $(OBJ)/verify.o \
79 $(OBJ)/file.o $(OBJ)/client.o $(OBJ)/protocol.o $(OBJ)/sthreads.o \
80 $(OBJ)/log.o $(OBJ)/options.o $(OBJ)/network.o $(OBJ)/resolver.o \
81 $(OBJ)/ui_win_cli.o $(OBJ)/str.o $(OBJ)/tls.o \
82 $(OBJ)/fd.o $(OBJ)/dhparam.o $(OBJ)/ocsp.o $(OBJ)/cron.o
83
84 CC=gcc
85 RC=windres
86
87 # pdelaage note: as a workaround for windres bug on resources.rc, equivalent to
88 # "use a temp file instead of popen" option between cpp and windres!
89 RCP=gcc -E -xc-header -DRC_INVOKED
90
91 DEFINES=-D_WIN32_WINNT=0x0501
92
93 # some preprocessing debug : $(info DEFINES is $(DEFINES) )
94
95 CFLAGS=-g -O2 -Wall $(DEFINES) -I$(SSLINC)
96
97 # RFLAGS, note of pdelaage: windres accepts -fo for compatibility with ms tools
98 # default options : -J rc -O coff, input rc file, output coff file.
99
100 RFLAGS=-v --use-temp-file $(DEFINES)
101 # following RFLAGS2 useful if one day use-temp-file does not exist anymore
102 RFLAGS2=-v $(DEFINES)
103 LDFLAGS=-s
104
105 LIBS=$(SSLLIBS) -lws2_32 -lpsapi -lgdi32 -lcrypt32 -lkernel32
106 TLIBS=$(SSLLIBS) -lws2_32 -lpsapi -lcrypt32 -lkernel32
107 # IMPORTANT pdelaage : restore this if you need (but I do not see why) -lzdll
108
109 $(OBJ)/%.o: $(SRC)/%.c
110 $(CC) $(CFLAGS) -o$@ -c $<
111
112 $(OBJ)/%.o: $(SRC)/%.cpp
113 $(CC) $(CFLAGS) -o$@ -c $<
114
115 $(OBJ)/%.o: $(SRC)/%.rc
116 $(RC) $(RFLAGS) -o$@ $<
117
118 # pdelaage : trick for windres preprocessing popen bug on Windows, in case the windres option
119 # use_temp_file disappear one day...
120 # comment out the $(RC) rule above to activate the following
121
122 $(OBJ)/%.rcp: $(SRC)/%.rc
123 $(RCP) $(DEFINES) -o$@ $<
124
125 $(OBJ)/%.o: $(OBJ)/%.rcp
126 $(RC) $(RFLAGS2) -o$@ $<
127
128 # Note : gnu-make will automatically RM the intermediate "rcp" file
129 # BUT it will ABSOLUTELY NEED the "rm" command available : not a problem on linux
130 # but on a windows dev host machine, one will need to install gnu-win32/rm command
131 # in the system...
132 # for debug of the preprocessed rcp file, because it is automatically deleted by gnu-make: cp $< $<.2
133
134 all: testenv makedirs $(BIN)/stunnel.exe $(BIN)/tstunnel.exe
135
136 testopenssl:
137 @if not exist $(SSLDIR) echo You mush have a compiled OpenSSL tree
138 @if not exist $(SSLINC)/openssl/applink.c $(COPYFILES) $(SSLDIR)/ms/applink.c $(SSLINC)/openssl
139
140 #pdelaage : testenv purpose is to detect, on windows, whether Gnu-win32 has been properly installed...
141 # a first call to "true" is made to detect availability, a second is made to stop the make process.
142 ifdef windir
143 testenv: testopenssl
144 -@ echo OFF
145 -@ true >$(NULLDEV) 2>&1 || echo You MUST install Gnu-Win32 coreutils \
146 from http://gnuwin32.sourceforge.net/downlinks/coreutils.php \
147 and set PATH to include C:\Program Files\GnuWin32\bin
148 @true >$(NULLDEV) 2>&1
149 else
150 testenv:
151 -@ true >$(NULLDEV) 2>&1 || echo Your system lacks Gnu coreutils tools !!!
152 @true >$(NULLDEV) 2>&1
153 endif
154
155 clean:
156 -@ $(DELFILES) $(OBJ)/*.o
157 -@ $(DELFILES) $(BIN)/stunnel.exe >$(NULLDEV) 2>&1
158 -@ $(DELDIR) $(OBJ) >$(NULLDEV) 2>&1
159 -@ $(DELDIR) $(BIN) >$(NULLDEV) 2>&1
160
161 makedirs:
162 -@ $(MKDIR) $(OBJROOT) >$(NULLDEV) 2>&1
163 -@ $(MKDIR) $(OBJ) >$(NULLDEV) 2>&1
164 -@ $(MKDIR) $(BINROOT) >$(NULLDEV) 2>&1
165 -@ $(MKDIR) $(BIN) >$(NULLDEV) 2>&1
166
167 # pseudo-target for RC-preprocessor debugging
168 # result appears OK, as a text file
169 faketest:
170 gcc -E -xc-header -DRC_INVOKED $(DEFINES) -o $(SRC)/resources.rcp $(SRC)/resources.rc
171
172 $(OBJS): *.h mingw.mak
173
174 $(BIN)/stunnel.exe: $(OBJS)
175 $(CC) $(LDFLAGS) -o $(BIN)/stunnel.exe $(OBJS) $(LIBS) -mwindows
176
177 $(BIN)/tstunnel.exe: $(TOBJS)
178 $(CC) $(LDFLAGS) -o $(BIN)/tstunnel.exe $(TOBJS) $(TLIBS)
179
180 # "missing separator" issue with mingw32-make: tabs MUST BE TABS in your text
181 # editor, and not set of spaces even if your development host is windows.
182 # Some \ are badly tolerated by mingw32-make "!" directives, eg as !IF,
183 # accepted in MS nmake and Borland make ARE NOT supported by gnu make but they
184 # all have their equivalents.
185 # Gnu-make is case sensitive, while ms nmake or borland make are not. Anyway,
186 # on reference to env vars nmake convert env vars to UPPERCASE macro names...
187