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 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217
|
void catFile(string destination, string source)
{
list record;
string line;
while (1)
{
record = fgets(source, record); // get a line from source
if (!record) // all done: leave.
break;
line = record[0] + "\n"; // get the line's contents
if
(
strfind(line, "#include \"") == 0 && strfind(line, ".f\"") != -1
) // saw #include
catFile(destination, strtok(line, "\"")[1]); // then include .f
else // or write the line
fprintf(destination, line); // to the dest.
}
}
void buildHeader(string destination, string class, list iFiles)
{
echo(OFF);
run("rm -f " + g_cwd + g_tmphdr + class);
echo(ON);
printf("Header ", g_tmphdr, class, "\n"); // show the name of the header
// to construct
catFile(destination, class);
}
void _iFiles(string class)
{
int idx;
string destination;
list iFiles;
int recreate = 0;
destination = g_cwd + g_tmphdr + class;
chdir(class);
// the destination file name
iFiles = makelist("*.f"); // create list of all f-files
if (class newer destination)
recreate = 1;
else
{
for (idx = listlen(iFiles); idx--; )
{
if (iFiles[idx] newer destination)
{
recreate = 1;
break;
}
}
}
if (recreate)
buildHeader(destination, class, iFiles);
chdir(g_cwd);
}
void _cpHeaders()
{
int idx;
for (idx = g_nClasses; idx--; )
_iFiles(g_classes[idx]);
}
int g_gch = 1;
void _precompileHeaders()
{
int idx;
string class;
string classIH;
string compiler;
if (!g_gch)
return;
for (int idx = 0; idx != listlen(g_classes); ++idx)
fprintf << "CLASSES.all" << g_classes[idx] << '\n';
run("icmake --spch -c CLASSES.all -n -l spch");
system("rm CLASSES.all");
run("icmake --spch --precompile=spch -u xerr/xerr.ih tmp/ "
"'g++ -c -o $2 '${ICMAKE_CPPSTD}' -Itmp -O2 -x c++-header $1'");
run("icmake --spch -s spch tmp/");
// compiler = g_cxx + " " + g_copt + " -isystem " + g_cwd + "tmp";
//
// for (idx = g_nClasses; idx--; )
// {
// class = g_classes[idx];
// classIH = class + ".ih";
//
// chdir(class);
//
// if (classIH younger class + ".ih.gch")
// run(compiler + " -x c++-header " + classIH);
// chdir(g_cwd);
// }
}
void static_library(string library)
{
if (listlen(makelist("*/oa/*.o")))
{
printf("\n"
"Creating static library ", library, "\n");
run("ar cr " + library + " */oa/*.o");
run("ranlib " + library);
run("rm */oa/*.o");
}
}
void _shared_library(string libso, string libsoshared,
int strip)
{
string libsomajor;
string gxx;
gxx = g_cxx + " " + g_copt;
if (listlen(makelist("*/os/*.o")))
{
printf("\n"
"Creating shared library ", libso, "\n");
libsomajor = libso + "." + element(0, strtok(g_version, "."));
run(gxx +
" " + setOpt(LDFLAGS, "LDFLAGS") +
" -pthread -shared -Wl,--as-needed,"
"-z,defs,-soname," +
libsomajor +
" -o " + g_tmplibso + "/" + libsoshared +
" */os/*.o " +
g_sharedLibReq);
chdir(g_tmplibso);
if (strip)
run("strip --strip-unneeded " + libsoshared);
run("chmod -x " + libsoshared);
run("ln -sf " + libsoshared + " " + libsomajor);
chdir(g_cwd + g_tmpliba);
run("ln -sf " + libsomajor + " " + libso);
chdir(g_cwd);
run("rm -f */os/*");
}
}
void libraries(int keepPch, string libname, int all, int strip, int select,
int headersOnly)
{
string libso;
string libsoshared;
string staticLib;
staticLib = g_tmpliba + "/lib" LIBRARY ".a";
addClasses("CLASSES");
special(1, all, select); // at this point the extra classes are
// also in g_classes
printf << "nclasses: " << g_nClasses << '\n';
md(g_tmpliba + " " + g_tmphdr + " " + g_tmplibso);
_cpHeaders();
if (headersOnly)
return;
_precompileHeaders();
g_copt += " -isystem " + g_cwd + "tmp";
library("oa", staticLib); // compile for static lib.
static_library(staticLib); // build static library
#ifdef BUILD_SHARED // cf. INSTALL.im
libso = "lib" LIBRARY ".so";
libsoshared = libso + "." + g_version;
g_copt += " -fPIC";
// adds option for shared lib
library("os", g_tmplibso + "/" + libsoshared); // compile the shared lib
_shared_library(libso, libsoshared, strip);
#endif
if (!keepPch)
run("rm -rf */*.ih.gch");
exit(0);
}
|