]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - tidl/tidl-api.git/blob - tidl_api/make.inc
Added version to tidl_viewer, build cleanup
[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.
27 # ------------------------------------------------------------------------------
28 #
29 # If making on x86 assume cross compile for ARM target
30 #
31 # Environment:
32 # - PSDK_LINUX : Target Linux Processor SDK for automatic configuration. If not
33 #   set, must specify paths in overridable variables.
34 # - PSDK_RTOS : Target RTOS Processor SDK for automatic configuration. If not
35 #   set and required (for persistent examples), must specify paths in
36 #   overridable variables.
37 #
38 # Overrides:
39 # - TARGET_ROOTDIR : ARM Linux devkit/filesystem
40 # - HOST_ROOTDIR : x86_64 Linux devkit
41 # - TI_OCL_INSTALL : TI OpenCL installation prefix if not from PSDK or target
42 #   devkit/filesystem
43 # - TI_OCL_CGT_INSTALL : TI C6x CGT installation directory if not from PSDK or
44 #   host devkit
45 # - CXX : C++ cross-compiler if not from PSDK or host devkit
46 # - CLOCL : clocl if not from PSDK, host devkit, or TI_OCL_INSTALL
47 #
48 # ------------------------------------------------------------------------------
49 #
50 # If making on the ARM target, use native compilation
51 #
52 # Overrides:
53 # - TI_OCL_INSTALL : TI OpenCL installation prefix if not system package
54 # - TI_OCL_CGT_INSTALL : TI C6x CGT installation directory if not system package
55 #
56 # ------------------------------------------------------------------------------
58 ifeq ($(MAKECMDGOALS),clean)
59     # config not required for clean
61 else
62 ifneq (,$(findstring 86, $(shell uname -m)))
63     # --------------------------------------------------------------------------
64     # host cross-compilation
66     ifeq ($(PSDK_LINUX),)
67         ifeq ($(TARGET_ROOTDIR),)
68             $(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)
69         endif
70     endif
72     export TARGET_ROOTDIR?=$(PSDK_LINUX)/linux-devkit/sysroots/armv7ahf-neon-linux-gnueabi
73     export HOST_ROOTDIR?=$(PSDK_LINUX)/linux-devkit/sysroots/x86_64-arago-linux
74     export TI_OCL_INSTALL?=$(TARGET_ROOTDIR)
75     export TI_OCL_CGT_INSTALL?=$(HOST_ROOTDIR)/usr/share/ti/cgt-c6x
77     # --------------------------------------------------------------------------
78     # ARM GCC
80     ifeq ($(origin CXX),default)
81         CXX=
82     endif
83     ifeq ($(CXX),)
84         ifneq ($(wildcard $(HOST_ROOTDIR)/usr/bin/arm-linux-gnueabihf-g++),)
85             CXX=$(HOST_ROOTDIR)/usr/bin/arm-linux-gnueabihf-g++
86         else
87             CXX=arm-linux-gnueabihf-g++
88         endif
89     endif
91     ifneq ($(shell which $(firstword $(CXX)) >/dev/null 2>/dev/null; echo $$?),0)
92         $(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.)
93     endif
95     # --------------------------------------------------------------------------
96     # clocl
98     ifeq ($(CLOCL),)
99         ifneq ($(wildcard $(TI_OCL_INSTALL)/usr/share/ti/opencl/bin/x86/clocl),)
100             CLOCL=$(TI_OCL_INSTALL)/usr/share/ti/opencl/bin/x86/clocl
101         else
102             ifneq ($(wildcard $(HOST_ROOTDIR)/usr/bin/clocl),)
103                 CLOCL=$(HOST_ROOTDIR)/usr/bin/clocl
104             else
105                 CLOCL=clocl
106             endif
107         endif
108     endif
110     ifneq ($(shell which $(firstword $(CLOCL)) >/dev/null 2>/dev/null; echo $$?),0)
111         $(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.)
112     endif
114     # --------------------------------------------------------------------------
115     # cl6x
117     ifeq ($(CL6X),)
118         ifneq ($(wildcard $(TI_OCL_CGT_INSTALL)/bin/cl6x),)
119             CL6X_BIN=$(TI_OCL_CGT_INSTALL)/bin
120             CL6X=$(TI_OCL_CGT_INSTALL)/bin/cl6x
121         else
122             ifneq ($(wildcard $(HOST_ROOTDIR)/usr/bin/cl6x),)
123                 CL6X_BIN=$(HOST_ROOTDIR)/usr/bin
124                 CL6X=$(HOST_ROOTDIR)/usr/bin/cl6x
125             else
126                 CL6X=cl6x
127             endif
128         endif
129     endif
131     ifneq ($(shell which $(firstword $(CL6X)) >/dev/null 2>/dev/null; echo $$?),0)
132         $(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.)
133     endif
135     # --------------------------------------------------------------------------
137     # gcc ARM cross compiler will not, by default, search the host's
138     # /usr/include.  Explicitly specify here to find dependent vendor headers
139     # Do not use /usr/include on host machine, it might have different gcc
140     # versions and could cause problems.
141     CXXFLAGS += "--sysroot=$(TARGET_ROOTDIR)"
142     CXXFLAGS += -I$(TI_OCL_INSTALL)/usr/include
143     CXXFLAGS += -I$(TARGET_ROOTDIR)/usr/include
145     # If cross-compiling, provide path to dependent ARM libraries on the
146     # target filesystem
147     LDFLAGS += "--sysroot=$(TARGET_ROOTDIR)"
149     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
151 else
152     # --------------------------------------------------------------------------
153     # target native compilation
155     CXX      = g++
156     CXXFLAGS += -I$(TI_OCL_INSTALL)/usr/include
157     LDFLAGS  += -L$(TI_OCL_INSTALL)/usr/lib
158     LIBS     += -lbfd
160     # --------------------------------------------------------------------------
161     # clocl
163     ifeq ($(CLOCL),)
164         ifneq ($(wildcard $(TI_OCL_INSTALL)/usr/bin/clocl),)
165             CLOCL=$(TI_OCL_INSTALL)/usr/bin/clocl
166         else
167             CLOCL=clocl
168         endif
169     endif
171     ifneq ($(shell which $(firstword $(CLOCL)) >/dev/null 2>/dev/null; echo $$?),0)
172         $(error CLOCL $(CLOCL) not found. Set TI_OCL_INSTALL to a valid TI OpenCL installation prefix.)
173     endif
175     # --------------------------------------------------------------------------
176     # cl6x
178     ifeq ($(CL6X),)
179         ifneq ($(wildcard $(TI_OCL_CGT_INSTALL)/bin/cl6x),)
180             CL6X_BIN=$(TI_OCL_CGT_INSTALL)/bin
181             CL6X=$(TI_OCL_CGT_INSTALL)/bin/cl6x
182         else
183             CL6X=cl6x
184         endif
185     endif
187     ifneq ($(shell which $(firstword $(CL6X)) >/dev/null 2>/dev/null; echo $$?),0)
188         $(error $(CL6X) not found. Set TI_OCL_CGT_INSTALL to a TI C6x CGT installation.)
189     endif
190 endif
192 # --------------------------------------------------------------------------
193 # RTOS components
194 # Used by persistent_* examples
196 ifeq ($(USE_RTOS),1)
197     ifeq ($(PSDK_RTOS),)
198         tmp_NEED_RTOS=
199         ifeq ($(XDC_DIR),)
200             tmp_NEED_RTOS += XDC_DIR
201         endif
203         ifneq ($(tmp_NEED_RTOS),)
204             $(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)
205         endif
206     endif
208     XDC_DIR   ?= $(wildcard $(PSDK_RTOS)/xdc*)/packages
209     BIOS_DIR  ?= $(TARGET_ROOTDIR)/usr/share/ti/ti-sysbios-tree/packages
210     IPC_DIR   ?= $(TARGET_ROOTDIR)/usr/share/ti/ti-ipc-tree/packages
212     DSP_INCLUDE += -I$(BIOS_DIR) -I$(XDC_DIR) -I$(IPC_DIR)
213 endif
215 endif
217 # --------------------------------------------------------------------------
219 # clocl executes "cl6x" directly; make sure it uses the selected CGT
220 ifneq ($(CL6X_BIN),)
221     CLOCL:=env PATH=$(CL6X_BIN):$(PATH) $(CLOCL)
222 endif
224 ifneq ($(TI_OCL_CGT_INSTALL),)
225     DSP_INCLUDE += -I$(TI_OCL_CGT_INSTALL)/include
226 endif
228 DSP_INCLUDE += -I$(TI_OCL_INSTALL)/usr/share/ti/opencl
229 DSP_INCLUDE += -I$(TARGET_ROOTDIR)/usr/share/ti/opencl
230 DSP_INCLUDE += -I$(TARGET_ROOTDIR)/usr/share/ti/cgt-c6x/include
232 CL6X += -mv6600 --abi=eabi $(DSP_INCLUDE)
234 LIBS  = -lOpenCL -locl_util
236 %.o: %.cpp
237         @echo Compiling $<
238         $(CXX) -c $(CXXFLAGS) $<
240 %.o: %.c
241         @echo Compiling $<
242         $(CXX) -c $(CXXFLAGS) $<
244 %.obj: %.c
245         @echo Compiling $<
246         $(CL6X) -c $(CL6XFLAGS) $<
248 $(EXE):
250 clean::
251         @$(RM) -f $(EXE) *.o *.obj *.out *.asm *.if *.opt *.bc *.objc *.map *.bin *.dsp_h
253 test: clean $(EXE)
254         @echo Running   $(EXE)
255         @./$(EXE) >/dev/null || echo "FAILED!!!"