| 1 |
#!/usr/bin/icmake -t. |
| 2 |
|
| 3 |
// script generated by the C++ icmake script version 1.62 |
| 4 |
|
| 5 |
/* |
| 6 |
Configurable defines for the build script: |
| 7 |
|
| 8 |
CLASSES: string of directory-names under which sources of classes |
| 9 |
are found. E.g., CLASSES = "class1 class2" |
| 10 |
|
| 11 |
All class-names must be stored in one string. |
| 12 |
If classes are removed from the CLASSES definition or if the |
| 13 |
names in the CLASSES definition are reordered, the compilation |
| 14 |
should start again from scratch. |
| 15 |
*/ |
| 16 |
|
| 17 |
string |
| 18 |
CLASSES; |
| 19 |
|
| 20 |
void setClasses() |
| 21 |
{ |
| 22 |
// ADD ADDITIONAL DIRECTORIES CONTAINING SOURCES OF CLASSES HERE |
| 23 |
// Use the construction `CLASSES += "classname1 classname2";' etc. |
| 24 |
|
| 25 |
CLASSES += "pipe ofdnstreambuf ifdnstreambuf opipe cinredirector " |
| 26 |
"childprocess fork"; |
| 27 |
} |
| 28 |
|
| 29 |
|
| 30 |
/* |
| 31 |
COMPILER: "g++" for C++ sources. Do not change this, unless you're |
| 32 |
sure you want something else. |
| 33 |
COPT: C-options used by COMPILER |
| 34 |
ECHO_REQUEST: ON (default) if command echoing is wanted, otherwise: set |
| 35 |
to OFF |
| 36 |
GDB: define if gdb-symbolic debug information is wanted |
| 37 |
(not defined by default) |
| 38 |
LIBS: Extra libraries used for linking |
| 39 |
LIBPATH: Extra library-searchpaths used for linking |
| 40 |
USE_LIBRARY: define this if you want a library for the object |
| 41 |
modules. Undefined by default: so NO LIBRARY IS USED. |
| 42 |
PROGRAM: define if a program is to be built. If not defined, |
| 43 |
library maintenance is assumed. |
| 44 |
(default: defined) |
| 45 |
RELINK: Defined by default, causing a program to be |
| 46 |
relinked every time the script is called. Do not |
| 47 |
define it if relinking should only occur if a |
| 48 |
source is compiled. No effect for library maintenance. |
| 49 |
|
| 50 |
Current values: |
| 51 |
*/ |
| 52 |
|
| 53 |
#define COMPILER "g++" |
| 54 |
|
| 55 |
// COPT: the set of C-options |
| 56 |
#define COPT " -Wall" |
| 57 |
|
| 58 |
#define ECHO_REQUEST ON |
| 59 |
|
| 60 |
// #define GDB |
| 61 |
|
| 62 |
// Extra libraries required. Remove lib and .a from the library names. |
| 63 |
// E.g., #define LIBS "m Xt" to link libm.a and libXt.a explicitly |
| 64 |
// Specify libs from the most specific to the most general one. |
| 65 |
#define LIBS "" |
| 66 |
|
| 67 |
// Extra library-paths required. |
| 68 |
// E.g., #define LIBPATH "/some/path /some/other/path" to search these paths |
| 69 |
// apart from the default paths |
| 70 |
#define LIBPATH "" |
| 71 |
|
| 72 |
// uncomment if you WANT to use a library |
| 73 |
#define USE_LIBRARY |
| 74 |
|
| 75 |
// #define PROGRAM |
| 76 |
|
| 77 |
#define RELINK |
| 78 |
|
| 79 |
// DO NOT ALTER THINGS BELOW THIS LINE |
| 80 |
string // contain options for |
| 81 |
libs, // extra libs, e.g., "-lrss -licce" |
| 82 |
libpath, // extra lib-paths, eg, "-L../rss" |
| 83 |
copt, |
| 84 |
lopt, |
| 85 |
libxxxa; // expanded lib-name |
| 86 |
int |
| 87 |
relink; // internally used: != 0 to relink |
| 88 |
|
| 89 |
string |
| 90 |
ofiles, // wildcards for o-files |
| 91 |
sources, // sources to be used |
| 92 |
wild, // wildcard of extension |
| 93 |
current; // contains name of current dir. |
| 94 |
/* |
| 95 |
O B J F I L E S . I M |
| 96 |
*/ |
| 97 |
|
| 98 |
list objfiles(list files) |
| 99 |
{ |
| 100 |
string |
| 101 |
file, |
| 102 |
objfile; |
| 103 |
int |
| 104 |
i; |
| 105 |
|
| 106 |
for (i = 0; i < sizeof(files); i++) |
| 107 |
{ |
| 108 |
file = element(i, files); // determine element of the list |
| 109 |
#ifdef USE_LIBRARY |
| 110 |
objfile = change_ext(file, "o"); // make obj-filename |
| 111 |
#else |
| 112 |
objfile = "./o/" + change_ext(file, "o"); // make obj-filename |
| 113 |
#endif |
| 114 |
if (objfile younger file) // objfile is younger |
| 115 |
{ |
| 116 |
files -= (list)file; // remove the file from the list |
| 117 |
i--; // reduce i to test the next |
| 118 |
} |
| 119 |
} |
| 120 |
return (files); |
| 121 |
} |
| 122 |
/* |
| 123 |
parser.im |
| 124 |
*/ |
| 125 |
|
| 126 |
void parser() |
| 127 |
{ |
| 128 |
chdir("parser/gramspec"); |
| 129 |
system("grambuild"); |
| 130 |
chdir(".."); |
| 131 |
|
| 132 |
if |
| 133 |
( |
| 134 |
exists("grammar") |
| 135 |
&& |
| 136 |
"grammar" younger "parser.cc" |
| 137 |
) // new parser needed |
| 138 |
{ |
| 139 |
exec("bison++", "-d", "-o", "parser.cc", "grammar"); |
| 140 |
printf("Note: the compilation of parser.cc may produce " |
| 141 |
"several compiler warnings.\n"); |
| 142 |
} |
| 143 |
|
| 144 |
chdir(".."); |
| 145 |
} |
| 146 |
/* |
| 147 |
scanner.im |
| 148 |
*/ |
| 149 |
|
| 150 |
void scanner() |
| 151 |
{ |
| 152 |
chdir("scanner"); |
| 153 |
|
| 154 |
if |
| 155 |
( // new lexer needed |
| 156 |
exists("lexer") |
| 157 |
&& |
| 158 |
( |
| 159 |
"lexer" younger "yylex.cc" |
| 160 |
|| |
| 161 |
"../parser/parser.h" younger "yylex.cc" |
| 162 |
) |
| 163 |
) |
| 164 |
{ |
| 165 |
exec("flex", |
| 166 |
#ifdef INTERACTIVE |
| 167 |
"-I", |
| 168 |
#endif |
| 169 |
"-oyylex.cc", "lexer"); |
| 170 |
|
| 171 |
printf("Note: the compilation of yylex.cc may produce " |
| 172 |
"several compiler warnings.\n"); |
| 173 |
} |
| 174 |
|
| 175 |
chdir(".."); |
| 176 |
} |
| 177 |
/* |
| 178 |
A L T E R E D . I M |
| 179 |
*/ |
| 180 |
|
| 181 |
list altered(list files, string target) |
| 182 |
{ |
| 183 |
int |
| 184 |
i; |
| 185 |
string |
| 186 |
file; |
| 187 |
|
| 188 |
for (i = 0; i < sizeof(files); i++) // try all elements of the list |
| 189 |
{ |
| 190 |
file = element(i, files); // use element i of the list |
| 191 |
|
| 192 |
if (file older target) // a file is older than the target |
| 193 |
{ |
| 194 |
files -= (list)file; // remove the file from the list |
| 195 |
i--; // reduce i to inspect the next |
| 196 |
} // file of the list |
| 197 |
} |
| 198 |
return (files); // return the new list |
| 199 |
} |
| 200 |
/* |
| 201 |
F I L E L I S T . I M |
| 202 |
*/ |
| 203 |
|
| 204 |
list file_list(string type, string library) |
| 205 |
{ |
| 206 |
list |
| 207 |
files; |
| 208 |
|
| 209 |
files = makelist(type); // make all files of certain type |
| 210 |
#ifdef USE_LIBRARY |
| 211 |
files = altered(files, library); // keep all files newer than lib. |
| 212 |
#endif |
| 213 |
files = objfiles(files); // remove if younger .obj exist |
| 214 |
|
| 215 |
return (files); |
| 216 |
} |
| 217 |
/* |
| 218 |
L I N K . I M |
| 219 |
*/ |
| 220 |
|
| 221 |
void link(string library, string exe) |
| 222 |
{ |
| 223 |
#ifndef RELINK |
| 224 |
if |
| 225 |
( |
| 226 |
relink // new library, new main.obj |
| 227 |
|| |
| 228 |
!exists(exe) // final program doesn't exist |
| 229 |
) |
| 230 |
#endif |
| 231 |
{ |
| 232 |
printf("\n"); |
| 233 |
exec(COMPILER, "-o", exe, |
| 234 |
#ifdef USE_LIBRARY |
| 235 |
"-l" + library, |
| 236 |
#else |
| 237 |
ofiles, |
| 238 |
#endif |
| 239 |
libs, "-L.", libpath, lopt |
| 240 |
#ifndef GDB |
| 241 |
, "-s" |
| 242 |
#endif |
| 243 |
); |
| 244 |
printf("ok: ", exe, "\n"); |
| 245 |
} |
| 246 |
} |
| 247 |
|
| 248 |
/* |
| 249 |
C C O M P I L E . I M |
| 250 |
*/ |
| 251 |
|
| 252 |
void c_compile(list cfiles) |
| 253 |
{ |
| 254 |
string |
| 255 |
nextfile; |
| 256 |
int |
| 257 |
i; |
| 258 |
|
| 259 |
#ifndef USE_LIBRARY |
| 260 |
if (!exists("o")) |
| 261 |
system("mkdir o"); |
| 262 |
|
| 263 |
#endif |
| 264 |
|
| 265 |
if (sizeof(cfiles)) // files to compile ? |
| 266 |
{ |
| 267 |
printf("\ncompiling: ", current, "\n\n"); |
| 268 |
|
| 269 |
// compile all files separately |
| 270 |
for (i = 0; nextfile = element(i, cfiles); i++) |
| 271 |
{ |
| 272 |
#ifdef USE_LIBRARY |
| 273 |
exec(COMPILER, |
| 274 |
"-c " |
| 275 |
COPT + " " + |
| 276 |
copt + " " + nextfile); |
| 277 |
#else |
| 278 |
exec(COMPILER, |
| 279 |
"-c -o o/" + change_ext(nextfile, "o") + " " |
| 280 |
COPT + " " + |
| 281 |
copt + " " + nextfile); |
| 282 |
#endif |
| 283 |
} |
| 284 |
relink = 1; |
| 285 |
printf("\n"); |
| 286 |
} |
| 287 |
printf("ok: ", current, "\n"); |
| 288 |
} |
| 289 |
/* |
| 290 |
U P D A T E L I . I M |
| 291 |
*/ |
| 292 |
|
| 293 |
void updatelib(string library) |
| 294 |
{ |
| 295 |
list |
| 296 |
arlist, |
| 297 |
objlist; |
| 298 |
string |
| 299 |
to, |
| 300 |
from; |
| 301 |
|
| 302 |
objlist = makelist("*.o"); |
| 303 |
|
| 304 |
if (!sizeof(objlist)) |
| 305 |
return; |
| 306 |
|
| 307 |
printf("\n"); |
| 308 |
relink = 1; |
| 309 |
|
| 310 |
exec("ar", "rvs", library, "*.o"); |
| 311 |
exec("rm", "*.o"); |
| 312 |
|
| 313 |
printf("\n"); |
| 314 |
} |
| 315 |
|
| 316 |
void prefix_class(string class_id) |
| 317 |
{ |
| 318 |
list |
| 319 |
o_files; |
| 320 |
string |
| 321 |
o_file; |
| 322 |
int |
| 323 |
i; |
| 324 |
|
| 325 |
o_files = makelist("*.o"); |
| 326 |
|
| 327 |
for (i = 0; o_file = element(i, o_files); i++) |
| 328 |
exec("mv", o_file, class_id + o_file); |
| 329 |
} |
| 330 |
/* |
| 331 |
S T D C P P . I M |
| 332 |
*/ |
| 333 |
|
| 334 |
void std_cpp(string library) |
| 335 |
{ |
| 336 |
list |
| 337 |
cfiles; |
| 338 |
|
| 339 |
cfiles = file_list(wild, library); // make list of all cpp-files |
| 340 |
|
| 341 |
c_compile(cfiles); // compile cpp-files |
| 342 |
} |
| 343 |
|
| 344 |
/* |
| 345 |
C P P M A K E . C |
| 346 |
|
| 347 |
CPP files are processed by stdmake. |
| 348 |
|
| 349 |
Arguments of CPPMAKE: |
| 350 |
|
| 351 |
cpp_make( |
| 352 |
string mainfile, : name of the main .cpp file, or "" for library |
| 353 |
maintenance |
| 354 |
string library, : name of the local library to use/create |
| 355 |
(without lib prefix, .a suffix |
| 356 |
if main is given here, libmain.a is created) |
| 357 |
string exe, : (path) name of the exe file to create |
| 358 |
) |
| 359 |
|
| 360 |
Both mainfile and library MUST be in the current directory |
| 361 |
*/ |
| 362 |
|
| 363 |
void cpp_make(string mainfile, string library, string exe) |
| 364 |
{ |
| 365 |
int |
| 366 |
n, |
| 367 |
index; |
| 368 |
list |
| 369 |
classes; |
| 370 |
string |
| 371 |
cwd; |
| 372 |
|
| 373 |
#ifdef BISON++ |
| 374 |
CLASSES += "parser "; |
| 375 |
if (exists("parser")) // subdir parser exists |
| 376 |
parser(); |
| 377 |
#endif |
| 378 |
|
| 379 |
#ifdef FLEX++ |
| 380 |
CLASSES += "scanner "; |
| 381 |
if (exists("scanner")) // subdir scannerexists |
| 382 |
scanner(); |
| 383 |
#endif |
| 384 |
|
| 385 |
setClasses(); // remaining classes |
| 386 |
|
| 387 |
cwd = chdir("."); |
| 388 |
|
| 389 |
ofiles = "o/*.o"; // std set of o-files |
| 390 |
|
| 391 |
classes = strtok(CLASSES, " "); // list of classes |
| 392 |
|
| 393 |
if (n = sizeof(classes)) |
| 394 |
ofiles += " */o/*.o"; // set ofiles for no LIBRARY use |
| 395 |
|
| 396 |
wild = sources; |
| 397 |
// make library name |
| 398 |
libxxxa = chdir(".") + "lib" + library + ".a"; |
| 399 |
|
| 400 |
// first process all classes |
| 401 |
for (index = 0; index < n; index++) |
| 402 |
{ |
| 403 |
current = element(index, classes); // next class to process |
| 404 |
chdir(current); // change to directory |
| 405 |
|
| 406 |
current = "subdir " + current; |
| 407 |
std_cpp (libxxxa); // compile all files |
| 408 |
chdir( cwd); // go back to parent dir |
| 409 |
} |
| 410 |
|
| 411 |
|
| 412 |
current = "auxiliary " + wild + " files"; |
| 413 |
std_cpp (libxxxa); // compile all files in current dir |
| 414 |
|
| 415 |
for (index = 0; index < n; index++) |
| 416 |
{ |
| 417 |
current = element(index, classes); // determine class name |
| 418 |
chdir( current); // chdir to a class directory. |
| 419 |
#ifdef USE_LIBRARY |
| 420 |
prefix_class((string)index); // prefix class-number for .o files |
| 421 |
updatelib(libxxxa); |
| 422 |
#endif |
| 423 |
chdir(cwd); // go back to parent dir |
| 424 |
} |
| 425 |
|
| 426 |
current = ""; // no class anymore |
| 427 |
|
| 428 |
#ifdef USE_LIBRARY |
| 429 |
updatelib(libxxxa); // update lib in current dir |
| 430 |
#endif |
| 431 |
|
| 432 |
if (mainfile != "") // mainfile -> do link |
| 433 |
{ |
| 434 |
link(library, exe); |
| 435 |
printf |
| 436 |
( |
| 437 |
"\nProgram construction completed.\n" |
| 438 |
"\n" |
| 439 |
); |
| 440 |
} |
| 441 |
} |
| 442 |
/* |
| 443 |
S E T L I B S . I M |
| 444 |
*/ |
| 445 |
void setlibs() |
| 446 |
{ |
| 447 |
int |
| 448 |
n, |
| 449 |
index; |
| 450 |
list |
| 451 |
cut; |
| 452 |
|
| 453 |
cut = strtok(LIBS, " "); // cut op libraries |
| 454 |
n = sizeof(cut); |
| 455 |
for (index = 0; index < n; index++) |
| 456 |
libs += " -l" + element(index, cut); |
| 457 |
|
| 458 |
#ifdef FLEX++ |
| 459 |
libs += " -lfl"; |
| 460 |
#endif |
| 461 |
|
| 462 |
cut = strtok(LIBPATH, " "); // cut up the paths |
| 463 |
n = sizeof(cut); |
| 464 |
for (index = 0; index < n; index++) |
| 465 |
libpath += " -L" + element(index, cut); |
| 466 |
} |
| 467 |
|
| 468 |
|
| 469 |
void main() |
| 470 |
{ |
| 471 |
|
| 472 |
echo(ECHO_REQUEST); |
| 473 |
|
| 474 |
sources = "*.cc"; |
| 475 |
|
| 476 |
setlibs(); |
| 477 |
|
| 478 |
#ifdef GDB |
| 479 |
copt = "-g"; |
| 480 |
#endif |
| 481 |
|
| 482 |
#ifdef PROGRAM |
| 483 |
cpp_make |
| 484 |
( |
| 485 |
"fork.cc", // program source |
| 486 |
"fork", // program library |
| 487 |
"fork" // binary program |
| 488 |
); |
| 489 |
#else |
| 490 |
cpp_make |
| 491 |
( |
| 492 |
"", |
| 493 |
"fork", // program library |
| 494 |
"" |
| 495 |
); |
| 496 |
#endif |
| 497 |
} |