mirror of
https://github.com/libssh2/libssh2.git
synced 2025-11-03 22:13:11 +03:00
win32/GNUmakefile: make it support non-Windows builds [ci skip]
With 20-ish extra lines, make this Makefile support all GCC-like
toolchains.
The temporary directory becomes `<triplet>-{release|debug}` from
the former `{release|debug}`.
Also change the lib directory name in the `dist` package from
`win32` to `lib`, to match other packages and build tools.
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
#########################################################################
|
#########################################################################
|
||||||
#
|
#
|
||||||
# Makefile for building libssh2 (Windows version - GNU Make)
|
# Makefile for building libssh2 with GCC-like toolchains.
|
||||||
# Use: make -f GNUmakefile [help|all|clean|dist|distclean|dll|objclean|test|testclean]
|
# Use: make -f GNUmakefile [help|all|clean|dist|distclean|dll|objclean|test|testclean]
|
||||||
#
|
#
|
||||||
# Hacked by: Guenter Knauf
|
# Hacked by: Guenter Knauf
|
||||||
@@ -46,16 +46,31 @@ else
|
|||||||
TRIPLET ?= $(shell $(CC) -dumpmachine)
|
TRIPLET ?= $(shell $(CC) -dumpmachine)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
ifneq ($(findstring -w,$(TRIPLET)),)
|
||||||
|
WIN32 := 1
|
||||||
|
BIN_EXT := .exe
|
||||||
|
DYN_EXT := .dll
|
||||||
|
endif
|
||||||
|
|
||||||
CPPFLAGS += -I$(PROOT)/win32 -I$(PROOT)/include
|
CPPFLAGS += -I$(PROOT)/win32 -I$(PROOT)/include
|
||||||
RCFLAGS += -I$(PROOT)/include
|
RCFLAGS += -I$(PROOT)/include
|
||||||
|
|
||||||
|
OBJ_DIR := $(TRIPLET)
|
||||||
|
|
||||||
# examples, tests
|
# examples, tests
|
||||||
|
|
||||||
LIBSSH2_LDFLAGS_BIN += -L$(PROOT)/win32
|
LIBSSH2_LDFLAGS_BIN += -L$(PROOT)/win32
|
||||||
LIBS_BIN := -lssh2 -lws2_32
|
LIBS_BIN := -lssh2
|
||||||
|
ifdef WIN32
|
||||||
|
LIBS_BIN += -lws2_32
|
||||||
|
endif
|
||||||
|
|
||||||
ifdef DYN
|
ifdef DYN
|
||||||
|
ifdef WIN32
|
||||||
libssh2_DEPENDENCIES := $(PROOT)/win32/libssh2.dll.a
|
libssh2_DEPENDENCIES := $(PROOT)/win32/libssh2.dll.a
|
||||||
|
else
|
||||||
|
libssh2_DEPENDENCIES := $(PROOT)/win32/libssh2$(DYN_EXT)
|
||||||
|
endif
|
||||||
LIBSSH2_LDFLAGS_BIN += -shared
|
LIBSSH2_LDFLAGS_BIN += -shared
|
||||||
else
|
else
|
||||||
libssh2_DEPENDENCIES := $(PROOT)/win32/libssh2.a
|
libssh2_DEPENDENCIES := $(PROOT)/win32/libssh2.a
|
||||||
@@ -68,9 +83,9 @@ endif
|
|||||||
DB ?= NDEBUG
|
DB ?= NDEBUG
|
||||||
CPPFLAGS += -D$(DB)
|
CPPFLAGS += -D$(DB)
|
||||||
ifeq ($(DB),NDEBUG)
|
ifeq ($(DB),NDEBUG)
|
||||||
OBJ_DIR := release
|
OBJ_DIR := $(OBJ_DIR)-release
|
||||||
else
|
else
|
||||||
OBJ_DIR := debug
|
OBJ_DIR := $(OBJ_DIR)-debug
|
||||||
CFLAGS += -g
|
CFLAGS += -g
|
||||||
CPPFLAGS += -DLIBSSH2DEBUG
|
CPPFLAGS += -DLIBSSH2DEBUG
|
||||||
endif
|
endif
|
||||||
@@ -101,7 +116,7 @@ else ifdef MBEDTLS_PATH
|
|||||||
_LDFLAGS += -L"$(MBEDTLS_PATH)/lib"
|
_LDFLAGS += -L"$(MBEDTLS_PATH)/lib"
|
||||||
_LIBS += -lmbedtls -lmbedx509 -lmbedcrypto
|
_LIBS += -lmbedtls -lmbedx509 -lmbedcrypto
|
||||||
include $(PROOT)/Makefile.mbedTLS.inc
|
include $(PROOT)/Makefile.mbedTLS.inc
|
||||||
else
|
else ifdef WIN32
|
||||||
CPPFLAGS += -DLIBSSH2_WINCNG
|
CPPFLAGS += -DLIBSSH2_WINCNG
|
||||||
include $(PROOT)/Makefile.WinCNG.inc
|
include $(PROOT)/Makefile.WinCNG.inc
|
||||||
endif
|
endif
|
||||||
@@ -113,7 +128,9 @@ ifdef ZLIB_PATH
|
|||||||
_LIBS += -lz
|
_LIBS += -lz
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
ifdef WIN32
|
||||||
_LIBS += -lws2_32 -lcrypt32 -lbcrypt
|
_LIBS += -lws2_32 -lcrypt32 -lbcrypt
|
||||||
|
endif
|
||||||
|
|
||||||
LIBSSH2_LDFLAGS_LIB += $(_LDFLAGS)
|
LIBSSH2_LDFLAGS_LIB += $(_LDFLAGS)
|
||||||
LIBS_LIB += $(_LIBS)
|
LIBS_LIB += $(_LIBS)
|
||||||
@@ -159,10 +176,15 @@ DISTDIR ?= $(TARGET)-$(LIBSSH2_VERSION_STR)-bin-$(word 1,$(subst -, ,$(TRIPLET))
|
|||||||
DISTARC := $(DISTDIR).zip
|
DISTARC := $(DISTDIR).zip
|
||||||
|
|
||||||
LIBSSH2_DLL_SUFFIX ?=
|
LIBSSH2_DLL_SUFFIX ?=
|
||||||
libssh2_dll_LIBRARY := $(TARGET)$(LIBSSH2_DLL_SUFFIX).dll
|
libssh2_dll_LIBRARY := $(TARGET)$(LIBSSH2_DLL_SUFFIX)$(DYN_EXT)
|
||||||
|
OBJS_dll := $(OBJS)
|
||||||
|
ifdef WIN32
|
||||||
libssh2_dll_a_LIBRARY := $(TARGET).dll.a
|
libssh2_dll_a_LIBRARY := $(TARGET).dll.a
|
||||||
|
OBJS_dll += $(OBJ_DIR)/$(TARGET).res
|
||||||
|
LIBSSH2_LDFLAGS_LIB += -Wl,--output-def,$(libssh2_dll_LIBRARY:$(DYN_EXT)=.def),--out-implib,$(libssh2_dll_a_LIBRARY)
|
||||||
|
endif
|
||||||
|
|
||||||
TARGETS_EXAMPLES := $(patsubst %.c,%.exe,$(strip $(wildcard $(PROOT)/example/*.c)))
|
TARGETS_EXAMPLES := $(patsubst %.c,%$(BIN_EXT),$(strip $(wildcard $(PROOT)/example/*.c)))
|
||||||
|
|
||||||
all: lib dll
|
all: lib dll
|
||||||
|
|
||||||
@@ -174,19 +196,20 @@ prebuild: $(OBJ_DIR) $(OBJ_DIR)/version.inc
|
|||||||
|
|
||||||
test: $(TARGETS_EXAMPLES)
|
test: $(TARGETS_EXAMPLES)
|
||||||
|
|
||||||
%.exe: %.c $(libssh2_DEPENDENCIES)
|
%$(BIN_EXT): %.c $(libssh2_DEPENDENCIES)
|
||||||
$(CC) -W -Wall $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $(LIBSSH2_LDFLAGS_BIN) $< -o $@ $(LIBS) $(LIBS_BIN)
|
$(CC) -W -Wall $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $(LIBSSH2_LDFLAGS_BIN) $< -o $@ $(LIBS) $(LIBS_BIN)
|
||||||
|
|
||||||
$(OBJ_DIR)/%.o: %.c
|
$(OBJ_DIR)/%.o: %.c
|
||||||
$(CC) -W -Wall $(CFLAGS) $(CPPFLAGS) -c $< -o $@
|
$(CC) -W -Wall $(CFLAGS) $(CPPFLAGS) -c $< -o $@
|
||||||
|
|
||||||
$(libssh2_dll_LIBRARY) $(libssh2_dll_a_LIBRARY): $(OBJS) $(OBJ_DIR)/$(TARGET).res
|
$(libssh2_dll_LIBRARY) $(libssh2_dll_a_LIBRARY): $(OBJS_dll)
|
||||||
@$(call DEL, $@)
|
@$(call DEL, $@)
|
||||||
$(CC) $(LDFLAGS) -shared $(LIBSSH2_LDFLAGS_LIB) $^ -o $@ $(LIBS) $(LIBS_LIB) \
|
$(CC) $(LDFLAGS) -shared $(LIBSSH2_LDFLAGS_LIB) $^ -o $@ $(LIBS) $(LIBS_LIB)
|
||||||
-Wl,--output-def,$(libssh2_dll_LIBRARY:.dll=.def),--out-implib,$(libssh2_dll_a_LIBRARY)
|
|
||||||
|
|
||||||
|
ifdef WIN32
|
||||||
$(OBJ_DIR)/%.res: %.rc
|
$(OBJ_DIR)/%.res: %.rc
|
||||||
$(RC) -O coff $(RCFLAGS) -i $< -o $@
|
$(RC) -O coff $(RCFLAGS) -i $< -o $@
|
||||||
|
endif
|
||||||
|
|
||||||
$(TARGET).a: $(OBJS)
|
$(TARGET).a: $(OBJS)
|
||||||
@$(call DEL, $@)
|
@$(call DEL, $@)
|
||||||
@@ -198,14 +221,14 @@ $(OBJ_DIR)/version.inc: $(PROOT)/get_ver.awk $(PROOT)/include/libssh2.h $(OBJ_DI
|
|||||||
dist: all $(DISTDIR) $(DISTDIR)/readme.txt
|
dist: all $(DISTDIR) $(DISTDIR)/readme.txt
|
||||||
@$(call MKDIR, $(DISTDIR)/bin)
|
@$(call MKDIR, $(DISTDIR)/bin)
|
||||||
@$(call MKDIR, $(DISTDIR)/include)
|
@$(call MKDIR, $(DISTDIR)/include)
|
||||||
@$(call MKDIR, $(DISTDIR)/win32)
|
@$(call MKDIR, $(DISTDIR)/lib)
|
||||||
@$(call COPY, $(PROOT)/COPYING, $(DISTDIR))
|
@$(call COPY, $(PROOT)/COPYING, $(DISTDIR))
|
||||||
@$(call COPY, $(PROOT)/README, $(DISTDIR))
|
@$(call COPY, $(PROOT)/README, $(DISTDIR))
|
||||||
@$(call COPY, $(PROOT)/RELEASE-NOTES, $(DISTDIR))
|
@$(call COPY, $(PROOT)/RELEASE-NOTES, $(DISTDIR))
|
||||||
@$(call COPY, $(libssh2_dll_LIBRARY), $(DISTDIR)/bin)
|
@$(call COPY, $(libssh2_dll_LIBRARY), $(DISTDIR)/bin)
|
||||||
@$(call COPY, $(PROOT)/include/*.h, $(DISTDIR)/include)
|
@$(call COPY, $(PROOT)/include/*.h, $(DISTDIR)/include)
|
||||||
@$(call COPY, libssh2_config.h, $(DISTDIR)/include)
|
@$(call COPY, libssh2_config.h, $(DISTDIR)/include)
|
||||||
@$(call COPY, *.a, $(DISTDIR)/win32)
|
@$(call COPY, *.a, $(DISTDIR)/lib)
|
||||||
@echo Creating... $(DISTARC)
|
@echo Creating... $(DISTARC)
|
||||||
@$(ZIP) $(DISTARC) $(DISTDIR)/* < $(DISTDIR)/readme.txt
|
@$(ZIP) $(DISTARC) $(DISTDIR)/* < $(DISTDIR)/readme.txt
|
||||||
|
|
||||||
@@ -220,7 +243,7 @@ testclean: clean
|
|||||||
$(call DEL, $(TARGETS_EXAMPLES))
|
$(call DEL, $(TARGETS_EXAMPLES))
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
$(call DEL, $(libssh2_dll_LIBRARY) $(libssh2_dll_LIBRARY:.dll=.def) $(TARGET).a $(libssh2_dll_a_LIBRARY))
|
$(call DEL, $(libssh2_dll_LIBRARY) $(libssh2_dll_LIBRARY:$(DYN_EXT)=.def) $(TARGET).a $(libssh2_dll_a_LIBRARY))
|
||||||
$(call RMDIR, $(OBJ_DIR))
|
$(call RMDIR, $(OBJ_DIR))
|
||||||
|
|
||||||
$(OBJ_DIR):
|
$(OBJ_DIR):
|
||||||
@@ -231,7 +254,7 @@ $(DISTDIR):
|
|||||||
|
|
||||||
$(DISTDIR)/readme.txt: GNUmakefile
|
$(DISTDIR)/readme.txt: GNUmakefile
|
||||||
@echo Creating... $@
|
@echo Creating... $@
|
||||||
@echo $(DL)This is a binary distribution for Windows.$(DL) > $@
|
@echo $(DL)This is a binary distribution for $(TRIPLET).$(DL) > $@
|
||||||
@echo $(DL)libssh2 version $(LIBSSH2_VERSION_STR)$(DL) >> $@
|
@echo $(DL)libssh2 version $(LIBSSH2_VERSION_STR)$(DL) >> $@
|
||||||
@echo $(DL)Please download the complete libssh2 package for$(DL) >> $@
|
@echo $(DL)Please download the complete libssh2 package for$(DL) >> $@
|
||||||
@echo $(DL)any further documentation:$(DL) >> $@
|
@echo $(DL)any further documentation:$(DL) >> $@
|
||||||
|
|||||||
Reference in New Issue
Block a user