2019-05-22 21:16:55 +00:00
|
|
|
GOOS ?= $(shell go env GOOS)
|
|
|
|
GOARCH ?= $(shell go env GOARCH)
|
|
|
|
GOOS_GOARCH := $(GOOS)_$(GOARCH)
|
|
|
|
GOOS_GOARCH_NATIVE := $(shell go env GOHOSTOS)_$(shell go env GOHOSTARCH)
|
|
|
|
LIBZSTD_NAME := libzstd_$(GOOS_GOARCH).a
|
2023-04-06 04:46:58 +00:00
|
|
|
ZSTD_VERSION ?= v1.5.5
|
2023-05-19 01:02:32 +00:00
|
|
|
ZIG_BUILDER_IMAGE=euantorano/zig:0.10.1
|
|
|
|
BUILDER_IMAGE := local/builder_musl:2.0.0-$(shell echo $(ZIG_BUILDER_IMAGE) | tr : _ | tr / _)-1
|
2019-05-22 21:16:55 +00:00
|
|
|
|
2022-02-07 16:31:13 +00:00
|
|
|
.PHONY: libzstd.a $(LIBZSTD_NAME)
|
2019-05-22 21:16:55 +00:00
|
|
|
|
|
|
|
libzstd.a: $(LIBZSTD_NAME)
|
|
|
|
$(LIBZSTD_NAME):
|
|
|
|
ifeq ($(GOOS_GOARCH),$(GOOS_GOARCH_NATIVE))
|
2023-05-19 01:02:32 +00:00
|
|
|
rm -f $(LIBZSTD_NAME)
|
2019-08-15 09:57:09 +00:00
|
|
|
cd zstd/lib && ZSTD_LEGACY_SUPPORT=0 MOREFLAGS=$(MOREFLAGS) $(MAKE) clean libzstd.a
|
2019-05-22 21:16:55 +00:00
|
|
|
mv zstd/lib/libzstd.a $(LIBZSTD_NAME)
|
2023-05-19 01:02:32 +00:00
|
|
|
else ifeq ($(GOOS_GOARCH),linux_amd64)
|
|
|
|
TARGET=x86_64-linux GOARCH=amd64 GOOS=linux $(MAKE) package-arch
|
|
|
|
else ifeq ($(GOOS_GOARCH),linux_arm)
|
|
|
|
TARGET=arm-linux-gnueabi GOARCH=arm GOOS=linux $(MAKE) package-arch
|
|
|
|
else ifeq ($(GOOS_GOARCH),linux_arm64)
|
|
|
|
TARGET=aarch64-linux GOARCH=arm64 GOOS=linux $(MAKE) package-arch
|
|
|
|
else ifeq ($(GOOS_GOARCH),linux_musl_amd64)
|
|
|
|
TARGET=x86_64-linux-musl GOARCH=amd64 GOOS=linux_musl $(MAKE) package-arch
|
|
|
|
else ifeq ($(GOOS_GOARCH),linux_musl_arm64)
|
|
|
|
TARGET=aarch64-linux-musl GOARCH=arm64 GOOS=linux_musl $(MAKE) package-arch
|
|
|
|
else ifeq ($(GOOS_GOARCH),darwin_arm64)
|
|
|
|
TARGET=aarch64-macos GOARCH=arm64 GOOS=darwin $(MAKE) package-arch
|
|
|
|
else ifeq ($(GOOS_GOARCH),darwin_amd64)
|
|
|
|
TARGET=x86_64-macos GOARCH=amd64 GOOS=darwin $(MAKE) package-arch
|
|
|
|
else ifeq ($(GOOS_GOARCH),windows_amd64)
|
|
|
|
TARGET=x86_64-windows GOARCH=amd64 GOOS=windows GOARCH=amd64 $(MAKE) package-arch
|
2019-05-22 21:16:55 +00:00
|
|
|
endif
|
|
|
|
|
2021-09-22 17:06:25 +00:00
|
|
|
package-builder:
|
|
|
|
(docker image ls --format '{{.Repository}}:{{.Tag}}' | grep -q '$(BUILDER_IMAGE)$$') \
|
|
|
|
|| docker build \
|
2023-05-19 01:02:32 +00:00
|
|
|
--build-arg builder_image=$(ZIG_BUILDER_IMAGE) \
|
2021-09-22 17:06:25 +00:00
|
|
|
--tag $(BUILDER_IMAGE) \
|
|
|
|
builder
|
|
|
|
|
2023-05-19 01:02:32 +00:00
|
|
|
package-arch: package-builder
|
|
|
|
rm -f $(LIBZSTD_NAME)
|
2022-02-07 16:31:13 +00:00
|
|
|
docker run --rm \
|
|
|
|
--mount type=bind,src="$(shell pwd)",dst=/zstd \
|
|
|
|
-w /zstd \
|
|
|
|
$(DOCKER_OPTS) \
|
|
|
|
$(BUILDER_IMAGE) \
|
2023-05-19 01:02:32 +00:00
|
|
|
-c 'cd zstd/lib && \
|
|
|
|
ZSTD_LEGACY_SUPPORT=0 AR="zig ar" \
|
|
|
|
CC="zig cc -target $(TARGET)" \
|
|
|
|
CXX="zig cc -target $(TARGET)" \
|
|
|
|
MOREFLAGS=$(MOREFLAGS) \
|
|
|
|
$(MAKE) clean libzstd.a'
|
|
|
|
mv -f zstd/lib/libzstd.a $(LIBZSTD_NAME)
|
2022-02-07 16:31:13 +00:00
|
|
|
|
2023-05-19 01:02:32 +00:00
|
|
|
# freebsd and illumos aren't supported by zig compiler atm.
|
|
|
|
release:
|
|
|
|
GOOS=linux GOARCH=amd64 $(MAKE) libzstd.a
|
|
|
|
GOOS=linux GOARCH=arm64 $(MAKE) libzstd.a
|
|
|
|
GOOS=linux GOARCH=arm $(MAKE) libzstd.a
|
|
|
|
GOOS=linux_musl GOARCH=amd64 $(MAKE) libzstd.a
|
|
|
|
GOOS=linux_musl GOARCH=arm64 $(MAKE) libzstd.a
|
|
|
|
GOOS=darwin GOARCH=arm64 $(MAKE) libzstd.a
|
|
|
|
GOOS=darwin GOARCH=amd64 $(MAKE) libzstd.a
|
|
|
|
GOOS=windows GOARCH=amd64 $(MAKE) libzstd.a
|
2021-09-22 17:06:25 +00:00
|
|
|
|
2019-05-22 21:16:55 +00:00
|
|
|
clean:
|
|
|
|
rm -f $(LIBZSTD_NAME)
|
2019-08-27 22:04:44 +00:00
|
|
|
cd zstd && $(MAKE) clean
|
2019-05-22 21:16:55 +00:00
|
|
|
|
|
|
|
update-zstd:
|
|
|
|
rm -rf zstd-tmp
|
2019-08-15 09:57:09 +00:00
|
|
|
git clone --branch $(ZSTD_VERSION) --depth 1 https://github.com/Facebook/zstd zstd-tmp
|
2019-05-22 21:16:55 +00:00
|
|
|
rm -rf zstd-tmp/.git
|
|
|
|
rm -rf zstd
|
|
|
|
mv zstd-tmp zstd
|
|
|
|
$(MAKE) clean libzstd.a
|
|
|
|
cp zstd/lib/zstd.h .
|
2021-05-16 22:41:26 +00:00
|
|
|
cp zstd/lib/zdict.h .
|
|
|
|
cp zstd/lib/zstd_errors.h .
|
2019-05-22 21:16:55 +00:00
|
|
|
|
|
|
|
test:
|
|
|
|
CGO_ENABLED=1 GODEBUG=cgocheck=2 go test -v
|
|
|
|
|
|
|
|
bench:
|
|
|
|
CGO_ENABLED=1 go test -bench=.
|