1
#!/usr/bin/icmake -qt/tmp/parser
3
// script generated by the C++ icmake script version 2.16a
6
Configurable defines for the build script:
8
CLASSES: string of directory-names under which sources of classes
9
are found. E.g., CLASSES = "class1 class2"
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.
22
// ADD ADDITIONAL DIRECTORIES CONTAINING SOURCES OF CLASSES HERE
23
// Use the construction `CLASSES += "classname1 classname2";' etc.
29
Default values for the following variables
30
are found in $IM/default/defines.im
32
BUILD_LIBRARY: define this if you want to create a library for the object
33
modules. Undefined by default: so NO LIBRARY IS
34
BUILT. This links ALL object files to a program, which is
35
a faster process than linking to a library. But it can
36
bloat the executable: all o-modules, rather than those
37
that are really used, become part of the program's code.
39
BUILD_PROGRAM: define if a program is to be built. If not defined,
40
library maintenance is assumed (default: defined).
42
COMPILER: The compiler to use.
43
COPT: C-options used by COMPILER
45
ECHO_REQUEST: ON (default) if command echoing is wanted, otherwise: set
47
GDB: define if gdb-symbolic debug information is wanted
48
(not defined by default)
50
LIBS: Extra libraries used for linking
51
LIBPATH: Extra library-searchpaths used for linking
53
QT: Define this (default: to "qt") if the unthreaded QT
54
library is used. Define as "qt-mt" if the threaded QT
56
If set, header files are grepped for the occurrence of
57
the string '^[[:space:]]*Q_OBJECT[[:space:]]*$'. If found,
58
moc -o moc<CLASSNAME>.cc <CLASSNAME>.h is called if
59
the moc-file doesn't exist or is older than the .h file.
60
Also, if defined the proper QT library is linked, assuming
61
that the library is found in the ld-search path
62
(E.g., see the environment variable $LIBRARY_PATH).
64
Note that namespaces are NOT part of the build-script: they are only
65
listed below for convenience. When they must be altered, the defaults must
66
be changed in $IM/default/defines.im
68
RELINK: Defined by default, causing a program to be
69
relinked every time the script is called. Do not
70
define it if relinking should only occur if a
71
source is compiled. No effect for library maintenance.
75
//#define BUILD_LIBRARY
78
#define COMPILER "g++"
79
#define COPT "--std=c++0x -Wall"
81
#define ECHO_REQUEST 1
87
// local namespace is: FBB
88
// using-declarations generated for: std::FBB
92
// qt-mt can be used to select the threaded QT library
95
// NO CONFIGURABLE PARTS BELOW THIS LINE
101
string // contain options for
103
libs, // extra libs, e.g., "-lrss -licce"
104
libpath, // extra lib-paths, eg, "-L../rss"
105
copt, // Compiler options
106
lopt, // Linker options
107
libxxx, // full library-path
108
ofiles, // wildcards for o-files
109
sources, // sources to be used
110
current; // contains name of current dir.
112
nClasses, // number of classes/subdirectories
113
program; // 1: program is built
115
classes; // list of classes/directories
125
if ("grammar" younger "parser.cc") // new parser needed
126
exec("bisonc++", "grammar");
146
( // new lexer needed
150
"lexer" younger "yylex.cc"
153
exists("../parser/parser.h")
155
"../parser/parser.h" younger "yylex.cc"
159
exec("flex", interactive, "lexer");
172
ofiles = "o/*.o"; // std set of o-files
188
if (exists("parser")) // subdir parser exists
190
CLASSES += "parser ";
193
if (exists("scanner")) // subdir scanner exists
195
CLASSES += "scanner ";
200
setClasses(); // remaining classes
202
classes = strtok(CLASSES, " "); // list of classes
204
nClasses = sizeof(classes);
210
void moc(string class)
216
hfile = class + ".h";
217
mocfile = "moc" + class + ".cc";
221
hfile younger mocfile // no mocfile or younger h file
222
&& // and Q_OBJECT found in .h file
224
"grep '^[[:space:]]*Q_OBJECT[;[:space:]]*$' " + hfile)
226
system("moc -o " + mocfile + " " + hfile);
229
O B J F I L E S . I M
232
list objfiles(list files)
240
for (i = 0; i < sizeof(files); i++)
242
file = element(i, files); // determine element of the list
243
objfile = "./o/" + change_ext(file, "o"); // make obj-filename
244
if (objfile younger file) // objfile is younger
246
files -= (list)file; // remove the file from the list
247
i--; // reduce i to test the next
256
list altered(list files, string target)
263
for (i = 0; i < sizeof(files); i++) // try all elements of the list
265
file = element(i, files); // use element i of the list
267
if (file older target) // a file is older than the target
269
files -= (list)file; // remove the file from the list
270
i--; // reduce i to inspect the next
271
} // file of the list
273
return (files); // return the new list
276
F I L E L I S T . I M
279
list file_list(string type, string library)
284
files = makelist(type); // make all files of certain type
286
files = altered(files, library); // keep all files newer than lib.
288
files = objfiles(files); // remove if younger .obj exist
296
void link(string library, string exe)
299
exec(COMPILER, "-o", exe,
314
printf("ok: ", exe, "\n");
317
P R E F I X C L . I M
319
void prefix_class(string class_id)
329
o_files = makelist("*.o");
330
for (i = 0; o_file = element(i, o_files); i++)
331
exec("mv", o_file, class_id + o_file);
335
R M C L A S S P . I M
339
string rm_class_id(string class_id, string ofile)
348
for (index = strlen(class_id); index < n; index++)
349
ret += element(index, ofile);
355
void rm_class_prefix(string class_id)
366
o_files = makelist("*.o");
367
for (i = 0; o_file = element(i, o_files); i++)
368
exec("mv", o_file, rm_class_id(class_id, o_file));
373
C C O M P I L E . I M
376
void c_compile(list cfiles)
386
if (sizeof(cfiles)) // files to compile ?
388
printf("\ncompiling: ", current, "\n\n");
390
// compile all files separately
391
for (i = 0; nextfile = element(i, cfiles); i++)
393
"-c -o o/" + change_ext(nextfile, "o"),
398
printf("ok: ", current, "\n");
401
U P D A T E L I . I M
404
void updatelib(string library)
414
objlist = makelist("o/*.o");
416
if (!sizeof(objlist))
421
exec("ar", "rvs", library, "o/*.o");
431
void std_cpp(string library)
436
cfiles = file_list(sources, library); // make list of all cpp-files
438
c_compile(cfiles); // compile cpp-files
443
CPP files are processed by stdmake.
445
Arguments of CPPMAKE:
448
string mainfile, : name of the main .cpp file, or "" for library
450
string library, : name of the local library to use/create
451
(without lib prefix or .a/.so suffix
452
(E.g., use `main' for `libmain.a')
453
string exe, : (path) name of the exe file to create
456
Both mainfile and library MUST be in the current directory
459
void cpp_make(string mainfile, string library, string exe)
466
ofiles += " */o/*.o"; // set ofiles for no LIBRARY use
470
libxxx = chdir(".") + "lib" + library + ".a";
472
// first process all classes
473
for (index = 0; index < nClasses; index++)
475
class = element(index, classes); // next class to process
476
chdir(class); // change to directory
478
current = "subdir " + class;
480
moc(class); // see if we should call moc
482
std_cpp(libxxx); // compile all files
483
chdir(cwd); // go back to parent dir
486
current = "auxiliary " + sources + " files";
487
std_cpp(libxxx); // compile all files in current dir
491
// prefix class-number for .o files
492
for (index = 0; index < nClasses; index++)
494
current = element(index, classes); // determine class name
495
chdir( current); // chdir to a class directory.
496
prefix_class((string)index);
498
chdir(cwd); // go back to parent dir
500
current = ""; // no class anymore
501
updatelib(libxxx); // update lib in current dir
504
if (mainfile != "") // mainfile -> do link
509
"\nProgram construction completed.\n"
526
cut = strtok(LIBS, " "); // cut op libraries
528
for (index = 0; index < n; index++)
529
libs += " -l" + element(index, cut);
531
cut = strtok(LIBPATH, " "); // cut up the paths
533
for (index = 0; index < n; index++)
534
libpath += " -L" + element(index, cut);
546
"parser.cc", // program source
547
"parser", // static program library
548
"calc" // binary program
554
"parser", // static- or so-library
6
usage: 'build prog' to build the program, 'build clean' to cleanup
12
bisonc++ grammar || exit 1
14
flexc++ lexer || exit 1
17
g++ --std=c++0x -Wall -ocalc *.cc */*.cc -lbobcat || exit 1
19
ready; run the program as './calc'
25
rm -f parse.cc parserbase.h
27
rm -f lex.cc scannerbase.h