1 %%{
2 /*
3 * Copyright (c) 2012-2013, Texas Instruments Incorporated
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");
37 var BIOS = xdc.module("ti.sysbios.BIOS");
39 var Build = xdc.module("ti.sysbios.Build");
41 var TARGET = $args[0];
43 var XOPTS = '-I "' + environment['xdc.rootDir'] + '/packages" '
44 + "-Dxdc_target_types__=" + TARGET.stdInclude
45 + " -Dxdc_target_name__=" + TARGET.name;
47 var CGEN = TARGET.rootDir.replace(/\\/g, "/");
49 function baseName(path) {
50 return path.substr(path.lastIndexOf('/') + 1).replace(/\.[^\.]+$/, "");
51 }
53 function packageName(path) {
54 var dirpath = path.substring(0, path.lastIndexOf('/'));
55 return dirpath.substr(dirpath.lastIndexOf('/') + 1);
56 }
57 var OBJS = [];
58 %%}
59 vpath % `File.getDOSPath(this.$package.packageRepository) + "ti/sysbios/"`
60 vpath %.c `environment['xdc.rootDir'] + '/packages/'`
62 CCOPTS = `BIOS.getCCOpts(TARGET.name)`
64 XDC_ROOT = `environment['xdc.rootDir'] + '/packages/'`
66 BIOS_ROOT = `File.getDOSPath(this.$package.packageRepository) + "ti/sysbios/"`
68 BIOS_DEFS = `BIOS.getDefs()`
70 BIOS_INC = -I"`File.getDOSPath(this.$package.packageRepository)`"
72 %if (TARGET.$name.match(/gnu/)) {
73 CC = `CGEN`/`TARGET.ccBin.cmd` $(CCOPTS) -I `CGEN`/arm-none-eabi/include
74 ASM = `CGEN`/`TARGET.asmBin.cmd` $(CCOPTS) -I `CGEN`/arm-none-eabi/include
75 AR = `CGEN`/`TARGET.arBin.cmd` `TARGET.ar.opts`
76 %}
77 %else {
78 CC = `CGEN`/bin/`TARGET.cc.cmd` $(CCOPTS) -I `CGEN`/include
79 ASM = `CGEN`/bin/`TARGET.asm.cmd` $(CCOPTS) -I `CGEN`/include
80 AR = `CGEN`/bin/`TARGET.ar.cmd` `TARGET.ar.opts`
81 %}
83 %if (environment["os.name"].match(/Windows.*/i)) {
84 DEL = cmd.exe /q /c del /f
85 CP = cmd.exe /q /c copy /Y
86 %}
87 %else {
88 DEL = rm -f
89 CP = cp -f
90 %}
92 define RM
93 $(if $(wildcard $1),$(DEL) $1,:)
94 endef
96 define ASSEMBLE
97 @echo asm`TARGET.suffix` $< ...
98 @$(ASM) $(BIOS_DEFS) `XOPTS` $(BIOS_INC) $<
99 endef
101 define COMPILE
102 @echo cl`TARGET.suffix` $< ...
103 @$(CC) $(BIOS_DEFS) `XOPTS` $(BIOS_INC) $<
104 endef
106 %var LIB = "sysbios.lib";
108 all: `LIB`
110 %var sources = BIOS.getAsmFiles(TARGET.$name);
111 %for each (var s in sources) {
112 %if (TARGET.$name.match(/gnu/)) {
113 % var obj = packageName(s) + "_" + baseName(s) + ".o";
114 %}
115 %else {
116 % var obj = packageName(s) + "_" + baseName(s) + ".obj";
117 %}
118 % OBJS.push(obj)
119 `obj`: `s` makefile
120 @-$(call RM, $@)
121 %if (TARGET.$name.match(/gnu/)) {
122 $(ASSEMBLE) -o `obj`
123 %}
124 %else {
125 $(ASSEMBLE) --output_file=`obj`
126 %}
128 %}
130 %var sources = BIOS.getCFiles(TARGET.name).split(' ');
131 %for each (var s in sources) {
132 %if (TARGET.$name.match(/gnu/)) {
133 % var obj = packageName(s) + "_" + baseName(s) + ".o";
134 %}
135 %else {
136 % var obj = packageName(s) + "_" + baseName(s) + ".obj";
137 %}
138 % OBJS.push(obj)
139 `obj`: `s` makefile
140 @-$(call RM, `obj`)
141 %if (TARGET.$name.match(/gnu/)) {
142 $(COMPILE) -o `obj`
143 %}
144 %else {
145 $(COMPILE) --output_file=`obj`
146 %}
147 %}
149 `LIB`: `OBJS.join(" ")`
150 @echo ar`TARGET.suffix` $^ ...
151 @-$(call RM, $@)
152 %if (BIOS.buildingAppLib == false) {
153 @-$(call RM, `Build.$private.libDir``LIB`)
154 %}
155 @$(AR) $@ $^
156 %if (BIOS.buildingAppLib == false) {
157 @$(CP) `LIB` `Build.$private.libDir`
158 %}
160 clean:
161 @-$(call RM, `LIB`)
162 %if (BIOS.buildingAppLib == false) {
163 @-$(call RM, `Build.$private.libDir``LIB`)
164 %}
165 %if (TARGET.$name.match(/gnu/)) {
166 @-$(call RM, BIOS.o)
167 %}
168 %else {
169 @-$(call RM, BIOS.obj)
170 %}
171 %for (var i = 0; i < OBJS.length; i++) {
172 @-$(call RM, `OBJS[i]`)
173 %}