1 %%{
2 /*
3 * Copyright (c) 2013-2014 Texas Instruments Incorporated - http://www.ti.com
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 *
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 *
17 * * Neither the name of Texas Instruments Incorporated nor the names of
18 * its contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
23 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
25 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
28 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
30 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
31 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33 %%}
34 %%{
35 var File = xdc.module("xdc.services.io.File");
36 var BIOS = xdc.module("ti.sysbios.BIOS");
37 var Build = xdc.module("ti.sdo.utils.Build");
38 var TARGET = $args[0];
39 var XDCROOT = String(environment['xdc.rootDir'] + '/packages/').replace(/\\/g, "/");
41 var CGEN = TARGET.rootDir.replace(/\\/g, "/");
43 function baseName(path) {
44 return path.substr(path.lastIndexOf('/') + 1).replace(/\.[^\.]+$/, "");
45 }
47 function packageName(path) {
48 var dirpath = path.substring(0, path.lastIndexOf('/'));
49 return dirpath.substr(dirpath.lastIndexOf('/') + 1);
50 }
51 var OBJS = [];
52 var CFILES = Build.getCFiles(TARGET.$name);
53 %%}
54 vpath % `File.getDOSPath(this.$package.packageRepository) + "ti/sdo/"`
55 vpath %.c `XDCROOT`
57 XOPTS = `'-I"' + XDCROOT + '"' + " -Dxdc_target_types__=" + File.getDOSPath(TARGET.$package.packageRepository) + TARGET.stdInclude + " -Dxdc_target_name__=" + TARGET.name`
59 CCOPTS = `BIOS.getCCOpts(TARGET.name)`
61 XDC_ROOT = `XDCROOT`
63 IPC_ROOT = `File.getDOSPath(this.$package.packageRepository) + "ti/sdo/"`
65 BUILD_DEFS = `Build.getDefs()`
67 SYSBIOS_INC = -I"`xdc.getPackageRepository("ti.sysbios")`"
69 IPC_INC = -I"`xdc.getPackageRepository("ti.sdo.ipc")`"
71 UTILS_INC = -I"`xdc.getPackageRepository("ti.sdo.utils")`"
73 %if (TARGET.$name.match(/gnu/)) {
74 CC = `CGEN`/`TARGET.ccBin.cmd` $(CCOPTS) -I `CGEN`/arm-none-eabi/include
75 ASM = `CGEN`/`TARGET.asmBin.cmd` $(CCOPTS) -I `CGEN`/arm-none-eabi/include
76 AR = `CGEN`/`TARGET.arBin.cmd` `TARGET.ar.opts`
77 %}
78 %else {
79 CC = `CGEN`/bin/`TARGET.cc.cmd` $(CCOPTS) -I `CGEN`/include
80 ASM = `CGEN`/bin/`TARGET.asm.cmd` $(CCOPTS) -I `CGEN`/include
81 AR = `CGEN`/bin/`TARGET.ar.cmd` `TARGET.ar.opts`
82 %}
84 %if (environment["os.name"].match(/Windows.*/i)) {
85 %if (BIOS.buildingAppLib == false) {
86 % Build.$private.libDir = Build.$private.libDir.replace(/\//g,'\\');
87 %}
88 DEL = cmd.exe /q /c del /f
89 CP = cmd.exe /q /c copy /Y
90 MKDIR = mkdir
91 %}
92 %else {
93 DEL = rm -f
94 CP = cp -f
95 MKDIR = mkdir -p
96 %}
98 define RM
99 $(if $(wildcard $1),$(DEL) $1,:)
100 endef
102 define ASSEMBLE
103 @echo asm`TARGET.suffix` $< ...
104 @$(ASM) $(BUILD_DEFS) $(XOPTS) $(UTILS_INC) $<
105 endef
107 %var LIB = "utils.a" + TARGET.suffix;
109 %if (BIOS.buildingAppLib == false) {
110 all: `Build.$private.libDir``LIB`
111 %}
112 %else {
113 all: `LIB`
114 %}
116 %var sources = Build.getAsmFiles(TARGET.$name);
117 %for each (var s in sources) {
118 %if (TARGET.$name.match(/gnu/)) {
119 % var obj = packageName(s) + "_" + baseName(s) + ".o";
120 %}
121 %else {
122 % var obj = packageName(s) + "_" + baseName(s) + ".obj";
123 %}
124 % OBJS.push(obj)
125 `obj`: `s` makefile
126 @-$(call RM, $@)
127 %if (TARGET.$name.match(/gnu/)) {
128 $(ASSEMBLE) -o `obj`
129 %}
130 %else {
131 $(ASSEMBLE) --output_file=`obj`
132 %}
134 %}
136 %if (TARGET.$name.match(/gnu/)) {
137 Ipc.o: `CFILES` makefile
138 @-$(call RM, Ipc.o)
139 @-$(call RM, Ipc.o.dep)
140 %}
141 %else {
142 UTILS.obj: `CFILES` makefile
143 @-$(call RM, $@)
144 %}
145 @echo cl`TARGET.suffix` $< ...
146 @$(CC) $(BUILD_DEFS) $(XOPTS) $(SYSBIOS_INC) \
147 $(IPC_INC) $(UTILS_INC) \
148 %var sources = CFILES.split(' ');
149 %for each (var s in sources) {
150 % if (s.substring(0,4) == "xdc/") {
151 $(XDC_ROOT)`s` \
152 % } else if (s.substring(0,2) == "./") {
153 `s` \
154 % } else {
155 $(IPC_ROOT)`s` \
156 % }
157 %}
159 %if (TARGET.$name.match(/gnu/)) {
160 `LIB`: UTILS.o `OBJS.join(" ")`
161 %}
162 %else {
163 `LIB`: UTILS.obj `OBJS.join(" ")`
164 %}
165 @-$(call RM, $@)
166 @echo ar`TARGET.suffix` $^ ...
167 @$(AR) $@ $^
169 %if (BIOS.buildingAppLib == false) {
170 `Build.$private.libDir``LIB`: `LIB`
171 @echo cp `LIB`
172 @-$(call RM, "`Build.$private.libDir``LIB`")
173 @$(CP) `LIB` "`Build.$private.libDir``LIB`"
174 %}
176 clean:
177 @-$(call RM, `LIB`)
178 %if (BIOS.buildingAppLib == false) {
179 @-$(call RM, "`Build.$private.libDir``LIB`")
180 %}
181 %if (TARGET.$name.match(/gnu/)) {
182 @-$(call RM, UTILS.o)
183 %}
184 %else {
185 @-$(call RM, UTILS.obj)
186 %}
187 %for (var i = 0; i < OBJS.length; i++) {
188 @-$(call RM, `OBJS[i]`)
189 %}
190 %if (Build.$private.libDir != null) {
192 # create output directories
193 ifneq ($(MAKECMDGOALS),clean)
194 ifeq ($(wildcard `Build.$private.libDir`),)
195 $(shell $(MKDIR) `Build.$private.libDir`)
196 endif
197 endif
198 %}