• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# ##########################################################################
2# LZ4 programs - Makefile
3# Copyright (C) Yann Collet 2011-2017
4#
5# This Makefile is validated for Linux, macOS, *BSD, Hurd, Solaris, MSYS2 targets
6#
7# GPL v2 License
8#
9# This program is free software; you can redistribute it and/or modify
10# it under the terms of the GNU General Public License as published by
11# the Free Software Foundation; either version 2 of the License, or
12# (at your option) any later version.
13#
14# This program is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17# GNU General Public License for more details.
18#
19# You should have received a copy of the GNU General Public License along
20# with this program; if not, write to the Free Software Foundation, Inc.,
21# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22#
23# You can contact the author at :
24#  - LZ4 homepage : http://www.lz4.org
25#  - LZ4 source repository : https://github.com/Cyan4973/lz4
26# ##########################################################################
27# lz4 : Command Line Utility, supporting gzip-like arguments
28# lz4c  : CLU, supporting also legacy lz4demo arguments
29# lz4c32: Same as lz4c, but forced to compile in 32-bits mode
30# ##########################################################################
31
32# Version numbers
33LZ4DIR   := ../lib
34LIBVER_SRC := $(LZ4DIR)/lz4.h
35LIBVER_MAJOR_SCRIPT:=`sed -n '/define LZ4_VERSION_MAJOR/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < $(LIBVER_SRC)`
36LIBVER_MINOR_SCRIPT:=`sed -n '/define LZ4_VERSION_MINOR/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < $(LIBVER_SRC)`
37LIBVER_PATCH_SCRIPT:=`sed -n '/define LZ4_VERSION_RELEASE/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < $(LIBVER_SRC)`
38LIBVER_SCRIPT:= $(LIBVER_MAJOR_SCRIPT).$(LIBVER_MINOR_SCRIPT).$(LIBVER_PATCH_SCRIPT)
39LIBVER_MAJOR := $(shell echo $(LIBVER_MAJOR_SCRIPT))
40LIBVER_MINOR := $(shell echo $(LIBVER_MINOR_SCRIPT))
41LIBVER_PATCH := $(shell echo $(LIBVER_PATCH_SCRIPT))
42LIBVER   := $(shell echo $(LIBVER_SCRIPT))
43
44SRCFILES := $(sort $(wildcard $(LZ4DIR)/*.c) $(wildcard *.c))
45OBJFILES := $(SRCFILES:.c=.o)
46
47CPPFLAGS += -I$(LZ4DIR) -DXXH_NAMESPACE=LZ4_
48CFLAGS   ?= -O3
49DEBUGFLAGS:=-Wall -Wextra -Wundef -Wcast-qual -Wcast-align -Wshadow \
50            -Wswitch-enum -Wdeclaration-after-statement -Wstrict-prototypes \
51            -Wpointer-arith -Wstrict-aliasing=1
52CFLAGS   += $(DEBUGFLAGS) $(MOREFLAGS)
53FLAGS     = $(CFLAGS) $(CPPFLAGS) $(LDFLAGS)
54
55LZ4_VERSION=$(LIBVER)
56MD2ROFF   = ronn
57MD2ROFF_FLAGS = --roff --warnings --manual="User Commands" --organization="lz4 $(LZ4_VERSION)"
58
59
60# Define *.exe as extension for Windows systems
61ifneq (,$(filter Windows%,$(OS)))
62EXT  :=.exe
63VOID := nul
64else
65EXT  :=
66VOID := /dev/null
67endif
68
69
70
71default: lz4-release
72
73all: lz4 lz4c
74
75all32: CFLAGS+=-m32
76all32: all
77
78lz4: $(OBJFILES)
79	$(CC) $(FLAGS) $^ -o $@$(EXT)
80
81lz4-release: DEBUGFLAGS=
82lz4-release: lz4
83
84lz4c: lz4
85	ln -s lz4$(EXT) lz4c$(EXT)
86
87lz4c32: CFLAGS += -m32
88lz4c32 : $(SRCFILES)
89	$(CC) $(FLAGS) $^ -o $@$(EXT)
90
91lz4.1: lz4.1.md $(LIBVER_SRC)
92	cat $< | $(MD2ROFF) $(MD2ROFF_FLAGS) | sed -n '/^\.\\\".*/!p' > $@
93
94man: lz4.1
95
96clean-man:
97	rm lz4.1
98
99preview-man: clean-man man
100	man ./lz4.1
101
102clean:
103	@$(MAKE) -C $(LZ4DIR) $@ > $(VOID)
104	@$(RM) core *.o *.test tmp* \
105           lz4$(EXT) lz4c$(EXT) lz4c32$(EXT) unlz4$(EXT) lz4cat$(EXT)
106	@echo Cleaning completed
107
108
109#-----------------------------------------------------------------------------
110# make install is validated only for Linux, OSX, BSD, Hurd and Solaris targets
111#-----------------------------------------------------------------------------
112ifneq (,$(filter $(shell uname),Linux Darwin GNU/kFreeBSD GNU OpenBSD FreeBSD NetBSD DragonFly SunOS Haiku MidnightBSD))
113
114unlz4: lz4
115	ln -s lz4$(EXT) unlz4$(EXT)
116
117lz4cat: lz4
118	ln -s lz4$(EXT) lz4cat$(EXT)
119
120DESTDIR     ?=
121# directory variables : GNU conventions prefer lowercase
122# see https://www.gnu.org/prep/standards/html_node/Makefile-Conventions.html
123# support both lower and uppercase (BSD), use lowercase in script
124PREFIX      ?= /usr/local
125prefix      ?= $(PREFIX)
126EXEC_PREFIX ?= $(prefix)
127exec_prefix ?= $(EXEC_PREFIX)
128BINDIR      ?= $(exec_prefix)/bin
129bindir      ?= $(BINDIR)
130DATAROOTDIR ?= $(prefix)/share
131datarootdir ?= $(DATAROOTDIR)
132MANDIR      ?= $(datarootdir)/man
133mandir      ?= $(MANDIR)
134MAN1DIR     ?= $(mandir)/man1
135man1dir     ?= $(MAN1DIR)
136
137ifneq (,$(filter $(shell uname),SunOS))
138INSTALL ?= ginstall
139else
140INSTALL ?= install
141endif
142
143INSTALL_PROGRAM ?= $(INSTALL) -m 755
144INSTALL_DATA    ?= $(INSTALL) -m 644
145
146
147install: lz4
148	@echo Installing binaries
149	@$(INSTALL) -d -m 755 $(DESTDIR)$(bindir)/ $(DESTDIR)$(man1dir)/
150	@$(INSTALL_PROGRAM) lz4$(EXT) $(DESTDIR)$(bindir)/lz4$(EXT)
151	@ln -sf lz4$(EXT) $(DESTDIR)$(bindir)/lz4c$(EXT)
152	@ln -sf lz4$(EXT) $(DESTDIR)$(bindir)/lz4cat$(EXT)
153	@ln -sf lz4$(EXT) $(DESTDIR)$(bindir)/unlz4$(EXT)
154	@echo Installing man pages
155	@$(INSTALL_DATA) lz4.1 $(DESTDIR)$(man1dir)/lz4.1
156	@ln -sf lz4.1 $(DESTDIR)$(man1dir)/lz4c.1
157	@ln -sf lz4.1 $(DESTDIR)$(man1dir)/lz4cat.1
158	@ln -sf lz4.1 $(DESTDIR)$(man1dir)/unlz4.1
159	@echo lz4 installation completed
160
161uninstall:
162	@$(RM) $(DESTDIR)$(bindir)/lz4cat$(EXT)
163	@$(RM) $(DESTDIR)$(bindir)/unlz4$(EXT)
164	@$(RM) $(DESTDIR)$(bindir)/lz4$(EXT)
165	@$(RM) $(DESTDIR)$(bindir)/lz4c$(EXT)
166	@$(RM) $(DESTDIR)$(man1dir)/lz4.1
167	@$(RM) $(DESTDIR)$(man1dir)/lz4c.1
168	@$(RM) $(DESTDIR)$(man1dir)/lz4cat.1
169	@$(RM) $(DESTDIR)$(man1dir)/unlz4.1
170	@echo lz4 programs successfully uninstalled
171
172endif
173