Debian Codegraph @

yo/concrete/fork2/pipe/driver/build

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