]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - ipc/ipcdev.git/blob - packages/ti/sdo/utils/Build.xs
Shared memory cache management
[ipc/ipcdev.git] / packages / ti / sdo / utils / Build.xs
1 /*
2  * Copyright (c) 2013, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * *  Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  *
12  * *  Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * *  Neither the name of Texas Instruments Incorporated nor the names of
17  *    its contributors may be used to endorse or promote products derived
18  *    from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
33 /*
34  *  ======== Build.xs ========
35  */
37 var BIOS = null;
38 var Build = null;
40 var custom6xOpts = " -q -mi10 -mo -pdr -pden -pds=238 -pds=880 -pds1110 ";
41 var customARP32xOpts = " -q --gen_func_subsections ";
42 var customArmOpts = " -q -ms --opt_for_speed=2 ";
43 var customGnuArmM3Opts = " ";
44 var customGnuArmM4Opts = " ";
45 var customGnuArmM4FOpts = " ";
46 var customGnuArmA9Opts = " ";
47 var customGnuArmA8Opts = " ";
48 var customGnuArmA15Opts = " ";
50 var ccOptsList = {
51     "ti.targets.C64P"                           : custom6xOpts,
52     "ti.targets.elf.C64P"                       : custom6xOpts,
53     "ti.targets.C64P_big_endian"                : custom6xOpts,
54     "ti.targets.elf.C64P_big_endian"            : custom6xOpts,
55     "ti.targets.C674"                           : custom6xOpts,
56     "ti.targets.elf.C674"                       : custom6xOpts,
57     "ti.targets.elf.C67P"                       : custom6xOpts,
58     "ti.targets.elf.C64T"                       : custom6xOpts,
59     "ti.targets.elf.C66"                        : custom6xOpts,
60     "ti.targets.elf.C66_big_endian"             : custom6xOpts,
61     "ti.targets.arp32.elf.ARP32"                : customARP32xOpts,
62     "ti.targets.arp32.elf.ARP32_far"            : customARP32xOpts,
63     "ti.targets.arm.elf.Arm9"                   : customArmOpts,
64     "ti.targets.arm.elf.A8F"                    : customArmOpts,
65     "ti.targets.arm.elf.A8Fnv"                  : customArmOpts,
66     "ti.targets.arm.elf.M3"                     : customArmOpts,
67     "ti.targets.arm.elf.M4"                     : customArmOpts,
68     "ti.targets.arm.elf.M4F"                    : customArmOpts,
69     "gnu.targets.arm.M3"                        : customGnuArmM3Opts,
70     "gnu.targets.arm.M4"                        : customGnuArmM4Opts,
71     "gnu.targets.arm.M4F"                       : customGnuArmM4FOpts,
72     "gnu.targets.arm.A8F"                       : customGnuArmA8Opts,
73     "gnu.targets.arm.A9F"                       : customGnuArmA9Opts,
74     "gnu.targets.arm.A15F"                      : customGnuArmA15Opts,
75 };
77 /*
78  *  ======== module$meta$init ========
79  */
80 function module$meta$init()
81 {
82     /* Only process during "cfg" phase */
83     if (xdc.om.$name != "cfg") {
84         return;
85     }
87     Build = this;
89     /*
90      * Set default verbose level for custom build flow
91      * User can override this in their cfg file.
92      */
93     var SourceDir = xdc.module("xdc.cfg.SourceDir");
94     SourceDir.verbose = 2;
95 }
97 /*
98  *  ======== module$use ========
99  */
100 function module$use()
102     BIOS = xdc.module("ti.sysbios.BIOS");
103     Build = this;
105 //  if (!Build.doBuild) {
106 //      return;
107 //  }
109     /*
110      * Get the profile associated with the ti.sdo.ipc package.
111      * The profile can be specified on a per package basis with a line like
112      * this in your .cfg script:
113      *
114      * xdc.loadPackage('ti.sysbios').profile = "release";
115      */
116     if (this.$package.profile != undefined) {
117         profile = this.$package.profile;
118     }
119     else {
120         profile = Program.build.profile;
121     }
123     /*
124      * Gracefully handle non-supported whole_program profiles
125      */
126     if (profile.match(/whole_program/)
127         && (BIOS.libType != BIOS.LibType_Debug)) {
128         /* allow build to proceed */
129         BIOS.libType = BIOS.LibType_Debug;
130         /* but warning the user */
131         BIOS.$logWarning("The '" + profile +
132             "' build profile will not be supported " +
133             "in future releases of SYS/BIOS.  " +
134             "Use 'release' or 'debug' profiles together with the " +
135             "'BIOS.libType' configuration parameter to specify your " +
136             "preferred library.  See the compatibility section of " +
137             "your SYS/BIOS release notes for more information.",
138             "Profile Deprecation Warning", BIOS);
139     }
140     /* inform getLibs() about location of library */
141     switch (BIOS.libType) {
142         case BIOS.LibType_Instrumented:
143             this.$private.libraryName = "/utils.a" + Program.build.target.suffix;
144             this.$private.outputDir = this.$package.packageBase + "lib/"
145                         + (BIOS.smpEnabled ? "smputils/instrumented/" : "utils/instrumented/");
146             break;
148         case BIOS.LibType_NonInstrumented:
149             this.$private.libraryName = "/utils.a" + Program.build.target.suffix;
150             this.$private.outputDir = this.$package.packageBase + "lib/"
151                         + (BIOS.smpEnabled ? "smputils/nonInstrumented/" : "utils/nonInstrumented/");
152             break;
154         case BIOS.LibType_Debug:
155         case BIOS.LibType_Custom:
156             this.$private.libraryName = "/utils.a" + Program.build.target.suffix;
157             var SourceDir = xdc.useModule("xdc.cfg.SourceDir");
158             /* if building a pre-built library */
159             if (BIOS.buildingAppLib == false) {
160                 var appName = Program.name.substring(0, Program.name.lastIndexOf('.'));
161                 this.$private.libDir = this.$package.packageBase + Build.libDir;
162                 if (!java.io.File(this.$private.libDir).exists()) {
163                     java.io.File(this.$private.libDir).mkdir();
164                 }
165             }
166             /*
167              * If building an application in CCS or package.bld world
168              * and libDir has been specified
169              */
170             if ((BIOS.buildingAppLib == true) && (Build.libDir !== null)) {
171                 SourceDir.outputDir = Build.libDir;
172                 var src = SourceDir.create("utils");
173                 src.libraryName = this.$private.libraryName.substring(1);
174                 this.$private.outputDir = src.getGenSourceDir();
175             }
176             else {
177                 var curPath = java.io.File(".").getCanonicalPath();
178                 /* If package.bld world AND building an application OR pre-built lib */
179                 if (java.io.File(curPath).getName() != "configPkg") {
180                     var appName = Program.name.substring(0, Program.name.lastIndexOf('.'));
181                     appName = appName + "_p" + Program.build.target.suffix + ".src";
182                     SourceDir.outputDir = "package/cfg/" + appName;
183                     SourceDir.toBuildDir = ".";
184                     var src = SourceDir.create("utils");
185                     src.libraryName = this.$private.libraryName.substring(1);
186                     this.$private.outputDir = src.getGenSourceDir();
187                 }
188                 /* Here ONLY if building an application in CCS world */
189                 else {
190                     /* request output source directory for generated files */
191                     var appName = Program.name.substring(0, Program.name.lastIndexOf('.'));
192                     appName = appName + "_" + Program.name.substr(Program.name.lastIndexOf('.')+1);
193                     SourceDir.toBuildDir = "..";
194                     var src = SourceDir.create("utils/");
195                     src.libraryName = this.$private.libraryName.substring(1);
197                     /* save this directory in our private state (to be read during
198                     * generation, see Gen.xdt)
199                     */
200                     this.$private.outputDir = src.getGenSourceDir();
201                 }
202             }
203             break;
204     }
207 /*
208  * Add pre-built Instrumented and Non-Intrumented release libs
209  */
210 var utilsSources = "utils/MultiProc.c " +
211                    "utils/List.c " +
212                    "utils/NameServerRemoteNull.c " +
213                    "utils/NameServer.c ";
215 var utilsPackages = [
216     "ti.sdo.utils",
217 ];
219 var asmListNone = [
220 ];
222 var cFiles = {
223     "ti.sdo.io.DriverTypes" :
224         { cSources: [] },
227 function getDefaultCustomCCOpts()
229     var BIOS = xdc.module('ti.sysbios.BIOS');
231     /* start with target.cc.opts */
232     var customCCOpts = Program.build.target.cc.opts;
234     /* add target unique custom ccOpts */
235     if (!(ccOptsList[Program.build.target.$name] === undefined)) {
236         customCCOpts += ccOptsList[Program.build.target.$name];
237     }
239     /* Gnu targets need to pick up ccOpts.prefix and suffix */
240     if (Program.build.target.$name.match(/gnu/)) {
241         customCCOpts += " -O3 ";
242         customCCOpts += " " + Program.build.target.ccOpts.prefix + " ";
243         customCCOpts += " " + Program.build.target.ccOpts.suffix + " ";
244     }
245     else if (Program.build.target.$name.match(/iar/)) {
246         customCCOpts += " --mfc ";
247     }
248     else {
249         /* ti targets do program level compile */
250         customCCOpts += " --program_level_compile -o3 -g " +
251                 "--optimize_with_debug ";
252     }
254     /* undo optimizations if this is a Debug build */
255     if (BIOS.libType == BIOS.LibType_Debug) {
256         if (Program.build.target.$name.match(/gnu/)) {
257             customCCOpts = customCCOpts.replace("-O3","");
258             /* add in stack frames for stack back trace */
259             customCCOpts += " -mapcs ";
260         }
261         else {
262             customCCOpts = customCCOpts.replace(" -o3","");
263             customCCOpts = customCCOpts.replace(" --optimize_with_debug","");
264             if (Program.build.target.$name.match(/arm/)) {
265                 customCCOpts = customCCOpts.replace(" --opt_for_speed=2","");
266             }
267         }
268     }
270     return (customCCOpts);
273 /*
274  *  ======== getDefs ========
275  */
276 function getDefs()
278     var Defaults = xdc.module('xdc.runtime.Defaults');
279     var Diags = xdc.module("xdc.runtime.Diags");
280     var BIOS = xdc.module("ti.sysbios.BIOS");
282     var defs = "";
284     if ((BIOS.assertsEnabled == false) ||
285         ((Defaults.common$.diags_ASSERT == Diags.ALWAYS_OFF)
286             && (Defaults.common$.diags_INTERNAL == Diags.ALWAYS_OFF))) {
287         defs += " -Dxdc_runtime_Assert_DISABLE_ALL";
288     }
290     if (BIOS.logsEnabled == false) {
291         defs += " -Dxdc_runtime_Log_DISABLE_ALL";
292     }
294     return (defs);
297 /*
298  *  ======== getCFiles ========
299  */
300 function getCFiles(target)
302     var BIOS = xdc.module("ti.sysbios.BIOS");
303     var localSources = "utils/UTILS.c ";
305     /*
306      * logic to trim the C files down to just what the application needs
307      * 3/2/11 disabled for now ...
308      */
309     if (BIOS.buildingAppLib == true) {
310         for each (var mod in Program.targetModules()) {
311             var mn = mod.$name;
312             var pn = mn.substring(0, mn.lastIndexOf("."));
313             var packageMatch = false;
315             for (var i = 0; i < utilsPackages.length; i++) {
316                 if (pn == utilsPackages[i]) {
317                     packageMatch = true;
318                     break;
319                 }
320             }
322             if (packageMatch && !mn.match(/Proxy/)) {
323                 if (cFiles[mn] === undefined) {
324                     var prefix = mn.substr(mn.indexOf("sdo")+4);
325                     var mod = mn.substr(mn.lastIndexOf(".")+1);
326                     prefix = prefix.substring(0, prefix.lastIndexOf('.')+1);
327                     prefix = prefix.replace(/\./g, "/");
328                     localSources += prefix + mod + ".c ";
329                 }
330                 else {
331                     for (i in cFiles[mn].cSources) {
332                         var prefix = mn.substr(mn.indexOf("sdo")+8);
333                         prefix = prefix.substring(0, prefix.lastIndexOf('.')+1);
334                         prefix = prefix.replace(/\./g, "/");
335                         localSources += prefix + cFiles[mn].cSources[i] + " ";
336                     }
337                 }
338             }
339         }
340     }
341     else {
342         localSources += utilsSources;
343     }
345     /* remove trailing " " */
346     localSources = localSources.substring(0, localSources.length-1);
348     return (localSources);
351 /*
352  *  ======== getAsmFiles ========
353  */
354 function getAsmFiles(target)
356     return (asmListNone);
359 /*
360  *  ======== getLibs ========
361  */
362 function getLibs(pkg)
364     var BIOS = xdc.module("ti.sysbios.BIOS");
366     switch (BIOS.libType) {
367         case BIOS.LibType_Custom:
368         case BIOS.LibType_Instrumented:
369         case BIOS.LibType_NonInstrumented:
370         case BIOS.LibType_Debug:
371             return null;
373         default:
374             throw new Error("BIOS.libType not supported: " + BIOS.libType);
375             break;
376     }
379 /*
380  *  ======== getProfiles ========
381  *  Determines which profiles to build for.
382  *
383  *  Any argument in XDCARGS which does not contain platform= is treated
384  *  as a profile. This way multiple build profiles can be specified by
385  *  separating them with a space.
386  */
387 function getProfiles(xdcArgs)
389     /*
390      * cmdlProf[1] gets matched to "whole_program,debug" if
391      * ["abc", "profile=whole_program,debug"] is passed in as xdcArgs
392      */
393     var cmdlProf = (" " + xdcArgs.join(" ") + " ").match(/ profile=([^ ]+) /);
395     if (cmdlProf == null) {
396         /* No profile=XYZ found */
397         return [];
398     }
400     /* Split "whole_program,debug" into ["whole_program", "debug"] */
401     var profiles = cmdlProf[1].split(',');
403     return profiles;
406 /*
407  *  ======== buildLibs ========
408  *  This function generates the makefile goals for the libraries
409  *  produced by a package.
410  */
411 function buildLibs(objList, relList, filter, xdcArgs)
413     var Build = xdc.useModule('xdc.bld.BuildEnvironment');
415     for (var i = 0; i < Build.targets.length; i++) {
416         var targ = Build.targets[i];
418         /* skip target if not supported */
419         if (!supportsTarget(targ, filter)) {
420             continue;
421         }
423         var profiles = getProfiles(xdcArgs);
425         /* If no profiles were assigned, use only the default one. */
426         if (profiles.length == 0) {
427             profiles[0] = "debug";
428         }
430         for (var j = 0; j < profiles.length; j++) {
431             var ccopts = "";
432             var asmopts = "";
434             if (profiles[j] == "smp") {
435                 var libPath = "lib/smputils/debug/";
436                 ccopts += " -Dti_sysbios_BIOS_smpEnabled__D=TRUE";
437                 asmopts += " -Dti_sysbios_BIOS_smpEnabled__D=TRUE";
438             }
439             else {
440                 var libPath = "lib/utils/debug/";
441                 /* build all package libs using Hwi macros */
442                 ccopts += " -Dti_sysbios_Build_useHwiMacros";
443                 ccopts += " -Dti_sysbios_BIOS_smpEnabled__D=FALSE";
444                 asmopts += " -Dti_sysbios_BIOS_smpEnabled__D=FALSE";
445             }
447             /* confirm that this target supports this profile */
448             if (targ.profiles[profiles[j]] !== undefined) {
449                 var profile = profiles[j];
450                 var lib = Pkg.addLibrary(libPath + Pkg.name,
451                                 targ, {
452                                 profile: profile,
453                                 copts: ccopts,
454                                 aopts: asmopts,
455                                 releases: relList
456                                 });
457                 lib.addObjects(objList);
458             }
459         }
460     }
463 /*
464  *  ======== supportsTarget ========
465  *  Returns true if target is in the filter object. If filter
466  *  is null or empty, that's taken to mean all targets are supported.
467  */
468 function supportsTarget(target, filter)
470     var list, field;
472     if (filter == null) {
473         return true;
474     }
476     /*
477      * For backwards compatibility, we support filter as an array of
478      * target names.  The preferred approach is to specify filter as
479      * an object with 'field' and 'list' elements.
480      *
481      * Old form:
482      *     var trgFilter = [ "Arm9", "Arm9t", "Arm9t_big_endian" ]
483      *
484      * New (preferred) form:
485      *
486      *     var trgFilter = {
487      *         field: "isa",
488      *         list: [ "v5T", "v7R" ]
489      *     };
490      *
491      */
492     if (filter instanceof Array) {
493         list = filter;
494         field = "name";
495     }
496     else {
497         list = filter.list;
498         field = filter.field;
499     }
501     if (list == null || field == null) {
502         throw("invalid filter parameter, must specify list and field!");
503     }
505     if (field == "noIsa") {
506         if (String(','+list.toString()+',').match(','+target["isa"]+',')) {
507             return (false);
508         }
509         return (true);
510     }
512     /*
513      * add ',' at front and and tail of list and field strings to allow
514      * use of simple match API.  For example, the string is updated to:
515      * ',v5T,v7R,' to allow match of ',v5t,'.
516      */
517     if (String(','+list.toString()+',').match(','+target[field]+',')) {
518         return (true);
519     }
521     return (false);