Home | History | Annotate | Download | only in programs
      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
     33 LZ4DIR   := ../lib
     34 LIBVER_SRC := $(LZ4DIR)/lz4.h
     35 LIBVER_MAJOR_SCRIPT:=`sed -n '/define LZ4_VERSION_MAJOR/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < $(LIBVER_SRC)`
     36 LIBVER_MINOR_SCRIPT:=`sed -n '/define LZ4_VERSION_MINOR/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < $(LIBVER_SRC)`
     37 LIBVER_PATCH_SCRIPT:=`sed -n '/define LZ4_VERSION_RELEASE/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < $(LIBVER_SRC)`
     38 LIBVER_SCRIPT:= $(LIBVER_MAJOR_SCRIPT).$(LIBVER_MINOR_SCRIPT).$(LIBVER_PATCH_SCRIPT)
     39 LIBVER_MAJOR := $(shell echo $(LIBVER_MAJOR_SCRIPT))
     40 LIBVER_MINOR := $(shell echo $(LIBVER_MINOR_SCRIPT))
     41 LIBVER_PATCH := $(shell echo $(LIBVER_PATCH_SCRIPT))
     42 LIBVER   := $(shell echo $(LIBVER_SCRIPT))
     43 
     44 SRCFILES := $(sort $(wildcard $(LZ4DIR)/*.c) $(wildcard *.c))
     45 OBJFILES := $(SRCFILES:.c=.o)
     46 
     47 CPPFLAGS += -I$(LZ4DIR) -DXXH_NAMESPACE=LZ4_
     48 CFLAGS   ?= -O3
     49 DEBUGFLAGS:=-Wall -Wextra -Wundef -Wcast-qual -Wcast-align -Wshadow \
     50             -Wswitch-enum -Wdeclaration-after-statement -Wstrict-prototypes \
     51             -Wpointer-arith -Wstrict-aliasing=1
     52 CFLAGS   += $(DEBUGFLAGS) $(MOREFLAGS)
     53 FLAGS     = $(CFLAGS) $(CPPFLAGS) $(LDFLAGS)
     54 
     55 LZ4_VERSION=$(LIBVER)
     56 MD2ROFF   = ronn
     57 MD2ROFF_FLAGS = --roff --warnings --manual="User Commands" --organization="lz4 $(LZ4_VERSION)"
     58 
     59 
     60 # Define *.exe as extension for Windows systems
     61 ifneq (,$(filter Windows%,$(OS)))
     62 EXT  :=.exe
     63 VOID := nul
     64 else
     65 EXT  :=
     66 VOID := /dev/null
     67 endif
     68 
     69 
     70 
     71 default: lz4-release
     72 
     73 all: lz4 lz4c
     74 
     75 all32: CFLAGS+=-m32
     76 all32: all
     77 
     78 lz4: $(OBJFILES)
     79 	$(CC) $(FLAGS) $^ -o $@$(EXT)
     80 
     81 lz4-release: DEBUGFLAGS=
     82 lz4-release: lz4
     83 
     84 lz4c: lz4
     85 	ln -s lz4$(EXT) lz4c$(EXT)
     86 
     87 lz4c32: CFLAGS += -m32
     88 lz4c32 : $(SRCFILES)
     89 	$(CC) $(FLAGS) $^ -o $@$(EXT)
     90 
     91 lz4.1: lz4.1.md $(LIBVER_SRC)
     92 	cat $< | $(MD2ROFF) $(MD2ROFF_FLAGS) | sed -n '/^\.\\\".*/!p' > $@
     93 
     94 man: lz4.1
     95 
     96 clean-man:
     97 	rm lz4.1
     98 
     99 preview-man: clean-man man
    100 	man ./lz4.1
    101 
    102 clean:
    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 #-----------------------------------------------------------------------------
    112 ifneq (,$(filter $(shell uname),Linux Darwin GNU/kFreeBSD GNU OpenBSD FreeBSD NetBSD DragonFly SunOS Haiku MidnightBSD))
    113 
    114 unlz4: lz4
    115 	ln -s lz4$(EXT) unlz4$(EXT)
    116 
    117 lz4cat: lz4
    118 	ln -s lz4$(EXT) lz4cat$(EXT)
    119 
    120 DESTDIR     ?=
    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
    124 PREFIX      ?= /usr/local
    125 prefix      ?= $(PREFIX)
    126 EXEC_PREFIX ?= $(prefix)
    127 exec_prefix ?= $(EXEC_PREFIX)
    128 BINDIR      ?= $(exec_prefix)/bin
    129 bindir      ?= $(BINDIR)
    130 DATAROOTDIR ?= $(prefix)/share
    131 datarootdir ?= $(DATAROOTDIR)
    132 MANDIR      ?= $(datarootdir)/man
    133 mandir      ?= $(MANDIR)
    134 MAN1DIR     ?= $(mandir)/man1
    135 man1dir     ?= $(MAN1DIR)
    136 
    137 ifneq (,$(filter $(shell uname),SunOS))
    138 INSTALL ?= ginstall
    139 else
    140 INSTALL ?= install
    141 endif
    142 
    143 INSTALL_PROGRAM ?= $(INSTALL) -m 755
    144 INSTALL_DATA    ?= $(INSTALL) -m 644
    145 
    146 
    147 install: 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 
    161 uninstall:
    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 
    172 endif
    173