]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - tidl/tidl-api.git/blob - tidl_api/make.inc
32635c08415d4e21bc5399e59b9d726537b778b5
[tidl/tidl-api.git] / tidl_api / make.inc
1 # Copyright (c) 2018 Texas Instruments Incorporated - http://www.ti.com/
2 # 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 are met:
6 # * Redistributions of source code must retain the above copyright
7 # notice, this list of conditions and the following disclaimer.
8 # * Redistributions in binary form must reproduce the above copyright
9 # notice, this list of conditions and the following disclaimer in the
10 # documentation and/or other materials provided with the distribution.
11 # * Neither the name of Texas Instruments Incorporated nor the
12 # names of its contributors may be used to endorse or promote products
13 # derived from this software without specific prior written permission.
14 #
15 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19 # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
25 # THE POSSIBILITY OF SUCH DAMAGE.
28 # ------------------------------------------------------------------------------
29 #
30 # If making on x86 assume cross compile for ARM target
31 #
32 # Environment:
33 # - PSDK_LINUX : Target Linux Processor SDK for automatic configuration. If not
34 #   set, must specify paths in overridable variables.
35 # - PSDK_RTOS : Target RTOS Processor SDK for automatic configuration. If not
36 #   set and required (for persistent examples), must specify paths in
37 #   overridable variables.
38 #
39 # Overrides:
40 # - TARGET_ROOTDIR : ARM Linux devkit/filesystem
41 # - HOST_ROOTDIR : x86_64 Linux devkit
42 # - TI_OCL_INSTALL : TI OpenCL installation prefix if not from PSDK or target
43 #   devkit/filesystem
44 # - TI_OCL_CGT_INSTALL : TI C6x CGT installation directory if not from PSDK or
45 #   host devkit
46 # - CXX : C++ cross-compiler if not from PSDK or host devkit
47 # - CLOCL : clocl if not from PSDK, host devkit, or TI_OCL_INSTALL
48 #
49 # ------------------------------------------------------------------------------
50 #
51 # If making on the ARM target, use native compilation
52 #
53 # Overrides:
54 # - TI_OCL_INSTALL : TI OpenCL installation prefix if not system package
55 # - TI_OCL_CGT_INSTALL : TI C6x CGT installation directory if not system package
56 #
57 # ------------------------------------------------------------------------------
59 ifeq ($(MAKECMDGOALS),clean)
60     # config not required for clean
62 else
63 ifneq (,$(findstring 86, $(shell uname -m)))
64     # --------------------------------------------------------------------------
65     # host cross-compilation
67     ifeq ($(PSDK_LINUX),)
68         ifeq ($(TARGET_ROOTDIR),)
69             $(error Environment variable PSDK_LINUX is not defined; set it to point at the target Linux PSDK for automatic configuration or set TARGET_ROOTDIR to the ARM Linux devkit/filesystem)
70         endif
71     endif
73     export TARGET_ROOTDIR?=$(PSDK_LINUX)/linux-devkit/sysroots/armv7ahf-neon-linux-gnueabi
74     export HOST_ROOTDIR?=$(PSDK_LINUX)/linux-devkit/sysroots/x86_64-arago-linux
75     export TI_OCL_INSTALL?=$(TARGET_ROOTDIR)
76     export TI_OCL_CGT_INSTALL?=$(HOST_ROOTDIR)/usr/share/ti/cgt-c6x
78     # --------------------------------------------------------------------------
79     # ARM GCC
81     ifeq ($(origin CXX),default)
82         CXX=
83     endif
84     ifeq ($(CXX),)
85         ifneq ($(wildcard $(HOST_ROOTDIR)/usr/bin/arm-linux-gnueabihf-g++),)
86             CXX=$(HOST_ROOTDIR)/usr/bin/arm-linux-gnueabihf-g++
87         else
88             CXX=arm-linux-gnueabihf-g++
89         endif
90     endif
92     ifneq ($(shell which $(firstword $(CXX)) >/dev/null 2>/dev/null; echo $$?),0)
93         $(error C++ cross-compiler $(CXX) not found. Set PSDK_LINUX to point to the target Linux PSDK for automatic configuration, set HOST_ROOTDIR to the x86_64 Linux devkit, or add the compiler bin directory to PATH.)
94     endif
96     # --------------------------------------------------------------------------
97     # clocl
99     ifeq ($(CLOCL),)
100         ifneq ($(wildcard $(TI_OCL_INSTALL)/usr/share/ti/opencl/bin/x86/clocl),)
101             CLOCL=$(TI_OCL_INSTALL)/usr/share/ti/opencl/bin/x86/clocl
102         else
103             ifneq ($(wildcard $(HOST_ROOTDIR)/usr/bin/clocl),)
104                 CLOCL=$(HOST_ROOTDIR)/usr/bin/clocl
105             else
106                 CLOCL=clocl
107             endif
108         endif
109     endif
111     ifneq ($(shell which $(firstword $(CLOCL)) >/dev/null 2>/dev/null; echo $$?),0)
112         $(error CLOCL $(CLOCL) not found. Set PSDK_LINUX to point to the target Linux PSDK for automatic configuration, set HOST_ROOTDIR to the x86_64 Linux devkit, or add the clocl bin directory to PATH.)
113     endif
115     # --------------------------------------------------------------------------
116     # cl6x
118     ifeq ($(CL6X),)
119         ifneq ($(wildcard $(TI_OCL_CGT_INSTALL)/bin/cl6x),)
120             CL6X_BIN=$(TI_OCL_CGT_INSTALL)/bin
121             CL6X=$(TI_OCL_CGT_INSTALL)/bin/cl6x
122         else
123             ifneq ($(wildcard $(HOST_ROOTDIR)/usr/bin/cl6x),)
124                 CL6X_BIN=$(HOST_ROOTDIR)/usr/bin
125                 CL6X=$(HOST_ROOTDIR)/usr/bin/cl6x
126             else
127                 CL6X=cl6x
128             endif
129         endif
130     endif
132     ifneq ($(shell which $(firstword $(CL6X)) >/dev/null 2>/dev/null; echo $$?),0)
133         $(error $(CL6X) not found. Set PSDK_LINUX to point to the target Linux PSDK for automatic configuration, set HOST_ROOTDIR to the x86_64 Linux devkit, or set TI_OCL_CGT_INSTALL to a TI C6x CGT installation.)
134     endif
136     # --------------------------------------------------------------------------
138     # gcc ARM cross compiler will not, by default, search the host's
139     # /usr/include.  Explicitly specify here to find dependent vendor headers
140     # Do not use /usr/include on host machine, it might have different gcc
141     # versions and could cause problems.
142     CXXFLAGS += "--sysroot=$(TARGET_ROOTDIR)"
143     CXXFLAGS += -I$(TI_OCL_INSTALL)/usr/include
144     CXXFLAGS += -I$(TARGET_ROOTDIR)/usr/include
146     # If cross-compiling, provide path to dependent ARM libraries on the
147     # target filesystem
148     LDFLAGS += "--sysroot=$(TARGET_ROOTDIR)"
150     LDFLAGS += -L$(TI_OCL_INSTALL)/usr/lib -L$(TARGET_ROOTDIR)/lib -L$(TARGET_ROOTDIR)/usr/lib -Wl,-rpath-link,$(TARGET_ROOTDIR)/lib -Wl,-rpath-link,$(TARGET_ROOTDIR)/usr/lib
152 else
153     # --------------------------------------------------------------------------
154     # target native compilation
156     CXX      = g++
157     CXXFLAGS += -I$(TI_OCL_INSTALL)/usr/include
158     LDFLAGS  += -L$(TI_OCL_INSTALL)/usr/lib
159     LIBS     += -lbfd
161     # --------------------------------------------------------------------------
162     # clocl
164     ifeq ($(CLOCL),)
165         ifneq ($(wildcard $(TI_OCL_INSTALL)/usr/bin/clocl),)
166             CLOCL=$(TI_OCL_INSTALL)/usr/bin/clocl
167         else
168             CLOCL=clocl
169         endif
170     endif
172     ifneq ($(shell which $(firstword $(CLOCL)) >/dev/null 2>/dev/null; echo $$?),0)
173         $(error CLOCL $(CLOCL) not found. Set TI_OCL_INSTALL to a valid TI OpenCL installation prefix.)
174     endif
176     # --------------------------------------------------------------------------
177     # cl6x
179     ifeq ($(CL6X),)
180         ifneq ($(wildcard $(TI_OCL_CGT_INSTALL)/bin/cl6x),)
181             CL6X_BIN=$(TI_OCL_CGT_INSTALL)/bin
182             CL6X=$(TI_OCL_CGT_INSTALL)/bin/cl6x
183         else
184             CL6X=cl6x
185         endif
186     endif
188     ifneq ($(shell which $(firstword $(CL6X)) >/dev/null 2>/dev/null; echo $$?),0)
189         $(error $(CL6X) not found. Set TI_OCL_CGT_INSTALL to a TI C6x CGT installation.)
190     endif
191 endif
193 # --------------------------------------------------------------------------
194 # RTOS components
195 # Used by persistent_* examples
197 ifeq ($(USE_RTOS),1)
198     ifeq ($(PSDK_RTOS),)
199         tmp_NEED_RTOS=
200         ifeq ($(XDC_DIR),)
201             tmp_NEED_RTOS += XDC_DIR
202         endif
204         ifneq ($(tmp_NEED_RTOS),)
205             $(error Environment variable PSDK_RTOS is not defined; set PSDK_RTOS to point at the target RTOS PSDK for automatic configuration or set $(tmp_NEED_RTOS) to the corresponding package directories)
206         endif
207     endif
209     XDC_DIR   ?= $(wildcard $(PSDK_RTOS)/xdc*)/packages
210     BIOS_DIR  ?= $(TARGET_ROOTDIR)/usr/share/ti/ti-sysbios-tree/packages
211     IPC_DIR   ?= $(TARGET_ROOTDIR)/usr/share/ti/ti-ipc-tree/packages
213     DSP_INCLUDE += -I$(BIOS_DIR) -I$(XDC_DIR) -I$(IPC_DIR)
214 endif
216 endif
218 # --------------------------------------------------------------------------
220 # clocl executes "cl6x" directly; make sure it uses the selected CGT
221 ifneq ($(CL6X_BIN),)
222     CLOCL:=env PATH=$(CL6X_BIN):$(PATH) $(CLOCL)
223 endif
225 ifneq ($(TI_OCL_CGT_INSTALL),)
226     DSP_INCLUDE += -I$(TI_OCL_CGT_INSTALL)/include
227 endif
229 DSP_INCLUDE += -I$(TI_OCL_INSTALL)/usr/share/ti/opencl
230 DSP_INCLUDE += -I$(TARGET_ROOTDIR)/usr/share/ti/opencl
231 DSP_INCLUDE += -I$(TARGET_ROOTDIR)/usr/share/ti/cgt-c6x/include
233 CL6X += -mv6600 --abi=eabi $(DSP_INCLUDE)
235 LIBS  = -lOpenCL -locl_util
237 %.o: %.cpp
238         @echo Compiling $<
239         $(CXX) -c $(CXXFLAGS) $<
241 %.o: %.c
242         @echo Compiling $<
243         $(CXX) -c $(CXXFLAGS) $<
245 %.obj: %.c
246         @echo Compiling $<
247         $(CL6X) -c $(CL6XFLAGS) $<
249 $(EXE):
251 clean::
252         @$(RM) -f $(EXE) *.o *.obj *.out *.asm *.if *.opt *.bc *.objc *.map *.bin *.dsp_h
254 test: clean $(EXE)
255         @echo Running   $(EXE)
256         @./$(EXE) >/dev/null || echo "FAILED!!!"