Makefile 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506
  1. # ################################################################
  2. # xxHash Makefile
  3. # Copyright (C) 2012-2020 Yann Collet
  4. #
  5. # GPL v2 License
  6. #
  7. # This program is free software; you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation; either version 2 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License along
  18. # with this program; if not, write to the Free Software Foundation, Inc.,
  19. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  20. #
  21. # You can contact the author at:
  22. # - xxHash homepage: https://www.xxhash.com
  23. # - xxHash source repository: https://github.com/Cyan4973/xxHash
  24. # ################################################################
  25. # xxhsum: provides 32/64 bits hash of one or multiple files, or stdin
  26. # ################################################################
  27. Q = $(if $(filter 1,$(V) $(VERBOSE)),,@)
  28. # Version numbers
  29. SED ?= sed
  30. SED_ERE_OPT ?= -E
  31. LIBVER_MAJOR_SCRIPT:=`$(SED) -n '/define XXH_VERSION_MAJOR/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < xxhash.h`
  32. LIBVER_MINOR_SCRIPT:=`$(SED) -n '/define XXH_VERSION_MINOR/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < xxhash.h`
  33. LIBVER_PATCH_SCRIPT:=`$(SED) -n '/define XXH_VERSION_RELEASE/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < xxhash.h`
  34. LIBVER_MAJOR := $(shell echo $(LIBVER_MAJOR_SCRIPT))
  35. LIBVER_MINOR := $(shell echo $(LIBVER_MINOR_SCRIPT))
  36. LIBVER_PATCH := $(shell echo $(LIBVER_PATCH_SCRIPT))
  37. LIBVER := $(LIBVER_MAJOR).$(LIBVER_MINOR).$(LIBVER_PATCH)
  38. CFLAGS ?= -O3
  39. DEBUGFLAGS+=-Wall -Wextra -Wconversion -Wcast-qual -Wcast-align -Wshadow \
  40. -Wstrict-aliasing=1 -Wswitch-enum -Wdeclaration-after-statement \
  41. -Wstrict-prototypes -Wundef -Wpointer-arith -Wformat-security \
  42. -Wvla -Wformat=2 -Winit-self -Wfloat-equal -Wwrite-strings \
  43. -Wredundant-decls -Wstrict-overflow=2
  44. CFLAGS += $(DEBUGFLAGS) $(MOREFLAGS)
  45. FLAGS = $(CFLAGS) $(CPPFLAGS)
  46. XXHSUM_VERSION = $(LIBVER)
  47. UNAME := $(shell uname)
  48. # Define *.exe as extension for Windows systems
  49. ifneq (,$(filter Windows%,$(OS)))
  50. EXT =.exe
  51. else
  52. EXT =
  53. endif
  54. # OS X linker doesn't support -soname, and use different extension
  55. # see: https://developer.apple.com/library/mac/documentation/DeveloperTools/Conceptual/DynamicLibraries/100-Articles/DynamicLibraryDesignGuidelines.html
  56. ifeq ($(UNAME), Darwin)
  57. SHARED_EXT = dylib
  58. SHARED_EXT_MAJOR = $(LIBVER_MAJOR).$(SHARED_EXT)
  59. SHARED_EXT_VER = $(LIBVER).$(SHARED_EXT)
  60. SONAME_FLAGS = -install_name $(LIBDIR)/libxxhash.$(SHARED_EXT_MAJOR) -compatibility_version $(LIBVER_MAJOR) -current_version $(LIBVER)
  61. else
  62. SONAME_FLAGS = -Wl,-soname=libxxhash.$(SHARED_EXT).$(LIBVER_MAJOR)
  63. SHARED_EXT = so
  64. SHARED_EXT_MAJOR = $(SHARED_EXT).$(LIBVER_MAJOR)
  65. SHARED_EXT_VER = $(SHARED_EXT).$(LIBVER)
  66. endif
  67. LIBXXH = libxxhash.$(SHARED_EXT_VER)
  68. XXHSUM_SRC_DIR = cli
  69. XXHSUM_SPLIT_SRCS = $(XXHSUM_SRC_DIR)/xsum_os_specific.c \
  70. $(XXHSUM_SRC_DIR)/xsum_output.c \
  71. $(XXHSUM_SRC_DIR)/xsum_sanity_check.c
  72. XXHSUM_SPLIT_OBJS = $(XXHSUM_SPLIT_SRCS:.c=.o)
  73. XXHSUM_HEADERS = $(XXHSUM_SRC_DIR)/xsum_config.h \
  74. $(XXHSUM_SRC_DIR)/xsum_arch.h \
  75. $(XXHSUM_SRC_DIR)/xsum_os_specific.h \
  76. $(XXHSUM_SRC_DIR)/xsum_output.h \
  77. $(XXHSUM_SRC_DIR)/xsum_sanity_check.h
  78. ## generate CLI and libraries in release mode (default for `make`)
  79. .PHONY: default
  80. default: DEBUGFLAGS=
  81. default: lib xxhsum_and_links
  82. .PHONY: all
  83. all: lib xxhsum xxhsum_inlinedXXH
  84. ## xxhsum is the command line interface (CLI)
  85. ifeq ($(DISPATCH),1)
  86. xxhsum: CPPFLAGS += -DXXHSUM_DISPATCH=1
  87. xxhsum: xxh_x86dispatch.o
  88. endif
  89. xxhsum: xxhash.o xxhsum.o $(XXHSUM_SPLIT_OBJS)
  90. $(CC) $(FLAGS) $^ $(LDFLAGS) -o $@$(EXT)
  91. xxhsum32: CFLAGS += -m32 ## generate CLI in 32-bits mode
  92. xxhsum32: xxhash.c xxhsum.c $(XXHSUM_SPLIT_SRCS) ## do not generate object (avoid mixing different ABI)
  93. $(CC) $(FLAGS) $^ $(LDFLAGS) -o $@$(EXT)
  94. ## dispatch only works for x86/x64 systems
  95. dispatch: CPPFLAGS += -DXXHSUM_DISPATCH=1
  96. dispatch: xxhash.o xxh_x86dispatch.o xxhsum.c $(XXHSUM_SPLIT_SRCS)
  97. $(CC) $(FLAGS) $^ $(LDFLAGS) -o $@$(EXT)
  98. xxhash.o: xxhash.c xxhash.h
  99. xxhsum.o: xxhsum.c $(XXHSUM_HEADERS) \
  100. xxhash.h xxh_x86dispatch.h
  101. xxh_x86dispatch.o: xxh_x86dispatch.c xxh_x86dispatch.h xxhash.h
  102. .PHONY: xxhsum_and_links
  103. xxhsum_and_links: xxhsum xxh32sum xxh64sum xxh128sum
  104. xxh32sum xxh64sum xxh128sum: xxhsum
  105. ln -sf $<$(EXT) $@$(EXT)
  106. xxhsum_inlinedXXH: CPPFLAGS += -DXXH_INLINE_ALL
  107. xxhsum_inlinedXXH: xxhsum.c $(XXHSUM_SPLIT_SRCS)
  108. $(CC) $(FLAGS) $< -o $@$(EXT)
  109. # library
  110. libxxhash.a: ARFLAGS = rcs
  111. libxxhash.a: xxhash.o
  112. $(AR) $(ARFLAGS) $@ $^
  113. $(LIBXXH): LDFLAGS += -shared
  114. ifeq (,$(filter Windows%,$(OS)))
  115. $(LIBXXH): CFLAGS += -fPIC
  116. endif
  117. ifeq ($(DISPATCH),1)
  118. $(LIBXXH): xxh_x86dispatch.c
  119. endif
  120. $(LIBXXH): xxhash.c
  121. $(CC) $(FLAGS) $^ $(LDFLAGS) $(SONAME_FLAGS) -o $@
  122. ln -sf $@ libxxhash.$(SHARED_EXT_MAJOR)
  123. ln -sf $@ libxxhash.$(SHARED_EXT)
  124. .PHONY: libxxhash
  125. libxxhash: ## generate dynamic xxhash library
  126. libxxhash: $(LIBXXH)
  127. .PHONY: lib
  128. lib: ## generate static and dynamic xxhash libraries
  129. lib: libxxhash.a libxxhash
  130. # helper targets
  131. AWK = awk
  132. GREP = grep
  133. SORT = sort
  134. .PHONY: list
  135. list: ## list all Makefile targets
  136. $(Q)$(MAKE) -pRrq -f $(lastword $(MAKEFILE_LIST)) : 2>/dev/null | $(AWK) -v RS= -F: '/^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' | $(SORT) | egrep -v -e '^[^[:alnum:]]' -e '^$@$$' | xargs
  137. .PHONY: help
  138. help: ## list documented targets
  139. $(Q)$(GREP) -E '^[0-9a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | \
  140. $(SORT) | \
  141. $(AWK) 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
  142. .PHONY: clean
  143. clean: ## remove all build artifacts
  144. $(Q)$(RM) -r *.dSYM # Mac OS-X specific
  145. $(Q)$(RM) core *.o *.obj *.$(SHARED_EXT) *.$(SHARED_EXT).* *.a libxxhash.pc
  146. $(Q)$(RM) xxhsum$(EXT) xxhsum32$(EXT) xxhsum_inlinedXXH$(EXT) dispatch$(EXT)
  147. $(Q)$(RM) xxh32sum$(EXT) xxh64sum$(EXT) xxh128sum$(EXT)
  148. $(Q)$(RM) $(XXHSUM_SRC_DIR)/*.o $(XXHSUM_SRC_DIR)/*.obj
  149. @echo cleaning completed
  150. # =================================================
  151. # tests
  152. # =================================================
  153. # make check can be run with cross-compiled binaries on emulated environments (qemu user mode)
  154. # by setting $(RUN_ENV) to the target emulation environment
  155. .PHONY: check
  156. check: xxhsum ## basic tests for xxhsum CLI, set RUN_ENV for emulated environments
  157. # stdin
  158. $(RUN_ENV) ./xxhsum$(EXT) < xxhash.c
  159. # multiple files
  160. $(RUN_ENV) ./xxhsum$(EXT) xxhash.* xxhsum.*
  161. # internal bench
  162. $(RUN_ENV) ./xxhsum$(EXT) -bi0
  163. # long bench command
  164. $(RUN_ENV) ./xxhsum$(EXT) --benchmark-all -i0
  165. # bench multiple variants
  166. $(RUN_ENV) ./xxhsum$(EXT) -b1,2,3 -i0
  167. # file bench
  168. $(RUN_ENV) ./xxhsum$(EXT) -bi0 xxhash.c
  169. # 32-bit
  170. $(RUN_ENV) ./xxhsum$(EXT) -H0 xxhash.c
  171. # 128-bit
  172. $(RUN_ENV) ./xxhsum$(EXT) -H2 xxhash.c
  173. # request incorrect variant
  174. $(RUN_ENV) ./xxhsum$(EXT) -H9 xxhash.c ; test $$? -eq 1
  175. @printf "\n ....... checks completed successfully ....... \n"
  176. .PHONY: test-unicode
  177. test-unicode:
  178. $(MAKE) -C tests test_unicode
  179. .PHONY: test-mem
  180. VALGRIND = valgrind --leak-check=yes --error-exitcode=1
  181. test-mem: RUN_ENV = $(VALGRIND)
  182. test-mem: xxhsum check
  183. .PHONY: test32
  184. test32: clean xxhsum32
  185. @echo ---- test 32-bit ----
  186. ./xxhsum32 -bi1 xxhash.c
  187. .PHONY: test-xxhsum-c
  188. test-xxhsum-c: xxhsum
  189. # xxhsum to/from pipe
  190. ./xxhsum xxh* | ./xxhsum -c -
  191. ./xxhsum -H0 xxh* | ./xxhsum -c -
  192. # xxhsum -q does not display "Loading" message into stderr (#251)
  193. ! ./xxhsum -q xxh* 2>&1 | grep Loading
  194. # xxhsum does not display "Loading" message into stderr either
  195. ! ./xxhsum xxh* 2>&1 | grep Loading
  196. # Check that xxhsum do display filename that it failed to open.
  197. LC_ALL=C ./xxhsum nonexistent 2>&1 | grep "Error: Could not open 'nonexistent'"
  198. # xxhsum to/from file, shell redirection
  199. ./xxhsum xxh* > .test.xxh64
  200. ./xxhsum --tag xxh* > .test.xxh64_tag
  201. ./xxhsum --little-endian xxh* > .test.le_xxh64
  202. ./xxhsum --tag --little-endian xxh* > .test.le_xxh64_tag
  203. ./xxhsum -H0 xxh* > .test.xxh32
  204. ./xxhsum -H0 --tag xxh* > .test.xxh32_tag
  205. ./xxhsum -H0 --little-endian xxh* > .test.le_xxh32
  206. ./xxhsum -H0 --tag --little-endian xxh* > .test.le_xxh32_tag
  207. ./xxhsum -H2 xxh* > .test.xxh128
  208. ./xxhsum -H2 --tag xxh* > .test.xxh128_tag
  209. ./xxhsum -H2 --little-endian xxh* > .test.le_xxh128
  210. ./xxhsum -H2 --tag --little-endian xxh* > .test.le_xxh128_tag
  211. ./xxhsum -c .test.xxh*
  212. ./xxhsum -c --little-endian .test.le_xxh*
  213. ./xxhsum -c .test.*_tag
  214. # read list of files from stdin
  215. ./xxhsum -c < .test.xxh64
  216. ./xxhsum -c < .test.xxh32
  217. cat .test.xxh* | ./xxhsum -c -
  218. # check variant with '*' marker as second separator
  219. $(SED) 's/ / \*/' .test.xxh32 | ./xxhsum -c
  220. # bsd-style output
  221. ./xxhsum --tag xxhsum* | $(GREP) XXH64
  222. ./xxhsum --tag -H0 xxhsum* | $(GREP) XXH32
  223. ./xxhsum --tag -H1 xxhsum* | $(GREP) XXH64
  224. ./xxhsum --tag -H2 xxhsum* | $(GREP) XXH128
  225. ./xxhsum --tag -H32 xxhsum* | $(GREP) XXH32
  226. ./xxhsum --tag -H64 xxhsum* | $(GREP) XXH64
  227. ./xxhsum --tag -H128 xxhsum* | $(GREP) XXH128
  228. ./xxhsum --tag -H0 --little-endian xxhsum* | $(GREP) XXH32_LE
  229. ./xxhsum --tag -H1 --little-endian xxhsum* | $(GREP) XXH64_LE
  230. ./xxhsum --tag -H2 --little-endian xxhsum* | $(GREP) XXH128_LE
  231. ./xxhsum --tag -H32 --little-endian xxhsum* | $(GREP) XXH32_LE
  232. ./xxhsum --tag -H64 --little-endian xxhsum* | $(GREP) XXH64_LE
  233. ./xxhsum --tag -H128 --little-endian xxhsum* | $(GREP) XXH128_LE
  234. # check bsd-style
  235. ./xxhsum --tag xxhsum* | ./xxhsum -c
  236. ./xxhsum --tag -H32 --little-endian xxhsum* | ./xxhsum -c
  237. # xxhsum -c warns improperly format lines.
  238. echo '12345678 ' >>.test.xxh32
  239. ./xxhsum -c .test.xxh32 | $(GREP) improperly
  240. echo '123456789 file' >>.test.xxh64
  241. ./xxhsum -c .test.xxh64 | $(GREP) improperly
  242. # Expects "FAILED"
  243. echo "0000000000000000 LICENSE" | ./xxhsum -c -; test $$? -eq 1
  244. echo "00000000 LICENSE" | ./xxhsum -c -; test $$? -eq 1
  245. # Expects "FAILED open or read"
  246. echo "0000000000000000 test-expects-file-not-found" | ./xxhsum -c -; test $$? -eq 1
  247. echo "00000000 test-expects-file-not-found" | ./xxhsum -c -; test $$? -eq 1
  248. @$(RM) .test.*
  249. .PHONY: armtest
  250. armtest: clean
  251. @echo ---- test ARM compilation ----
  252. CC=arm-linux-gnueabi-gcc MOREFLAGS="-Werror -static" $(MAKE) xxhsum
  253. .PHONY: clangtest
  254. clangtest: clean
  255. @echo ---- test clang compilation ----
  256. CC=clang MOREFLAGS="-Werror -Wconversion -Wno-sign-conversion" $(MAKE) all
  257. .PHONY: cxxtest
  258. cxxtest: clean
  259. @echo ---- test C++ compilation ----
  260. CC="$(CXX) -Wno-deprecated" $(MAKE) all CFLAGS="-O3 -Wall -Wextra -Wundef -Wshadow -Wcast-align -Werror -fPIC"
  261. .PHONY: c90test
  262. ifeq ($(NO_C90_TEST),true)
  263. c90test:
  264. @echo no c90 compatibility test
  265. else
  266. c90test: CPPFLAGS += -DXXH_NO_LONG_LONG
  267. c90test: CFLAGS += -std=c90 -Werror -pedantic
  268. c90test: xxhash.c
  269. @echo ---- test strict C90 compilation [xxh32 only] ----
  270. $(RM) xxhash.o
  271. $(CC) $(FLAGS) $^ $(LDFLAGS) -c
  272. $(RM) xxhash.o
  273. endif
  274. .PHONY: usan
  275. usan: CC=clang
  276. usan: CXX=clang++
  277. usan: ## check CLI runtime for undefined behavior, using clang's sanitizer
  278. @echo ---- check undefined behavior - sanitize ----
  279. $(MAKE) clean
  280. $(MAKE) test CC=$(CC) CXX=$(CXX) MOREFLAGS="-g -fsanitize=undefined -fno-sanitize-recover=all"
  281. .PHONY: staticAnalyze
  282. SCANBUILD ?= scan-build
  283. staticAnalyze: clean ## check C source files using $(SCANBUILD) static analyzer
  284. @echo ---- static analyzer - $(SCANBUILD) ----
  285. CFLAGS="-g -Werror" $(SCANBUILD) --status-bugs -v $(MAKE) all
  286. CPPCHECK ?= cppcheck
  287. .PHONY: cppcheck
  288. cppcheck: ## check C source files using $(CPPCHECK) static analyzer
  289. @echo ---- static analyzer - $(CPPCHECK) ----
  290. $(CPPCHECK) . --force --enable=warning,portability,performance,style --error-exitcode=1 > /dev/null
  291. .PHONY: namespaceTest
  292. namespaceTest: ## ensure XXH_NAMESPACE redefines all public symbols
  293. $(CC) -c xxhash.c
  294. $(CC) -DXXH_NAMESPACE=TEST_ -c xxhash.c -o xxhash2.o
  295. $(CC) xxhash.o xxhash2.o xxhsum.c $(XXHSUM_SPLIT_SRCS) -o xxhsum2 # will fail if one namespace missing (symbol collision)
  296. $(RM) *.o xxhsum2 # clean
  297. MD2ROFF ?= ronn
  298. MD2ROFF_FLAGS ?= --roff --warnings --manual="User Commands" --organization="xxhsum $(XXHSUM_VERSION)"
  299. xxhsum.1: xxhsum.1.md xxhash.h
  300. cat $< | $(MD2ROFF) $(MD2ROFF_FLAGS) | $(SED) -n '/^\.\\\".*/!p' > $@
  301. .PHONY: man
  302. man: xxhsum.1 ## generate man page from markdown source
  303. .PHONY: clean-man
  304. clean-man:
  305. $(RM) xxhsum.1
  306. .PHONY: preview-man
  307. preview-man: man
  308. man ./xxhsum.1
  309. .PHONY: test
  310. test: DEBUGFLAGS += -DXXH_DEBUGLEVEL=1
  311. test: all namespaceTest check test-xxhsum-c c90test test-tools
  312. .PHONY: test-inline
  313. test-inline:
  314. $(MAKE) -C tests test_multiInclude
  315. .PHONY: test-all
  316. test-all: CFLAGS += -Werror
  317. test-all: test test32 clangtest cxxtest usan test-inline listL120 trailingWhitespace test-unicode
  318. .PHONY: test-tools
  319. test-tools:
  320. CFLAGS=-Werror $(MAKE) -C tests/bench
  321. CFLAGS=-Werror $(MAKE) -C tests/collisions
  322. .PHONY: listL120
  323. listL120: # extract lines >= 120 characters in *.{c,h}, by Takayuki Matsuoka (note: $$, for Makefile compatibility)
  324. find . -type f -name '*.c' -o -name '*.h' | while read -r filename; do awk 'length > 120 {print FILENAME "(" FNR "): " $$0}' $$filename; done
  325. .PHONY: trailingWhitespace
  326. trailingWhitespace:
  327. ! $(GREP) -E "`printf '[ \\t]$$'`" xxhsum.1 *.c *.h LICENSE Makefile cmake_unofficial/CMakeLists.txt
  328. # =========================================================
  329. # make install is validated only for the following targets
  330. # =========================================================
  331. ifneq (,$(filter Linux Darwin GNU/kFreeBSD GNU Haiku OpenBSD FreeBSD NetBSD DragonFly SunOS CYGWIN% , $(UNAME)))
  332. DESTDIR ?=
  333. # directory variables: GNU conventions prefer lowercase
  334. # see https://www.gnu.org/prep/standards/html_node/Makefile-Conventions.html
  335. # support both lower and uppercase (BSD), use uppercase in script
  336. prefix ?= /usr/local
  337. PREFIX ?= $(prefix)
  338. exec_prefix ?= $(PREFIX)
  339. EXEC_PREFIX ?= $(exec_prefix)
  340. libdir ?= $(EXEC_PREFIX)/lib
  341. LIBDIR ?= $(libdir)
  342. includedir ?= $(PREFIX)/include
  343. INCLUDEDIR ?= $(includedir)
  344. bindir ?= $(EXEC_PREFIX)/bin
  345. BINDIR ?= $(bindir)
  346. datarootdir ?= $(PREFIX)/share
  347. mandir ?= $(datarootdir)/man
  348. man1dir ?= $(mandir)/man1
  349. ifneq (,$(filter $(UNAME),FreeBSD NetBSD DragonFly))
  350. PKGCONFIGDIR ?= $(PREFIX)/libdata/pkgconfig
  351. else
  352. PKGCONFIGDIR ?= $(LIBDIR)/pkgconfig
  353. endif
  354. ifneq (,$(filter $(UNAME),OpenBSD FreeBSD NetBSD DragonFly SunOS))
  355. MANDIR ?= $(PREFIX)/man/man1
  356. else
  357. MANDIR ?= $(man1dir)
  358. endif
  359. ifneq (,$(filter $(UNAME),SunOS))
  360. INSTALL ?= ginstall
  361. else
  362. INSTALL ?= install
  363. endif
  364. INSTALL_PROGRAM ?= $(INSTALL)
  365. INSTALL_DATA ?= $(INSTALL) -m 644
  366. PCLIBDIR ?= $(shell echo "$(LIBDIR)" | $(SED) -n $(SED_ERE_OPT) -e "s@^$(EXEC_PREFIX)(/|$$)@@p")
  367. PCINCDIR ?= $(shell echo "$(INCLUDEDIR)" | $(SED) -n $(SED_ERE_OPT) -e "s@^$(PREFIX)(/|$$)@@p")
  368. PCEXECDIR?= $(if $(filter $(PREFIX),$(EXEC_PREFIX)),$$\{prefix\},$(EXEC_PREFIX))
  369. ifeq (,$(PCLIBDIR))
  370. # Additional prefix check is required, since the empty string is technically a
  371. # valid PCLIBDIR
  372. ifeq (,$(shell echo "$(LIBDIR)" | $(SED) -n $(SED_ERE_OPT) -e "\\@^$(EXEC_PREFIX)(/|$$)@ p"))
  373. $(error configured libdir ($(LIBDIR)) is outside of exec_prefix ($(EXEC_PREFIX)), can't generate pkg-config file)
  374. endif
  375. endif
  376. ifeq (,$(PCINCDIR))
  377. # Additional prefix check is required, since the empty string is technically a
  378. # valid PCINCDIR
  379. ifeq (,$(shell echo "$(INCLUDEDIR)" | $(SED) -n $(SED_ERE_OPT) -e "\\@^$(PREFIX)(/|$$)@ p"))
  380. $(error configured includedir ($(INCLUDEDIR)) is outside of prefix ($(PREFIX)), can't generate pkg-config file)
  381. endif
  382. endif
  383. libxxhash.pc: libxxhash.pc.in
  384. @echo creating pkgconfig
  385. $(Q)$(SED) $(SED_ERE_OPT) -e 's|@PREFIX@|$(PREFIX)|' \
  386. -e 's|@EXECPREFIX@|$(PCEXECDIR)|' \
  387. -e 's|@LIBDIR@|$(PCLIBDIR)|' \
  388. -e 's|@INCLUDEDIR@|$(PCINCDIR)|' \
  389. -e 's|@VERSION@|$(LIBVER)|' \
  390. $< > $@
  391. .PHONY: install
  392. install: lib libxxhash.pc xxhsum ## install libraries, CLI, links and man page
  393. @echo Installing libxxhash
  394. $(Q)$(INSTALL) -d -m 755 $(DESTDIR)$(LIBDIR)
  395. $(Q)$(INSTALL_DATA) libxxhash.a $(DESTDIR)$(LIBDIR)
  396. $(Q)$(INSTALL_PROGRAM) $(LIBXXH) $(DESTDIR)$(LIBDIR)
  397. $(Q)ln -sf $(LIBXXH) $(DESTDIR)$(LIBDIR)/libxxhash.$(SHARED_EXT_MAJOR)
  398. $(Q)ln -sf $(LIBXXH) $(DESTDIR)$(LIBDIR)/libxxhash.$(SHARED_EXT)
  399. $(Q)$(INSTALL) -d -m 755 $(DESTDIR)$(INCLUDEDIR) # includes
  400. $(Q)$(INSTALL_DATA) xxhash.h $(DESTDIR)$(INCLUDEDIR)
  401. $(Q)$(INSTALL_DATA) xxh3.h $(DESTDIR)$(INCLUDEDIR) # for compatibility, will be removed in v0.9.0
  402. ifeq ($(DISPATCH),1)
  403. $(Q)$(INSTALL_DATA) xxh_x86dispatch.h $(DESTDIR)$(INCLUDEDIR)
  404. endif
  405. @echo Installing pkgconfig
  406. $(Q)$(INSTALL) -d -m 755 $(DESTDIR)$(PKGCONFIGDIR)/
  407. $(Q)$(INSTALL_DATA) libxxhash.pc $(DESTDIR)$(PKGCONFIGDIR)/
  408. @echo Installing xxhsum
  409. $(Q)$(INSTALL) -d -m 755 $(DESTDIR)$(BINDIR)/ $(DESTDIR)$(MANDIR)/
  410. $(Q)$(INSTALL_PROGRAM) xxhsum $(DESTDIR)$(BINDIR)/xxhsum
  411. $(Q)ln -sf xxhsum $(DESTDIR)$(BINDIR)/xxh32sum
  412. $(Q)ln -sf xxhsum $(DESTDIR)$(BINDIR)/xxh64sum
  413. $(Q)ln -sf xxhsum $(DESTDIR)$(BINDIR)/xxh128sum
  414. @echo Installing man pages
  415. $(Q)$(INSTALL_DATA) xxhsum.1 $(DESTDIR)$(MANDIR)/xxhsum.1
  416. $(Q)ln -sf xxhsum.1 $(DESTDIR)$(MANDIR)/xxh32sum.1
  417. $(Q)ln -sf xxhsum.1 $(DESTDIR)$(MANDIR)/xxh64sum.1
  418. $(Q)ln -sf xxhsum.1 $(DESTDIR)$(MANDIR)/xxh128sum.1
  419. @echo xxhash installation completed
  420. .PHONY: uninstall
  421. uninstall: ## uninstall libraries, CLI, links and man page
  422. $(Q)$(RM) $(DESTDIR)$(LIBDIR)/libxxhash.a
  423. $(Q)$(RM) $(DESTDIR)$(LIBDIR)/libxxhash.$(SHARED_EXT)
  424. $(Q)$(RM) $(DESTDIR)$(LIBDIR)/libxxhash.$(SHARED_EXT_MAJOR)
  425. $(Q)$(RM) $(DESTDIR)$(LIBDIR)/$(LIBXXH)
  426. $(Q)$(RM) $(DESTDIR)$(INCLUDEDIR)/xxhash.h
  427. $(Q)$(RM) $(DESTDIR)$(INCLUDEDIR)/xxh3.h
  428. $(Q)$(RM) $(DESTDIR)$(INCLUDEDIR)/xxh_x86dispatch.h
  429. $(Q)$(RM) $(DESTDIR)$(PKGCONFIGDIR)/libxxhash.pc
  430. $(Q)$(RM) $(DESTDIR)$(BINDIR)/xxh32sum
  431. $(Q)$(RM) $(DESTDIR)$(BINDIR)/xxh64sum
  432. $(Q)$(RM) $(DESTDIR)$(BINDIR)/xxh128sum
  433. $(Q)$(RM) $(DESTDIR)$(BINDIR)/xxhsum
  434. $(Q)$(RM) $(DESTDIR)$(MANDIR)/xxh32sum.1
  435. $(Q)$(RM) $(DESTDIR)$(MANDIR)/xxh64sum.1
  436. $(Q)$(RM) $(DESTDIR)$(MANDIR)/xxh128sum.1
  437. $(Q)$(RM) $(DESTDIR)$(MANDIR)/xxhsum.1
  438. @echo xxhsum successfully uninstalled
  439. endif