File: icmake.c

package info (click to toggle)
icmake 6.22-2
  • links: PTS
  • area: main
  • in suites: woody
  • size: 2,120 kB
  • ctags: 1,045
  • sloc: ansic: 9,241; makefile: 1,138; asm: 126; sh: 124
file content (169 lines) | stat: -rw-r--r-- 5,466 bytes parent folder | download | duplicates (3)
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
/*
                         I C M A K E . C
*/

#include "icmake.h"

#ifdef MSDOS
#   pragma comment(lib, "icmake")
#   pragma comment(lib, "..\\rss\\icrss")
#endif

static char
    bim[]       = "bim",
    icm_comp[]  = ICMCOMP,
    icm_exec[]  = ICMEXEC,
    icm_pp[]    = ICMPP,
    pim[]       = "pim";

int main (argc, argv)              /* icmake source(txt) dest(bin) */
    int
        argc;
    char
        **argv;
{
    register int
        argc2,
        ret;
    char
        *prog;

    argc2 = options(argv, &argc);           /* process options */
                                            /* argc2 is index of args to
                                               icm-exec
                                            */
    if (!(flags & f_quiet))
        copyright("Make Utility", version, release, 1);

    prog = program_name(argv[0]);

    if (!(flags & f_icmake) && argc2 == 1)  /* argv[1]: already for icm-exec */
        error
        (
            "Icmake by Frank B. Brokken and Karel Kubat.\n"
            "\n"
            "Usage: %s [flags] source[.im] [dest[.bim]] [-- [args]]\n"
            "where:\n"
            "\tflags:  optional flags:\n"
            "\t\t-a     : information about %s\n"
            "\t\t-b     : blunt execution of the destinationfile\n"
            "\t\t-c     : the destination file is compiled\n"
            "\t\t-i file: 'file': name of source, argument processing stops\n"
#ifdef MSDOS
            "\t\t-o file: all icmake output is redirected to `file'\n"
#endif
            "\t\t-p     : only the preprocessor is activated\n"
            "\t\t-q     : quiet mode: copyright banner not displayed\n"
#ifndef MSDOS
            "\t\t-t file: 'file' is used as a temporary bim-file, to be removed\n"
            "\t\t         on exit. Argument processing stops.\n"
#endif
            "\tsource: make description source file (default extension: .im)\n"
            "\tdest:   binary make file             (default:    source.bim)\n"
            "\t        (not used with the -t option)\n"
            "\t-- :   optional icmake-file arguments separator\n"
            "\targs:  optional arguments following -- received by\n"
            "\t       the icmake file in its argv-list"
            , prog
            , prog
        );

#ifdef MSDOS
    if (redirect_nr != ~0)
    {
        if
        (
            !redirect_start(fileno(stderr), redirect_nr)
            ||
            !redirect_start(fileno(stdout), redirect_nr)
        )
            error("Output redirection to file fails");

        copyright("Make Utility", version, release, 1);
    }
#endif

    if (!(flags & f_icmake))                /* do not take source literally */
    {
        source_name =                       /* determine source */
            change_ext(argv[1], "im");      /* update the extension    */

        if (!(flags & f_tmpbim))            /* only if not a temp. bimfile */
            dest_name =
                argc2 >= 3 ?
                    argv[2]
                :
                    argv[1];
    }
    else if (!(flags & f_tmpbim))           /* only if not a temp. bimfile */
        dest_name = source_name;

    if (!(flags & f_tmpbim))                /* adapt extension of destination */
        dest_name = change_ext(dest_name, bim); /* if not tmp. bimfile */

    if
    (
        !(flags & f_blunt)                  /* no forced execution */
        &&
        compile_test()                      /* compilation needed */
    )
    {
                                            /* preprocessor filename */
        if (!(flags & f_tmpbim))            /* use .pim unless -t given */
            temporary = change_ext(source_name, pim);

        signal(SIGINT, abnormal_exit);      /* abnormal exits process */
                                            /* do the preprocessing */
        ret = _spawnlp(P_WAIT, icm_pp, icm_pp, source_name, temporary, NULL);
        if (ret)
        {
            if (ret == -1)
                spawn_err(icm_pp);
            cleanup();
            return (1);
        }

        if (flags & f_preprocessor)
            return (0);

                                            /* do the compilation */
        errors = _spawnlp(P_WAIT, icm_comp, icm_comp,
                                  temporary, dest_name, NULL);
        cleanup();

        if (errors)
        {
            if (errors == -1)
                spawn_err(icm_comp);
            return (1);
        }

        if (flags & f_compiler)
            return (0);
    }

    if (flags & f_tmpbim)                       /* -t used */
    {
        argc2 -= 3;                             /* set index to start of args */
        argv[argc2 + 1] = "-t";                 /* signal temporary */
        argv[argc2 + 2] = dest_name;            /* store dest-name */
    }
    else
    {
        argc2 -= 2;                             /* set index to start of args */
        argv[argc2 + 1] = dest_name;            /* store dest-name */
    }
    argv[argc2] = icm_exec;                     /* store executor's name */

#ifdef MSDOS
    quote_blanks(&argv[argc2]);             /* quote arguments with blanks */
#endif

                                            /* do the making of the file */
    errors = _execvp(icm_exec, &argv[argc2]);

    spawn_err(icm_exec);                    /* shouldn't get here ... */

    cleanup();                              /* remove tempfiles etc. */
    return (1);
}