mk: adjust options for mingw cross compilation

Check compiler target triplet for the strings 'windows' or 'mingw'
and set OS to Windows. If found, adjust basic parameters:

Set EXEEXT to indicate executables have .exe suffix.
Exclude 'relro' and 'now' flags which are not recognised on Windows.
Exclude 'noexecstack' flag which is not recognised on Windows.
Exclude -pthread flag because Windows doesn't have POSIX threads.
Include libssp.a to support stack-protector and _FORTIFY_SOURCE.

Signed-off-by: Nick Connolly <nick.connolly@mayadata.io>
Change-Id: I94a45d3123ebc81f5529006fa07b05da897e5866
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/6574
Community-CI: Mellanox Build Bot
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-by: Aleksey Marchuk <alexeymar@mellanox.com>
This commit is contained in:
Nick Connolly 2021-02-25 18:31:54 +00:00 committed by Tomasz Zawadzki
parent b3139d716b
commit af17c1d44d

View File

@ -69,10 +69,17 @@ endif
ifneq ($(filter freebsd%,$(TARGET_TRIPLET_WORDS)),)
OS = FreeBSD
endif
ifneq ($(filter mingw% windows%,$(TARGET_TRIPLET_WORDS)),)
OS = Windows
endif
TARGET_ARCHITECTURE ?= $(CONFIG_ARCH)
TARGET_MACHINE := $(firstword $(TARGET_TRIPLET_WORDS))
ifeq ($(OS),Windows)
EXEEXT = .exe
endif
COMMON_CFLAGS = -g $(C_OPT) -Wall -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -Wmissing-declarations -fno-strict-aliasing -I$(SPDK_ROOT_DIR)/include
ifneq ($(filter powerpc% ppc%,$(TARGET_MACHINE)),)
@ -127,11 +134,15 @@ COMMON_CFLAGS += -fno-common
# Enable full RELRO - no lazy relocation (resolve everything at load time).
# This allows the GOT to be made read-only early in the loading process.
ifneq ($(OS),Windows)
LDFLAGS += -Wl,-z,relro,-z,now
endif
# Make the stack non-executable.
# This is the default in most environments, but it doesn't hurt to set it explicitly.
ifneq ($(OS),Windows)
LDFLAGS += -Wl,-z,noexecstack
endif
# Specify the linker to use
ifneq ($(LD_TYPE),)
@ -253,8 +264,10 @@ ifneq (, $(SPDK_GIT_COMMIT))
COMMON_CFLAGS += -DSPDK_GIT_COMMIT=$(SPDK_GIT_COMMIT)
endif
ifneq ($(OS),Windows)
COMMON_CFLAGS += -pthread
LDFLAGS += -pthread
endif
CFLAGS += $(COMMON_CFLAGS) -Wno-pointer-sign -Wstrict-prototypes -Wold-style-definition -std=gnu99
CXXFLAGS += $(COMMON_CFLAGS)
@ -267,6 +280,11 @@ ifneq ($(CONFIG_NVME_CUSE)$(CONFIG_FUSE),nn)
SYS_LIBS += -lfuse3
endif
ifeq ($(OS).$(CC_TYPE),Windows.gcc)
# Include libssp.a for stack-protector and _FORTIFY_SOURCE
SYS_LIBS += -l:libssp.a
endif
MAKEFLAGS += --no-print-directory
C_SRCS += $(C_SRCS-y)