1# Copyright (c) 2005-2020 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# This file should be always located and called in $(tbb_root)/examples
16
17# Usage:
18#   make [all] [clean] [release] [debug] [test]
19#      executes specified targets for all examples.
20#   make {example's dir}/{target}
21#      calls specified example with specified target.
22#      For instance: make task/tree_sum/all
23
24tbb_root?=..
25BUILDING_PHASE:=0
26include ../build/common.inc
27
28#check, if tbb_root is not absolute path (the filter keeps only /* paths)
29ifeq ($(filter /% $(SLASH)%, $(subst :, ,$(tbb_root)) ),)
30    # also changes related variables like work_dir
31    override tbb_root := $(CWD)$(SLASH)..
32    export TBBROOT := $(tbb_root)
33endif
34
35override CXXFLAGS += $(CXX_STD_FLAGS)
36
37# give stdver priotity over autodetection
38ifneq (,$(stdver))
39    CXX0XFLAGS=-std=$(stdver)
40else
41    include common/examples-common.inc
42endif
43# empty CXX0XFLAGS exported as well, to have control over C++ autodetection
44export CXX0XFLAGS
45
46ifeq ($(tbb_os),windows)
47    ifeq ($(UNIXMODE),1)
48        EXAMPLE_MAKEFILE = Makefile
49        EXAMPLES = $(wildcard */*/$(EXAMPLE_MAKEFILE))
50        ifeq ($(compiler),gcc)
51            override CXXFLAGS += -Wl,--enable-auto-import
52        endif
53        export CPATH := $(CPATH);$(tbb_root)/include
54        export LIBRARY_PATH := $(LIBRARY_PATH);$(work_dir)_release;$(work_dir)_debug
55        export RM = cmd /C del /Q /F
56    else
57        EXAMPLE_MAKEFILE = Makefile.windows
58        EXAMPLES = $(wildcard */*/$(EXAMPLE_MAKEFILE))
59        EXAMPLE_MAKEFILE := $(if $(EXAMPLES),Makefile.windows,Makefile)
60        export INCLUDE := $(tbb_root)$(SLASH)include;$(INCLUDE)
61        export LIB := $(work_dir)_release;$(work_dir)_debug;$(LIB)
62    endif
63    work_dir := $(subst /,$(SLASH),$(work_dir))
64    export PATH := $(work_dir)_release;$(work_dir)_debug;$(PATH)
65    export TBB_ARCH_PLATFORM = $(arch)\$(runtime)
66    export TBB_TARGET_ARCH = $(arch)
67else
68    EXAMPLE_MAKEFILE = Makefile
69    EXAMPLES := $(wildcard */*/$(EXAMPLE_MAKEFILE))
70    # platform-specific settings
71    ifeq ($(arch),ia64)
72        override CXXFLAGS += $(PIC_KEY)
73    endif
74    ifneq ($(filter suncc gcc clang,$(compiler)),)
75        ifeq ($(compiler),suncc)
76            override CXXFLAGS += -I$(tbb_root)$(SLASH)include -library=stlport4 -M$(tbb_root)/build/suncc.map.pause -erroff=unassigned,attrskipunsup,badargtype2w,badbinaryopw,wbadasg,wvarhidemem,wbadinit
77        endif
78        ifeq ($(arch),intel64)
79            override CXXFLAGS += -m64
80        endif
81        ifeq ($(arch),ia32)
82            override CXXFLAGS += -m32
83        endif
84        ifeq ($(arch),ppc64)
85            override CXXFLAGS += -m64
86        endif
87        ifeq ($(arch),ppc32)
88            override CXXFLAGS += -m32
89        endif
90        ifeq ($(arch),sparc)
91            override CXXFLAGS += -mcpu=v9 -m64
92        endif
93    endif
94    ifeq ($(compiler),xl)
95        # -qsuppress=1540-0198 suppresses warnings like "1540-0198 (W) The omitted keyword "private" is assumed for base class "no_copy"."
96        # -qsuppress=1540-1401 suppresses warnings like "1540-1401 (I) An unknown "pragma ivdep" is specified."
97        override CXXFLAGS += -I$(tbb_root)$(SLASH)include -qsuppress=1540-0198:1540-1401 -L$(work_dir)_release -L$(work_dir)_debug
98        ifeq ($(arch),intel64)
99            override CXXFLAGS += -q64
100        endif
101        ifeq ($(arch),ia32)
102            override CXXFLAGS += -q32
103        endif
104        ifeq ($(arch),ppc64)
105            override CXXFLAGS += -q64
106        endif
107        ifeq ($(arch),ppc32)
108            override CXXFLAGS += -q32
109        endif
110    endif
111    ifeq ($(tbb_os),macos)
112        export DYLD_LIBRARY_PATH := $(DYLD_LIBRARY_PATH):$(work_dir)_release:$(work_dir)_debug
113        override CXXFLAGS += -Wl,-rpath,$(work_dir)_release -Wl,-rpath,$(work_dir)_debug
114    else
115        export LD_LIBRARY_PATH := $(LD_LIBRARY_PATH):$(work_dir)_release:$(work_dir)_debug
116        ifeq ($(findstring mic,$(offload) $(target)),mic)
117            mic_path=$(tbb_build_dir)$(SLASH)$(mic_tbb_build_prefix)
118            export MIC_LIBRARY_PATH := $(mic_path)_release:$(mic_path)_debug:$(MIC_LIBRARY_PATH)
119            export MIC_LD_LIBRARY_PATH := $(mic_path)_release:$(mic_path)_debug:$(MIC_LD_LIBRARY_PATH)
120        else
121            # -L necessary for non-native compilers which don't search $LIBRARY_PATH
122            override CXXFLAGS += -L$(work_dir)_release -L$(work_dir)_debug
123        endif
124    endif
125    export LIBS
126    export LIBRARY_PATH := $(LIBRARY_PATH):$(work_dir)_release:$(work_dir)_debug
127    export CPATH := $(CPATH):$(tbb_root)/include
128endif
129
130export CXXFLAGS
131COMMON_TARGETS := all clean release debug test perf_build perf_run
132# list of directories of examples
133EXAMPLES_DIRS := $(foreach T,$(EXAMPLES),$(dir $(T)))
134# targets to explicitly call example have format: {example's dir}/{example's target}
135EXAMPLES_TARGETS := $(foreach T,$(COMMON_TARGETS),$(addsuffix $(T),$(EXAMPLES_DIRS)))
136
137.PHONY: $(COMMON_TARGETS) $(EXAMPLES_TARGETS)
138
139.DEFAULT: all
140
141# execute standard targets for all examples
142$(COMMON_TARGETS):: % : $(addsuffix %,$(EXAMPLES_DIRS))
143
144# proxy rule for calling appropriate example
145$(EXAMPLES_TARGETS)::
146	@echo ------------------------ $@ ------------------------
147	-$(MAKE) -C $(@D)  -f $(EXAMPLE_MAKEFILE) $(notdir $@) CXX="$(CPLUS)" $(if $(run_cmd),run_cmd="$(run_cmd)",) $(if $(args),ARGS="$(args)",)  $(if $(UI),UI="$(UI)")
148
149printenv:
150ifeq ($(tbb_os),windows)
151	@cmd /C set PATH
152	@cmd /C set LIB
153	@cmd /C set INCLUDE
154else
155	@env | grep PATH
156endif
157
158