1 ########################################################################
2 # Copyright(c) 2011-2018 Intel Corporation All rights reserved.
4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions
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
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.
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 ########################################################################
31 # Makefile include for optimized libraries
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
43 host_cpu ?= $(shell uname -m | sed -e 's/amd/x86_/')
44 arch ?= $(shell uname | grep -v -e Linux -e BSD )
46 # aarch64 cpu arch = aarch64
47 ifeq ($(host_cpu)_$(arch),aarch64_)
56 DEBUG_yasm = -g dwarf2
59 # Default arch= build options
63 STRIP_gcc = strip -d -R .comment $@
65 # arch=32 build options
70 # arch=win64 build options
71 ASFLAGS_win64 = -f win64
72 CFLAGS_icl = -Qstd=c99
73 ARFLAGS_win64 = -out:$@
75 # arch=mingw build options
76 ASFLAGS_mingw = -f win64
79 LDFLAGS_so = -Wl,-soname,$(soname)
82 CC=x86_64-w64-mingw32-gcc
83 AR=x86_64-w64-mingw32-ar
85 LDFLAGS += -Wl,--force-exe-suffix
91 # arch=noarch build options
92 ARFLAGS_noarch = cr $@
97 # arch=aarch64 build options
99 ASFLAGS_aarch64 = -g -c
104 ARFLAGS_aarch64 = cr $@
105 ifeq ($(arch),aarch64)
106 AS=$(CC) -D__ASSEMBLY__
110 ASFLAGS_Darwin = -f macho64 --prefix=_
111 ARFLAGS_Darwin = -r $@
112 ifeq ($(shell uname),Darwin)
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)
124 # set host_cpu=base_aliases for unsupported CPUs
125 ifeq ($(filter aarch64 x86_%,$(host_cpu)),)
126 host_cpu=base_aliases
129 other_tests += $(other_tests_$(host_cpu))
131 lsrc += $(lsrc_$(host_cpu))
133 lobj += $(patsubst %.c,%.o,$(patsubst %.S,%.o,$(patsubst %.asm,%.o,$(lsrc) $(lsrc_intrinsic))))
134 objs = $(addprefix $(O)/,$(notdir $(lobj)))
138 default: lib slib progs
140 # Defaults for windows build
144 OUTPUT_OPTION = -Fo$@
146 lib_name := $(basename $(lib_name)).lib
149 unit_testswin64 = $(unit_tests)
150 exampleswin64 = $(examples)
151 perf_testswin64 = $(perf_tests)
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)))
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)
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 $@
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;"
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})
186 ifneq ($(findstring $(as_feature_level),6 10),)
187 D_HAVE_AS_KNOWS_AVX512_y := -DHAVE_AS_KNOWS_AVX512
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)
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
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 --
216 @echo Finished running $@
219 $(O): ; mkdir -p $(O)
221 # Build rule to run tests
222 $(addsuffix .run,$(all_tests)): %.run : %
224 @echo Completed run: $<
227 msg = $(if $(DEBUG),DEBUG) $(patsubst 32,32-bit,$(host_cpu)) $D
229 # yasm/nasm assembly files
231 @echo " ---> Building $< $(msg)"
232 @$(AS) $(ASFLAGS) -o $@ $<
235 $(O)/%.o: $(host_cpu)/%.S
236 @echo " ---> Building $< $(msg)"
237 @$(AS) $(ASFLAGS) -o $@ $<
239 $(O)/%.o : $(host_cpu)/%.c
240 @echo " ---> Building $< $(msg)"
241 @$(COMPILE.c) $(OUTPUT_OPTION) $<
243 @echo " ---> Building $< $(msg)"
244 @$(COMPILE.c) $(OUTPUT_OPTION) $<
247 @echo " ---> Building Test $@ $(msg)"
248 @$(LINK.o) $(CFLAGS) $^ $(LDLIBS) -o $@
250 $(bin_PROGRAMS): % : %_cli.c $(lib_name)
251 @echo " ---> Building Programs $@ $(msg)"
252 @$(LINK.o) $(CFLAGS) $^ $(LDLIBS) -o $@
255 # Target to build lib files
257 ifneq ($(lib_debug),1)
258 $(lib_name): DEBUG_$(AS)= # Don't put debug symbols in the lib
260 $(lib_name): DEFINES+=-D NDEBUG
262 ifeq ($(lib_debug),1)
263 DEBUG+=-D DEBUG # Define DEBUG for macros
266 #lib $(lib_name): $(lib_name)(${objs})
268 @echo " ---> Creating Lib $@"
270 ifneq ($(lib_debug),1)
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)))
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)))))
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
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))
311 @echo ' * @file isa-l.h' >> $@
312 @echo ' * @brief Include for ISA-L library' >> $@
315 @echo '#ifndef _ISAL_H_' >> $@
316 @echo '#define _ISAL_H_' >> $@
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)' >> $@
324 @for unit in $(sort $(extern_hdrs)); do echo "#include <isa-l/$$unit>" | sed -e 's;include/;;' >> $@; done
325 @echo '#endif //_ISAL_H_' >> $@
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
344 which libtool && libtool --mode=finish $(prefix)/lib || \
345 echo 'Lib installed at $(prefix)/lib. Run system-dependent programs to add shared lib path.'
347 install -m 774 $(bin_PROGRAMS) $(prefix)/bin/.
348 install -m 664 $(dist_man_MANS) $(man1dir)/.
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))
361 # Collect performance data
362 rpt_name = perf_report_$(shell uname -n)_$(shell date +%y%m%d).perf
365 echo Results for $(rpt_name) >> $(rpt_name)
366 $(MAKE) -f Makefile.unx -k perf | tee -a $(rpt_name)
368 -grep runtime $(rpt_name)
373 @$(RM) -r $(CLEANFILES)
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