]> git.proxmox.com Git - ceph.git/blob - ceph/src/isa-l/make.inc
a5a7a02ee8d80bc39e355bfaf9d377f78ce076a5
[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 ?= #auto filled on release
43
44 CC = gcc
45 AS = yasm
46 SIM = sde $(SIMFLAGS) --
47
48 DEBUG = -g
49 DEBUG_yasm = -g dwarf2
50 DEBUG_nasm = -g
51
52 # Default arch= build options
53 CFLAGS_gcc = -Wall
54 ASFLAGS_ = -f elf64
55 ARFLAGS_ = cr $@
56 STRIP_gcc = strip -d -R .comment $@
57
58 # arch=32 build options
59 ASFLAGS_32 = -f elf32
60 CFLAGS_32 = -m32
61 ARFLAGS_32 = cr $@
62
63 # arch=win64 build options
64 ASFLAGS_win64 = -f win64
65 CFLAGS_icl = -Qstd=c99
66 ARFLAGS_win64 = -out:$@
67
68 # arch=mingw build options
69 ASFLAGS_mingw = -f win64
70 ARFLAGS_mingw = cr $@
71 lsrcmingw = $(lsrc)
72 unit_testsmingw = $(unit_tests)
73 examplesmingw = $(examples)
74 perf_testsmingw = $(perf_tests)
75
76 ifeq ($(arch),mingw)
77 CC=x86_64-w64-mingw32-gcc
78 AR=x86_64-w64-mingw32-ar
79 LDFLAGS = -Wl,--force-exe-suffix
80 endif
81
82
83 INCLUDE = $(patsubst %,-I%/,$(subst :, ,$(VPATH)))
84 CFLAGS = $(CFLAGS_$(arch)) $(CFLAGS_$(CC)) $(DEBUG) -O2 $(DEFINES) $(INCLUDE)
85 ASFLAGS = $(ASFLAGS_$(arch)) $(ASFLAGS_$(CC)) $(DEBUG_$(AS)) $(DEFINES) $(INCLUDE)
86 ARFLAGS = $(ARFLAGS_$(arch))
87 DEFINES += $(addprefix -D , $D)
88
89 O = bin
90 lobj += $(patsubst %.c,%.o,$(patsubst %.asm,%.o,$(lsrc$(arch)) $(lsrc_intrinsic)))
91 objs = $(addprefix $(O)/,$(notdir $(lobj)))
92
93
94 lib_name ?= isa-l.a
95 default: lib slib
96
97 # Defaults for windows build
98 ifeq ($(arch),win64)
99 AR=lib
100 CC=cl
101 OUTPUT_OPTION = -Fo$@
102 DEBUG=
103 lib_name := $(basename $(lib_name)).lib
104 endif
105 lsrcwin64 = $(lsrc)
106 unit_testswin64 = $(unit_tests)
107 exampleswin64 = $(examples)
108 perf_testswin64 = $(perf_tests)
109
110 # Build and run unit tests, performance tests, etc.
111 all_tests = $(notdir $(sort $(perf_tests$(arch)) $(check_tests$(arch)) $(unit_tests$(arch)) $(examples$(arch)) $(other_tests)))
112 all_unit_tests = $(notdir $(sort $(check_tests$(arch)) $(unit_tests$(arch))))
113 all_perf_tests = $(notdir $(sort $(perf_tests$(arch))))
114
115 $(all_unit_tests): % : %.c $(lib_name)
116 $(all_perf_tests): % : %.c $(lib_name)
117 $(sort $(notdir $(examples$(arch)))): % : %.c $(lib_name)
118 $(sort $(notdir $(other_tests))): % : %.c $(lib_name)
119
120 sim test trace: $(addsuffix .run,$(all_unit_tests))
121 perf: $(addsuffix .run,$(all_perf_tests))
122 ex: $(notdir $(examples$(arch)))
123 all: lib $(all_tests)
124 other: $(notdir $(other_tests))
125 tests: $(all_unit_tests)
126 perfs: $(all_perf_tests)
127 check test perf: SIM=
128 trace: SIMFLAGS = -debugtrace
129 check test sim:
130 @echo Finished running $@
131
132 $(objs): | $(O)
133 $(O): ; mkdir -p $(O)
134
135 # Build rule to run tests
136 $(addsuffix .run,$(all_tests)): %.run : %
137 $(SIM) ./$<
138 @echo Completed run: $<
139
140 # Other build rules
141 msg = $(if $(DEBUG),DEBUG) $(patsubst 32,32-bit,$(arch)) $D
142
143 $(O)/%.o: %.asm
144 @echo " ---> Building $< $(msg)"
145 @$(AS) $(ASFLAGS) -o $@ $<
146
147 $(O)/%.o %.o: %.c
148 @echo " ---> Building $< $(msg)"
149 @$(COMPILE.c) $(OUTPUT_OPTION) $<
150
151 $(all_tests):
152 @echo " ---> Building Test $@ $(msg)"
153 @$(LINK.o) $(CFLAGS) $^ $(LDLIBS) -o $@
154
155
156 # Target to build lib files
157 lib: $(lib_name)
158 ifneq ($(lib_debug),1)
159 $(lib_name): DEBUG_$(AS)= # Don't put debug symbols in the lib
160 $(lib_name): DEBUG=
161 $(lib_name): DEFINES+=-D NDEBUG
162 endif
163 ifeq ($(lib_debug),1)
164 DEBUG+=-D DEBUG # Define DEBUG for macros
165 endif
166
167 #lib $(lib_name): $(lib_name)(${objs})
168 $(lib_name): $(objs)
169 @echo " ---> Creating Lib $@"
170 @$(AR) $(ARFLAGS) $^
171 @$(STRIP_$(CC))
172
173
174 # Target for shared lib
175 so_lib_name = bin/libisal.so
176 so_lib_inst = $(notdir $(so_lib_name))
177 so_lib_ver = $(so_lib_inst).$(version)
178 soname = $(so_lib_inst).$(word 1, $(subst ., ,$(version)))
179
180 slib: $(so_lib_name)
181 aobjs += $(addprefix $(O)/,$(patsubst %.asm,%.o,$(filter %.asm,$(notdir $(lsrc$(arch)) $(lsrc_intrinsic)))))
182 shared_objs += $(addprefix $(O)/shared_ver_,$(patsubst %.c,%.o,$(filter %.c,$(notdir $(lsrc$(arch)) $(lsrc_intrinsic)))))
183
184 $(O)/shared_ver_%.o: %.c
185 @echo " ---> Building shared $< $(msg)"
186 @$(COMPILE.c) $(OUTPUT_OPTION) $<
187
188 ifneq ($(lib_debug),1)
189 $(so_lib_name): DEBUG_$(AS)=
190 $(so_lib_name): DEBUG=
191 $(so_lib_name): DEFINES+=-D NDEBUG
192 endif
193
194 $(shared_objs): CFLAGS += -fPIC
195 $(shared_objs) $(aobjs): | $(O)
196 $(so_lib_name): LDFLAGS+=-Wl,-soname,$(soname)
197 $(so_lib_name): $(shared_objs) $(aobjs)
198 @echo " ---> Creating Shared Lib $@"
199 @$(CC) $(CFLAGS) --shared $(LDFLAGS) -o $@ $^
200 @(cd $(@D); ln -f -s $(so_lib_inst) $(soname))
201
202 # Target for install
203 prefix = /usr/local
204 install_dirs = $(prefix)/lib $(prefix)/include/isa-l
205 $(install_dirs): ; mkdir -p $@
206 install: $(sort $(extern_hdrs)) | $(install_dirs) $(lib_name) $(so_lib_name) isa-l.h
207 install -m 644 $(lib_name) $(prefix)/lib/libisal.a
208 install -m 644 $^ $(prefix)/include/isa-l/.
209 install -m 664 include/isa-l.h $(prefix)/include/.
210 install -m 664 $(so_lib_name) $(prefix)/lib/$(so_lib_ver)
211 (cd $(prefix)/lib && ln -f -s $(so_lib_ver) $(soname) && ln -f -s $(so_lib_ver) $(so_lib_inst))
212 ifeq ($(shell uname),Darwin)
213 (cd $(prefix)/lib && ln -f -s $(so_lib_ver) $(basename $(so_lib_inst)).dylib)
214 endif
215 which libtool && libtool --mode=finish $(prefix)/lib || \
216 echo 'Lib installed at $(prefix)/lib. Run system-dependent programs to add shared lib path.'
217
218 uninstall:
219 $(RM) $(prefix)/lib/libisal.a
220 $(RM) $(prefix)/lib/$(soname)
221 $(RM) $(prefix)/lib/$(so_lib_ver)
222 $(RM) $(prefix)/lib/$(so_lib_inst)
223 $(RM) -r $(prefix)/include/isa-l
224 $(RM) $(prefix)/include/isa-l.h
225 $(RM) $(prefix)/lib/$(basename $(so_lib_inst)).dylib
226
227 # Collect performance data
228 rpt_name = perf_report_$(shell uname -n)_$(shell date +%y%m%d).perf
229
230 perf_report:
231 echo Results for $(rpt_name) >> $(rpt_name)
232 $(MAKE) -f Makefile.unx -k perf | tee -a $(rpt_name)
233 @echo Summary:
234 -grep runtime $(rpt_name)
235
236
237 clean:
238 @echo Cleaning up
239 @$(RM) -r $(O) *.o *.a $(all_tests) $(lib_name) $(so_lib_name)
240
241
242