File: link

package info (click to toggle)
icmake 13.05.01-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 7,132 kB
  • sloc: cpp: 11,595; fortran: 883; makefile: 853; sh: 546; pascal: 342
file content (59 lines) | stat: -rw-r--r-- 1,390 bytes parent folder | download | duplicates (4)
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
    // flag must start with a blank (" -l", " -L")
string addLibs(string spec, string flag)
{
    string ret;
    list cut = strtok(spec, " ");        // cut up the specification
    for (int idx = 0, end = listlen(cut); idx != end; ++idx)
        ret += flag + cut[idx];

    return ret;
}

#ifdef ADD_LIBRARIES
string useLibs()
{
    return addLibs(ADD_LIBRARIES, " -l") + addLibs(ADD_LIBRARY_PATHS, " -L");
}
#endif

            // the binary is installed under TMP_DIR
void link(string maino)
{
    chdir(TMP_DIR);

    string compiler = g_compiler + " -o bin/binary " + maino;

    #ifdef LIBRARY
        compiler += " -l" LIBRARY " -L.";
    #else
        if (listlen(makelist("o/*" OBJ_EXT)))
            compiler += " o/*" OBJ_EXT;
    #endif

    #ifdef ADD_LIBRARIES
        compiler += useLibs();         // use extra libraries (if specified)
    #endif

    #ifdef LDFLAGS
        compiler += " " + setOpt(LDFLAGS, "LDFLAGS");
    #else
        #ifdef LINKER_OPTIONS
            compiler += " " + LINKER_OPTIONS;
        #endif
    #endif

    #ifndef REFRESH             // then check for the need to refresh
        if (g_compiled || maino younger "../bin/binary" 
        #ifdef LIBRARY
            || 
            "lib" LIBRARY ".a" younger "../bin/binary"
        #endif
        )
    #endif
    {
        showCd(TMP_DIR);
        system(compiler);
    }

    chdir("");
}