Skip to content

Commit

Permalink
MinGW build: some GNUMakefile tweaks.
Browse files Browse the repository at this point in the history
Added architecture autodetection; added switches to CFLAGS and
RCFLAGS to make sure that the right architecture is used.
Added support to build with WinCNG.
  • Loading branch information
gknauf committed Nov 30, 2014
1 parent 46f017e commit e4ba5fa
Showing 1 changed file with 35 additions and 14 deletions.
49 changes: 35 additions & 14 deletions win32/GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@ ifndef OPENSSL_PATH
OPENSSL_PATH = ../../openssl-0.9.8y
endif

# Edit the var below to set to your architecture or set environment var.
ifndef ARCH
ARCH = w32
endif

# Edit the path below to point to your Distribution folder.
ifndef DISTDIR
DISTDIR = libssh2-$(LIBSSH2_VERSION_STR)-bin-$(ARCH)
Expand Down Expand Up @@ -95,14 +90,24 @@ 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 ($(ARCH),w64)
CFLAGS += -D_AMD64_
endif

ifeq ($(CC),mwcc)
LD = mwld
Expand All @@ -129,13 +134,26 @@ LIBEXT = a
RANLIB = $(CROSSPREFIX)ranlib
#LDLIBS += -lwsock32
LDLIBS += -lws2_32
RCFLAGS = -I. -I ../include -O coff -i
RCFLAGS = -I ../include -O coff
CFLAGS += -fno-builtin
CFLAGS += -fno-strict-aliasing
CFLAGS += -Wall # -pedantic
ifeq ($(ARCH),w64)
CFLAGS += -D_AMD64_
RCFLAGS += -F pe-x86-64
else
CFLAGS += -m32
RCFLAGS += -F pe-i386
endif
endif

INCLUDES = -I. -I../include

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
Expand Down Expand Up @@ -164,6 +182,7 @@ ifdef LINK_OPENSSL_STATIC
else
LDLIBS += $(patsubst %,$(OPENSSL_LIBPATH)/lib%.$(LIBEXT), $(OPENSSL_LIBS_DYN))
endif
endif

ifdef WITH_ZLIB
CFLAGS += -DLIBSSH2_HAVE_ZLIB
Expand All @@ -177,11 +196,13 @@ endif

CFLAGS += $(INCLUDES)

vpath %.c . ../src
vpath %.c ../src

# only OpenSSL is supported with this build system
CFLAGS += -DLIBSSH2_OPENSSL
ifdef WITH_WINCNG
include ../Makefile.WinCNG.inc
else
include ../Makefile.OpenSSL.inc
endif

# include Makefile.inc to get CSOURCES define
include ../Makefile.inc
Expand Down Expand Up @@ -237,7 +258,7 @@ dev: all $(DEVLDIR) $(DEVLDIR)/readme.txt
@echo Creating $(DEVLARC)
@$(ZIP) $(DEVLARC) $(DEVLDIR)/* < $(DEVLDIR)/readme.txt

distclean: clean
distclean vclean: clean
$(call RMDIR, $(DISTDIR))
$(call DEL, $(DISTARC))

Expand Down Expand Up @@ -281,7 +302,7 @@ $(TARGET).dll $(TARGET)dll.a: $(OBJL)

$(OBJDIR)/%.res: %.rc
@echo Creating $@
@$(RC) $(RCFLAGS) $< -o $@
@$(RC) $(RCFLAGS) -i $< -o $@


$(DISTDIR)/readme.txt: GNUmakefile
Expand Down

0 comments on commit e4ba5fa

Please sign in to comment.