]> git.proxmox.com Git - ceph.git/blob - ceph/src/isa-l/make.inc
import quincy beta 17.1.0
[ceph.git] / ceph / src / isa-l / make.inc
1 ########################################################################
2 # Copyright(c) 2011-2018 Intel Corporation All rights reserved.
3 #
4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions
6 # are met:
7 # * Redistributions of source code must retain the above copyright
8 # notice, this list of conditions and the following disclaimer.
9 # * Redistributions in binary form must reproduce the above copyright
10 # notice, this list of conditions and the following disclaimer in
11 # the documentation and/or other materials provided with the
12 # distribution.
13 # * Neither the name of Intel Corporation nor the names of its
14 # contributors may be used to endorse or promote products derived
15 # from this software without specific prior written permission.
16 #
17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 ########################################################################
29
30
31 # Makefile include for optimized libraries
32 # make targets:
33 # lib - build library of optimized functions
34 # slib - build shared library
35 # test - run unit tests of functions
36 # perf - run performance tests
37 # install - install headers and libs to system location
38 # sim - run on simulator
39 # trace - get simulator trace
40 # clean - remove object files
41
42 version ?= 2.30.0
43 host_cpu ?= $(shell uname -m | sed -e 's/amd/x86_/')
44 arch ?= $(shell uname | grep -v -e Linux -e BSD )
45
46 # aarch64 cpu arch = aarch64
47 ifeq ($(host_cpu)_$(arch),aarch64_)
48 arch = aarch64
49 endif
50
51 CC = gcc
52 AS = nasm
53 AWK = awk
54
55 DEBUG = -g
56 DEBUG_yasm = -g dwarf2
57 DEBUG_nasm = -g
58
59 # Default arch= build options
60 CFLAGS_ = -Wall
61 ASFLAGS_ = -f elf64
62 ARFLAGS_ = cr $@
63 STRIP_gcc = strip -d -R .comment $@
64
65 # arch=32 build options
66 ASFLAGS_32 = -f elf32
67 CFLAGS_32 = -m32
68 ARFLAGS_32 = cr $@
69
70 # arch=win64 build options
71 ASFLAGS_win64 = -f win64
72 CFLAGS_icl = -Qstd=c99
73 ARFLAGS_win64 = -out:$@
74
75 # arch=mingw build options
76 ASFLAGS_mingw = -f win64
77 ARFLAGS_mingw = cr $@
78
79 LDFLAGS_so = -Wl,-soname,$(soname)
80
81 ifeq ($(arch),mingw)
82 CC=x86_64-w64-mingw32-gcc
83 AR=x86_64-w64-mingw32-ar
84 AS=yasm
85 LDFLAGS += -Wl,--force-exe-suffix
86 SIM=wine
87 EXT=.exe
88 CLEANFILES+=*.exe
89 endif
90
91 # arch=noarch build options
92 ARFLAGS_noarch = cr $@
93 ifeq ($(arch),noarch)
94 host_cpu=base_aliases
95 endif
96
97 # arch=aarch64 build options
98 ifeq ($(lib_debug),1)
99 ASFLAGS_aarch64 = -g -c
100 else
101 ASFLAGS_aarch64 = -c
102 endif
103
104 ARFLAGS_aarch64 = cr $@
105 ifeq ($(arch),aarch64)
106 AS=$(CC) -D__ASSEMBLY__
107 SIM=
108 endif
109
110 ASFLAGS_Darwin = -f macho64 --prefix=_
111 ARFLAGS_Darwin = -r $@
112 ifeq ($(shell uname),Darwin)
113 LDFLAGS_so =
114 STRIP_gcc =
115 endif
116
117 INCLUDE = $(patsubst %,-I%/,$(subst :, ,$(VPATH)))
118 CFLAGS = $(CFLAGS_$(arch)) $(CFLAGS_$(CC)) $(DEBUG) -O2 $(DEFINES) $(INCLUDE)
119 ASFLAGS = $(ASFLAGS_$(arch)) $(ASFLAGS_$(CC)) $(DEBUG_$(AS)) $(DEFINES) $(INCLUDE)
120 ARFLAGS = $(ARFLAGS_$(arch))
121 DEFINES += $(addprefix -D , $D)
122 CLEANFILES += $(O) *.o *.a $(all_tests) $(bin_PROGRAMS) $(lib_name) $(so_lib_name) $(all_llvm_fuzz_tests)
123
124 # set host_cpu=base_aliases for unsupported CPUs
125 ifeq ($(filter aarch64 x86_%,$(host_cpu)),)
126 host_cpu=base_aliases
127 endif
128
129 other_tests += $(other_tests_$(host_cpu))
130
131 lsrc += $(lsrc_$(host_cpu))
132 O = bin
133 lobj += $(patsubst %.c,%.o,$(patsubst %.S,%.o,$(patsubst %.asm,%.o,$(lsrc) $(lsrc_intrinsic))))
134 objs = $(addprefix $(O)/,$(notdir $(lobj)))
135
136
137 lib_name ?= isa-l.a
138 default: lib slib progs
139
140 # Defaults for windows build
141 ifeq ($(arch),win64)
142 AR=lib
143 CC=cl
144 OUTPUT_OPTION = -Fo$@
145 DEBUG=
146 lib_name := $(basename $(lib_name)).lib
147 endif
148 lsrcwin64 = $(lsrc)
149 unit_testswin64 = $(unit_tests)
150 exampleswin64 = $(examples)
151 perf_testswin64 = $(perf_tests)
152
153
154 # Build and run unit tests, performance tests, etc.
155 all_tests = $(notdir $(sort $(perf_tests) $(check_tests) $(unit_tests) $(examples) $(other_tests)))
156 all_unit_tests = $(notdir $(sort $(check_tests) $(unit_tests)))
157 all_perf_tests = $(notdir $(sort $(perf_tests)))
158 all_check_tests = $(notdir $(sort $(check_tests)))
159 all_llvm_fuzz_tests = $(notdir $(sort $(llvm_fuzz_tests)))
160
161 $(all_unit_tests): % : %.c $(lib_name)
162 $(all_perf_tests): % : %.c $(lib_name)
163 $(sort $(notdir $(examples))): % : %.c $(lib_name)
164 $(sort $(notdir $(other_tests))): % : %.c $(lib_name)
165
166 fuzz_args = -fsanitize=fuzzer,address
167 $(all_llvm_fuzz_tests): FUZZLINK = $(fuzz_args)
168 $(all_llvm_fuzz_tests): CFLAGS += $(fuzz_args)
169 $(all_llvm_fuzz_tests): CXXFLAGS += $(fuzz_args)
170 $(all_llvm_fuzz_tests): % : %.o $(lib_name)
171 $(CXX) $(CXXFLAGS) $^ $(LDLIBS) $(FUZZLINK) -o $@
172
173
174 # Check for modern as
175 test-as = $(shell hash printf && printf $(3) > $(2) && $(AS) $(ASFLAGS) ${tmpf} -o /dev/null 2> /dev/null && echo $(1) || echo $(4))
176 as_4 := "pblendvb xmm2, xmm1;"
177 as_6 := "vinserti32x8 zmm0, ymm1, 1;"
178 as_10 := "vpcompressb zmm0 {k1}, zmm1;"
179
180 tmpf := $(shell mktemp)
181 as_feature_level := $(call test-as, 4, $(tmpf), $(as_4), $(as_feature_level))
182 as_feature_level := $(call test-as, 6, $(tmpf), $(as_6), $(as_feature_level))
183 as_feature_level := $(call test-as, 10, $(tmpf), $(as_10), $(as_feature_level))
184 tmpf := $(shell rm ${tmpf})
185
186 ifneq ($(findstring $(as_feature_level),6 10),)
187 D_HAVE_AS_KNOWS_AVX512_y := -DHAVE_AS_KNOWS_AVX512
188 endif
189
190 CFLAGS += -DAS_FEATURE_LEVEL=$(as_feature_level) $(D_HAVE_AS_KNOWS_AVX512_y)
191 ASFLAGS += -DAS_FEATURE_LEVEL=$(as_feature_level) $(D_HAVE_AS_KNOWS_AVX512_y)
192
193
194 # Check for pthreads
195 have_threads ?= $(shell printf "\#include <pthread.h>\nint main(void){return 0;}\n" | $(CC) -x c - -o /dev/null -lpthread && echo y )
196 THREAD_LD_$(have_threads) := -lpthread
197 THREAD_CFLAGS_$(have_threads) := -DHAVE_THREADS
198
199 progs: $(bin_PROGRAMS)
200 $(bin_PROGRAMS): CFLAGS += -DVERSION=\"$(version)\"
201 $(bin_PROGRAMS): LDLIBS += $(THREAD_LD_y)
202 $(bin_PROGRAMS): CFLAGS += $(THREAD_CFLAGS_y)
203 sim test trace: $(addsuffix .run,$(all_unit_tests))
204 perf: $(addsuffix .run,$(all_perf_tests))
205 check: $(addsuffix .run,$(all_check_tests))
206 ex: $(notdir $(examples))
207 all: lib $(all_tests)
208 other: $(notdir $(other_tests))
209 llvm_fuzz_tests: $(all_llvm_fuzz_tests)
210 tests: $(all_unit_tests)
211 perfs: $(all_perf_tests)
212 checks: $(all_check_tests)
213 trace: SIM=sde -debugtrace --
214 sim: SIM=sde --
215 check test sim:
216 @echo Finished running $@
217
218 $(objs): | $(O)
219 $(O): ; mkdir -p $(O)
220
221 # Build rule to run tests
222 $(addsuffix .run,$(all_tests)): %.run : %
223 $(SIM) ./$<$(EXT)
224 @echo Completed run: $<
225
226 # Other build rules
227 msg = $(if $(DEBUG),DEBUG) $(patsubst 32,32-bit,$(host_cpu)) $D
228
229 # yasm/nasm assembly files
230 $(O)/%.o: %.asm
231 @echo " ---> Building $< $(msg)"
232 @$(AS) $(ASFLAGS) -o $@ $<
233
234 # gcc assembly files
235 $(O)/%.o: $(host_cpu)/%.S
236 @echo " ---> Building $< $(msg)"
237 @$(AS) $(ASFLAGS) -o $@ $<
238
239 $(O)/%.o : $(host_cpu)/%.c
240 @echo " ---> Building $< $(msg)"
241 @$(COMPILE.c) $(OUTPUT_OPTION) $<
242 $(O)/%.o %.o: %.c
243 @echo " ---> Building $< $(msg)"
244 @$(COMPILE.c) $(OUTPUT_OPTION) $<
245
246 $(all_tests):
247 @echo " ---> Building Test $@ $(msg)"
248 @$(LINK.o) $(CFLAGS) $^ $(LDLIBS) -o $@
249
250 $(bin_PROGRAMS): % : %_cli.c $(lib_name)
251 @echo " ---> Building Programs $@ $(msg)"
252 @$(LINK.o) $(CFLAGS) $^ $(LDLIBS) -o $@
253
254
255 # Target to build lib files
256 lib: $(lib_name)
257 ifneq ($(lib_debug),1)
258 $(lib_name): DEBUG_$(AS)= # Don't put debug symbols in the lib
259 $(lib_name): DEBUG=
260 $(lib_name): DEFINES+=-D NDEBUG
261 endif
262 ifeq ($(lib_debug),1)
263 DEBUG+=-D DEBUG # Define DEBUG for macros
264 endif
265
266 #lib $(lib_name): $(lib_name)(${objs})
267 $(lib_name): $(objs)
268 @echo " ---> Creating Lib $@"
269 @$(AR) $(ARFLAGS) $^
270 ifneq ($(lib_debug),1)
271 @$(STRIP_$(CC))
272 endif
273
274
275 # Target for shared lib
276 so_lib_name = bin/libisal.so
277 so_lib_inst = $(notdir $(so_lib_name))
278 so_lib_ver = $(so_lib_inst).$(version)
279 soname = $(so_lib_inst).$(word 1, $(subst ., ,$(version)))
280
281 slib: $(so_lib_name)
282 aobjs += $(addprefix $(O)/,$(patsubst %.asm,%.o,$(filter %.asm,$(notdir $(lsrc) $(lsrc_intrinsic)))))
283 aobjs += $(addprefix $(O)/,$(patsubst %.S,%.o,$(filter %.S,$(notdir $(lsrc) $(lsrc_intrinsic)))))
284 shared_objs += $(addprefix $(O)/shared_ver_,$(patsubst %.c,%.o,$(filter %.c,$(notdir $(lsrc) $(lsrc_intrinsic)))))
285
286 $(O)/shared_ver_%.o: %.c
287 @echo " ---> Building shared $< $(msg)"
288 @$(COMPILE.c) $(OUTPUT_OPTION) $<
289 $(O)/shared_ver_%.o: $(host_cpu)/%.c
290 @echo " ---> Building shared $< $(msg)"
291 @$(COMPILE.c) $(OUTPUT_OPTION) $<
292 ifneq ($(lib_debug),1)
293 $(so_lib_name): DEBUG_$(AS)=
294 $(so_lib_name): DEBUG=
295 $(so_lib_name): DEFINES+=-D NDEBUG
296 endif
297
298 $(shared_objs): CFLAGS += -fPIC
299 $(shared_objs) $(aobjs): | $(O)
300 $(so_lib_name): LDFLAGS+=$(LDFLAGS_so)
301 $(so_lib_name): $(shared_objs) $(aobjs)
302 @echo " ---> Creating Shared Lib $@"
303 @$(CC) $(CFLAGS) --shared $(LDFLAGS) -o $@ $^
304 @(cd $(@D); ln -f -s $(so_lib_inst) $(soname))
305
306
307 isa-l.h:
308 @echo 'Building $@'
309 @echo '' >> $@
310 @echo '/**' >> $@
311 @echo ' * @file isa-l.h' >> $@
312 @echo ' * @brief Include for ISA-L library' >> $@
313 @echo ' */' >> $@
314 @echo '' >> $@
315 @echo '#ifndef _ISAL_H_' >> $@
316 @echo '#define _ISAL_H_' >> $@
317 @echo '' >> $@
318 @echo '#define.ISAL_MAJOR_VERSION.${version}' | ${AWK} -F . '{print $$1, $$2, $$3}' >> $@
319 @echo '#define.ISAL_MINOR_VERSION.${version}' | ${AWK} -F . '{print $$1, $$2, $$4}' >> $@
320 @echo '#define.ISAL_PATCH_VERSION.${version}' | ${AWK} -F . '{print $$1, $$2, $$5}' >> $@
321 @echo '#define ISAL_MAKE_VERSION(maj, min, patch) ((maj) * 0x10000 + (min) * 0x100 + (patch))' >> $@
322 @echo '#define ISAL_VERSION ISAL_MAKE_VERSION(ISAL_MAJOR_VERSION, ISAL_MINOR_VERSION, ISAL_PATCH_VERSION)' >> $@
323 @echo '' >> $@
324 @for unit in $(sort $(extern_hdrs)); do echo "#include <isa-l/$$unit>" | sed -e 's;include/;;' >> $@; done
325 @echo '#endif //_ISAL_H_' >> $@
326
327
328 # Target for install
329 prefix = /usr/local
330 man1dir ?= $(prefix)/share/man/man1
331 install_dirs = $(prefix)/lib $(prefix)/include/isa-l $(prefix)/bin $(man1dir)
332 $(install_dirs): ; mkdir -p $@
333 install: $(sort $(extern_hdrs)) | $(install_dirs) $(lib_name) $(so_lib_name) isa-l.h $(bin_PROGRAMS)
334 install -m 644 $(lib_name) $(prefix)/lib/libisal.a
335 install -m 644 $^ $(prefix)/include/isa-l/.
336 install -m 664 isa-l.h $(prefix)/include/.
337 install -m 664 include/types.h $(prefix)/include/isa-l/.
338 install -m 664 $(so_lib_name) $(prefix)/lib/$(so_lib_ver)
339 (cd $(prefix)/lib && ln -f -s $(so_lib_ver) $(soname) && ln -f -s $(so_lib_ver) $(so_lib_inst))
340 ifeq ($(shell uname),Darwin)
341 (cd $(prefix)/lib && ln -f -s $(so_lib_ver) $(basename $(so_lib_inst)).dylib)
342 which glibtool && glibtool --mode=finish $(prefix)/lib
343 else
344 which libtool && libtool --mode=finish $(prefix)/lib || \
345 echo 'Lib installed at $(prefix)/lib. Run system-dependent programs to add shared lib path.'
346 endif
347 install -m 774 $(bin_PROGRAMS) $(prefix)/bin/.
348 install -m 664 $(dist_man_MANS) $(man1dir)/.
349
350 uninstall:
351 $(RM) $(prefix)/lib/libisal.a
352 $(RM) $(prefix)/lib/$(soname)
353 $(RM) $(prefix)/lib/$(so_lib_ver)
354 $(RM) $(prefix)/lib/$(so_lib_inst)
355 $(RM) -r $(prefix)/include/isa-l
356 $(RM) $(prefix)/include/isa-l.h
357 $(RM) $(prefix)/lib/$(basename $(so_lib_inst)).dylib
358 $(RM) $(prefix)/bin/$(notdir $(bin_PROGRAMS))
359 $(RM) $(man1dir)/$(notdir $(dist_man_MANS))
360
361 # Collect performance data
362 rpt_name = perf_report_$(shell uname -n)_$(shell date +%y%m%d).perf
363
364 perf_report:
365 echo Results for $(rpt_name) >> $(rpt_name)
366 $(MAKE) -f Makefile.unx -k perf | tee -a $(rpt_name)
367 @echo Summary:
368 -grep runtime $(rpt_name)
369
370
371 clean:
372 @echo Cleaning up
373 @$(RM) -r $(CLEANFILES)
374
375
376 doc: isa-l.h
377 (cat Doxyfile; echo 'PROJECT_NUMBER=$(version)') | doxygen -
378 $(MAKE) -C generated_doc/latex &> generated_doc/latex_build_api.log
379 cp generated_doc/latex/refman.pdf isa-l_api_$(version).pdf
380