1 ########################################################################
2 # Copyright(c) 2011-2015 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
42 version ?= #auto filled on release
46 SIM = sde $(SIMFLAGS) --
49 DEBUG_yasm = -g dwarf2
52 # Default arch= build options
56 STRIP_gcc = strip -d -R .comment $@
58 # arch=32 build options
63 # arch=win64 build options
64 ASFLAGS_win64 = -f win64
65 CFLAGS_icl = -Qstd=c99
66 ARFLAGS_win64 = -out:$@
68 # arch=mingw build options
69 ASFLAGS_mingw = -f win64
72 unit_testsmingw = $(unit_tests)
73 examplesmingw = $(examples)
74 perf_testsmingw = $(perf_tests)
77 CC=x86_64-w64-mingw32-gcc
78 AR=x86_64-w64-mingw32-ar
79 LDFLAGS = -Wl,--force-exe-suffix
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)
90 lobj += $(patsubst %.c,%.o,$(patsubst %.asm,%.o,$(lsrc$(arch)) $(lsrc_intrinsic)))
91 objs = $(addprefix $(O)/,$(notdir $(lobj)))
97 # Defaults for windows build
101 OUTPUT_OPTION = -Fo$@
103 lib_name := $(basename $(lib_name)).lib
106 unit_testswin64 = $(unit_tests)
107 exampleswin64 = $(examples)
108 perf_testswin64 = $(perf_tests)
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))))
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)
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
130 @echo Finished running $@
133 $(O): ; mkdir -p $(O)
135 # Build rule to run tests
136 $(addsuffix .run,$(all_tests)): %.run : %
138 @echo Completed run: $<
141 msg = $(if $(DEBUG),DEBUG) $(patsubst 32,32-bit,$(arch)) $D
144 @echo " ---> Building $< $(msg)"
145 @$(AS) $(ASFLAGS) -o $@ $<
148 @echo " ---> Building $< $(msg)"
149 @$(COMPILE.c) $(OUTPUT_OPTION) $<
152 @echo " ---> Building Test $@ $(msg)"
153 @$(LINK.o) $(CFLAGS) $^ $(LDLIBS) -o $@
156 # Target to build lib files
158 ifneq ($(lib_debug),1)
159 $(lib_name): DEBUG_$(AS)= # Don't put debug symbols in the lib
161 $(lib_name): DEFINES+=-D NDEBUG
163 ifeq ($(lib_debug),1)
164 DEBUG+=-D DEBUG # Define DEBUG for macros
167 #lib $(lib_name): $(lib_name)(${objs})
169 @echo " ---> Creating Lib $@"
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)))
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)))))
184 $(O)/shared_ver_%.o: %.c
185 @echo " ---> Building shared $< $(msg)"
186 @$(COMPILE.c) $(OUTPUT_OPTION) $<
188 ifneq ($(lib_debug),1)
189 $(so_lib_name): DEBUG_$(AS)=
190 $(so_lib_name): DEBUG=
191 $(so_lib_name): DEFINES+=-D NDEBUG
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))
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)
215 which libtool && libtool --mode=finish $(prefix)/lib || \
216 echo 'Lib installed at $(prefix)/lib. Run system-dependent programs to add shared lib path.'
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
227 # Collect performance data
228 rpt_name = perf_report_$(shell uname -n)_$(shell date +%y%m%d).perf
231 echo Results for $(rpt_name) >> $(rpt_name)
232 $(MAKE) -f Makefile.unx -k perf | tee -a $(rpt_name)
234 -grep runtime $(rpt_name)
239 @$(RM) -r $(O) *.o *.a $(all_tests) $(lib_name) $(so_lib_name)