8
string // contain options for
9
g_copt, // compiler options
11
libs, // extra libs, e.g., "-lrss -licce"
12
libpath, // extra lib-paths, eg, "-L../rss"
13
g_sources, // sources to be used
14
g_binary; // the name of the program to create
16
g_nClasses; // number of classes/subdirectories
18
g_classes; // list of classes/directories
20
string setOpt(string install_im, string envvar)
25
optvar = getenv(envvar);
40
while (sizeof(class = fgets("CLASSES", (int)element(1, class))))
42
candidate = strtok(element(0, class), " \t\n");
44
// if the line contains info not starting with #, add the class
45
if (sizeof(candidate) && element(0, element(0, candidate)) != "#")
46
g_classes += (list)element(0, strtok(element(0, class), " \t\n"));
49
g_nClasses = sizeof(g_classes);
52
void static_lib(string ofiles, string library)
54
if (sizeof(makelist(ofiles)))
56
run("ar cru " + library + " " + ofiles);
57
run("ranlib " + library);
62
void static_library(string library)
64
static_lib("*/o/*.o", library);
65
static_lib("o/*.o", library);
75
"lexer" younger "yylex.cc"
77
exec("flex", "lexer");
90
g_binary = "tmp/bin/oxref" EXTENSION;
94
if (exists("scanner")) // subdir scanner exists
97
setClasses(); // remaining classes
104
list inspect(int prefix, list srcList, string library)
111
oprefix = "./o/" + (string)prefix;
113
for (idx = sizeof(srcList); idx--; )
115
file = element(idx, srcList);
117
ofile = oprefix + change_ext(file, "o"); // make o-filename
119
// A file s must be recompiled if it's newer than its object
120
// file o or newer than its target library l, or if neither o nor l
122
// Since `a newer b' is true if a is newer than b, or if a exists and
123
// b doesn't exist s must be compiled if s newer o and s newer l.
124
// So, it doesn't have to be compiled if s older o or s older l.
125
// redo if file has changed
126
if (file older ofile || file older library)
127
srcList -= (list)file;
133
void c_compile(int prefix, string srcDir, list cfiles)
139
compiler = COMPILER + " -Wall --std=c++0x -c -o " +
140
srcDir + "/o/" + (string)prefix;
144
for (idx = sizeof(cfiles); idx--; )
146
file = element(idx, cfiles);
148
run(compiler + change_ext(file, "o") + " " +
149
g_copt + " " + srcDir + "/" + file);
153
void std_cpp(int prefix, string srcDir, string library)
158
// make list of all files
159
files = inspect(prefix, makelist(g_sources), library);
163
c_compile(prefix, srcDir, files); // compile files
166
void cpp_make(string mainfile, string library, int lib_only)
172
fullLibname = "lib" + library + ".a";
174
for (idx = g_nClasses; idx--; )
175
std_cpp(idx, element(idx, g_classes), "../" + fullLibname);
177
if (!lib_only) // compile all files in current
179
std_cpp(g_nClasses, ".", fullLibname);
181
static_library(fullLibname); // make the library
192
cut = strtok(LIBS, " "); // cut op libraries
194
for (index = 0; index < n; index++)
195
libs += " -l" + element(index, cut);
197
cut = strtok(LIBPATH, " "); // cut up the paths
199
for (index = 0; index < n; index++)
200
libpath += " -L" + element(index, cut);
203
void library(int lib_only)
212
g_copt = setOpt(CXXFLAGS, "CXXFLAGS");
216
"oxref.cc", // program source
217
"oxref", // static program library base name
218
lib_only // don't compile maindir for lib construction