File: build

package info (click to toggle)
bobcat 1.11.0-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 3,344 kB
  • ctags: 473
  • sloc: makefile: 12,078; cpp: 5,121; ansic: 63; sh: 14
file content (650 lines) | stat: -rwxr-xr-x 17,874 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
#!/usr/bin/icmake -qt/tmp/driver

// script generated by the C++ icmake script version 2.03

/*
Configurable defines for the build script:

    CLASSES:        string of directory-names under which sources of classes
                    are found. E.g., CLASSES  = "class1 class2"

                All class-names must be stored in one string.
                If classes are removed from the CLASSES definition or if the
                names in the CLASSES definition are reordered, the compilation
                should start again from scratch.
*/

string
    CLASSES;

void setClasses()
{
//  ADD ADDITIONAL DIRECTORIES CONTAINING SOURCES OF CLASSES HERE
//  Use the construction `CLASSES += "classname1 classname2";' etc.

    CLASSES += " ";
}

/*
    Default values for the following variables 
    are found in $IM/default/defines.im

    BUILD_LIBRARY:  define this if you want to create a library for the object
                    modules. Undefined by default: so NO LIBRARY IS
                    BUILT. This links ALL object files to a program, which is
                    a faster process than linking to a library. But it can
                    bloat the executable: all o-modules, rather than those
                    that are really used, become part of the program's code.
    
                    When defined as an EMPTY STRING, the static library
                    libXXX.a is created: all programs linked to this library
                    will themselves contain the code of the required object
                    modules. This will result in code duplication over
                    different programs linked to this library.

                    When defined as a VERSION STRING, e.g., 1.0.4, a shared 
                    library libXXX.so.VERSION is constructed, as well as the 
                    links libXXX.so.MAINVERSION and libXXX.so (e.g. 1.0.0
                    creates libXXX.so.1.0.0, libXXX.so.1 and libXXX.so).

                    Note that with a shared library, the library is always 
                    constructed fresh from the compiled object files. But
                    programs linked to this library will SHARE the code stored 
                    in the shared library. These programs will therefore
                    tend to be relatively small.

                    Also note that `ldconfig -v' might be required after
                    installing a shared library (libXXX.so) for the first
                    time, so that the linker knows of its existence (in
                    ld.so.cache)

    BUILD_PROGRAM:  define if a program is to be built. If not defined,
                    library maintenance is assumed (default: defined).

    COMPILER:       The compiler to use. 
    COPT:           C-options used by COMPILER

    ECHO_REQUEST:   ON (default) if command echoing is wanted, otherwise: set
                    to OFF
    GDB:            define if gdb-symbolic debug information is wanted
                    (not defined by default)

    LIBS:           Extra libraries used for linking
    LIBPATH:        Extra library-searchpaths used for linking

    LOCAL_NAMESPACE:The namespace that you, the programmer, use yourself.
    USING:          List of :-separated namespaces to be used in sources and
                    .ih files, appearing in `using' directives.
                    USING does NOT automatically include LOCAL_NAMESPACE: 
                    add your LOCAL_NAMESPACE name to this list if want a 
                    `using' directive for your own namespace as well.

    Note that namespaces are NOT part of the build-script: they are only
    listed below for convenience. When they must be altered, the defaults must
    be changed in $IM/default/defines.im

    RELINK:         Defined by default, causing a program to be
                    relinked every time the script is called. Do not
                    define it if relinking should only occur if a
                    source is compiled. No effect for library maintenance.

    Current values:
*/
//#define BUILD_LIBRARY    ""
#define BUILD_PROGRAM

#define COMPILER           "g++"
#define COPT               "-Wall"

#define ECHO_REQUEST       1
//#define GDB              "-g"

#define LIBS               "bobcat"
#define LIBPATH            ""

// local namespace is: FBB
// using-declarations generated for: std:FBB

//                      NO CONFIGURABLE PARTS BELOW THIS LINE

/*
                            V A R S . I M
*/

string                  // contain options for
    cwd,                // current WD
    libs,               // extra libs, e.g., "-lrss -licce"
    libpath,            // extra lib-paths, eg, "-L../rss"
    copt,               // Compiler options
    lopt,               // Linker options
    libxxx,             // full library-path
    libso,              // symbolic link to so.major library path
    libsomajor,         // lib.so.major path
    ofiles,             // wildcards for o-files
    sources,            // sources to be used
    current;            // contains name of current dir.
int
    nClasses,           // number of classes/subdirectories
    program,            // 1: program is built
    so_lib;             // 1: so_lib is built
list
    classes;            // list of classes/directories
/*
                                 parser.im
*/

void parser()
{
    #ifdef GRAMBUILD
        chdir("parser/gramspec");
        system("grambuild");
        chdir("..");
    
        if
        (
            exists("grammar")
            &&
            "grammar" younger "parser.cc"
        )                                   // new parser needed
        {
            exec("bison++", "-d", "-o", "parser.cc", "grammar");
            printf("Note: the compilation of parser.cc may produce "
                   "several compiler warnings.\n");
        }
            
        chdir("..");
    #endif
}
/*
                                 S C A N N E R . I M
*/
void scanner()
{
    string
        interactive;
    
    #ifdef INTERACTIVE
        interactive = "-I";
    #endif
    
    #ifdef GRAMBUILD
        chdir("scanner");
        if
        (                                           // new lexer needed
            exists("lexer")
            &&
            (
                "lexer" younger "yylex.cc"
                ||
                "../parser/parser.h" younger "yylex.cc"
            )
        )
        {
            exec("flex++", interactive,
                        "-oyylex.cc", "lexer");
                        
            printf("Note: the compilation of yylex.cc may produce "
                   "several compiler warnings.\n");
        }
        chdir("..");
    #endif
}
/*
                                I N I T I A L . I M
*/
void initialize()
{
    echo(ECHO_REQUEST);
    sources = "*.cc";
    ofiles = "o/*.o";                       // std set of o-files
    copt = COPT;

    #ifdef GDB
        copt += " " + GDB;
    #endif

    #ifdef BUILD_PROGRAM
        program = 1;
        so_lib = 0;
    #else
        program = 0;
    #endif;

    #ifdef BUILD_LIBRARY
        if (strlen(BUILD_LIBRARY))
            so_lib = !program;
        else
            so_lib = 0;
    #else
        if (!program)
        {
            printf("no program, no library ?\n");
            exit(1);
        }
    #endif

    if (so_lib)
        copt += " -fPIC";

    cwd = chdir(".");

    #ifdef GRAMBUILD
        CLASSES = "parser scanner ";
        if (exists("parser"))                  // subdir parser exists
            parser(); 
        if (exists("scanner"))                  // subdir scannerexists
            scanner(); 
    #endif
    
    setClasses();                           // remaining classes

    classes = strtok(CLASSES, " ");         // list of classes

    nClasses = sizeof(classes);
}
/*
                                O B J F I L E S . I M
*/

list objfiles(list files)
{
    string
        file,
        objfile;
    int
        i;

    for (i = 0; i < sizeof(files); i++)
    {
        file = element(i, files);           // determine element of the list
        objfile = "./o/" + change_ext(file, "o");    // make obj-filename
        if (objfile younger file)           // objfile is younger
        {
            files -= (list)file;            // remove the file from the list
            i--;                            // reduce i to test the next
        }
    }
    return (files);
}
/*
                                A L T E R E D . I M
*/

list altered(list files, string target)
{
    int
        i;
    string
        file;

    for (i = 0; i < sizeof(files); i++)     // try all elements of the list
    {
        file = element(i, files);           // use element i of the list
            
        if (file older target)              // a file is older than the target
        {
            files -= (list)file;            // remove the file from the list
            i--;                            // reduce i to inspect the next
        }                                   // file of the list
    }
    return (files);                         // return the new list
}
/*
                            F I L E L I S T . I M
*/

list file_list(string type, string library)
{
    list
        files;

    files = makelist(type);                 // make all files of certain type
    #ifdef BUILD_LIBRARY
        if (!so_lib)                        // keep all files with so libs
            files = altered(files, library);// keep all files newer than lib.
    #endif
    files = objfiles(files);                // remove if younger .obj exist

    return (files);
}
/*
                        L I N K . I M
*/

void link(string library, string exe)
{
    printf("\n");
    exec(COMPILER, "-o", exe,
        #ifdef BUILD_LIBRARY
            "-l" + library,
        #else
            ofiles,
        #endif
        libs,
        #ifdef GRAMBUILD
            "-lfl",
        #endif
        "-L.", libpath, lopt
        #ifndef GDB
            , "-s"
        #endif
    );
    printf("ok: ", exe, "\n");
}
/*
                          P R E F I X C L . I M
*/
void prefix_class(string class_id)
{
    list
        o_files;
    string
        o_file;
    int
        i;

    chdir("o");
    o_files = makelist("*.o");
    for (i = 0; o_file = element(i, o_files); i++)
        exec("mv", o_file, class_id + o_file);
    chdir("..");
}
/*
                          R M C L A S S P . I M
*/

#ifdef BUILD_LIBRARY
    string rm_class_id(string class_id, string ofile)
    {
        string
            ret;
        int
            index,
            n;
    
        n = strlen(ofile);
        for (index = strlen(class_id); index < n; index++)
            ret += element(index, ofile);
    
        return ret;
    }
#endif

void rm_class_prefix(string class_id)
{
    #ifdef BUILD_LIBRARY
        list
            o_files;
        string
            o_file;
        int
            i;
    
        chdir("o");
        o_files = makelist("*.o");
        for (i = 0; o_file = element(i, o_files); i++)
            exec("mv", o_file, rm_class_id(class_id, o_file));
        chdir("..");
    #endif
}
/*
                        L I N K S O . I M
*/

void link_solib(string library)
{
    string
        gdb;

    #ifdef GDB
        gdb = GDB;
    #endif

    #ifdef BUILD_LIBRARY
        int
            index;
        list
            sofiles,
            version;
    
        version = strtok(BUILD_LIBRARY, ".");
        libso = "lib" + library + ".so";
        libxxx = libso + ".";
        libsomajor = libxxx + element(0, version);
        libxxx += BUILD_LIBRARY;
    
        for (index = 0; index < nClasses; index++)
        {
            current = element(index, classes);  // determine class name
            chdir(current);                 // chdir to a class directory.
            prefix_class((string)index);  
            chdir(cwd);                     // go back to parent dir
        }
    
        if (!makelist("o/*.o"))
            ofiles = "*/o/*.o";
    
        printf("\n");
        exec(COMPILER,
            gdb,
            "-shared",
            "-Wl,-soname," + libsomajor,
            "-o", libxxx,
            ofiles,
            libs,
            "-L.", libpath,
            lopt
        );
        printf("ok: ", libxxx, "\n");
    
        for (index = 0; index < nClasses; index++)
        {
            current = element(index, classes);  // determine class name
            chdir(current);                 // chdir to a class directory.
            rm_class_prefix((string)index);  
            chdir(cwd);                     // go back to parent dir
        }
    
    
        exec("ln", "-sf", libxxx, libsomajor);
        printf("ok: ", libsomajor, "\n");
    
        exec("ln", "-sf", libsomajor, libso);
        printf("ok: ", libso, "\n");
    #endif
}
/*
                            C C O M P I L E . I M
*/

void c_compile(list cfiles)
{
        string
                nextfile;
        int
                i;
                
    if (!exists("o"))
        system("mkdir o");
                                                      
    if (sizeof(cfiles))                 // files to compile ?
    {
        printf("\ncompiling: ", current, "\n\n");
        
                                        // compile all files separately
        for (i = 0; nextfile = element(i, cfiles); i++)
            exec(COMPILER,
                "-c -o o/" + change_ext(nextfile, "o"),
                copt, nextfile);

        printf("\n");
    }
    printf("ok: ", current, "\n");
}
/*
                            U P D A T E L I . I M
*/

void updatelib(string library)
{
    #ifdef BUILD_LIBRARY
        list
            arlist,
            objlist;
        string
            to,
            from;
    
        objlist = makelist("o/*.o");
    
        if (!sizeof(objlist))
            return;
    
        printf("\n");
    
        exec("ar", "rvs", library, "o/*.o");
        exec("rm", "o/*.o");
    
        printf("\n");
    #endif
}
/*
                                S T D C P P . I M
*/

void std_cpp(string library)
{
    list
        cfiles;

    cfiles = file_list(sources, library);     // make list of all cpp-files

    c_compile(cfiles);                      // compile cpp-files
}
/*
                                C P P M A K E . C

    CPP files are processed by stdmake.

    Arguments of CPPMAKE:

    cpp_make(
        string mainfile,    : name of the main .cpp file, or "" for library
                              maintenance
        string library,     : name of the local library to use/create
                                (without lib prefix or .a/.so suffix
                                (E.g., use `main' for `libmain.a')
        string exe,         : (path) name of the exe file to create
        )

    Both mainfile and library MUST be in the current directory
*/

void cpp_make(string mainfile, string library, string exe)
{
    int
        index;
        
    if (nClasses)
        ofiles += " */o/*.o";               // set ofiles for no LIBRARY use

                                            // make library name
    #ifdef BUILD_LIBRARY
        if (!so_lib)
            libxxx = chdir(".") + "lib" + library + ".a";
    #endif
                                            // first process all classes
    for (index = 0; index < nClasses; index++)
    {
        current = element(index, classes);  // next class to process
        chdir(current);                     // change to directory

        current = "subdir " + current;
        std_cpp(libxxx);                    // compile all files
        chdir(cwd);                         // go back to parent dir
    }

    current = "auxiliary " + sources + " files";
    std_cpp(libxxx);                        // compile all files in current dir

    
    #ifdef BUILD_LIBRARY
        if (!so_lib)
        {                               // prefix class-number for .o files
            for (index = 0; index < nClasses; index++)
            {
                current = element(index, classes);  // determine class name
                chdir( current);              // chdir to a class directory.
                prefix_class((string)index);  
                updatelib(libxxx);
                chdir(cwd);                // go back to parent dir
            }
            current = "";                  // no class anymore
            updatelib(libxxx);             // update lib in current dir
        }
        else
        {
            link_solib(library);           // separate processing for so-lib
            return;
        }
    #endif

    if (mainfile != "")                // mainfile -> do link
    {
        link(library, exe);
        printf
        (
            "\nProgram construction completed.\n"
            "\n"
        );
    }
}
/*
                        S E T L I B S . I M
*/
void setlibs()
{
    #ifdef LIBS
        int
            n,
            index;
        list
            cut;
            
        cut = strtok(LIBS, " ");        // cut op libraries
        n = sizeof(cut);
        for (index = 0; index < n; index++)
            libs += " -l" + element(index, cut);

        #ifdef GRAMBUILD        
            libs += " -lfl";
        #endif
    
        cut = strtok(LIBPATH, " ");     // cut up the paths
        n = sizeof(cut);
        for (index = 0; index < n; index++)
            libpath += " -L" + element(index, cut);
    #endif
}

void main()
{
    initialize();
    setlibs();

    #ifdef BUILD_PROGRAM
        cpp_make
        (
            "driver.cc", // program source
            "driver", // static program library
            "driver"  // binary program
        );
    #else
        cpp_make
        (
            "",
            "driver", // static- or so-library
            ""
        );
    #endif
}