]> git.proxmox.com Git - ceph.git/blame - ceph/src/isa-l/make.inc
buildsys: fix parallel builds
[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
42version ?= #auto filled on release
43
44CC = gcc
45AS = yasm
46SIM = sde $(SIMFLAGS) --
47
48DEBUG = -g
49DEBUG_yasm = -g dwarf2
50DEBUG_nasm = -g
51
52# Default arch= build options
53CFLAGS_gcc = -Wall
54ASFLAGS_ = -f elf64
55ARFLAGS_ = cr $@
56STRIP_gcc = strip -d -R .comment $@
57
58# arch=32 build options
59ASFLAGS_32 = -f elf32
60CFLAGS_32 = -m32
61ARFLAGS_32 = cr $@
62
63# arch=win64 build options
64ASFLAGS_win64 = -f win64
65CFLAGS_icl = -Qstd=c99
66ARFLAGS_win64 = -out:$@
67
68# arch=mingw build options
69ASFLAGS_mingw = -f win64
70ARFLAGS_mingw = cr $@
71lsrcmingw = $(lsrc)
72unit_testsmingw = $(unit_tests)
73examplesmingw = $(examples)
74perf_testsmingw = $(perf_tests)
75
76ifeq ($(arch),mingw)
77 CC=x86_64-w64-mingw32-gcc
78 AR=x86_64-w64-mingw32-ar
79 LDFLAGS = -Wl,--force-exe-suffix
80endif
81
82
83INCLUDE = $(patsubst %,-I%/,$(subst :, ,$(VPATH)))
84CFLAGS = $(CFLAGS_$(arch)) $(CFLAGS_$(CC)) $(DEBUG) -O2 $(DEFINES) $(INCLUDE)
85ASFLAGS = $(ASFLAGS_$(arch)) $(ASFLAGS_$(CC)) $(DEBUG_$(AS)) $(DEFINES) $(INCLUDE)
86ARFLAGS = $(ARFLAGS_$(arch))
87DEFINES += $(addprefix -D , $D)
88
89O = bin
90lobj += $(patsubst %.c,%.o,$(patsubst %.asm,%.o,$(lsrc$(arch)) $(lsrc_intrinsic)))
91objs = $(addprefix $(O)/,$(notdir $(lobj)))
92
93
94lib_name ?= isa-l.a
95default: lib slib
96
97# Defaults for windows build
98ifeq ($(arch),win64)
99 AR=lib
100 CC=cl
101 OUTPUT_OPTION = -Fo$@
102 DEBUG=
103 lib_name := $(basename $(lib_name)).lib
104endif
105lsrcwin64 = $(lsrc)
106unit_testswin64 = $(unit_tests)
107exampleswin64 = $(examples)
108perf_testswin64 = $(perf_tests)
109
110# Build and run unit tests, performance tests, etc.
111all_tests = $(notdir $(sort $(perf_tests$(arch)) $(check_tests$(arch)) $(unit_tests$(arch)) $(examples$(arch)) $(other_tests)))
112all_unit_tests = $(notdir $(sort $(check_tests$(arch)) $(unit_tests$(arch))))
113all_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
120sim test trace: $(addsuffix .run,$(all_unit_tests))
121perf: $(addsuffix .run,$(all_perf_tests))
122ex: $(notdir $(examples$(arch)))
123all: lib $(all_tests)
124other: $(notdir $(other_tests))
125tests: $(all_unit_tests)
126perfs: $(all_perf_tests)
127check test perf: SIM=
128trace: SIMFLAGS = -debugtrace
129check 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
141msg = $(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
157lib: $(lib_name)
158ifneq ($(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
162endif
163ifeq ($(lib_debug),1)
164 DEBUG+=-D DEBUG # Define DEBUG for macros
165endif
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
175so_lib_name = bin/libisal.so
176so_lib_inst = $(notdir $(so_lib_name))
177so_lib_ver = $(so_lib_inst).$(version)
178soname = $(so_lib_inst).$(word 1, $(subst ., ,$(version)))
179
180slib: $(so_lib_name)
181aobjs += $(addprefix $(O)/,$(patsubst %.asm,%.o,$(filter %.asm,$(notdir $(lsrc$(arch)) $(lsrc_intrinsic)))))
182shared_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
188ifneq ($(lib_debug),1)
189 $(so_lib_name): DEBUG_$(AS)=
190 $(so_lib_name): DEBUG=
191 $(so_lib_name): DEFINES+=-D NDEBUG
192endif
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
203prefix = /usr/local
204install_dirs = $(prefix)/lib $(prefix)/include/isa-l
205$(install_dirs): ; mkdir -p $@
206install: $(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))
212ifeq ($(shell uname),Darwin)
213 (cd $(prefix)/lib && ln -f -s $(so_lib_ver) $(basename $(so_lib_inst)).dylib)
214endif
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
218uninstall:
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
228rpt_name = perf_report_$(shell uname -n)_$(shell date +%y%m%d).perf
229
230perf_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
237clean:
238 @echo Cleaning up
239 @$(RM) -r $(O) *.o *.a $(all_tests) $(lib_name) $(so_lib_name)
240
241
242