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

« back to all changes in this revision

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