~ubuntu-branches/ubuntu/utopic/oxref/utopic

« back to all changes in this revision

Viewing changes to icmake/library

  • Committer: Package Import Robot
  • Author(s): Frank B. Brokken, Frank B. Brokken, tony mancill
  • Date: 2013-01-25 10:57:14 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20130125105714-emfjxxkxcqf6kt9x
Tags: 0.91.00-1
[ Frank B. Brokken ]
* --help, --version options return 0, catching Errno exceptions removed from
  main() 

[ tony mancill ]
* Bump Standards-Version to 3.9.4 (no changes).
* Change build-dep for CXX to g++-4.7.
* Update Vcs fields to point to new package repo on git.debian.org.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
 
2
 
#define ECHO_REQUEST       1
3
 
 
4
 
#define LIBS               "bobcat"
5
 
#define LIBPATH            ""
6
 
 
7
 
 
8
 
string                  // contain options for
9
 
    g_copt,             // compiler options
10
 
    g_cwd,              // current WD
11
 
    libs,               // extra libs, e.g., "-lrss -licce"
12
 
    libpath,            // extra lib-paths, eg, "-L../rss"
13
 
    g_sources,          // sources to be used
14
 
    g_binary;           // the name of the program to create
15
 
int
16
 
    g_nClasses;         // number of classes/subdirectories
17
 
list
18
 
    g_classes;          // list of classes/directories
19
 
 
20
 
string setOpt(string install_im, string envvar)
21
 
{
22
 
    list optvar;
23
 
    string ret;
24
 
 
25
 
    optvar = getenv(envvar);    
26
 
 
27
 
    if (optvar[0] == "1")
28
 
        ret = optvar[1];
29
 
    else 
30
 
        ret = install_im;
31
 
 
32
 
    return ret;
33
 
}
34
 
 
35
 
void setClasses()
36
 
{
37
 
    list candidate;
38
 
    list class;
39
 
 
40
 
    while (sizeof(class = fgets("CLASSES", (int)element(1, class))))
41
 
    {
42
 
        candidate = strtok(element(0, class), " \t\n");
43
 
 
44
 
        // if the line contains info not starting with #, add the class
45
 
        if (sizeof(candidate) && element(0, element(0, candidate)) != "#")
46
 
            g_classes += (list)element(0, strtok(element(0, class), " \t\n"));
47
 
    }
48
 
 
49
 
    g_nClasses = sizeof(g_classes);
50
 
}
51
 
 
52
 
void static_lib(string ofiles, string library)
53
 
{
54
 
    if (sizeof(makelist(ofiles)))
55
 
    {
56
 
        run("ar cru " + library + " " + ofiles);
57
 
        run("ranlib " + library);
58
 
        run("rm " + ofiles);
59
 
    }
60
 
}
61
 
 
62
 
void static_library(string library)
63
 
{
64
 
    static_lib("*/o/*.o", library);
65
 
    static_lib("o/*.o", library);
66
 
}
67
 
 
68
 
void scanner()
69
 
{
70
 
    chdir("scanner");
71
 
    if
72
 
    (                                           // new lexer needed
73
 
        exists("lexer")
74
 
        &&
75
 
        "lexer" younger "yylex.cc"
76
 
    )
77
 
        exec("flex", "lexer");
78
 
 
79
 
    chdir("..");
80
 
}
81
 
 
82
 
/*
83
 
                                I N I T I A L . I M
84
 
*/
85
 
void initialize()
86
 
{
87
 
    echo(ECHO_REQUEST);
88
 
    g_sources = "*.cc";
89
 
 
90
 
    g_binary = "tmp/bin/oxref" EXTENSION;
91
 
 
92
 
    g_cwd = chdir(".");
93
 
 
94
 
    if (exists("scanner"))                  // subdir scanner exists
95
 
        scanner(); 
96
 
    
97
 
    setClasses();                           // remaining classes
98
 
}
99
 
 
100
 
/*
101
 
                        L I N K . I M
102
 
*/
103
 
 
104
 
list inspect(int prefix, list srcList, string library)
105
 
{
106
 
    int idx;
107
 
    string ofile;
108
 
    string oprefix;
109
 
    string file;
110
 
 
111
 
    oprefix = "./o/" + (string)prefix;
112
 
 
113
 
    for (idx = sizeof(srcList); idx--; )
114
 
    {
115
 
        file  = element(idx, srcList);   
116
 
 
117
 
        ofile   = oprefix + change_ext(file, "o");    // make o-filename
118
 
 
119
 
        // A file s must be recompiled if it's newer than its object
120
 
        // file o or newer than its target library l, or if neither o nor l
121
 
        // exist. 
122
 
        // Since `a newer b' is true if a is newer than b, or if a exists and
123
 
        // b doesn't exist s must be compiled if s newer o and s newer l.
124
 
        // So, it doesn't have to be compiled if s older o or s older l.
125
 
                                            // redo if file has changed
126
 
        if (file older ofile || file older library)
127
 
            srcList -= (list)file;
128
 
    }
129
 
    return srcList;
130
 
}
131
 
 
132
 
 
133
 
void c_compile(int prefix, string srcDir, list cfiles)
134
 
{
135
 
    int idx;
136
 
    string compiler;
137
 
    string file;
138
 
 
139
 
    compiler = COMPILER + " -Wall --std=c++0x -c -o " + 
140
 
                                srcDir + "/o/" + (string)prefix;
141
 
 
142
 
    md(srcDir + "/o");
143
 
 
144
 
    for (idx = sizeof(cfiles); idx--; )
145
 
    {
146
 
        file = element(idx, cfiles);
147
 
        
148
 
        run(compiler + change_ext(file, "o") + " " + 
149
 
                g_copt + " " + srcDir + "/" + file);
150
 
    }
151
 
}
152
 
 
153
 
void std_cpp(int prefix, string srcDir, string library)
154
 
{
155
 
    list files;
156
 
 
157
 
    chdir(srcDir);
158
 
                                                      // make list of all files
159
 
    files = inspect(prefix, makelist(g_sources), library);  
160
 
    chdir(g_cwd);
161
 
 
162
 
    if (sizeof(files))
163
 
        c_compile(prefix, srcDir, files);             // compile files
164
 
}
165
 
 
166
 
void cpp_make(string mainfile, string library, int lib_only)
167
 
{
168
 
    int idx;
169
 
    string class;
170
 
    string fullLibname;
171
 
 
172
 
    fullLibname = "lib" + library + ".a";
173
 
 
174
 
    for (idx = g_nClasses; idx--; )
175
 
        std_cpp(idx, element(idx, g_classes), "../" + fullLibname);
176
 
 
177
 
    if (!lib_only)                          // compile all files in current
178
 
                                            // dir
179
 
        std_cpp(g_nClasses, ".", fullLibname);  
180
 
 
181
 
    static_library(fullLibname);            // make the library
182
 
}
183
 
 
184
 
void setlibs()
185
 
{
186
 
        int
187
 
            n,
188
 
            index;
189
 
        list
190
 
            cut;
191
 
            
192
 
        cut = strtok(LIBS, " ");        // cut op libraries
193
 
        n = sizeof(cut);
194
 
        for (index = 0; index < n; index++)
195
 
            libs += " -l" + element(index, cut);
196
 
 
197
 
        cut = strtok(LIBPATH, " ");     // cut up the paths
198
 
        n = sizeof(cut);
199
 
        for (index = 0; index < n; index++)
200
 
            libpath += " -L" + element(index, cut);
201
 
}
202
 
 
203
 
void library(int lib_only)
204
 
{
205
 
    initialize();
206
 
    setlibs();
207
 
    
208
 
    md("tmp/bin tmp/o");
209
 
 
210
 
    special();
211
 
 
212
 
    g_copt = setOpt(CXXFLAGS, "CXXFLAGS");
213
 
 
214
 
    cpp_make
215
 
    (
216
 
        "oxref.cc",      // program source
217
 
        "oxref",         // static program library base name
218
 
        lib_only            // don't compile maindir for lib construction
219
 
    );
220
 
 
221
 
    if (lib_only)
222
 
        exit(0);
223
 
}