]> git.proxmox.com Git - ceph.git/blame - ceph/src/isa-l/make.inc
update sources to v12.1.1
[ceph.git] / ceph / src / isa-l / make.inc
CommitLineData
7c673cae
FG
1########################################################################
2# Copyright(c) 2011-2015 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
224ce89b
WB
42version ?= 2.18.0
43host_cpu ?= $(shell uname -m | sed -e 's/amd/x86_/')
44arch ?= $(shell uname | grep -v -e Linux -e BSD )
7c673cae
FG
45
46CC = gcc
47AS = yasm
48SIM = sde $(SIMFLAGS) --
224ce89b 49AWK = awk
7c673cae
FG
50
51DEBUG = -g
52DEBUG_yasm = -g dwarf2
53DEBUG_nasm = -g
54
55# Default arch= build options
224ce89b 56CFLAGS_ = -Wall
7c673cae
FG
57ASFLAGS_ = -f elf64
58ARFLAGS_ = cr $@
59STRIP_gcc = strip -d -R .comment $@
60
61# arch=32 build options
62ASFLAGS_32 = -f elf32
63CFLAGS_32 = -m32
64ARFLAGS_32 = cr $@
65
66# arch=win64 build options
67ASFLAGS_win64 = -f win64
68CFLAGS_icl = -Qstd=c99
69ARFLAGS_win64 = -out:$@
70
71# arch=mingw build options
72ASFLAGS_mingw = -f win64
73ARFLAGS_mingw = cr $@
224ce89b
WB
74LDFLAGS_mingw = -Wl,--force-exe-suffix
75
76LDFLAGS_so = -Wl,-soname,$(soname)
7c673cae
FG
77
78ifeq ($(arch),mingw)
79 CC=x86_64-w64-mingw32-gcc
80 AR=x86_64-w64-mingw32-ar
7c673cae
FG
81endif
82
224ce89b
WB
83# arch=noarch build options
84ARFLAGS_noarch = cr $@
85ifeq ($(arch),noarch)
86 host_cpu=base_aliases
87endif
88
89ASFLAGS_Darwin = -f macho64 --prefix=_
90ARFLAGS_Darwin = -r $@
91ifeq ($(arch),Darwin)
92 LDFLAGS_so =
93 STRIP_gcc =
94endif
7c673cae
FG
95
96INCLUDE = $(patsubst %,-I%/,$(subst :, ,$(VPATH)))
97CFLAGS = $(CFLAGS_$(arch)) $(CFLAGS_$(CC)) $(DEBUG) -O2 $(DEFINES) $(INCLUDE)
98ASFLAGS = $(ASFLAGS_$(arch)) $(ASFLAGS_$(CC)) $(DEBUG_$(AS)) $(DEFINES) $(INCLUDE)
99ARFLAGS = $(ARFLAGS_$(arch))
100DEFINES += $(addprefix -D , $D)
101
224ce89b 102lsrc += $(lsrc_$(host_cpu))
7c673cae 103O = bin
224ce89b 104lobj += $(patsubst %.c,%.o,$(patsubst %.asm,%.o,$(lsrc) $(lsrc_intrinsic)))
7c673cae
FG
105objs = $(addprefix $(O)/,$(notdir $(lobj)))
106
107
108lib_name ?= isa-l.a
109default: lib slib
110
111# Defaults for windows build
112ifeq ($(arch),win64)
113 AR=lib
114 CC=cl
115 OUTPUT_OPTION = -Fo$@
116 DEBUG=
117 lib_name := $(basename $(lib_name)).lib
118endif
119lsrcwin64 = $(lsrc)
120unit_testswin64 = $(unit_tests)
121exampleswin64 = $(examples)
122perf_testswin64 = $(perf_tests)
123
124# Build and run unit tests, performance tests, etc.
224ce89b
WB
125all_tests = $(notdir $(sort $(perf_tests) $(check_tests) $(unit_tests) $(examples) $(other_tests)))
126all_unit_tests = $(notdir $(sort $(check_tests) $(unit_tests)))
127all_perf_tests = $(notdir $(sort $(perf_tests)))
128all_check_tests = $(notdir $(sort $(check_tests)))
7c673cae
FG
129
130$(all_unit_tests): % : %.c $(lib_name)
131$(all_perf_tests): % : %.c $(lib_name)
224ce89b 132$(sort $(notdir $(examples))): % : %.c $(lib_name)
7c673cae
FG
133$(sort $(notdir $(other_tests))): % : %.c $(lib_name)
134
135sim test trace: $(addsuffix .run,$(all_unit_tests))
136perf: $(addsuffix .run,$(all_perf_tests))
224ce89b
WB
137check: $(addsuffix .run,$(all_check_tests))
138ex: $(notdir $(examples))
7c673cae
FG
139all: lib $(all_tests)
140other: $(notdir $(other_tests))
141tests: $(all_unit_tests)
142perfs: $(all_perf_tests)
224ce89b 143checks: $(all_check_tests)
7c673cae
FG
144check test perf: SIM=
145trace: SIMFLAGS = -debugtrace
146check test sim:
147 @echo Finished running $@
148
149$(objs): | $(O)
150$(O): ; mkdir -p $(O)
151
152# Build rule to run tests
153$(addsuffix .run,$(all_tests)): %.run : %
154 $(SIM) ./$<
155 @echo Completed run: $<
156
157# Other build rules
224ce89b 158msg = $(if $(DEBUG),DEBUG) $(patsubst 32,32-bit,$(host_cpu)) $D
7c673cae
FG
159
160$(O)/%.o: %.asm
161 @echo " ---> Building $< $(msg)"
162 @$(AS) $(ASFLAGS) -o $@ $<
163
164$(O)/%.o %.o: %.c
165 @echo " ---> Building $< $(msg)"
166 @$(COMPILE.c) $(OUTPUT_OPTION) $<
167
168$(all_tests):
169 @echo " ---> Building Test $@ $(msg)"
170 @$(LINK.o) $(CFLAGS) $^ $(LDLIBS) -o $@
171
172
173# Target to build lib files
174lib: $(lib_name)
175ifneq ($(lib_debug),1)
176 $(lib_name): DEBUG_$(AS)= # Don't put debug symbols in the lib
177 $(lib_name): DEBUG=
178 $(lib_name): DEFINES+=-D NDEBUG
179endif
180ifeq ($(lib_debug),1)
181 DEBUG+=-D DEBUG # Define DEBUG for macros
182endif
183
184#lib $(lib_name): $(lib_name)(${objs})
185$(lib_name): $(objs)
186 @echo " ---> Creating Lib $@"
187 @$(AR) $(ARFLAGS) $^
188 @$(STRIP_$(CC))
189
190
191# Target for shared lib
192so_lib_name = bin/libisal.so
193so_lib_inst = $(notdir $(so_lib_name))
194so_lib_ver = $(so_lib_inst).$(version)
195soname = $(so_lib_inst).$(word 1, $(subst ., ,$(version)))
196
197slib: $(so_lib_name)
224ce89b
WB
198aobjs += $(addprefix $(O)/,$(patsubst %.asm,%.o,$(filter %.asm,$(notdir $(lsrc) $(lsrc_intrinsic)))))
199shared_objs += $(addprefix $(O)/shared_ver_,$(patsubst %.c,%.o,$(filter %.c,$(notdir $(lsrc) $(lsrc_intrinsic)))))
7c673cae
FG
200
201$(O)/shared_ver_%.o: %.c
202 @echo " ---> Building shared $< $(msg)"
203 @$(COMPILE.c) $(OUTPUT_OPTION) $<
204
205ifneq ($(lib_debug),1)
206 $(so_lib_name): DEBUG_$(AS)=
207 $(so_lib_name): DEBUG=
208 $(so_lib_name): DEFINES+=-D NDEBUG
209endif
210
211$(shared_objs): CFLAGS += -fPIC
212$(shared_objs) $(aobjs): | $(O)
224ce89b 213$(so_lib_name): LDFLAGS+=$(LDFLAGS_so)
7c673cae
FG
214$(so_lib_name): $(shared_objs) $(aobjs)
215 @echo " ---> Creating Shared Lib $@"
216 @$(CC) $(CFLAGS) --shared $(LDFLAGS) -o $@ $^
217 @(cd $(@D); ln -f -s $(so_lib_inst) $(soname))
218
224ce89b
WB
219
220isa-l.h:
221 @echo 'Building $@'
222 @echo '' >> $@
223 @echo '#ifndef _ISAL_H_' >> $@
224 @echo '#define _ISAL_H_' >> $@
225 @echo '' >> $@
226 @echo '#define.ISAL_MAJOR_VERSION.${version}' | ${AWK} -F . '{print $$1, $$2, $$3}' >> $@
227 @echo '#define.ISAL_MINOR_VERSION.${version}' | ${AWK} -F . '{print $$1, $$2, $$4}' >> $@
228 @echo '#define.ISAL_PATCH_VERSION.${version}' | ${AWK} -F . '{print $$1, $$2, $$5}' >> $@
229 @echo '#define ISAL_MAKE_VERSION(maj, min, patch) ((maj) * 0x10000 + (min) * 0x100 + (patch))' >> $@
230 @echo '#define ISAL_VERSION ISAL_MAKE_VERSION(ISAL_MAJOR_VERSION, ISAL_MINOR_VERSION, ISAL_PATCH_VERSION)' >> $@
231 @echo '' >> $@
232 @for unit in $(sort $(extern_hdrs)); do echo "#include <isa-l/$$unit>" | sed -e 's;include/;;' >> $@; done
233 @echo '#endif //_ISAL_H_' >> $@
234
235
7c673cae
FG
236# Target for install
237prefix = /usr/local
238install_dirs = $(prefix)/lib $(prefix)/include/isa-l
239$(install_dirs): ; mkdir -p $@
240install: $(sort $(extern_hdrs)) | $(install_dirs) $(lib_name) $(so_lib_name) isa-l.h
241 install -m 644 $(lib_name) $(prefix)/lib/libisal.a
242 install -m 644 $^ $(prefix)/include/isa-l/.
224ce89b
WB
243 install -m 664 isa-l.h $(prefix)/include/.
244 install -m 664 include/types.h $(prefix)/include/isa-l/.
7c673cae
FG
245 install -m 664 $(so_lib_name) $(prefix)/lib/$(so_lib_ver)
246 (cd $(prefix)/lib && ln -f -s $(so_lib_ver) $(soname) && ln -f -s $(so_lib_ver) $(so_lib_inst))
247ifeq ($(shell uname),Darwin)
248 (cd $(prefix)/lib && ln -f -s $(so_lib_ver) $(basename $(so_lib_inst)).dylib)
224ce89b
WB
249 which glibtool && glibtool --mode=finish $(prefix)/lib
250else
7c673cae
FG
251 which libtool && libtool --mode=finish $(prefix)/lib || \
252 echo 'Lib installed at $(prefix)/lib. Run system-dependent programs to add shared lib path.'
224ce89b 253endif
7c673cae
FG
254
255uninstall:
256 $(RM) $(prefix)/lib/libisal.a
257 $(RM) $(prefix)/lib/$(soname)
258 $(RM) $(prefix)/lib/$(so_lib_ver)
259 $(RM) $(prefix)/lib/$(so_lib_inst)
260 $(RM) -r $(prefix)/include/isa-l
261 $(RM) $(prefix)/include/isa-l.h
262 $(RM) $(prefix)/lib/$(basename $(so_lib_inst)).dylib
263
264# Collect performance data
265rpt_name = perf_report_$(shell uname -n)_$(shell date +%y%m%d).perf
266
267perf_report:
268 echo Results for $(rpt_name) >> $(rpt_name)
269 $(MAKE) -f Makefile.unx -k perf | tee -a $(rpt_name)
270 @echo Summary:
271 -grep runtime $(rpt_name)
272
273
274clean:
275 @echo Cleaning up
276 @$(RM) -r $(O) *.o *.a $(all_tests) $(lib_name) $(so_lib_name)
277
278
224ce89b
WB
279doc: isa-l.h
280 (cat Doxyfile; echo 'PROJECT_NUMBER=$(version)') | doxygen -
281 $(MAKE) -C generated_doc/latex &> generated_doc/latex_build_api.log
282 cp generated_doc/latex/refman.pdf isa-l_api_$(version).pdf
7c673cae 283