From 0621f97c7b59afb44b6a8a99a088e3103f33a699 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Sat, 11 Mar 2023 11:06:42 +0100 Subject: [PATCH] GNUmakefile: cleanups [ci skip] (#840) - indent - sync `test/GNUmakefile` with main - delete `RANLIB` - use `else if` - use more `?=` - use ASCII-7 copyright symbol (in test) --- win32/GNUmakefile | 152 +++++++++++++------------------- win32/test/GNUmakefile | 191 ++++++++++++++++++++--------------------- 2 files changed, 157 insertions(+), 186 deletions(-) diff --git a/win32/GNUmakefile b/win32/GNUmakefile index 31ca1505..e7d38498 100644 --- a/win32/GNUmakefile +++ b/win32/GNUmakefile @@ -7,15 +7,14 @@ # ######################################################################### +# Project root +PROOT := .. + # Edit the path below to point to the base of your Zlib sources. -ifndef ZLIB_PATH -ZLIB_PATH = ../../zlib -endif +ZLIB_PATH ?= $(PROOT)/../zlib # Edit the path below to point to the base of your OpenSSL package. -ifndef OPENSSL_PATH -OPENSSL_PATH = ../../openssl -endif +OPENSSL_PATH ?= $(PROOT)/../openssl # Edit the path below to point to your Distribution folder. ifndef DISTDIR @@ -29,9 +28,6 @@ DEVLDIR = libssh2-$(LIBSSH2_VERSION_STR)-dev-$(ARCH) endif DEVLARC = $(DEVLDIR).zip -# Project root -PROOT = .. - # Edit the vars below to change target settings. TARGET = libssh2 WWWURL = https://www.libssh2.org/ @@ -39,10 +35,7 @@ DESCR = libssh2 $(LIBSSH2_VERSION_STR) #STACK = 64000 # must be equal to DEBUG or NDEBUG -ifndef DB - DB = NDEBUG -# DB = DEBUG -endif +DB ?= NDEBUG # Optimization: -O or debugging: -g ifeq ($(DB),NDEBUG) OPT = -O2 @@ -86,37 +79,26 @@ CAT = type ECHONL = $(ComSpec) /c echo. endif -ifeq ($(LIBSSH2_RC),) -LIBSSH2_RC := $(CROSSPREFIX)windres -endif -ifeq ($(LIBSSH2_CC),) -LIBSSH2_CC := $(CROSSPREFIX)gcc -endif -ifeq ($(LIBSSH2_AR),) -LIBSSH2_AR := $(CROSSPREFIX)ar -endif -ifeq ($(LIBSSH2_RANLIB),) -LIBSSH2_RANLIB := $(CROSSPREFIX)ranlib -endif -ifeq ($(LIBSSH2_DLL_A_SUFFIX),) -LIBSSH2_DLL_A_SUFFIX := dll -endif +LIBSSH2_RC ?= $(CROSSPREFIX)windres +LIBSSH2_CC ?= $(CROSSPREFIX)gcc +LIBSSH2_AR ?= $(CROSSPREFIX)ar +LIBSSH2_DLL_A_SUFFIX ?= dll libssh2_dll_LIBRARY = $(TARGET)$(LIBSSH2_DLL_SUFFIX).dll CC = $(LIBSSH2_CC) # 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 + 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 @@ -132,66 +114,61 @@ RC = $(LIBSSH2_RC) LDFLAGS += -s -shared -Wl,--output-def,$(libssh2_dll_LIBRARY:.dll=.def),--out-implib,$(TARGET)$(LIBSSH2_DLL_A_SUFFIX).$(LIBEXT) AR = $(LIBSSH2_AR) ARFLAGS = cru -RANLIB = $(LIBSSH2_RANLIB) RCFLAGS = -I $(PROOT)/include -O coff CFLAGS += -fno-builtin CFLAGS += -fno-strict-aliasing CFLAGS += -Wall # -pedantic ifeq ($(ARCH),w64) -CFLAGS += -m64 -LDFLAGS += -m64 -RCFLAGS += -F pe-x86-64 -else -ifeq ($(ARCH),w32) -CFLAGS += -m32 -LDFLAGS += -m32 -RCFLAGS += -F pe-i386 -endif + CFLAGS += -m64 + LDFLAGS += -m64 + RCFLAGS += -F pe-x86-64 +else ifeq ($(ARCH),w32) + CFLAGS += -m32 + LDFLAGS += -m32 + RCFLAGS += -F pe-i386 endif INCLUDES = -I$(PROOT)/win32 -I$(PROOT)/include ifdef WITH_WINCNG -CFLAGS += -DLIBSSH2_WINCNG -LDLIBS += -lbcrypt -lcrypt32 + CFLAGS += -DLIBSSH2_WINCNG + LDLIBS += -lbcrypt -lcrypt32 +else ifdef MBEDTLS_PATH + CFLAGS += -DLIBSSH2_MBEDTLS + CFLAGS += -I"$(MBEDTLS_PATH)/include" + LIBPATH += -L"$(MBEDTLS_PATH)/libs" + LDLIBS += -lmbedtls -lmbedx509 -lmbedcrypto else -ifdef MBEDTLS_PATH -CFLAGS += -DLIBSSH2_MBEDTLS -CFLAGS += -I"$(MBEDTLS_PATH)/include" -LIBPATH += -L"$(MBEDTLS_PATH)/libs" -LDLIBS += -lmbedtls -lmbedx509 -lmbedcrypto -else -CFLAGS += -DLIBSSH2_OPENSSL -ifndef OPENSSL_INCLUDE - ifeq "$(wildcard $(OPENSSL_PATH)/outinc)" "$(OPENSSL_PATH)/outinc" - OPENSSL_INCLUDE = $(OPENSSL_PATH)/outinc + 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 - ifeq "$(wildcard $(OPENSSL_PATH)/include)" "$(OPENSSL_PATH)/include" - OPENSSL_INCLUDE = $(OPENSSL_PATH)/include + ifneq "$(wildcard $(OPENSSL_INCLUDE)/openssl/opensslv.h)" "$(OPENSSL_INCLUDE)/openssl/opensslv.h" + $(error Invalid OPENSSL_PATH: $(OPENSSL_PATH)) 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 + 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 - ifeq "$(wildcard $(OPENSSL_PATH)/lib)" "$(OPENSSL_PATH)/lib" - OPENSSL_LIBPATH = $(OPENSSL_PATH)/lib - OPENSSL_LIBS_DYN = crypto.dll ssl.dll + 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 -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 LDLIBS += -lws2_32 ifdef WITH_ZLIB @@ -209,13 +186,11 @@ CFLAGS += $(INCLUDES) vpath %.c $(PROOT)/src ifdef WITH_WINCNG -include $(PROOT)/Makefile.WinCNG.inc + include $(PROOT)/Makefile.WinCNG.inc +else ifdef MBEDTLS_PATH + include $(PROOT)/Makefile.mbedTLS.inc else -ifdef MBEDTLS_PATH -include $(PROOT)/Makefile.mbedTLS.inc -else -include $(PROOT)/Makefile.OpenSSL.inc -endif + include $(PROOT)/Makefile.OpenSSL.inc endif # include Makefile.inc to get CSOURCES define @@ -305,9 +280,6 @@ $(TARGET).$(LIBEXT): $(OBJS) @echo Creating $@ @$(call DEL, $@) @$(AR) $(ARFLAGS) $@ $^ -ifdef RANLIB - @$(RANLIB) $@ -endif $(libssh2_dll_LIBRARY) $(TARGET)$(LIBSSH2_DLL_A_SUFFIX).$(LIBEXT): $(OBJL) @echo Linking $@ diff --git a/win32/test/GNUmakefile b/win32/test/GNUmakefile index 9195b3d0..67fc451f 100644 --- a/win32/test/GNUmakefile +++ b/win32/test/GNUmakefile @@ -7,34 +7,27 @@ # ######################################################################### +# Project root +PROOT := ../.. + # Edit the path below to point to the base of your Zlib sources. -ifndef ZLIB_PATH -ZLIB_PATH = ../../../zlib -endif +ZLIB_PATH ?= $(PROOT)/../zlib # Edit the path below to point to the base of your OpenSSL package. -ifndef OPENSSL_PATH -OPENSSL_PATH = ../../../openssl -endif - -# Project root -PROOT = ../.. +OPENSSL_PATH ?= $(PROOT)/../openssl # Edit the var below to enable static linking of libssh2 and libz -LINK_STATIC = 1 +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 = https://www.libssh2.org/ -DESCR = libssh2 $(subst .rc,,$(notdir $@)) $(LIBSSH2_VERSION_STR) +DESCR = libssh2 $(subst .rc,,$(notdir $@)) $(LIBSSH2_VERSION_STR) #STACK = 64000 # must be equal to DEBUG or NDEBUG -ifndef DB - DB = NDEBUG -# DB = DEBUG -endif +DB ?= NDEBUG # Optimization: -O or debugging: -g ifeq ($(DB),NDEBUG) OPT = -O2 @@ -46,78 +39,81 @@ 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 +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 = ' +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) +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) +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. +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 -CC = $(CROSSPREFIX)gcc +LIBSSH2_RC ?= $(CROSSPREFIX)windres +LIBSSH2_CC ?= $(CROSSPREFIX)gcc +LIBSSH2_AR ?= $(CROSSPREFIX)ar + +CC = $(LIBSSH2_CC) # 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 + 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) +CFLAGS = $(LIBSSH2_CFLAG_EXTRAS) $(OPT) -D$(DB) +LDFLAGS = $(LIBSSH2_LDFLAG_EXTRAS) -LD = $(CROSSPREFIX)gcc -RC = $(CROSSPREFIX)windres -LDFLAGS = -s -AR = $(CROSSPREFIX)ar -ARFLAGS = -cq LIBEXT = a -#LDLIBS += -lwsock32 -LDLIBS += -lws2_32 +LD = $(LIBSSH2_CC) +RC = $(LIBSSH2_RC) +LDFLAGS += -s +AR = $(LIBSSH2_AR) +ARFLAGS = cru RCFLAGS = -I $(PROOT)/include -O coff CFLAGS += -fno-builtin CFLAGS += -fno-strict-aliasing -CFLAGS += -Wall #-Wno-unused #-pedantic +CFLAGS += -Wall # -pedantic ifeq ($(ARCH),w64) -CFLAGS += -m64 -RCFLAGS += -F pe-x86-64 -else -ifeq ($(ARCH),w32) -CFLAGS += -m32 -RCFLAGS += -F pe-i386 -endif + CFLAGS += -m64 + LDFLAGS += -m64 + RCFLAGS += -F pe-x86-64 +else ifeq ($(ARCH),w32) + CFLAGS += -m32 + LDFLAGS += -m32 + RCFLAGS += -F pe-i386 endif INCLUDES = -I$(PROOT)/win32 -I$(PROOT)/include @@ -130,41 +126,44 @@ else endif ifdef WITH_WINCNG -# CFLAGS += -DLIBSSH2_WINCNG -LDLIBS += -lbcrypt -lcrypt32 + LDLIBS += -lbcrypt -lcrypt32 +else ifdef MBEDTLS_PATH + CFLAGS += -I"$(MBEDTLS_PATH)/include" + LIBPATH += -L"$(MBEDTLS_PATH)/libs" + LDLIBS += -lmbedtls -lmbedx509 -lmbedcrypto else -# CFLAGS += -DLIBSSH2_OPENSSL -ifndef OPENSSL_INCLUDE - ifeq "$(wildcard $(OPENSSL_PATH)/outinc)" "$(OPENSSL_PATH)/outinc" - OPENSSL_INCLUDE = $(OPENSSL_PATH)/outinc + 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 - ifeq "$(wildcard $(OPENSSL_PATH)/include)" "$(OPENSSL_PATH)/include" - OPENSSL_INCLUDE = $(OPENSSL_PATH)/include + 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 -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 +LDLIBS += -lws2_32 ifdef WITH_ZLIB CFLAGS += -DLIBSSH2_HAVE_ZLIB @@ -172,7 +171,7 @@ ifdef WITH_ZLIB ifdef LINK_ZLIB_STATIC LDLIBS += $(ZLIB_PATH)/libz.$(LIBEXT) else - LDLIBS += $(ZLIB_PATH)/libzdll.$(LIBEXT) + LDLIBS += $(ZLIB_PATH)/libz.dll.$(LIBEXT) endif endif @@ -227,7 +226,7 @@ $(OBJDIR)/%.rc: GNUmakefile $(OBJDIR)/version.inc @echo $(DL) BEGIN$(DL) >> $@ @echo $(DL) BLOCK "040904E4"$(DL) >> $@ @echo $(DL) BEGIN$(DL) >> $@ - @echo $(DL) VALUE "LegalCopyright","\xA9 $(LIBSSH2_COPYRIGHT_STR)\0"$(DL) >> $@ + @echo $(DL) VALUE "LegalCopyright","(C) $(LIBSSH2_COPYRIGHT_STR)\0"$(DL) >> $@ ifdef COMPANY @echo $(DL) VALUE "CompanyName","$(COMPANY)\0"$(DL) >> $@ endif