github.com/grailbio/base@v0.0.11/compress/libdeflate/Makefile (about) 1 # 2 # Use 'make help' to list available targets. 3 # 4 # Define V=1 to enable "verbose" mode, showing all executed commands. 5 # 6 # Define DECOMPRESSION_ONLY to omit all compression code, building a 7 # decompression-only library. If doing this, you must also build a specific 8 # library target such as 'libdeflate.a', as the programs will no longer compile. 9 # 10 # Define DISABLE_GZIP to disable support for the gzip wrapper format. 11 # 12 # Define DISABLE_ZLIB to disable support for the zlib wrapper format. 13 # 14 ############################################################################## 15 16 #### Common compiler flags. 17 #### Flags given here are not intended to be overridden, but you can add more 18 #### by defining CFLAGS in the environment or on the 'make' command line. 19 20 cc-option = $(shell if $(CC) $(1) -c -x c /dev/null -o /dev/null \ 21 1>&2 2>/dev/null; then echo $(1); fi) 22 23 override CFLAGS := \ 24 $(CFLAGS) -O2 -fomit-frame-pointer -std=c99 -I. -Icommon \ 25 -Wall -Wundef \ 26 $(call cc-option,-Wpedantic) \ 27 $(call cc-option,-Wdeclaration-after-statement) \ 28 $(call cc-option,-Wmissing-prototypes) \ 29 $(call cc-option,-Wstrict-prototypes) \ 30 $(call cc-option,-Wvla) 31 32 ############################################################################## 33 34 STATIC_LIB_SUFFIX := .a 35 SHARED_LIB_SUFFIX := .so 36 SHARED_LIB_CFLAGS := -fPIC 37 PROG_SUFFIX := 38 PROG_CFLAGS := 39 HARD_LINKS := 1 40 41 # Compiling for Windows with MinGW? 42 ifneq ($(findstring -mingw,$(shell $(CC) -dumpmachine 2>/dev/null)),) 43 STATIC_LIB_SUFFIX := .lib 44 SHARED_LIB_SUFFIX := .dll 45 SHARED_LIB_CFLAGS := 46 PROG_SUFFIX := .exe 47 PROG_CFLAGS := -static -municode 48 HARD_LINKS := 49 override CFLAGS := $(CFLAGS) $(call cc-option,-Wno-pedantic-ms-format) 50 51 # If AR was not already overridden, then derive it from $(CC). 52 # Note that CC may take different forms, e.g. "cc", "gcc", 53 # "x86_64-w64-mingw32-gcc", or "x86_64-w64-mingw32-gcc-6.3.1". 54 # On Windows it may also have a .exe extension. 55 ifeq ($(AR),ar) 56 AR := $(shell echo $(CC) | \ 57 sed -E 's/g?cc(-?[0-9]+(\.[0-9]+)*)?(\.exe)?$$/ar\3/') 58 endif 59 endif 60 61 ############################################################################## 62 63 #### Quiet make is enabled by default. Define V=1 to disable. 64 65 ifneq ($(findstring s,$(MAKEFLAGS)),s) 66 ifneq ($(V),1) 67 QUIET_CC = @echo ' CC ' $@; 68 QUIET_CCLD = @echo ' CCLD ' $@; 69 QUIET_AR = @echo ' AR ' $@; 70 QUIET_LN = @echo ' LN ' $@; 71 QUIET_CP = @echo ' CP ' $@; 72 QUIET_GEN = @echo ' GEN ' $@; 73 endif 74 endif 75 76 ############################################################################## 77 78 COMMON_HEADERS := $(wildcard common/*.h) 79 DEFAULT_TARGETS := 80 81 #### Library 82 83 STATIC_LIB := libdeflate$(STATIC_LIB_SUFFIX) 84 SHARED_LIB := libdeflate$(SHARED_LIB_SUFFIX) 85 86 LIB_CFLAGS += $(CFLAGS) -fvisibility=hidden -D_ANSI_SOURCE 87 88 LIB_HEADERS := $(wildcard lib/*.h) $(wildcard lib/*/*.h) 89 90 LIB_SRC := lib/aligned_malloc.c lib/deflate_decompress.c \ 91 $(wildcard lib/*/cpu_features.c) 92 93 DECOMPRESSION_ONLY := 94 ifndef DECOMPRESSION_ONLY 95 LIB_SRC += lib/deflate_compress.c 96 endif 97 98 DISABLE_ZLIB := 99 ifndef DISABLE_ZLIB 100 LIB_SRC += lib/adler32.c lib/zlib_decompress.c 101 ifndef DECOMPRESSION_ONLY 102 LIB_SRC += lib/zlib_compress.c 103 endif 104 endif 105 106 DISABLE_GZIP := 107 ifndef DISABLE_GZIP 108 LIB_SRC += lib/crc32.c lib/gzip_decompress.c 109 ifndef DECOMPRESSION_ONLY 110 LIB_SRC += lib/gzip_compress.c 111 endif 112 endif 113 114 STATIC_LIB_OBJ := $(LIB_SRC:.c=.o) 115 SHARED_LIB_OBJ := $(LIB_SRC:.c=.shlib.o) 116 117 # Compile static library object files 118 $(STATIC_LIB_OBJ): %.o: %.c $(LIB_HEADERS) $(COMMON_HEADERS) .lib-cflags 119 $(QUIET_CC) $(CC) -o $@ -c $(LIB_CFLAGS) $< 120 121 # Compile shared library object files 122 $(SHARED_LIB_OBJ): %.shlib.o: %.c $(LIB_HEADERS) $(COMMON_HEADERS) .lib-cflags 123 $(QUIET_CC) $(CC) -o $@ -c $(LIB_CFLAGS) $(SHARED_LIB_CFLAGS) -DLIBDEFLATE_DLL $< 124 125 # Create static library 126 $(STATIC_LIB):$(STATIC_LIB_OBJ) 127 $(QUIET_AR) $(AR) cr $@ $+ 128 129 DEFAULT_TARGETS += $(STATIC_LIB) 130 131 # Create shared library 132 $(SHARED_LIB):$(SHARED_LIB_OBJ) 133 $(QUIET_CCLD) $(CC) -o $@ $(LDFLAGS) $(LIB_CFLAGS) -shared $+ 134 135 DEFAULT_TARGETS += $(SHARED_LIB) 136 137 # Rebuild if CC or LIB_CFLAGS changed 138 .lib-cflags: FORCE 139 @flags='$(CC):$(LIB_CFLAGS)'; \ 140 if [ "$$flags" != "`cat $@ 2>/dev/null`" ]; then \ 141 [ -e $@ ] && echo "Rebuilding library due to new compiler flags"; \ 142 echo "$$flags" > $@; \ 143 fi 144 145 ############################################################################## 146 147 #### Programs 148 149 PROG_CFLAGS += $(CFLAGS) \ 150 -D_POSIX_C_SOURCE=200809L \ 151 -D_FILE_OFFSET_BITS=64 \ 152 -DHAVE_CONFIG_H 153 154 PROG_COMMON_HEADERS := programs/prog_util.h programs/config.h 155 PROG_COMMON_SRC := programs/prog_util.c programs/tgetopt.c 156 NONTEST_PROGRAM_SRC := programs/gzip.c 157 TEST_PROGRAM_SRC := programs/benchmark.c programs/test_checksums.c \ 158 programs/checksum.c 159 160 NONTEST_PROGRAMS := $(NONTEST_PROGRAM_SRC:programs/%.c=%$(PROG_SUFFIX)) 161 DEFAULT_TARGETS += $(NONTEST_PROGRAMS) 162 TEST_PROGRAMS := $(TEST_PROGRAM_SRC:programs/%.c=%$(PROG_SUFFIX)) 163 164 PROG_COMMON_OBJ := $(PROG_COMMON_SRC:%.c=%.o) 165 NONTEST_PROGRAM_OBJ := $(NONTEST_PROGRAM_SRC:%.c=%.o) 166 TEST_PROGRAM_OBJ := $(TEST_PROGRAM_SRC:%.c=%.o) 167 PROG_OBJ := $(PROG_COMMON_OBJ) $(NONTEST_PROGRAM_OBJ) $(TEST_PROGRAM_OBJ) 168 169 # Generate autodetected configuration header 170 programs/config.h:programs/detect.sh .prog-cflags 171 $(QUIET_GEN) CC="$(CC)" CFLAGS="$(PROG_CFLAGS)" $< > $@ 172 173 # Compile program object files 174 $(PROG_OBJ): %.o: %.c $(PROG_COMMON_HEADERS) $(COMMON_HEADERS) .prog-cflags 175 $(QUIET_CC) $(CC) -o $@ -c $(PROG_CFLAGS) $< 176 177 # Link the programs. 178 # 179 # Note: the test programs are not compiled by default. One reason is that the 180 # test programs must be linked with zlib for doing comparisons. 181 182 $(NONTEST_PROGRAMS): %$(PROG_SUFFIX): programs/%.o $(PROG_COMMON_OBJ) $(STATIC_LIB) 183 $(QUIET_CCLD) $(CC) -o $@ $(LDFLAGS) $(PROG_CFLAGS) $+ 184 185 $(TEST_PROGRAMS): %$(PROG_SUFFIX): programs/%.o $(PROG_COMMON_OBJ) $(STATIC_LIB) 186 $(QUIET_CCLD) $(CC) -o $@ $(LDFLAGS) $(PROG_CFLAGS) $+ -lz 187 188 ifdef HARD_LINKS 189 # Hard link gunzip to gzip 190 gunzip$(PROG_SUFFIX):gzip$(PROG_SUFFIX) 191 $(QUIET_LN) ln -f $< $@ 192 else 193 # No hard links; copy gzip to gunzip 194 gunzip$(PROG_SUFFIX):gzip$(PROG_SUFFIX) 195 $(QUIET_CP) cp -f $< $@ 196 endif 197 198 DEFAULT_TARGETS += gunzip$(PROG_SUFFIX) 199 200 # Rebuild if CC or PROG_CFLAGS changed 201 .prog-cflags: FORCE 202 @flags='$(CC):$(PROG_CFLAGS)'; \ 203 if [ "$$flags" != "`cat $@ 2>/dev/null`" ]; then \ 204 [ -e $@ ] && echo "Rebuilding programs due to new compiler flags"; \ 205 echo "$$flags" > $@; \ 206 fi 207 208 ############################################################################## 209 210 all:$(DEFAULT_TARGETS) 211 212 test_programs:$(TEST_PROGRAMS) 213 214 help: 215 @echo "Available targets:" 216 @echo "------------------" 217 @for target in $(DEFAULT_TARGETS) $(TEST_PROGRAMS); do \ 218 echo -e "$$target"; \ 219 done 220 221 clean: 222 rm -f *.a *.dll *.exe *.exp *.so \ 223 lib/*.o lib/*/*.o \ 224 lib/*.obj lib/*/*.obj \ 225 lib/*.dllobj lib/*/*.dllobj \ 226 programs/*.o programs/*.obj \ 227 $(DEFAULT_TARGETS) $(TEST_PROGRAMS) programs/config.h \ 228 libdeflate.lib libdeflatestatic.lib \ 229 .lib-cflags .prog-cflags 230 231 realclean: clean 232 rm -f tags cscope* run_tests.log 233 234 FORCE: 235 236 .PHONY: all test_programs help clean realclean 237 238 .DEFAULT_GOAL = all