2e30ddd21357ac134124add2e787c6b2990d749f
1 %%{
2 /*
3 * Copyright (c) 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.sdo.utils.Build");
41 var TARGET = $args[0];
43 var XDCROOT = String(environment['xdc.rootDir'] + '/packages/').replace(/\\/g, "/");
45 var XOPTS = '-I "' + XDCROOT + '"'
46 + " -Dxdc_target_types__=" + File.getDOSPath(TARGET.$package.packageRepository) + TARGET.stdInclude
47 + " -Dxdc_target_name__=" + TARGET.name;
49 var CGEN = TARGET.rootDir.replace(/\\/g, "/");
51 function baseName(path) {
52 return path.substr(path.lastIndexOf('/') + 1).replace(/\.[^\.]+$/, "");
53 }
55 function packageName(path) {
56 var dirpath = path.substring(0, path.lastIndexOf('/'));
57 return dirpath.substr(dirpath.lastIndexOf('/') + 1);
58 }
59 var OBJS = [];
60 %%}
61 vpath % `File.getDOSPath(this.$package.packageRepository) + "ti/sdo/"`
62 vpath %.c `XDCROOT`
64 CCOPTS = `BIOS.getCCOpts(TARGET.$name)`
66 XDC_ROOT = `XDCROOT`
68 BUILD_DEFS = `Build.getDefs()`
70 BIOS_INC = -I"`xdc.getPackageRepository("ti.sysbios")`"
72 UTILS_INC = -I"`xdc.getPackageRepository("ti.sdo.utils")`"
75 CC = `CGEN`/`TARGET.ccBin.cmd` $(CCOPTS) -I `CGEN`/arm-none-eabi/include
76 ASM = `CGEN`/`TARGET.asmBin.cmd` $(CCOPTS) -I `CGEN`/arm-none-eabi/include
77 AR = `CGEN`/`TARGET.arBin.cmd` `TARGET.ar.opts`
79 %if (environment["os.name"].match(/Windows.*/i)) {
80 %if (BIOS.buildingAppLib == false) {
81 % Build.$private.libDir = Build.$private.libDir.replace(/\//g,'\\');
82 %}
83 DEL = cmd.exe /q /c del /f
84 CP = cmd.exe /q /c copy /Y
85 %}
86 %else {
87 DEL = rm -f
88 CP = cp -f
89 %}
91 define RM
92 $(if $(wildcard $1),$(DEL) $1,:)
93 endef
95 define ASSEMBLE
96 @echo asm`TARGET.suffix` $< ...
97 @$(ASM) $(BUILD_DEFS) `XOPTS` $(BIOS_INC) $<
98 endef
100 define COMPILE
101 @echo cl`TARGET.suffix` $< ...
102 @$(CC) $(BUILD_DEFS) `XOPTS` $(BIOS_INC) $(UTILS_INC) $<
103 endef
105 %var LIB = "utils.a" + TARGET.suffix;
107 all: `LIB`
109 %var sources = Build.getAsmFiles(TARGET.$name);
110 %for each (var s in sources) {
111 % var obj = packageName(s) + "_" + baseName(s) + ".o";
112 % OBJS.push(obj)
113 `obj`: `s` makefile
114 @-$(call RM, $@)
115 $(ASSEMBLE) -o `obj`
117 %}
119 %var sources = Build.getCFiles(TARGET.$name).split(' ');
120 %for each (var s in sources) {
121 % var obj = packageName(s) + "_" + baseName(s) + ".o";
122 % OBJS.push(obj)
123 `obj`: `s` makefile
124 @-$(call RM, `obj`)
125 $(COMPILE) -o `obj`
126 %}
128 `LIB`: `OBJS.join(" ")`
129 @echo ar`TARGET.suffix` $^ ...
130 @-$(call RM, $@)
131 @$(AR) $@ $^
132 %if (BIOS.buildingAppLib == false) {
133 @-$(call RM, "`Build.$private.libDir``LIB`")
134 $(CP) `LIB` "`Build.$private.libDir``LIB`"
135 %}
137 clean:
138 @-$(call RM, `LIB`)
139 %if (BIOS.buildingAppLib == false) {
140 @-$(call RM, "`Build.$private.libDir``LIB`")
141 %}
142 %if (TARGET.$name.match(/gnu/)) {
143 @-$(call RM, BIOS.o)
144 %}
145 %else {
146 @-$(call RM, BIOS.obj)
147 %}
148 %for (var i = 0; i < OBJS.length; i++) {
149 @-$(call RM, `OBJS[i]`)
150 %}