| 1 |
#!/usr/bin/icmake -t. |
| 2 |
|
| 3 |
#include "../../compilers.im" |
| 4 |
|
| 5 |
string CLASSES; |
| 6 |
|
| 7 |
void setClasses() |
| 8 |
{ |
| 9 |
CLASSES += " aux indexentry"; |
| 10 |
} |
| 11 |
|
| 12 |
#define ECHO_REQUEST ON |
| 13 |
|
| 14 |
// Extra libraries required. Remove lib and .a from the library names. |
| 15 |
// E.g., #define LIBS "m Xt" to link libm.a and libXt.a explicitly |
| 16 |
// Specify libs from the most specific to the most general one. |
| 17 |
#define LIBS ${BOBCAT} |
| 18 |
|
| 19 |
// Extra library-paths required. |
| 20 |
// E.g., #define LIBPATH "/some/path /some/other/path" to search these paths |
| 21 |
// apart from the default paths |
| 22 |
#define LIBPATH ${LPATH} |
| 23 |
|
| 24 |
// DO NOT ALTER THINGS BELOW THIS LINE |
| 25 |
string // contain options for |
| 26 |
libs, // extra libs, e.g., "-lrss -licce" |
| 27 |
libpath, // extra lib-paths, eg, "-L../rss" |
| 28 |
lopt, |
| 29 |
libxxxa; // expanded lib-name |
| 30 |
|
| 31 |
string |
| 32 |
g_std = getenv("ICMAKE_CPPSTD")[1], |
| 33 |
ofiles, // wildcards for o-files |
| 34 |
sources, // sources to be used |
| 35 |
wild, // wildcard of extension |
| 36 |
current; // contains name of current dir. |
| 37 |
|
| 38 |
list objfiles(list files) |
| 39 |
{ |
| 40 |
string |
| 41 |
file, |
| 42 |
objfile; |
| 43 |
int |
| 44 |
i; |
| 45 |
|
| 46 |
for (i = 0; i < listlen(files); i++) |
| 47 |
{ |
| 48 |
file = element(i, files); // determine element of the list |
| 49 |
|
| 50 |
objfile = "./o/" + change_ext(file, "o"); // make obj-filename |
| 51 |
|
| 52 |
if (objfile younger file) // objfile is younger |
| 53 |
{ |
| 54 |
files -= (list)file; // remove the file from the list |
| 55 |
i--; // reduce i to test the next |
| 56 |
} |
| 57 |
} |
| 58 |
return (files); |
| 59 |
} |
| 60 |
|
| 61 |
list altered(list files, string target) |
| 62 |
{ |
| 63 |
int |
| 64 |
i; |
| 65 |
string |
| 66 |
file; |
| 67 |
|
| 68 |
for (i = 0; i < listlen(files); i++) // try all elements of the list |
| 69 |
{ |
| 70 |
file = element(i, files); // use element i of the list |
| 71 |
|
| 72 |
if (file older target) // a file is older than the target |
| 73 |
{ |
| 74 |
files -= (list)file; // remove the file from the list |
| 75 |
i--; // reduce i to inspect the next |
| 76 |
} // file of the list |
| 77 |
} |
| 78 |
return (files); // return the new list |
| 79 |
} |
| 80 |
|
| 81 |
list file_list(string type, string library) |
| 82 |
{ |
| 83 |
list |
| 84 |
files; |
| 85 |
|
| 86 |
files = makelist(type); // make all files of certain type |
| 87 |
|
| 88 |
files = objfiles(files); // remove if younger .obj exist |
| 89 |
|
| 90 |
return (files); |
| 91 |
} |
| 92 |
|
| 93 |
void link(string library, string exe) |
| 94 |
{ |
| 95 |
exec(GPP, "-o", exe, |
| 96 |
ofiles, |
| 97 |
libs, "-L.", libpath, lopt |
| 98 |
); |
| 99 |
} |
| 100 |
|
| 101 |
void c_compile(list cfiles) |
| 102 |
{ |
| 103 |
string nextfile; |
| 104 |
int i; |
| 105 |
|
| 106 |
if (!exists("o")) |
| 107 |
system("mkdir o"); |
| 108 |
|
| 109 |
if (listlen(cfiles)) // files to compile ? |
| 110 |
{ |
| 111 |
printf(current, "\n"); |
| 112 |
|
| 113 |
// compile all files separately |
| 114 |
for (i = 0; nextfile = element(i, cfiles); i++) |
| 115 |
{ |
| 116 |
exec(GPP, g_std, |
| 117 |
"-c -o o/" + change_ext(nextfile, "o") + " " |
| 118 |
CPPOPT + " " + nextfile); |
| 119 |
} |
| 120 |
} |
| 121 |
} |
| 122 |
|
| 123 |
void updatelib(string library) |
| 124 |
{ |
| 125 |
list |
| 126 |
arlist, |
| 127 |
objlist; |
| 128 |
string |
| 129 |
to, |
| 130 |
from; |
| 131 |
|
| 132 |
objlist = makelist("*.o"); |
| 133 |
|
| 134 |
if (!listlen(objlist)) |
| 135 |
return; |
| 136 |
|
| 137 |
printf("\n"); |
| 138 |
|
| 139 |
exec("ar", "rvs", library, "*.o"); |
| 140 |
exec("rm", "*.o"); |
| 141 |
|
| 142 |
printf("\n"); |
| 143 |
} |
| 144 |
|
| 145 |
void prefix_class(string class_id) |
| 146 |
{ |
| 147 |
list |
| 148 |
o_files; |
| 149 |
string |
| 150 |
o_file; |
| 151 |
int |
| 152 |
i; |
| 153 |
|
| 154 |
o_files = makelist("*.o"); |
| 155 |
|
| 156 |
for (i = 0; o_file = element(i, o_files); i++) |
| 157 |
exec("mv", o_file, class_id + o_file); |
| 158 |
} |
| 159 |
|
| 160 |
void std_cpp(string library) |
| 161 |
{ |
| 162 |
list |
| 163 |
cfiles; |
| 164 |
|
| 165 |
cfiles = file_list(wild, library); // make list of all cpp-files |
| 166 |
|
| 167 |
c_compile(cfiles); // compile cpp-files |
| 168 |
} |
| 169 |
|
| 170 |
void cpp_make(string mainfile, string library, string exe) |
| 171 |
{ |
| 172 |
int |
| 173 |
n, |
| 174 |
index; |
| 175 |
list |
| 176 |
classes; |
| 177 |
string |
| 178 |
cwd; |
| 179 |
|
| 180 |
setClasses(); // remaining classes |
| 181 |
|
| 182 |
cwd = chdir("."); |
| 183 |
|
| 184 |
ofiles = "o/*.o"; // std set of o-files |
| 185 |
|
| 186 |
classes = strtok(CLASSES, " "); // list of classes |
| 187 |
|
| 188 |
if (n = listlen(classes)) |
| 189 |
ofiles += " */o/*.o"; // set ofiles for no LIBRARY use |
| 190 |
|
| 191 |
wild = sources; |
| 192 |
// make library name |
| 193 |
libxxxa = chdir(".") + "lib" + library + ".a"; |
| 194 |
|
| 195 |
// first process all classes |
| 196 |
for (index = 0; index < n; index++) |
| 197 |
{ |
| 198 |
current = element(index, classes); // next class to process |
| 199 |
chdir(current); // change to directory |
| 200 |
|
| 201 |
current = "subdir " + current; |
| 202 |
std_cpp (libxxxa); // compile all files |
| 203 |
chdir( cwd); // go back to parent dir |
| 204 |
} |
| 205 |
|
| 206 |
|
| 207 |
current = "auxiliary " + wild + " files"; |
| 208 |
std_cpp (libxxxa); // compile all files in current dir |
| 209 |
|
| 210 |
for (index = 0; index < n; index++) |
| 211 |
{ |
| 212 |
current = element(index, classes); // determine class name |
| 213 |
chdir( current); // chdir to a class directory. |
| 214 |
chdir(cwd); // go back to parent dir |
| 215 |
} |
| 216 |
|
| 217 |
current = ""; // no class anymore |
| 218 |
|
| 219 |
if (mainfile != "") // mainfile -> do link |
| 220 |
link(library, exe); |
| 221 |
} |
| 222 |
|
| 223 |
void setlibs() |
| 224 |
{ |
| 225 |
int |
| 226 |
n, |
| 227 |
index; |
| 228 |
list |
| 229 |
cut; |
| 230 |
|
| 231 |
cut = strtok(LIBS, " "); // cut op libraries |
| 232 |
n = listlen(cut); |
| 233 |
for (index = 0; index < n; index++) |
| 234 |
libs += " -l" + element(index, cut); |
| 235 |
|
| 236 |
cut = strtok(LIBPATH, " "); // cut up the paths |
| 237 |
n = listlen(cut); |
| 238 |
for (index = 0; index < n; index++) |
| 239 |
libpath += " -L" + element(index, cut); |
| 240 |
} |
| 241 |
|
| 242 |
void main() |
| 243 |
{ |
| 244 |
echo(ECHO_REQUEST); |
| 245 |
|
| 246 |
sources = "*.cc"; |
| 247 |
|
| 248 |
setlibs(); |
| 249 |
|
| 250 |
lopt = "-s"; |
| 251 |
|
| 252 |
system("mkdir -p ../../tmp/bin"); // make destination if it doesn't |
| 253 |
// already exist |
| 254 |
cpp_make |
| 255 |
( |
| 256 |
"htmlindex.cc", // program source |
| 257 |
"htmlindex", // program library |
| 258 |
"../../tmp/bin/htmlindex" // binary program |
| 259 |
); |
| 260 |
} |