]> git.proxmox.com Git - ceph.git/blob - ceph/src/isa-l/make.inc
update sources to v12.1.1
[ceph.git] / ceph / src / isa-l / make.inc
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
42 version ?= 2.18.0
43 host_cpu ?= $(shell uname -m | sed -e 's/amd/x86_/')
44 arch ?= $(shell uname | grep -v -e Linux -e BSD )
45
46 CC = gcc
47 AS = yasm
48 SIM = sde $(SIMFLAGS) --
49 AWK = awk
50
51 DEBUG = -g
52 DEBUG_yasm = -g dwarf2
53 DEBUG_nasm = -g
54
55 # Default arch= build options
56 CFLAGS_ = -Wall
57 ASFLAGS_ = -f elf64
58 ARFLAGS_ = cr $@
59 STRIP_gcc = strip -d -R .comment $@
60
61 # arch=32 build options
62 ASFLAGS_32 = -f elf32
63 CFLAGS_32 = -m32
64 ARFLAGS_32 = cr $@
65
66 # arch=win64 build options
67 ASFLAGS_win64 = -f win64
68 CFLAGS_icl = -Qstd=c99
69 ARFLAGS_win64 = -out:$@
70
71 # arch=mingw build options
72 ASFLAGS_mingw = -f win64
73 ARFLAGS_mingw = cr $@
74 LDFLAGS_mingw = -Wl,--force-exe-suffix
75
76 LDFLAGS_so = -Wl,-soname,$(soname)
77
78 ifeq ($(arch),mingw)
79 CC=x86_64-w64-mingw32-gcc
80 AR=x86_64-w64-mingw32-ar
81 endif
82
83 # arch=noarch build options
84 ARFLAGS_noarch = cr $@
85 ifeq ($(arch),noarch)
86 host_cpu=base_aliases
87 endif
88
89 ASFLAGS_Darwin = -f macho64 --prefix=_
90 ARFLAGS_Darwin = -r $@
91 ifeq ($(arch),Darwin)
92 LDFLAGS_so =
93 STRIP_gcc =
94 endif
95
96 INCLUDE = $(patsubst %,-I%/,$(subst :, ,$(VPATH)))
97 CFLAGS = $(CFLAGS_$(arch)) $(CFLAGS_$(CC)) $(DEBUG) -O2 $(DEFINES) $(INCLUDE)
98 ASFLAGS = $(ASFLAGS_$(arch)) $(ASFLAGS_$(CC)) $(DEBUG_$(AS)) $(DEFINES) $(INCLUDE)
99 ARFLAGS = $(ARFLAGS_$(arch))
100 DEFINES += $(addprefix -D , $D)
101
102 lsrc += $(lsrc_$(host_cpu))
103 O = bin
104 lobj += $(patsubst %.c,%.o,$(patsubst %.asm,%.o,$(lsrc) $(lsrc_intrinsic)))
105 objs = $(addprefix $(O)/,$(notdir $(lobj)))
106
107
108 lib_name ?= isa-l.a
109 default: lib slib
110
111 # Defaults for windows build
112 ifeq ($(arch),win64)
113 AR=lib
114 CC=cl
115 OUTPUT_OPTION = -Fo$@
116 DEBUG=
117 lib_name := $(basename $(lib_name)).lib
118 endif
119 lsrcwin64 = $(lsrc)
120 unit_testswin64 = $(unit_tests)
121 exampleswin64 = $(examples)
122 perf_testswin64 = $(perf_tests)
123
124 # Build and run unit tests, performance tests, etc.
125 all_tests = $(notdir $(sort $(perf_tests) $(check_tests) $(unit_tests) $(examples) $(other_tests)))
126 all_unit_tests = $(notdir $(sort $(check_tests) $(unit_tests)))
127 all_perf_tests = $(notdir $(sort $(perf_tests)))
128 all_check_tests = $(notdir $(sort $(check_tests)))
129
130 $(all_unit_tests): % : %.c $(lib_name)
131 $(all_perf_tests): % : %.c $(lib_name)
132 $(sort $(notdir $(examples))): % : %.c $(lib_name)
133 $(sort $(notdir $(other_tests))): % : %.c $(lib_name)
134
135 sim test trace: $(addsuffix .run,$(all_unit_tests))
136 perf: $(addsuffix .run,$(all_perf_tests))
137 check: $(addsuffix .run,$(all_check_tests))
138 ex: $(notdir $(examples))
139 all: lib $(all_tests)
140 other: $(notdir $(other_tests))
141 tests: $(all_unit_tests)
142 perfs: $(all_perf_tests)
143 checks: $(all_check_tests)
144 check test perf: SIM=
145 trace: SIMFLAGS = -debugtrace
146 check 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
158 msg = $(if $(DEBUG),DEBUG) $(patsubst 32,32-bit,$(host_cpu)) $D
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
174 lib: $(lib_name)
175 ifneq ($(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
179 endif
180 ifeq ($(lib_debug),1)
181 DEBUG+=-D DEBUG # Define DEBUG for macros
182 endif
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
192 so_lib_name = bin/libisal.so
193 so_lib_inst = $(notdir $(so_lib_name))
194 so_lib_ver = $(so_lib_inst).$(version)
195 soname = $(so_lib_inst).$(word 1, $(subst ., ,$(version)))
196
197 slib: $(so_lib_name)
198 aobjs += $(addprefix $(O)/,$(patsubst %.asm,%.o,$(filter %.asm,$(notdir $(lsrc) $(lsrc_intrinsic)))))
199 shared_objs += $(addprefix $(O)/shared_ver_,$(patsubst %.c,%.o,$(filter %.c,$(notdir $(lsrc) $(lsrc_intrinsic)))))
200
201 $(O)/shared_ver_%.o: %.c
202 @echo " ---> Building shared $< $(msg)"
203 @$(COMPILE.c) $(OUTPUT_OPTION) $<
204
205 ifneq ($(lib_debug),1)
206 $(so_lib_name): DEBUG_$(AS)=
207 $(so_lib_name): DEBUG=
208 $(so_lib_name): DEFINES+=-D NDEBUG
209 endif
210
211 $(shared_objs): CFLAGS += -fPIC
212 $(shared_objs) $(aobjs): | $(O)
213 $(so_lib_name): LDFLAGS+=$(LDFLAGS_so)
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
219
220 isa-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
236 # Target for install
237 prefix = /usr/local
238 install_dirs = $(prefix)/lib $(prefix)/include/isa-l
239 $(install_dirs): ; mkdir -p $@
240 install: $(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/.
243 install -m 664 isa-l.h $(prefix)/include/.
244 install -m 664 include/types.h $(prefix)/include/isa-l/.
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))
247 ifeq ($(shell uname),Darwin)
248 (cd $(prefix)/lib && ln -f -s $(so_lib_ver) $(basename $(so_lib_inst)).dylib)
249 which glibtool && glibtool --mode=finish $(prefix)/lib
250 else
251 which libtool && libtool --mode=finish $(prefix)/lib || \
252 echo 'Lib installed at $(prefix)/lib. Run system-dependent programs to add shared lib path.'
253 endif
254
255 uninstall:
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
265 rpt_name = perf_report_$(shell uname -n)_$(shell date +%y%m%d).perf
266
267 perf_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
274 clean:
275 @echo Cleaning up
276 @$(RM) -r $(O) *.o *.a $(all_tests) $(lib_name) $(so_lib_name)
277
278
279 doc: 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
283