Debian Codegraph @

yo/classtemplates/examples/table/build.obs

raw
1 #!/usr/bin/icmake -t.
2
3 // script generated by the C++ icmake script version 2.18
4
5 /*
6 Configurable defines:
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 names in the
13 CLASSES definition are reordered, the compilation should start again from
14 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 += "tabletype ";
26 }
27
28 /*
29 Default values for the following variables
30 are found in $IM/default/defines.im
31
32 BISON_FLAGS: This directive is only used when a grammar is generated
33 using bison++. It defines the set of flags that are
34 given to bison++ when bison++ generates the parser.
35 By default the following flags are specified: -v -l
36 The -d and -o flags are always provided (not configurable)
37
38 BUILD_LIBRARY: define this if you want to create a library for the object
39 modules. Undefined by default: so NO LIBRARY IS
40 BUILT. This links ALL object files to a program, which is
41 a faster process than linking to a library. But it can
42 bloat the executable: all o-modules, rather than those
43 that are really used, become part of the program's code.
44
45 BUILD_PROGRAM: define if a program is to be built. If not defined,
46 library maintenance is assumed (by default it is defined
47 to the name of the program to be created).
48
49 COMPILER: The compiler to use.
50 COPT: C-options used by COMPILER
51
52 ECHO_REQUEST: ON (default) if command echoing is wanted, otherwise: set
53 to OFF
54 GDB: define if gdb-symbolic debug information is wanted
55 (not defined by default)
56
57 GRAMMAR_LINES: When this directive is defined, #line directives will
58 be generated at the first C++ compound statement
59 in each individual grammar specification file. Undefine
60 if no such #line directives are required.
61
62 LIBS: Extra libraries used for linking
63 LIBPATH: Extra library-searchpaths used for linking
64
65 QT: Define this (default: to "qt") if the unthreaded QT
66 library is used. Define as "qt-mt" if the threaded QT
67 library is used.
68 If set, header files are grepped for the occurrence of
69 the string '^[[:space:]]*Q_OBJECT[[:space:]]*$'. If found,
70 moc -o moc<CLASSNAME>.cc <CLASSNAME>.h is called if
71 the moc-file doesn't exist or is older than the .h file.
72 Also, if defined the proper QT library is linked, assuming
73 that the library is found in the ld-search path
74 (E.g., see the environment variable $LIBRARY_PATH).
75
76 Note that namespaces are NOT part of the build-script: they are only
77 listed below for convenience. When they must be altered, the defaults must
78 be changed in $IM/default/defines.im
79
80 RELINK: Defined by default, causing a program to be
81 relinked every time the script is called. Do not
82 define it if relinking should only occur if a
83 source is compiled. No effect for library maintenance.
84
85 Current values:
86 */
87 //#define BUILD_LIBRARY
88 #define BUILD_PROGRAM "demo"
89
90 #define COMPILER "g++"
91 #define COPT "--std=c++11 -Wall"
92
93 #define ECHO_REQUEST 1
94 //#define GDB "-g"
95
96 #define LIBS ""
97 #define LIBPATH ""
98
99 // local namespace is: FBB
100 // using-declarations generated for: std:FBB
101
102 // qt-mt can be used to select the threaded QT library
103 //#define QT "qt"
104
105 // NO CONFIGURABLE PARTS BELOW THIS LINE
106
107 /*
108 V A R S . I M
109 */
110
111 string // contain options for
112 cwd, // current WD
113 libs, // extra libs, e.g., "-lrss -licce"
114 libpath, // extra lib-paths, eg, "-L../rss"
115 copt, // Compiler options
116 lopt, // Linker options
117 libxxx, // full library-path
118 ofiles, // wildcards for o-files
119 sources, // sources to be used
120 current, // contains name of current dir.
121 programname; // the name of the program to create
122 int
123 nClasses, // number of classes/subdirectories
124 program; // 1: program is built
125 list
126 classes; // list of classes/directories
127 /*
128 parser.im
129 */
130
131 void parser()
132 {
133 #ifdef GRAMBUILD
134 chdir("parser/gramspec");
135 #ifdef GRAMMAR_LINES
136 system("./grambuild lines");
137 #else
138 system("./grambuild");
139 #endif
140 chdir("..");
141
142 if
143 (
144 exists("grammar")
145 &&
146 "grammar" younger "parser.cc"
147 ) // new parser needed
148 {
149 #ifdef BISON_FLAGS
150 exec("bison++", BISON_FLAGS, "-d", "-o", "parser.cc",
151 "grammar");
152 #else
153 exec("bison++", "-d", "-o", "parser.cc", "grammar");
154 #endif
155 }
156
157 chdir("..");
158 #endif
159 }
160 /*
161 S C A N N E R . I M
162 */
163 void scanner()
164 {
165 string
166 interactive;
167
168 #ifdef INTERACTIVE
169 interactive = "-I";
170 #endif
171
172 #ifdef GRAMBUILD
173 chdir("scanner");
174 if
175 ( // new lexer needed
176 exists("lexer")
177 &&
178 (
179 "lexer" younger "yylex.cc"
180 ||
181 (
182 exists("../parser/parser.h")
183 &&
184 "../parser/parser.h" younger "yylex.cc"
185 )
186 )
187 )
188 exec("flex", interactive, "lexer");
189
190 chdir("..");
191 #endif
192 }
193
194 /*
195 I N I T I A L . I M
196 */
197 void initialize()
198 {
199 echo(ECHO_REQUEST);
200 sources = "*.cc";
201 ofiles = "o/*.o"; // std set of o-files
202 copt = COPT;
203
204 #ifdef GDB
205 copt += " " + GDB;
206 #endif
207
208 #ifdef BUILD_PROGRAM
209 program = 1;
210 programname = BUILD_PROGRAM;
211 #else
212 program = 0;
213 #endif
214
215 cwd = chdir(".");
216
217 #ifdef GRAMBUILD
218 if (exists("parser")) // subdir parser exists
219 {
220 CLASSES += "parser ";
221 parser();
222 }
223 if (exists("scanner")) // subdir scanner exists
224 {
225 CLASSES += "scanner ";
226 scanner();
227 }
228 #endif
229
230 setClasses(); // remaining classes
231
232 classes = strtok(CLASSES, " "); // list of classes
233
234 nClasses = sizeof(classes);
235 }
236
237
238 /*
239 M O C . I M
240 */
241
242 void moc(string class)
243 {
244 string hfile;
245 string mocfile;
246 int ret;
247
248 hfile = class + ".h";
249 mocfile = "moc" + class + ".cc";
250
251 if
252 (
253 hfile younger mocfile // no mocfile or younger h file
254 && // and Q_OBJECT found in .h file
255 !system(P_NOCHECK,
256 "grep '^[[:space:]]*Q_OBJECT[;[:space:]]*$' " + hfile)
257 ) // then call moc.
258 system("moc -o " + mocfile + " " + hfile);
259 }
260 /*
261 O B J F I L E S . I M
262 */
263
264 list objfiles(list files)
265 {
266 string
267 file,
268 objfile;
269 int
270 i;
271
272 for (i = 0; i < sizeof(files); i++)
273 {
274 file = element(i, files); // determine element of the list
275 objfile = "./o/" + change_ext(file, "o"); // make obj-filename
276 if (objfile younger file) // objfile is younger
277 {
278 files -= (list)file; // remove the file from the list
279 i--; // reduce i to test the next
280 }
281 }
282 return (files);
283 }
284 /*
285 A L T E R E D . I M
286 */
287
288 list altered(list files, string target)
289 {
290 int
291 i;
292 string
293 file;
294
295 for (i = 0; i < sizeof(files); i++) // try all elements of the list
296 {
297 file = element(i, files); // use element i of the list
298
299 if (file older target) // a file is older than the target
300 {
301 files -= (list)file; // remove the file from the list
302 i--; // reduce i to inspect the next
303 } // file of the list
304 }
305 return (files); // return the new list
306 }
307 /*
308 F I L E L I S T . I M
309 */
310
311 list file_list(string type, string library)
312 {
313 list
314 files;
315
316 files = makelist(type); // make all files of certain type
317 #ifdef BUILD_LIBRARY
318 files = altered(files, library); // keep all files newer than lib.
319 #endif
320 files = objfiles(files); // remove if younger .obj exist
321
322 return (files);
323 }
324 /*
325 L I N K . I M
326 */
327
328 void link(string library)
329 {
330 printf("\n");
331 exec(COMPILER, "-o", programname,
332 #ifdef BUILD_LIBRARY
333 "-l" + library,
334 #else
335 ofiles,
336 #endif
337 libs,
338 #ifdef QT
339 "-l" + QT,
340 #endif
341 "-L.", libpath, lopt
342 #ifndef GDB
343 , "-s"
344 #endif
345 );
346 printf("ok: ", programname, "\n");
347 }
348 /*
349 P R E F I X C L . I M
350 */
351 void prefix_class(string class_id)
352 {
353 list
354 o_files;
355 string
356 o_file;
357 int
358 i;
359
360 chdir("o");
361 o_files = makelist("*.o");
362 for (i = 0; o_file = element(i, o_files); i++)
363 exec("mv", o_file, class_id + o_file);
364 chdir("..");
365 }
366 /*
367 R M C L A S S P . I M
368 */
369
370 #ifdef BUILD_LIBRARY
371 string rm_class_id(string class_id, string ofile)
372 {
373 string
374 ret;
375 int
376 index,
377 n;
378
379 n = strlen(ofile);
380 for (index = strlen(class_id); index < n; index++)
381 ret += element(index, ofile);
382
383 return ret;
384 }
385 #endif
386
387 void rm_class_prefix(string class_id)
388 {
389 #ifdef BUILD_LIBRARY
390 list
391 o_files;
392 string
393 o_file;
394 int
395 i;
396
397 chdir("o");
398 o_files = makelist("*.o");
399 for (i = 0; o_file = element(i, o_files); i++)
400 exec("mv", o_file, rm_class_id(class_id, o_file));
401 chdir("..");
402 #endif
403 }
404 /*
405 C C O M P I L E . I M
406 */
407
408 void c_compile(list cfiles)
409 {
410 string
411 nextfile;
412 int
413 i;
414
415 if (!exists("o"))
416 system("mkdir o");
417
418 if (sizeof(cfiles)) // files to compile ?
419 {
420 printf("\ncompiling: ", current, "\n\n");
421
422 // compile all files separately
423 for (i = 0; nextfile = element(i, cfiles); i++)
424 exec(COMPILER,
425 "-c -o o/" + change_ext(nextfile, "o"),
426 copt, nextfile);
427
428 printf("\n");
429 }
430 printf("ok: ", current, "\n");
431 }
432 /*
433 U P D A T E L I . I M
434 */
435
436 void updatelib(string library)
437 {
438 #ifdef BUILD_LIBRARY
439 list
440 arlist,
441 objlist;
442 string
443 to,
444 from;
445
446 objlist = makelist("o/*.o");
447
448 if (!sizeof(objlist))
449 return;
450
451 printf("\n");
452
453 exec("ar", "rvs", library, "o/*.o");
454 exec("rm", "o/*.o");
455
456 printf("\n");
457 #endif
458 }
459 /*
460 S T D C P P . I M
461 */
462
463 void std_cpp(string library)
464 {
465 list
466 cfiles;
467
468 cfiles = file_list(sources, library); // make list of all cpp-files
469
470 c_compile(cfiles); // compile cpp-files
471 }
472 /*
473 C P P M A K E . C
474
475 CPP files are processed by stdmake.
476
477 Arguments of CPPMAKE:
478
479 cpp_make(
480 string mainfile, : name of the main .cpp file, or "" for library
481 maintenance
482 string library, : name of the local library to use/create
483 (without lib prefix or .a/.so suffix
484 (E.g., use `main' for `libmain.a')
485 )
486
487 Both mainfile and library MUST be in the current directory
488 */
489
490 void cpp_make(string mainfile, string library)
491 {
492 int
493 index;
494 string class;
495
496 if (nClasses)
497 ofiles += " */o/*.o"; // set ofiles for no LIBRARY use
498
499 // make library name
500 #ifdef BUILD_LIBRARY
501 libxxx = chdir(".") + "lib" + library + ".a";
502 #endif
503 // first process all classes
504 for (index = 0; index < nClasses; index++)
505 {
506 class = element(index, classes); // next class to process
507 chdir(class); // change to directory
508
509 current = "subdir " + class;
510 #ifdef QT
511 moc(class); // see if we should call moc
512 #endif
513 std_cpp(libxxx); // compile all files
514 chdir(cwd); // go back to parent dir
515 }
516
517 current = "auxiliary " + sources + " files";
518 std_cpp(libxxx); // compile all files in current dir
519
520
521 #ifdef BUILD_LIBRARY
522 // prefix class-number for .o files
523 for (index = 0; index < nClasses; index++)
524 {
525 current = element(index, classes); // determine class name
526 chdir( current); // chdir to a class directory.
527 prefix_class((string)index);
528 updatelib(libxxx);
529 chdir(cwd); // go back to parent dir
530 }
531 current = ""; // no class anymore
532 updatelib(libxxx); // update lib in current dir
533 #endif
534
535 if (mainfile != "") // mainfile -> do link
536 {
537 link(library);
538 printf
539 (
540 "\nProgram construction completed.\n"
541 "\n"
542 );
543 }
544 }
545 /*
546 S E T L I B S . I M
547 */
548 void setlibs()
549 {
550 #ifdef LIBS
551 int
552 n,
553 index;
554 list
555 cut;
556
557 cut = strtok(LIBS, " "); // cut op libraries
558 n = sizeof(cut);
559 for (index = 0; index < n; index++)
560 libs += " -l" + element(index, cut);
561
562 cut = strtok(LIBPATH, " "); // cut up the paths
563 n = sizeof(cut);
564 for (index = 0; index < n; index++)
565 libpath += " -L" + element(index, cut);
566 #endif
567 }
568
569 void main()
570 {
571 initialize();
572 setlibs();
573
574 #ifdef BUILD_PROGRAM
575 cpp_make
576 (
577 "table.cc", // program source
578 "table" // static program library
579 );
580 #else
581 cpp_make
582 (
583 "",
584 "table" // static- or so-library
585 );
586 #endif
587 }