blob: a0e00dca0303b203db0f64bcd8d6f01dd7e39567 [file] [log] [blame]
William A. Kennington IIIac69b482021-06-02 12:28:27 -07001From ab9a34c92eec815ef214470c927ddbe2e950e7e5 Mon Sep 17 00:00:00 2001
2From: Joshua Watt <JPEWhacker@gmail.com>
3Date: Wed, 26 May 2021 09:15:40 -0500
4Subject: [PATCH] MinGW Build Fixes
5
6Fixes building on MinGW by
7 1) Exporting the OS variable so that it is visible to sub-make
8 invocations
9 2) Fixing the extension handling so that make correctly identifies when
10 targets need to be rebuilt. Without the correct handling, make would
11 rebuild the executable targets when running `make install` because
12 it couldn't find them with the correct extension.
13
14Upstream-Status: Submitted [https://github.com/facebook/zstd/pull/2685]
15Signed-off-by: Joshua Watt <JPEWhacker@gmail.com>
16---
17 Makefile | 1 +
18 programs/Makefile | 74 +++++++++++++++++++++++------------------------
19 2 files changed, 38 insertions(+), 37 deletions(-)
20
21diff --git a/Makefile b/Makefile
22index c1908f0a..f9ce9504 100644
23--- a/Makefile
24+++ b/Makefile
25@@ -29,6 +29,7 @@ VOID = /dev/null
26 # fail on other tested distros (ubuntu, debian) even
27 # without manually specifying the TARGET_SYSTEM.
28 TARGET_SYSTEM ?= $(OS)
29+export OS
30
31 ifneq (,$(filter Windows%,$(TARGET_SYSTEM)))
32 EXT =.exe
33diff --git a/programs/Makefile b/programs/Makefile
34index 599fb02f..79b45c83 100644
35--- a/programs/Makefile
36+++ b/programs/Makefile
37@@ -209,37 +209,37 @@ SET_CACHE_DIRECTORY = \
38
39
40 .PHONY: all
41-all: zstd
42+all: zstd$(EXT)
43
44 .PHONY: allVariants
45-allVariants: zstd zstd-compress zstd-decompress zstd-small zstd-nolegacy zstd-dictBuilder
46+allVariants: zstd$(EXT) zstd-compress$(EXT) zstd-decompress$(EXT) zstd-small$(EXT) zstd-nolegacy$(EXT) zstd-dictBuilder$(EXT)
47
48 .PHONY: zstd # must always be run
49-zstd : CPPFLAGS += $(THREAD_CPP) $(ZLIBCPP) $(LZMACPP) $(LZ4CPP)
50-zstd : LDFLAGS += $(THREAD_LD) $(DEBUGFLAGS_LD)
51-zstd : LDLIBS += $(ZLIBLD) $(LZMALD) $(LZ4LD)
52-zstd : CPPFLAGS += -DZSTD_LEGACY_SUPPORT=$(ZSTD_LEGACY_SUPPORT)
53+zstd$(EXT) : CPPFLAGS += $(THREAD_CPP) $(ZLIBCPP) $(LZMACPP) $(LZ4CPP)
54+zstd$(EXT) : LDFLAGS += $(THREAD_LD) $(DEBUGFLAGS_LD)
55+zstd$(EXT) : LDLIBS += $(ZLIBLD) $(LZMALD) $(LZ4LD)
56+zstd$(EXT) : CPPFLAGS += -DZSTD_LEGACY_SUPPORT=$(ZSTD_LEGACY_SUPPORT)
57 ifneq (,$(filter Windows%,$(OS)))
58-zstd : $(RES_FILE)
59+zstd$(EXT) : $(RES_FILE)
60 endif
61
62 ifndef BUILD_DIR
63 # generate BUILD_DIR from flags
64
65-zstd:
66+zstd$(EXT):
67 $(SET_CACHE_DIRECTORY)
68
69 else
70 # BUILD_DIR is defined
71
72 ZSTD_OBJ := $(addprefix $(BUILD_DIR)/, $(ZSTD_ALL_OBJ))
73-$(BUILD_DIR)/zstd : $(ZSTD_OBJ)
74+$(BUILD_DIR)/zstd$(EXT) : $(ZSTD_OBJ)
75 @echo "$(THREAD_MSG)"
76 @echo "$(ZLIB_MSG)"
77 @echo "$(LZMA_MSG)"
78 @echo "$(LZ4_MSG)"
79 @echo LINK $@
80- $(CC) $(FLAGS) $^ $(LDLIBS) -o $@$(EXT)
81+ $(CC) $(FLAGS) $^ $(LDLIBS) -o $@
82
83 ifeq ($(HAVE_HASH),1)
84 SRCBIN_HASH = $(shell cat $(BUILD_DIR)/zstd 2> $(VOID) | $(HASH) | cut -f 1 -d " ")
85@@ -249,7 +249,7 @@ else
86 BIN_ISDIFFERENT = 1
87 endif
88
89-zstd : $(BUILD_DIR)/zstd
90+zstd$(EXT) : $(BUILD_DIR)/zstd$(EXT)
91 if [ $(BIN_ISDIFFERENT) -eq 1 ]; then \
92 cp -f $< $@; \
93 echo zstd build completed; \
94@@ -263,46 +263,46 @@ endif # BUILD_DIR
95 .PHONY: zstd-release
96 zstd-release: DEBUGFLAGS := -DBACKTRACE_ENABLE=0
97 zstd-release: DEBUGFLAGS_LD :=
98-zstd-release: zstd
99+zstd-release: zstd$(EXT)
100
101-zstd32 : CPPFLAGS += $(THREAD_CPP)
102-zstd32 : LDFLAGS += $(THREAD_LD)
103-zstd32 : CPPFLAGS += -DZSTD_LEGACY_SUPPORT=$(ZSTD_LEGACY_SUPPORT)
104+zstd32$(EXT) : CPPFLAGS += $(THREAD_CPP)
105+zstd32$(EXT) : LDFLAGS += $(THREAD_LD)
106+zstd32$(EXT) : CPPFLAGS += -DZSTD_LEGACY_SUPPORT=$(ZSTD_LEGACY_SUPPORT)
107 ifneq (,$(filter Windows%,$(OS)))
108-zstd32 : $(RES32_FILE)
109+zstd32$(EXT) : $(RES32_FILE)
110 endif
111-zstd32 : $(ZSTDLIB_FULL_SRC) $(ZSTD_CLI_SRC)
112- $(CC) -m32 $(FLAGS) $^ -o $@$(EXT)
113+zstd32$(EXT) : $(ZSTDLIB_FULL_SRC) $(ZSTD_CLI_SRC)
114+ $(CC) -m32 $(FLAGS) $^ -o $@
115
116 ## zstd-nolegacy: same scope as zstd, with just support of legacy formats removed
117-zstd-nolegacy : LDFLAGS += $(THREAD_LD) $(ZLIBLD) $(LZMALD) $(LZ4LD) $(DEBUGFLAGS_LD)
118-zstd-nolegacy : $(ZSTDLIB_CORE_SRC) $(ZDICT_SRC) $(ZSTD_CLI_OBJ)
119- $(CC) $(FLAGS) $^ -o $@$(EXT) $(LDFLAGS)
120+zstd-nolegacy$(EXT) : LDFLAGS += $(THREAD_LD) $(ZLIBLD) $(LZMALD) $(LZ4LD) $(DEBUGFLAGS_LD)
121+zstd-nolegacy$(EXT) : $(ZSTDLIB_CORE_SRC) $(ZDICT_SRC) $(ZSTD_CLI_OBJ)
122+ $(CC) $(FLAGS) $^ -o $@ $(LDFLAGS)
123
124 .PHONY: zstd-nomt
125 zstd-nomt : THREAD_CPP :=
126 zstd-nomt : THREAD_LD :=
127 zstd-nomt : THREAD_MSG := - multi-threading disabled
128-zstd-nomt : zstd
129+zstd-nomt : zstd$(EXT)
130
131 .PHONY: zstd-nogz
132 zstd-nogz : ZLIBCPP :=
133 zstd-nogz : ZLIBLD :=
134 zstd-nogz : ZLIB_MSG := - gzip support is disabled
135-zstd-nogz : zstd
136+zstd-nogz : zstd$(EXT)
137
138 .PHONY: zstd-noxz
139 zstd-noxz : LZMACPP :=
140 zstd-noxz : LZMALD :=
141 zstd-noxz : LZMA_MSG := - xz/lzma support is disabled
142-zstd-noxz : zstd
143+zstd-noxz : zstd$(EXT)
144
145 ## zstd-dll: zstd executable linked to dynamic library libzstd (must have same version)
146 .PHONY: zstd-dll
147 zstd-dll : LDFLAGS+= -L$(ZSTDDIR)
148 zstd-dll : LDLIBS += -lzstd
149 zstd-dll : ZSTDLIB_LOCAL_SRC = xxhash.c
150-zstd-dll : zstd
151+zstd-dll : zstd$(EXT)
152
153
154 ## zstd-pgo: zstd executable optimized with PGO.
155@@ -321,23 +321,23 @@ zstd-pgo :
156 $(MAKE) zstd MOREFLAGS=-fprofile-use
157
158 ## zstd-small: minimal target, supporting only zstd compression and decompression. no bench. no legacy. no other format.
159-zstd-small: CFLAGS = -Os -s
160-zstd-frugal zstd-small: $(ZSTDLIB_CORE_SRC) zstdcli.c util.c timefn.c fileio.c
161- $(CC) $(FLAGS) -DZSTD_NOBENCH -DZSTD_NODICT -DZSTD_NOTRACE $^ -o $@$(EXT)
162+zstd-small$(EXT): CFLAGS = -Os -s
163+zstd-frugal$(EXT) zstd-small$(EXT): $(ZSTDLIB_CORE_SRC) zstdcli.c util.c timefn.c fileio.c
164+ $(CC) $(FLAGS) -DZSTD_NOBENCH -DZSTD_NODICT -DZSTD_NOTRACE $^ -o $@
165
166-zstd-decompress: $(ZSTDLIB_COMMON_C) $(ZSTDLIB_DECOMPRESS_C) zstdcli.c util.c timefn.c fileio.c
167- $(CC) $(FLAGS) -DZSTD_NOBENCH -DZSTD_NODICT -DZSTD_NOCOMPRESS -DZSTD_NOTRACE $^ -o $@$(EXT)
168+zstd-decompress$(EXT): $(ZSTDLIB_COMMON_C) $(ZSTDLIB_DECOMPRESS_C) zstdcli.c util.c timefn.c fileio.c
169+ $(CC) $(FLAGS) -DZSTD_NOBENCH -DZSTD_NODICT -DZSTD_NOCOMPRESS -DZSTD_NOTRACE $^ -o $@
170
171-zstd-compress: $(ZSTDLIB_COMMON_C) $(ZSTDLIB_COMPRESS_C) zstdcli.c util.c timefn.c fileio.c
172- $(CC) $(FLAGS) -DZSTD_NOBENCH -DZSTD_NODICT -DZSTD_NODECOMPRESS -DZSTD_NOTRACE $^ -o $@$(EXT)
173+zstd-compress$(EXT): $(ZSTDLIB_COMMON_C) $(ZSTDLIB_COMPRESS_C) zstdcli.c util.c timefn.c fileio.c
174+ $(CC) $(FLAGS) -DZSTD_NOBENCH -DZSTD_NODICT -DZSTD_NODECOMPRESS -DZSTD_NOTRACE $^ -o $@
175
176 ## zstd-dictBuilder: executable supporting dictionary creation and compression (only)
177-zstd-dictBuilder: CPPFLAGS += -DZSTD_NOBENCH -DZSTD_NODECOMPRESS -DZSTD_NOTRACE
178-zstd-dictBuilder: $(ZSTDLIB_COMMON_C) $(ZSTDLIB_COMPRESS_C) $(ZDICT_SRC) zstdcli.c util.c timefn.c fileio.c dibio.c
179- $(CC) $(FLAGS) $^ -o $@$(EXT)
180+zstd-dictBuilder$(EXT): CPPFLAGS += -DZSTD_NOBENCH -DZSTD_NODECOMPRESS -DZSTD_NOTRACE
181+zstd-dictBuilder$(EXT): $(ZSTDLIB_COMMON_C) $(ZSTDLIB_COMPRESS_C) $(ZDICT_SRC) zstdcli.c util.c timefn.c fileio.c dibio.c
182+ $(CC) $(FLAGS) $^ -o $@
183
184-zstdmt: zstd
185- ln -sf zstd zstdmt
186+zstdmt$(EXT): zstd$(EXT)
187+ ln -sf zstd$(EXT) zstdmt$(EXT)
188
189 .PHONY: generate_res
190 generate_res: $(RES64_FILE) $(RES32_FILE)
191--
1922.31.1
193