1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
|
list _inspect(string dstPrefix, list srcList, string library)
{
int idx;
string ofile;
string file;
for (idx = listlen(srcList); idx--; )
{
file = element(idx, srcList);
ofile = dstPrefix + change_ext(file, "o"); // make o-filename
// A file s must be recompiled if it's newer than its object
// file o or newer than its target library l, or if neither o nor l
// exist.
// Since `a newer b' is true if a is newer than b, or if a exists and
// b doesn't exist s must be compiled if s newer o and s newer l.
// So, it doesn't have to be compiled if s older o or s older l.
// redo if file has changed
if (file older ofile || file older library)
srcList -= (list)file;
}
return srcList;
}
list _inspect2(string dstPrefix, list srcList)
{
int idx;
string ofile;
string file;
for (idx = listlen(srcList); idx--; )
{
file = element(idx, srcList);
ofile = dstPrefix + change_ext(file, "o"); // make o-filename
// A file s must be recompiled if it's newer than its object
// file o
if (file older ofile)
srcList -= (list)file;
}
return srcList;
}
// c_compile: compile all sources in `{srcDir}/{cfiles}', storing the object
// files in {oDst}/filename.o
void _c_compile(string oDst, list cfiles)
{
int idx;
string compdest;
string file;
compdest = COMPILER + " -c -o " + oDst;
#ifndef ECHO_COMPILE
echo(OFF);
#endif
for (idx = listlen(cfiles); idx--; )
{
file = cfiles[idx];
#ifndef ECHO_COMPILE
printf << " " << file << '\n';
#endif
g_compiled = 1;
run(compdest + change_ext(file, "o") + " " + g_copt + " -c " + file);
}
echo(ON);
}
void std_cpp(string oDstDir, int prefix, string srcDir, string library)
{
list files;
chdir(srcDir);
oDstDir = "../" + oDstDir;
md(oDstDir);
oDstDir += "/" + (string)prefix;
// make list of all files
if (library == "")
files = _inspect2(oDstDir, makelist("*.c"));
else
files = _inspect(oDstDir, makelist("*.c"), g_cwd + library);
if (listlen(files))
{
printf("Compiling sources in `" + srcDir + "'\n");
_c_compile(oDstDir, files); // compile files
}
chdir(g_cwd);
}
|