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
43 host_cpu ?= $(shell uname -m | sed -e 's/amd/x86_/')
44 arch ?= $(shell uname | grep -v -e Linux -e BSD )
48 SIM = sde $(SIMFLAGS) --
52 DEBUG_yasm = -g dwarf2
55 # Default arch= build options
59 STRIP_gcc = strip -d -R .comment $@
61 # arch=32 build options
66 # arch=win64 build options
67 ASFLAGS_win64 = -f win64
68 CFLAGS_icl = -Qstd=c99
69 ARFLAGS_win64 = -out:$@
71 # arch=mingw build options
72 ASFLAGS_mingw = -f win64
74 LDFLAGS_mingw = -Wl,--force-exe-suffix
76 LDFLAGS_so = -Wl,-soname,$(soname)
79 CC=x86_64-w64-mingw32-gcc
80 AR=x86_64-w64-mingw32-ar
83 # arch=noarch build options
84 ARFLAGS_noarch = cr $@
89 ASFLAGS_Darwin = -f macho64 --prefix=_
90 ARFLAGS_Darwin = -r $@
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)
102 lsrc += $(lsrc_$(host_cpu))
104 lobj += $(patsubst %.c,%.o,$(patsubst %.asm,%.o,$(lsrc) $(lsrc_intrinsic)))
105 objs = $(addprefix $(O)/,$(notdir $(lobj)))
111 # Defaults for windows build
115 OUTPUT_OPTION = -Fo$@
117 lib_name := $(basename $(lib_name)).lib
120 unit_testswin64 = $(unit_tests)
121 exampleswin64 = $(examples)
122 perf_testswin64 = $(perf_tests)
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)))
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)
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
147 @echo Finished running $@
150 $(O): ; mkdir -p $(O)
152 # Build rule to run tests
153 $(addsuffix .run,$(all_tests)): %.run : %
155 @echo Completed run: $<
158 msg = $(if $(DEBUG),DEBUG) $(patsubst 32,32-bit,$(host_cpu)) $D
161 @echo " ---> Building $< $(msg)"
162 @$(AS) $(ASFLAGS) -o $@ $<
165 @echo " ---> Building $< $(msg)"
166 @$(COMPILE.c) $(OUTPUT_OPTION) $<
169 @echo " ---> Building Test $@ $(msg)"
170 @$(LINK.o) $(CFLAGS) $^ $(LDLIBS) -o $@
173 # Target to build lib files
175 ifneq ($(lib_debug),1)
176 $(lib_name): DEBUG_$(AS)= # Don't put debug symbols in the lib
178 $(lib_name): DEFINES+=-D NDEBUG
180 ifeq ($(lib_debug),1)
181 DEBUG+=-D DEBUG # Define DEBUG for macros
184 #lib $(lib_name): $(lib_name)(${objs})
186 @echo " ---> Creating Lib $@"
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)))
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)))))
201 $(O)/shared_ver_%.o: %.c
202 @echo " ---> Building shared $< $(msg)"
203 @$(COMPILE.c) $(OUTPUT_OPTION) $<
205 ifneq ($(lib_debug),1)
206 $(so_lib_name): DEBUG_$(AS)=
207 $(so_lib_name): DEBUG=
208 $(so_lib_name): DEFINES+=-D NDEBUG
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))
223 @echo '#ifndef _ISAL_H_' >> $@
224 @echo '#define _ISAL_H_' >> $@
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)' >> $@
232 @for unit in $(sort $(extern_hdrs)); do echo "#include <isa-l/$$unit>" | sed -e 's;include/;;' >> $@; done
233 @echo '#endif //_ISAL_H_' >> $@
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
251 which libtool && libtool --mode=finish $(prefix)/lib || \
252 echo 'Lib installed at $(prefix)/lib. Run system-dependent programs to add shared lib path.'
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
264 # Collect performance data
265 rpt_name = perf_report_$(shell uname -n)_$(shell date +%y%m%d).perf
268 echo Results for $(rpt_name) >> $(rpt_name)
269 $(MAKE) -f Makefile.unx -k perf | tee -a $(rpt_name)
271 -grep runtime $(rpt_name)
276 @$(RM) -r $(O) *.o *.a $(all_tests) $(lib_name) $(so_lib_name)
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