| 1 | # ################################################################ |
| 2 | # Copyright (c) Meta Platforms, Inc. and affiliates. |
| 3 | # All rights reserved. |
| 4 | # |
| 5 | # This source code is licensed under both the BSD-style license (found in the |
| 6 | # LICENSE file in the root directory of this source tree) and the GPLv2 (found |
| 7 | # in the COPYING file in the root directory of this source tree). |
| 8 | # You may select, at your option, one of the above-listed licenses. |
| 9 | # ################################################################ |
| 10 | |
| 11 | ZSTD ?= zstd # note: requires zstd installation on local system |
| 12 | |
| 13 | UNAME?= $(shell uname) |
| 14 | ifeq ($(UNAME), SunOS) |
| 15 | DIFF ?= gdiff |
| 16 | else |
| 17 | DIFF ?= diff |
| 18 | endif |
| 19 | |
| 20 | HARNESS_FILES=*.c |
| 21 | |
| 22 | MULTITHREAD_LDFLAGS = -pthread |
| 23 | DEBUGFLAGS= -g -DZSTD_DEBUG=1 |
| 24 | CPPFLAGS += -I$(ZSTDDIR) -I$(ZSTDDIR)/common -I$(ZSTDDIR)/compress \ |
| 25 | -I$(ZSTDDIR)/dictBuilder -I$(ZSTDDIR)/deprecated -I$(PRGDIR) |
| 26 | CFLAGS ?= -O2 |
| 27 | CFLAGS += -Wall -Wextra -Wcast-qual -Wcast-align -Wshadow \ |
| 28 | -Wstrict-aliasing=1 -Wswitch-enum \ |
| 29 | -Wredundant-decls -Wstrict-prototypes -Wundef \ |
| 30 | -Wvla -Wformat=2 -Winit-self -Wfloat-equal -Wwrite-strings \ |
| 31 | -std=c99 |
| 32 | CFLAGS += $(DEBUGFLAGS) |
| 33 | CFLAGS += $(MOREFLAGS) |
| 34 | FLAGS = $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) $(MULTITHREAD_LDFLAGS) |
| 35 | |
| 36 | harness: $(HARNESS_FILES) |
| 37 | $(CC) $(FLAGS) $^ -o $@ |
| 38 | |
| 39 | clean: |
| 40 | @$(RM) harness *.o |
| 41 | @$(RM) -rf harness.dSYM # MacOS specific |
| 42 | |
| 43 | test: harness |
| 44 | # |
| 45 | # Testing single-file decompression with educational decoder |
| 46 | # |
| 47 | @$(ZSTD) -f README.md -o tmp.zst |
| 48 | @./harness tmp.zst tmp |
| 49 | @$(DIFF) -s tmp README.md |
| 50 | @$(RM) tmp* |
| 51 | # |
| 52 | # Testing dictionary decompression with education decoder |
| 53 | # |
| 54 | # note : files are presented multiple for training, to reach minimum threshold |
| 55 | @$(ZSTD) --train harness.c zstd_decompress.c zstd_decompress.h README.md \ |
| 56 | harness.c zstd_decompress.c zstd_decompress.h README.md \ |
| 57 | harness.c zstd_decompress.c zstd_decompress.h README.md \ |
| 58 | -o dictionary |
| 59 | @$(ZSTD) -f README.md -D dictionary -o tmp.zst |
| 60 | @./harness tmp.zst tmp dictionary |
| 61 | @$(DIFF) -s tmp README.md |
| 62 | @$(RM) tmp* dictionary |