Debian Codegraph @

icmake/stdcpp

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