d56b92485ada3879b623709cd449ffec8ce2f070
[platform/upstream/tbb.git] / build / common_rules.inc
1 # Copyright (c) 2005-2019 Intel Corporation
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #     http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15
16 ifeq ($(tbb_strict),1)
17   ifeq ($(WARNING_AS_ERROR_KEY),)
18     $(error WARNING_AS_ERROR_KEY is empty)
19   endif
20   # Do not remove line below!
21   WARNING_KEY += $(WARNING_AS_ERROR_KEY)
22 endif
23
24 ifneq (,$(findstring s,$(MAKEFLAGS)))
25   override largs+=-q
26 endif
27 ifneq (,$(repeat))
28   override largs+=-r $(repeat)
29 endif
30 ifneq (,$(largs)$(run_prefix))
31   override run_cmd:=$(run_cmd) $(TEST_LAUNCHER)
32   TEST_LAUNCHER=
33   ifeq (,$(strip $(run_cmd)))
34     $(warning Test launcher is not defined for the platform, ignoring launcher arguments)
35   endif
36 endif
37
38 ifndef TEST_EXT
39     TEST_EXT = exe
40 endif
41
42 INCLUDES += $(INCLUDE_KEY)$(tbb_root)/src $(INCLUDE_KEY)$(tbb_root)/src/rml/include $(INCLUDE_KEY)$(tbb_root)/include
43
44 CPLUS_FLAGS += $(WARNING_KEY) $(CXXFLAGS)
45 ifeq (1,$(tbb_cpf))
46 CPLUS_FLAGS += $(DEFINE_KEY)__TBB_CPF_BUILD=1
47 endif
48 ifeq (0,$(exceptions))
49 CPLUS_FLAGS += $(DEFINE_KEY)TBB_USE_EXCEPTIONS=0
50 endif
51 LINK_FLAGS += $(LDFLAGS)
52 LIB_LINK_FLAGS += $(LDFLAGS)
53
54 LIB_LINK_CMD ?= $(CPLUS) $(PIC_KEY)
55 ifeq ($(origin LIB_OUTPUT_KEY), undefined)
56     LIB_OUTPUT_KEY = $(OUTPUT_KEY)
57 endif
58 ifeq ($(origin LIB_LINK_LIBS), undefined)
59     LIB_LINK_LIBS = $(LIBDL) $(LIBS)
60 endif
61
62 # some platforms do not provide separate C-only compiler
63 CONLY ?= $(CPLUS)
64
65 # The most generic rules
66 #$(1) - is the target pattern
67 define make-cxx-obj
68 $1: %.cpp
69         $$(CPLUS) $$(OUTPUTOBJ_KEY)$$@ $$(COMPILE_ONLY) $$(CPLUS_FLAGS) $$(CXX_ONLY_FLAGS) $$(CXX_WARN_SUPPRESS) $$(INCLUDES) $$<
70 endef
71
72 TEST_AFFIXES_OBJS=$(addsuffix .$(OBJ),$(addprefix %_,$(TEST_SUFFIXES)) $(addsuffix _%,$(TEST_PREFIXES)))
73
74 # Make will not process the same recipe for each test pattern (since the dependency on the same %.cpp)
75 # thus the separated recipes should be provided
76 $(foreach t,%.$(OBJ) $(TEST_AFFIXES_OBJS),$(eval $(call make-cxx-obj,$(t))))
77
78 .PRECIOUS: %.$(OBJ) %.$(TEST_EXT) %.res $(TEST_AFFIXES_OBJS)
79
80 # Rules for generating a test DLL
81 %_dll.$(OBJ): %.cpp
82         $(CPLUS) $(COMPILE_ONLY) $(OUTPUTOBJ_KEY)$@ $(CPLUS_FLAGS) $(PIC_KEY) $(DEFINE_KEY)_USRDLL $(INCLUDES) $<
83
84 #$(1) - is the binary name
85 #$(2) - is the input obj files and libraries
86 define make-test-binary
87         $(CPLUS) $(OUTPUT_KEY)$(strip $1) $(CPLUS_FLAGS) $(2) $(LIBS) $(LINK_FLAGS)
88 endef
89
90 # LINK_FILES the list of options to link test specific files (libraries and object files)
91 LINK_FILES+=$(TEST_LIBS)
92 # Rule for generating executable test
93 %.$(TEST_EXT): %.$(OBJ) $(TEST_LIBS) $(TEST_PREREQUISITE) $(if $(use_proxy),$(PROXY.LIB))
94         $(call make-test-binary,$@,$< $(LINK_FILES) $(PIE_FLAG))
95
96 # Rules for generating a test DLL
97 %_dll.$(DLL): LINK_FLAGS += $(PIC_KEY) $(DYLIB_KEY)
98 %_dll.$(DLL): TEST_LIBS := $(subst %_dll.$(DLL),,$(TEST_LIBS))
99 %_dll.$(DLL): %_dll.$(OBJ)
100         $(call make-test-binary,$@,$< $(LINK_FILES))
101 .PRECIOUS: %_dll.$(OBJ) %_dll.$(DLL)
102
103 %.$(OBJ): %.c
104         $(CONLY) $(COMPILE_ONLY) $(OUTPUTOBJ_KEY)$@ $(C_FLAGS) $(INCLUDES) $<
105
106 %.$(OBJ): %.asm
107         $(ASM) $(ASM_FLAGS) $<
108
109 %.$(OBJ): %.s
110         cpp <$< | grep -v '^#' >$*.tmp
111         $(ASM) $(ASM_FLAGS) -o $@ $*.tmp
112
113 # Rule for generating .E file if needed for visual inspection
114 # Note that ICL treats an argument after PREPROC_ONLY as a file to open,
115 # so all uses of PREPROC_ONLY should be immediately followed by a file name
116 %.E: %.cpp
117         $(CPLUS) $(CPLUS_FLAGS) $(CXX_ONLY_FLAGS) $(INCLUDES) $(PREPROC_ONLY) $< >$@
118
119 # TODO Rule for generating .asm file if needed for visual inspection
120 %.asm: %.cpp
121         $(CPLUS) /c /FAs /Fa $(CPLUS_FLAGS) $(CXX_ONLY_FLAGS) $(INCLUDES) $<
122
123 # TODO Rule for generating .s file if needed for visual inspection
124 %.s: %.cpp
125         $(CPLUS) -S $(CPLUS_FLAGS) $(CXX_ONLY_FLAGS) $(INCLUDES) $<
126
127 # Customizations
128 $(KNOWN_WARNINGS): %.$(OBJ): %.cpp
129         $(CPLUS) $(COMPILE_ONLY) $(subst $(WARNING_KEY),,$(CPLUS_FLAGS)) $(CXX_ONLY_FLAGS) $(CXX_WARN_SUPPRESS) $(INCLUDES) $<
130
131 tbb_misc.$(OBJ): version_string.ver
132 tbb_misc.$(OBJ): INCLUDES+=$(INCLUDE_KEY).
133
134 tbb_misc.E: tbb_misc.cpp version_string.ver
135         $(CPLUS) $(CPLUS_FLAGS) $(CXX_ONLY_FLAGS) $(INCLUDE_KEY). $(INCLUDES) $(PREPROC_ONLY) $< >$@
136
137 %.res: %.rc version_string.ver $(TBB.MANIFEST)
138         rc /Fo$@ $(INCLUDES) $(filter /D%,$(CPLUS_FLAGS)) $<
139
140 # TODO: add $(LIB_LINK_LIBS) $(LIB_LINK_FLAGS) (in a separate line?) and remove useless $(INCLUDES)
141 VERSION_FLAGS=$(CPLUS) $(CPLUS_FLAGS) $(CXX_ONLY_FLAGS) $(INCLUDES)
142
143 ifneq (,$(TBB.MANIFEST))
144 $(TBB.MANIFEST):
145         cmd /C "echo #include ^<stdio.h^> >tbbmanifest.c"
146         cmd /C "echo int main(){return 0;} >>tbbmanifest.c"
147         cl /nologo $(C_FLAGS) tbbmanifest.c
148
149 version_string.ver: $(TBB.MANIFEST)
150         $(MAKE_VERSIONS)
151         cmd /C "echo #define TBB_MANIFEST 1 >> version_string.ver"
152 # TODO: fix parallel build by writing to a temporary file and rename it when complete
153 else
154 # TODO: make version strings directly representative for all the libraries
155 version_string.ver:
156         $(MAKE_VERSIONS)
157 endif
158
159 test_% debug_%: test_%.$(TEST_EXT) $(TEST_PREREQUISITE)
160         $(run_cmd) ./$< $(args)
161 ifneq (,$(codecov))
162         profmerge
163         codecov $(if $(findstring -,$(codecov)),$(codecov),) -demang -comp $(tbb_root)/build/codecov.txt
164 endif
165