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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
|
#########################################################################
#
## Makefile for building libssh2 samples (Win32 version - gnu make)
## Use: make -f GNUmakefile [help]
##
## Hacked by: Guenter Knauf
#
#########################################################################
# Edit the path below to point to the base of your Zlib sources.
ifndef ZLIB_PATH
ZLIB_PATH = ../../../zlib-1.2.8
endif
# Edit the path below to point to the base of your OpenSSL package.
ifndef OPENSSL_PATH
OPENSSL_PATH = ../../../openssl-0.9.8zc
endif
# Project root
PROOT = ../..
# Edit the var below to enable static linking of libssh2 and libz
LINK_STATIC = 1
# Edit the vars below to change target settings.
SAMPLES = $(PROOT)/example
TARGETS := $(filter-out x11.exe,$(patsubst $(SAMPLES)/%.c,%.exe,$(strip $(wildcard $(SAMPLES)/*.c))))
WWWURL = http://www.libssh2.org/
DESCR = libssh2 $(subst .rc,,$(notdir $@)) $(LIBSSH2_VERSION_STR)
#STACK = 64000
# must be equal to DEBUG or NDEBUG
ifndef DB
DB = NDEBUG
# DB = DEBUG
endif
# Optimization: -O<n> or debugging: -g
ifeq ($(DB),NDEBUG)
OPT = -O2
OBJDIR = release
else
OPT = -g
OBJDIR = debug
endif
# Here you can find a native Win32 binary of the original awk:
# http://www.gknw.net/development/prgtools/awk-20100523.zip
AWK = awk
ZIP = zip -qzr9
# Platform-dependent helper tool macros
ifeq ($(findstring /sh,$(SHELL)),/sh)
DEL = rm -f $1
RMDIR = rm -fr $1
MKDIR = mkdir -p $1
COPY = -cp -afv $1 $2
#COPYR = -cp -afr $1/* $2
COPYR = -rsync -aC $1/* $2
TOUCH = touch $1
CAT = cat
ECHONL = echo ""
DL = '
else
ifeq "$(OS)" "Windows_NT"
DEL = -del 2>NUL /q /f $(subst /,\,$1)
RMDIR = -rd 2>NUL /q /s $(subst /,\,$1)
else
DEL = -del 2>NUL $(subst /,\,$1)
RMDIR = -deltree 2>NUL /y $(subst /,\,$1)
endif
MKDIR = -md 2>NUL $(subst /,\,$1)
COPY = -copy 2>NUL /y $(subst /,\,$1) $(subst /,\,$2)
COPYR = -xcopy 2>NUL /q /y /e $(subst /,\,$1) $(subst /,\,$2)
TOUCH = copy 2>&1>NUL /b $(subst /,\,$1) +,,
CAT = type
ECHONL = $(ComSpec) /c echo.
endif
# The following line defines your compiler.
ifdef METROWERKS
CC = mwcc
else
CC = $(CROSSPREFIX)gcc
endif
# Set environment var ARCH to your architecture to override autodetection.
ifndef ARCH
ifeq ($(findstring gcc,$(CC)),gcc)
ifeq ($(findstring x86_64,$(shell $(CC) -dumpmachine)),x86_64)
ARCH = w64
else
ARCH = w32
endif
else
ARCH = w32
endif
endif
# Include the version info retrieved from libssh2.h
-include $(OBJDIR)/version.inc
# Global flags for all compilers
CFLAGS = $(OPT) -D$(DB) -DLIBSSH2_WIN32 # -DHAVE_CONFIG_H
ifeq ($(CC),mwcc)
LD = mwld
RC = mwwinrc
LDFLAGS = -nostdlib
AR = $(LD)
ARFLAGS = -nostdlib -library -o
LIBEXT = lib
LIBPATH += -lr "$(METROWERKS)/MSL" -lr "$(METROWERKS)/Win32-x86 Support"
LDLIBS += -lMSL_Runtime_x86.lib -lMSL_C_x86.lib -lMSL_Extras_x86.lib
LDLIBS += -lkernel32.lib -luser32.lib -lwsock32.lib
RCFLAGS =
CFLAGS += -nostdinc -gccinc -msgstyle gcc -inline off -opt nointrinsics -proc 586
CFLAGS += -ir "$(METROWERKS)/MSL" -ir "$(METROWERKS)/Win32-x86 Support"
CFLAGS += -w on,nounused,nounusedexpr # -ansi strict
else
LD = $(CROSSPREFIX)gcc
RC = $(CROSSPREFIX)windres
LDFLAGS = -s
AR = $(CROSSPREFIX)ar
ARFLAGS = -cq
LIBEXT = a
#LDLIBS += -lwsock32
LDLIBS += -lws2_32
RCFLAGS = -I $(PROOT)/include -O coff
CFLAGS += -fno-builtin
CFLAGS += -fno-strict-aliasing
CFLAGS += -Wall #-Wno-unused #-pedantic
ifeq ($(ARCH),w64)
CFLAGS += -D_AMD64_
RCFLAGS += -F pe-x86-64
else
CFLAGS += -m32
RCFLAGS += -F pe-i386
endif
endif
INCLUDES = -I$(PROOT)/win32 -I$(PROOT)/include
LIBPATH += -L$(PROOT)/win32
ifdef LINK_STATIC
LDLIBS += -llibssh2
else
LDLIBS += -llibssh2dll
endif
ifdef WITH_WINCNG
# CFLAGS += -DLIBSSH2_WINCNG
LDLIBS += -lbcrypt -lcrypt32
else
# CFLAGS += -DLIBSSH2_OPENSSL
ifndef OPENSSL_INCLUDE
ifeq "$(wildcard $(OPENSSL_PATH)/outinc)" "$(OPENSSL_PATH)/outinc"
OPENSSL_INCLUDE = $(OPENSSL_PATH)/outinc
endif
ifeq "$(wildcard $(OPENSSL_PATH)/include)" "$(OPENSSL_PATH)/include"
OPENSSL_INCLUDE = $(OPENSSL_PATH)/include
endif
endif
ifneq "$(wildcard $(OPENSSL_INCLUDE)/openssl/opensslv.h)" "$(OPENSSL_INCLUDE)/openssl/opensslv.h"
$(error Invalid OPENSSL_PATH: $(OPENSSL_PATH))
endif
INCLUDES += -I"$(OPENSSL_INCLUDE)"
ifndef OPENSSL_LIBPATH
OPENSSL_LIBS_STAT = crypto ssl
ifeq "$(wildcard $(OPENSSL_PATH)/out)" "$(OPENSSL_PATH)/out"
OPENSSL_LIBPATH = $(OPENSSL_PATH)/out
OPENSSL_LIBS_DYN = eay32 ssl32
endif
ifeq "$(wildcard $(OPENSSL_PATH)/lib)" "$(OPENSSL_PATH)/lib"
OPENSSL_LIBPATH = $(OPENSSL_PATH)/lib
OPENSSL_LIBS_DYN = crypto.dll ssl.dll
endif
endif
ifdef LINK_STATIC
ifdef LINK_OPENSSL_STATIC
LDLIBS += $(patsubst %,$(OPENSSL_LIBPATH)/lib%.$(LIBEXT), $(OPENSSL_LIBS_STAT)) -lgdi32
else
LDLIBS += $(patsubst %,$(OPENSSL_LIBPATH)/lib%.$(LIBEXT), $(OPENSSL_LIBS_DYN))
endif
endif
endif
ifdef WITH_ZLIB
CFLAGS += -DLIBSSH2_HAVE_ZLIB
INCLUDES += -I$(ZLIB_PATH)
ifdef LINK_ZLIB_STATIC
LDLIBS += $(ZLIB_PATH)/libz.$(LIBEXT)
else
LDLIBS += $(ZLIB_PATH)/libzdll.$(LIBEXT)
endif
endif
CFLAGS += $(INCLUDES)
vpath %.c $(PROOT)/example
.PRECIOUS: $(OBJDIR)/%.o $(OBJDIR)/%.rc $(OBJDIR)/%.res
all: prebuild $(TARGETS)
prebuild: $(OBJDIR) $(OBJDIR)/version.inc
$(OBJDIR)/%.o: %.c
# @echo Compiling $<
$(CC) $(CFLAGS) -c $< -o $@
$(OBJDIR)/version.inc: $(PROOT)/include/libssh2.h $(OBJDIR)
@echo Creating $@
@$(AWK) -f $(PROOT)/get_ver.awk $< > $@
objclean:
$(call RMDIR, $(OBJDIR))
clean: objclean
$(call DEL, $(TARGETS))
$(OBJDIR):
$(call MKDIR, $@)
%.exe: $(OBJDIR)/%.o $(OBJDIR)/%.res
@echo Linking $@
@$(call DEL, $@)
$(LD) $(LDFLAGS) $^ -o $@ $(LIBPATH) $(LDLIBS)
$(OBJDIR)/%.res: $(OBJDIR)/%.rc
@echo Creating $@
@$(RC) $(RCFLAGS) -i $< -o $@
$(OBJDIR)/%.rc: GNUmakefile $(OBJDIR)/version.inc
@echo $(DL)1 VERSIONINFO$(DL) > $@
@echo $(DL) FILEVERSION $(LIBSSH2_VERSION),0$(DL) >> $@
@echo $(DL) PRODUCTVERSION $(LIBSSH2_VERSION),0$(DL) >> $@
@echo $(DL) FILEFLAGSMASK 0x3fL$(DL) >> $@
@echo $(DL) FILEOS 0x40004L$(DL) >> $@
@echo $(DL) FILEFLAGS 0x0L$(DL) >> $@
@echo $(DL) FILETYPE 0x1L$(DL) >> $@
@echo $(DL) FILESUBTYPE 0x0L$(DL) >> $@
@echo $(DL)BEGIN$(DL) >> $@
@echo $(DL) BLOCK "StringFileInfo"$(DL) >> $@
@echo $(DL) BEGIN$(DL) >> $@
@echo $(DL) BLOCK "040904E4"$(DL) >> $@
@echo $(DL) BEGIN$(DL) >> $@
@echo $(DL) VALUE "LegalCopyright","\xA9 $(LIBSSH2_COPYRIGHT_STR)\0"$(DL) >> $@
ifdef COMPANY
@echo $(DL) VALUE "CompanyName","$(COMPANY)\0"$(DL) >> $@
endif
@echo $(DL) VALUE "ProductName","$(notdir $(@:.rc=.exe))\0"$(DL) >> $@
@echo $(DL) VALUE "ProductVersion","$(LIBSSH2_VERSION_STR)\0"$(DL) >> $@
@echo $(DL) VALUE "License","Released under GPL.\0"$(DL) >> $@
@echo $(DL) VALUE "FileDescription","$(DESCR)\0"$(DL) >> $@
@echo $(DL) VALUE "FileVersion","$(LIBSSH2_VERSION_STR)\0"$(DL) >> $@
@echo $(DL) VALUE "InternalName","$(notdir $(@:.rc=))\0"$(DL) >> $@
@echo $(DL) VALUE "OriginalFilename","$(notdir $(@:.rc=.exe))\0"$(DL) >> $@
@echo $(DL) VALUE "WWW","$(WWWURL)\0"$(DL) >> $@
@echo $(DL) END$(DL) >> $@
@echo $(DL) END$(DL) >> $@
@echo $(DL) BLOCK "VarFileInfo"$(DL) >> $@
@echo $(DL) BEGIN$(DL) >> $@
@echo $(DL) VALUE "Translation", 0x409, 1252$(DL) >> $@
@echo $(DL) END$(DL) >> $@
@echo $(DL)END$(DL) >> $@
ifdef ICON
@echo $(DL)10 ICON DISCARDABLE "$(ICON)"$(DL) >> $@
endif
help: $(OBJDIR)/version.inc
@echo $(DL)===========================================================$(DL)
@echo $(DL)OpenSSL path = $(OPENSSL_PATH)$(DL)
@echo $(DL)Zlib path = $(ZLIB_PATH)$(DL)
@echo $(DL)===========================================================$(DL)
@echo $(DL)libssh $(LIBSSH2_VERSION_STR) - available targets are:$(DL)
@echo $(DL)$(MAKE) all$(DL)
@echo $(DL)$(MAKE) clean$(DL)
@echo $(DL)$(MAKE) objclean$(DL)
@echo $(DL)===========================================================$(DL)
|