1
#!/usr/bin/icmake -qt/tmp/lexer
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
91
// qt-mt can be used to select the threaded QT library
94
// NO CONFIGURABLE PARTS BELOW THIS LINE
100
string // contain options for
102
libs, // extra libs, e.g., "-lrss -licce"
103
libpath, // extra lib-paths, eg, "-L../rss"
104
copt, // Compiler options
105
lopt, // Linker options
106
libxxx, // full library-path
107
ofiles, // wildcards for o-files
108
sources, // sources to be used
109
current; // contains name of current dir.
111
nClasses, // number of classes/subdirectories
112
program; // 1: program is built
114
classes; // list of classes/directories
122
chdir("parser/gramspec");
130
"grammar" younger "parser.cc"
131
) // new parser needed
133
exec("bison++", "-d", "-o", "parser.cc", "grammar");
154
( // new lexer needed
158
"lexer" younger "yylex.cc"
161
exists("../parser/parser.h")
163
"../parser/parser.h" younger "yylex.cc"
167
exec("flex", interactive, "lexer");
180
ofiles = "o/*.o"; // std set of o-files
196
if (exists("parser")) // subdir parser exists
198
CLASSES += "parser ";
201
if (exists("scanner")) // subdir scanner exists
203
CLASSES += "scanner ";
208
setClasses(); // remaining classes
210
classes = strtok(CLASSES, " "); // list of classes
212
nClasses = sizeof(classes);
218
void moc(string class)
224
hfile = class + ".h";
225
mocfile = "moc" + class + ".cc";
229
hfile younger mocfile // no mocfile or younger h file
230
&& // and Q_OBJECT found in .h file
232
"grep '^[[:space:]]*Q_OBJECT[;[:space:]]*$' " + hfile)
234
system("moc -o " + mocfile + " " + hfile);
237
O B J F I L E S . I M
240
list objfiles(list files)
248
for (i = 0; i < sizeof(files); i++)
250
file = element(i, files); // determine element of the list
251
objfile = "./o/" + change_ext(file, "o"); // make obj-filename
252
if (objfile younger file) // objfile is younger
254
files -= (list)file; // remove the file from the list
255
i--; // reduce i to test the next
264
list altered(list files, string target)
271
for (i = 0; i < sizeof(files); i++) // try all elements of the list
273
file = element(i, files); // use element i of the list
275
if (file older target) // a file is older than the target
277
files -= (list)file; // remove the file from the list
278
i--; // reduce i to inspect the next
279
} // file of the list
281
return (files); // return the new list
284
F I L E L I S T . I M
287
list file_list(string type, string library)
292
files = makelist(type); // make all files of certain type
294
files = altered(files, library); // keep all files newer than lib.
296
files = objfiles(files); // remove if younger .obj exist
304
void link(string library, string exe)
307
exec(COMPILER, "-o", exe,
327
printf("ok: ", exe, "\n");
330
P R E F I X C L . I M
332
void prefix_class(string class_id)
342
o_files = makelist("*.o");
343
for (i = 0; o_file = element(i, o_files); i++)
344
exec("mv", o_file, class_id + o_file);
348
R M C L A S S P . I M
352
string rm_class_id(string class_id, string ofile)
361
for (index = strlen(class_id); index < n; index++)
362
ret += element(index, ofile);
368
void rm_class_prefix(string class_id)
379
o_files = makelist("*.o");
380
for (i = 0; o_file = element(i, o_files); i++)
381
exec("mv", o_file, rm_class_id(class_id, o_file));
386
C C O M P I L E . I M
389
void c_compile(list cfiles)
399
if (sizeof(cfiles)) // files to compile ?
401
printf("\ncompiling: ", current, "\n\n");
403
// compile all files separately
404
for (i = 0; nextfile = element(i, cfiles); i++)
406
"-c -o o/" + change_ext(nextfile, "o"),
411
printf("ok: ", current, "\n");
414
U P D A T E L I . I M
417
void updatelib(string library)
427
objlist = makelist("o/*.o");
429
if (!sizeof(objlist))
434
exec("ar", "rvs", library, "o/*.o");
444
void std_cpp(string library)
449
cfiles = file_list(sources, library); // make list of all cpp-files
451
c_compile(cfiles); // compile cpp-files
456
CPP files are processed by stdmake.
458
Arguments of CPPMAKE:
461
string mainfile, : name of the main .cpp file, or "" for library
463
string library, : name of the local library to use/create
464
(without lib prefix or .a/.so suffix
465
(E.g., use `main' for `libmain.a')
466
string exe, : (path) name of the exe file to create
469
Both mainfile and library MUST be in the current directory
472
void cpp_make(string mainfile, string library, string exe)
479
ofiles += " */o/*.o"; // set ofiles for no LIBRARY use
483
libxxx = chdir(".") + "lib" + library + ".a";
485
// first process all classes
486
for (index = 0; index < nClasses; index++)
488
class = element(index, classes); // next class to process
489
chdir(class); // change to directory
491
current = "subdir " + class;
493
moc(class); // see if we should call moc
495
std_cpp(libxxx); // compile all files
496
chdir(cwd); // go back to parent dir
499
current = "auxiliary " + sources + " files";
500
std_cpp(libxxx); // compile all files in current dir
504
// prefix class-number for .o files
505
for (index = 0; index < nClasses; index++)
507
current = element(index, classes); // determine class name
508
chdir( current); // chdir to a class directory.
509
prefix_class((string)index);
511
chdir(cwd); // go back to parent dir
513
current = ""; // no class anymore
514
updatelib(libxxx); // update lib in current dir
517
if (mainfile != "") // mainfile -> do link
522
"\nProgram construction completed.\n"
539
cut = strtok(LIBS, " "); // cut op libraries
541
for (index = 0; index < n; index++)
542
libs += " -l" + element(index, cut);
548
cut = strtok(LIBPATH, " "); // cut up the paths
550
for (index = 0; index < n; index++)
551
libpath += " -L" + element(index, cut);
563
"lexer.cc", // program source
564
"lexer", // static program library
565
"lexer" // binary program
571
"lexer", // static- or so-library
6
usage: 'build prog' to build the program, 'build clean' to cleanup
12
flexc++ lexer || exit 1
15
g++ --std=c++0x -Wall -olexer lexer.cc scanner/*.cc || exit 1
17
ready; run the program as 'lexer in.1'
22
rm -f ../lexer lex.cc scannerbase.h