~ubuntu-branches/ubuntu/trusty/c++-annotations/trusty

« back to all changes in this revision

Viewing changes to yo/concrete/lexer/build

  • Committer: Package Import Robot
  • Author(s): tony mancill, Frank B. Brokken, tony mancill
  • Date: 2012-02-28 00:50:21 UTC
  • mfrom: (1.1.19)
  • Revision ID: package-import@ubuntu.com-20120228005021-sz7nnodntkvgh7qf
Tags: 9.2.1-1
[ Frank B. Brokken ]
* New upstream release (using flexc++, reauthored polymorphic semantic
  values and unrestricted unions). Upstream release 9.2.0 is implied by
  this release.

[ tony mancill ]
* Set Standards-Version to 3.9.3.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/icmake -qt/tmp/lexer
2
 
 
3
 
// script generated by the C++ icmake script version 2.16a
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
 
    Default values for the following variables 
30
 
    are found in $IM/default/defines.im
31
 
 
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.
38
 
    
39
 
    BUILD_PROGRAM:  define if a program is to be built. If not defined,
40
 
                    library maintenance is assumed (default: defined).
41
 
 
42
 
    COMPILER:       The compiler to use. 
43
 
    COPT:           C-options used by COMPILER
44
 
 
45
 
    ECHO_REQUEST:   ON (default) if command echoing is wanted, otherwise: set
46
 
                    to OFF
47
 
    GDB:            define if gdb-symbolic debug information is wanted
48
 
                    (not defined by default)
49
 
 
50
 
    LIBS:           Extra libraries used for linking
51
 
    LIBPATH:        Extra library-searchpaths used for linking
52
 
 
53
 
    QT:             Define this (default: to "qt") if the unthreaded QT 
54
 
                    library is used. Define as "qt-mt" if the threaded QT
55
 
                    library is used.
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).
63
 
 
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
67
 
 
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.
72
 
 
73
 
    Current values:
74
 
*/
75
 
//#define BUILD_LIBRARY
76
 
#define BUILD_PROGRAM
77
 
 
78
 
#define COMPILER           "g++"
79
 
#define COPT               "--std=c++0x -Wall"
80
 
 
81
 
#define ECHO_REQUEST       1
82
 
//#define GDB              "-g"
83
 
 
84
 
#define LIBS               ""
85
 
#define LIBPATH            ""
86
 
 
87
 
// local namespace is: FBB
88
 
// using-declarations generated for: std:FBB
89
 
#define GRAMBUILD
90
 
 
91
 
// qt-mt can be used to select the threaded QT library
92
 
//#define QT               "qt"
93
 
 
94
 
//                      NO CONFIGURABLE PARTS BELOW THIS LINE
95
 
 
96
 
/*
97
 
                            V A R S . I M
98
 
*/
99
 
 
100
 
string                  // contain options for
101
 
    cwd,                // current WD
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.
110
 
int
111
 
    nClasses,           // number of classes/subdirectories
112
 
    program;            // 1: program is built
113
 
list
114
 
    classes;            // list of classes/directories
115
 
/*
116
 
                                 parser.im
117
 
*/
118
 
 
119
 
void parser()
120
 
{
121
 
    #ifdef GRAMBUILD
122
 
        chdir("parser/gramspec");
123
 
        system("grambuild");
124
 
        chdir("..");
125
 
    
126
 
        if
127
 
        (
128
 
            exists("grammar")
129
 
            &&
130
 
            "grammar" younger "parser.cc"
131
 
        )                                   // new parser needed
132
 
        {
133
 
            exec("bison++", "-d", "-o", "parser.cc", "grammar");
134
 
        }
135
 
            
136
 
        chdir("..");
137
 
    #endif
138
 
}
139
 
/*
140
 
                                 S C A N N E R . I M
141
 
*/
142
 
void scanner()
143
 
{
144
 
    string
145
 
        interactive;
146
 
    
147
 
    #ifdef INTERACTIVE
148
 
        interactive = "-I";
149
 
    #endif
150
 
    
151
 
    #ifdef GRAMBUILD
152
 
        chdir("scanner");
153
 
        if
154
 
        (                                           // new lexer needed
155
 
            exists("lexer")
156
 
            &&
157
 
            (
158
 
                "lexer" younger "yylex.cc"
159
 
                ||
160
 
                (
161
 
                    exists("../parser/parser.h") 
162
 
                    &&
163
 
                    "../parser/parser.h" younger "yylex.cc"
164
 
                )
165
 
            )
166
 
        )
167
 
            exec("flex", interactive, "lexer");
168
 
 
169
 
        chdir("..");
170
 
    #endif
171
 
}
172
 
 
173
 
/*
174
 
                                I N I T I A L . I M
175
 
*/
176
 
void initialize()
177
 
{
178
 
    echo(ECHO_REQUEST);
179
 
    sources = "*.cc";
180
 
    ofiles = "o/*.o";                       // std set of o-files
181
 
    copt = COPT;
182
 
 
183
 
    #ifdef GDB
184
 
        copt += " " + GDB;
185
 
    #endif
186
 
 
187
 
    #ifdef BUILD_PROGRAM
188
 
        program = 1;
189
 
    #else
190
 
        program = 0;
191
 
    #endif;
192
 
 
193
 
    cwd = chdir(".");
194
 
 
195
 
    #ifdef GRAMBUILD
196
 
        if (exists("parser"))                  // subdir parser exists
197
 
        {
198
 
            CLASSES += "parser ";
199
 
            parser(); 
200
 
        }
201
 
        if (exists("scanner"))                  // subdir scanner exists
202
 
        {
203
 
            CLASSES += "scanner ";
204
 
            scanner(); 
205
 
        }
206
 
    #endif
207
 
    
208
 
    setClasses();                           // remaining classes
209
 
 
210
 
    classes = strtok(CLASSES, " ");         // list of classes
211
 
 
212
 
    nClasses = sizeof(classes);
213
 
}
214
 
/*
215
 
                                M O C . I M
216
 
*/
217
 
 
218
 
void moc(string class)
219
 
{
220
 
    string hfile;
221
 
    string mocfile;
222
 
    int ret;
223
 
 
224
 
    hfile = class + ".h";
225
 
    mocfile = "moc" + class + ".cc";
226
 
 
227
 
    if 
228
 
    (
229
 
        hfile younger mocfile       // no mocfile or younger h file
230
 
        &&                          // and Q_OBJECT found in .h file
231
 
        !system(P_NOCHECK, 
232
 
                "grep '^[[:space:]]*Q_OBJECT[;[:space:]]*$' " + hfile)
233
 
    )                               // then call moc.
234
 
        system("moc -o " + mocfile + " " + hfile);
235
 
}
236
 
/*
237
 
                                O B J F I L E S . I M
238
 
*/
239
 
 
240
 
list objfiles(list files)
241
 
{
242
 
    string
243
 
        file,
244
 
        objfile;
245
 
    int
246
 
        i;
247
 
 
248
 
    for (i = 0; i < sizeof(files); i++)
249
 
    {
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
253
 
        {
254
 
            files -= (list)file;            // remove the file from the list
255
 
            i--;                            // reduce i to test the next
256
 
        }
257
 
    }
258
 
    return (files);
259
 
}
260
 
/*
261
 
                                A L T E R E D . I M
262
 
*/
263
 
 
264
 
list altered(list files, string target)
265
 
{
266
 
    int
267
 
        i;
268
 
    string
269
 
        file;
270
 
 
271
 
    for (i = 0; i < sizeof(files); i++)     // try all elements of the list
272
 
    {
273
 
        file = element(i, files);           // use element i of the list
274
 
            
275
 
        if (file older target)              // a file is older than the target
276
 
        {
277
 
            files -= (list)file;            // remove the file from the list
278
 
            i--;                            // reduce i to inspect the next
279
 
        }                                   // file of the list
280
 
    }
281
 
    return (files);                         // return the new list
282
 
}
283
 
/*
284
 
                            F I L E L I S T . I M
285
 
*/
286
 
 
287
 
list file_list(string type, string library)
288
 
{
289
 
    list
290
 
        files;
291
 
 
292
 
    files = makelist(type);                 // make all files of certain type
293
 
    #ifdef BUILD_LIBRARY
294
 
        files = altered(files, library);    // keep all files newer than lib.
295
 
    #endif
296
 
    files = objfiles(files);                // remove if younger .obj exist
297
 
 
298
 
    return (files);
299
 
}
300
 
/*
301
 
                        L I N K . I M
302
 
*/
303
 
 
304
 
void link(string library, string exe)
305
 
{
306
 
    printf("\n");
307
 
    exec(COMPILER, "-o", exe,
308
 
        #ifdef BUILD_LIBRARY
309
 
            "-l" + library,
310
 
        #else
311
 
            ofiles,
312
 
        #endif
313
 
        libs,
314
 
/*
315
 
        #ifdef GRAMBUILD
316
 
            "-lfl",
317
 
        #endif
318
 
*/
319
 
        #ifdef QT
320
 
            "-l" + QT,
321
 
        #endif
322
 
        "-L.", libpath, lopt
323
 
        #ifndef GDB
324
 
            , "-s"
325
 
        #endif
326
 
    );
327
 
    printf("ok: ", exe, "\n");
328
 
}
329
 
/*
330
 
                          P R E F I X C L . I M
331
 
*/
332
 
void prefix_class(string class_id)
333
 
{
334
 
    list
335
 
        o_files;
336
 
    string
337
 
        o_file;
338
 
    int
339
 
        i;
340
 
 
341
 
    chdir("o");
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);
345
 
    chdir("..");
346
 
}
347
 
/*
348
 
                          R M C L A S S P . I M
349
 
*/
350
 
 
351
 
#ifdef BUILD_LIBRARY
352
 
    string rm_class_id(string class_id, string ofile)
353
 
    {
354
 
        string
355
 
            ret;
356
 
        int
357
 
            index,
358
 
            n;
359
 
    
360
 
        n = strlen(ofile);
361
 
        for (index = strlen(class_id); index < n; index++)
362
 
            ret += element(index, ofile);
363
 
    
364
 
        return ret;
365
 
    }
366
 
#endif
367
 
 
368
 
void rm_class_prefix(string class_id)
369
 
{
370
 
    #ifdef BUILD_LIBRARY
371
 
        list
372
 
            o_files;
373
 
        string
374
 
            o_file;
375
 
        int
376
 
            i;
377
 
    
378
 
        chdir("o");
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));
382
 
        chdir("..");
383
 
    #endif
384
 
}
385
 
/*
386
 
                            C C O M P I L E . I M
387
 
*/
388
 
 
389
 
void c_compile(list cfiles)
390
 
{
391
 
        string
392
 
                nextfile;
393
 
        int
394
 
                i;
395
 
                
396
 
    if (!exists("o"))
397
 
        system("mkdir o");
398
 
                                                      
399
 
    if (sizeof(cfiles))                 // files to compile ?
400
 
    {
401
 
        printf("\ncompiling: ", current, "\n\n");
402
 
        
403
 
                                        // compile all files separately
404
 
        for (i = 0; nextfile = element(i, cfiles); i++)
405
 
            exec(COMPILER,
406
 
                "-c -o o/" + change_ext(nextfile, "o"),
407
 
                copt, nextfile);
408
 
 
409
 
        printf("\n");
410
 
    }
411
 
    printf("ok: ", current, "\n");
412
 
}
413
 
/*
414
 
                            U P D A T E L I . I M
415
 
*/
416
 
 
417
 
void updatelib(string library)
418
 
{
419
 
    #ifdef BUILD_LIBRARY
420
 
        list
421
 
            arlist,
422
 
            objlist;
423
 
        string
424
 
            to,
425
 
            from;
426
 
    
427
 
        objlist = makelist("o/*.o");
428
 
    
429
 
        if (!sizeof(objlist))
430
 
            return;
431
 
    
432
 
        printf("\n");
433
 
    
434
 
        exec("ar", "rvs", library, "o/*.o");
435
 
        exec("rm", "o/*.o");
436
 
    
437
 
        printf("\n");
438
 
    #endif
439
 
}
440
 
/*
441
 
                                S T D C P P . I M
442
 
*/
443
 
 
444
 
void std_cpp(string library)
445
 
{
446
 
    list
447
 
        cfiles;
448
 
 
449
 
    cfiles = file_list(sources, library);     // make list of all cpp-files
450
 
 
451
 
    c_compile(cfiles);                      // compile cpp-files
452
 
}
453
 
/*
454
 
                                C P P M A K E . C
455
 
 
456
 
    CPP files are processed by stdmake.
457
 
 
458
 
    Arguments of CPPMAKE:
459
 
 
460
 
    cpp_make(
461
 
        string mainfile,    : name of the main .cpp file, or "" for library
462
 
                              maintenance
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
467
 
        )
468
 
 
469
 
    Both mainfile and library MUST be in the current directory
470
 
*/
471
 
 
472
 
void cpp_make(string mainfile, string library, string exe)
473
 
{
474
 
    int
475
 
        index;
476
 
    string class;
477
 
        
478
 
    if (nClasses)
479
 
        ofiles += " */o/*.o";               // set ofiles for no LIBRARY use
480
 
 
481
 
                                            // make library name
482
 
    #ifdef BUILD_LIBRARY
483
 
        libxxx = chdir(".") + "lib" + library + ".a";
484
 
    #endif
485
 
                                            // first process all classes
486
 
    for (index = 0; index < nClasses; index++)
487
 
    {
488
 
        class = element(index, classes);  // next class to process
489
 
        chdir(class);                     // change to directory
490
 
 
491
 
        current = "subdir " + class;
492
 
        #ifdef QT
493
 
            moc(class);                     // see if we should call moc
494
 
        #endif
495
 
        std_cpp(libxxx);                    // compile all files
496
 
        chdir(cwd);                         // go back to parent dir
497
 
    }
498
 
 
499
 
    current = "auxiliary " + sources + " files";
500
 
    std_cpp(libxxx);                        // compile all files in current dir
501
 
 
502
 
    
503
 
    #ifdef BUILD_LIBRARY
504
 
                                        // prefix class-number for .o files
505
 
        for (index = 0; index < nClasses; index++)
506
 
        {
507
 
            current = element(index, classes);  // determine class name
508
 
            chdir( current);              // chdir to a class directory.
509
 
            prefix_class((string)index);  
510
 
            updatelib(libxxx);
511
 
            chdir(cwd);                // go back to parent dir
512
 
        }
513
 
        current = "";                  // no class anymore
514
 
        updatelib(libxxx);             // update lib in current dir
515
 
    #endif
516
 
 
517
 
    if (mainfile != "")                // mainfile -> do link
518
 
    {
519
 
        link(library, exe);
520
 
        printf
521
 
        (
522
 
            "\nProgram construction completed.\n"
523
 
            "\n"
524
 
        );
525
 
    }
526
 
}
527
 
/*
528
 
                        S E T L I B S . I M
529
 
*/
530
 
void setlibs()
531
 
{
532
 
    #ifdef LIBS
533
 
        int
534
 
            n,
535
 
            index;
536
 
        list
537
 
            cut;
538
 
            
539
 
        cut = strtok(LIBS, " ");        // cut op libraries
540
 
        n = sizeof(cut);
541
 
        for (index = 0; index < n; index++)
542
 
            libs += " -l" + element(index, cut);
543
 
 
544
 
        #ifdef GRAMBUILD        
545
 
            libs += " -lfl";
546
 
        #endif
547
 
    
548
 
        cut = strtok(LIBPATH, " ");     // cut up the paths
549
 
        n = sizeof(cut);
550
 
        for (index = 0; index < n; index++)
551
 
            libpath += " -L" + element(index, cut);
552
 
    #endif
553
 
}
554
 
 
555
 
void main()
556
 
{
557
 
    initialize();
558
 
    setlibs();
559
 
 
560
 
    #ifdef BUILD_PROGRAM
561
 
        cpp_make
562
 
        (
563
 
            "lexer.cc", // program source
564
 
            "lexer", // static program library
565
 
            "lexer"  // binary program
566
 
        );
567
 
    #else
568
 
        cpp_make
569
 
        (
570
 
            "",
571
 
            "lexer", // static- or so-library
572
 
            ""
573
 
        );
574
 
    #endif
575
 
}
 
1
#!/bin/bash
 
2
 
 
3
case "$1" in
 
4
    ("")
 
5
        echo "
 
6
usage: 'build prog' to build the program, 'build clean' to cleanup
 
7
"
 
8
        exit 1
 
9
    ;;
 
10
    (prog)
 
11
        cd scanner
 
12
        flexc++ lexer || exit 1
 
13
        cd ..
 
14
        
 
15
        g++ --std=c++0x -Wall -olexer lexer.cc scanner/*.cc || exit 1
 
16
        echo "
 
17
ready; run the program as 'lexer in.1'
 
18
"
 
19
    ;;
 
20
    (clean)
 
21
        cd scanner
 
22
        rm -f ../lexer lex.cc scannerbase.h
 
23
        echo "
 
24
done
 
25
"   
 
26
        ;;
 
27
esac
 
28
    
 
29
exit 1
 
30
 
 
31
 
 
32