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
|
/*
Copyright (c) 1990, 1991 X Consortium
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Except as contained in this notice, the name of the X Consortium shall not be
used in advertising or otherwise to promote the sale, use or other dealings
in this Software without prior written authorization from the X Consortium.
*
* Copyright 1990, 1991 by UniSoft Group Limited.
*
* Permission to use, copy, modify, distribute, and sell this software and
* its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and that
* both that copyright notice and this permission notice appear in
* supporting documentation, and that the name of UniSoft not be
* used in advertising or publicity pertaining to distribution of the
* software without specific, written prior permission. UniSoft
* makes no representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*
* $XConsortium: make.c,v 1.8 92/06/11 15:38:14 rws Exp $
*
* Author: Steve Ratcliffe, UniSoft Ltd.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "mc.h"
#define MAXNAMES 20
#define MAXMLINES 20
#define CFILELINELEN 65
extern struct state State;
#define F_BANNER "mmbanner.tmc"
#define F_DEFINES "mmdefs.tmc"
#define F_SA "mmsa.mc"
#define F_MSA "mmmsa.mc"
#define F_LINK "mmlink.mc"
#define F_MLINK "mmmlink.mc"
#define F_LIB "mmlib.mc"
#define F_MISC "mmmisc.mc"
#define F_PGEN "mmpgen.mc"
#define F_XPINIT "mmxpinit.mc"
#define F_XPLIB "mmxplib.mc"
#define F_DEPS "mmdeps.tmc"
#define F_TOP "mmtop.tmc"
static FILE *FpBanner;
static FILE *FpDefines;
static FILE *FpDepends;
static FILE *FpTop;
/*
* Which parts to include, this is so the makefiles can be made
* without eg. pixgen, or the library stuff.
*/
static char *incwhich = "lLmp";
extern struct settings Settings;
extern int dflag;
extern int lflag;
extern int sflag;
extern char *sopt;
void makename();
void makeline();
extern struct mclist *Sources;
struct mclist *filenames;
/*ARGSUSED*/
void
mmstart(buf)
char *buf;
{
/* sections to include */
if (sflag)
incwhich = sopt;
/* Index into files is one more than number of files */
filenames = createmclist();
FpBanner = cretmpfile(F_BANNER);
FpDefines = cretmpfile(F_DEFINES);
FpDepends = cretmpfile(F_DEPS);
FpTop = cretmpfile(F_TOP);
}
/*ARGSUSED*/
void
mmend(buf)
char *buf;
{
char *lp;
int i;
int linepos;
(void) fprintf(FpDefines, "SOURCES=");
linepos = strlen("SOURCES=");
for (i = 0; lp = getmclistitem(Sources, i); i++) {
linepos += strlen(lp);
if (linepos > CFILELINELEN) {
(void) fprintf(FpDefines, "\\\n\t");
linepos = 8;
}
(void) fprintf(FpDefines, "%s ", lp);
}
(void) fprintf(FpDefines, "\n");
(void) fprintf(FpDefines, "CFILES=Test.c ");
linepos = strlen("CFILES=Test.c ");
for (i = 0; lp = getmclistitem(filenames, i); i++) {
linepos += strlen(lp);
if (linepos > CFILELINELEN) {
(void) fprintf(FpDefines, "\\\n\t");
linepos = 8;
}
(void) fprintf(FpDefines, "%s ", lp);
}
(void) fprintf(FpDefines, "\n");
(void) fprintf(FpDefines, "OFILES=Test.o ");
linepos = strlen("OFILES=Test.o ");
for (i = 0; lp = getmclistitem(filenames, i); i++) {
linepos += strlen(lp);
if (linepos > CFILELINELEN) {
(void) fprintf(FpDefines, "\\\n\t");
linepos = 8;
}
/* Convert to dot-o */
lp[strlen(lp)-1] = 'o';
(void) fprintf(FpDefines, "%s ", lp);
}
(void) fprintf(FpDefines, "\n");
if (Settings.macro) {
(void) fprintf(FpDefines, "MOFILES=MTest.o ");
linepos = strlen("OFILES=MTest.o ");
for (i = 0; lp = getmclistitem(filenames, i); i++) {
linepos += strlen(lp);
if (linepos > CFILELINELEN) {
(void) fprintf(FpDefines, "\\\n\t");
linepos = 8;
}
/* Convert to dot-o */
lp[strlen(lp)-1] = 'o';
(void) fprintf(FpDefines, "%s ", lp);
}
(void) fprintf(FpDefines, "\n");
}
(void) fprintf(FpDefines, "LOFILES=link.o ");
if (Settings.macro)
fprintf(FpDefines, "mlink.o ");
linepos = strlen("LOFILES=link.o ");
for (i = 0; lp = getmclistitem(filenames, i); i++) {
linepos += strlen(lp);
if (linepos > CFILELINELEN) {
(void) fprintf(FpDefines, "\\\n\t");
linepos = 8;
}
/* Convert to dot-o */
lp[strlen(lp)-1] = 'o';
(void) fprintf(FpDefines, "%s ", lp);
}
(void) fprintf(FpDefines, "\n");
(void) fprintf(FpDefines, "LINKOBJ=%s.o\n", name10lc(State.name));
(void) fprintf(FpDefines, "LINKEXEC=%s\n", name10lc(State.name));
(void) fprintf(FpDefines, "\n\n");
/*
* Now the makefile is output using the saved information and
* the skeleton files. There are a few variations depending
* on whether the test has a macro version or is an X protocol
* test.
*/
/* The top of the makefile */
outfile(FpBanner);
outfile(FpDefines);
if (State.xproto)
outcopy(F_XPINIT);
outfile(FpTop);
/* The rules for the standalone tests */
outcopy(F_SA);
if (Settings.macro)
outcopy(F_MSA);
/* Do the combined parts, if they are wanted */
if (strchr(incwhich, 'l')) {
outcopy(F_LINK);
if (Settings.macro)
outcopy(F_MLINK);
}
/* Do the library rules, if they are wanted */
if (strchr(incwhich, 'L')) {
if (State.xproto)
outcopy(F_XPLIB);
else
outcopy(F_LIB);
}
/* The misc rules, if wanted */
if (strchr(incwhich, 'm'))
outcopy(F_MISC);
/*
* We assume here that neither the xproto tests or tests that have
* a macro version use Pixel Generation.
* This is true at present.
*/
if (!State.xproto && !Settings.macro && strchr(incwhich, 'p'))
outcopy(F_PGEN);
/* Depends */
outfile(FpDepends);
}
void
mmcopyright(fp, buf)
FILE *fp;
char *buf;
{
static int firsttime = 1;
while (newline(fp, buf) != NULL && !SECSTART(buf)) {
if (strncmp(buf, " */", 3) == 0)
strcpy(buf, " * \n");
if (firsttime || strinstr(buf, "SCCS")) {
buf[0] = '#';
buf[1] = ' ';
if (buf[2] == '/')
buf[2] = ' ';
fputs(buf, FpBanner);
}
}
firsttime = 0;
}
void
mmheader(fp, buf)
FILE *fp;
char *buf;
{
/*
* This is a name of the function that the test is being
* built for.
*/
if (State.name) {
(void) fprintf(FpDefines, "#\n# Makefile for %s\n", State.name);
(void) fprintf(FpDefines, "#\n\n");
}
skip(fp, buf);
}
void
mmmake(fp, buf)
FILE *fp;
char *buf;
{
echon(fp, buf, FpTop);
}
void
mmcfiles(fp, buf)
FILE *fp;
char *buf;
{
char *cp;
char *tok;
cp = buf+strlen(D_CFILE);
for (tok = strtok(cp, " \t\n"); tok; tok = strtok((char*)0, " \t\n")) {
filenames = addmclist(filenames, tok);
}
skip(fp, buf);
}
void
mmincstart(name)
char *name;
{
/* If this is temp file then don't bother with it */
if (strcmp(name+strlen(name)-4, ".tmc") == 0)
return;
/* If this is a gc or error include then put in a dependency */
if (strncmp(name, "gc/", 3) == 0 || strncmp(name, "error/", 6) == 0) {
fprintf(FpDepends, "Test.c link.c: $(XTESTLIBDIR)/%s\n", name);
} else {
/* Otherwise put in dependency as it is */
fprintf(FpDepends, "Test.c link.c: %s\n", name);
}
}
#define MCLINIT 10 /* Initial number of slots to create */
/*
* create an mclist structure and initialise it
*/
struct mclist *
createmclist()
{
struct mclist *mclp;
mclp = (struct mclist *)malloc(sizeof(struct mclist)+MCLINIT*sizeof(char*));
if (mclp == NULL) {
(void) fprintf(stderr, "Out of memory\n");
errexit();
}
mclp->num = 0;
mclp->size = MCLINIT;
return(mclp);
}
/*
* Add a string to the list. The given string will be copied.
* A pointer to the list is returned, it may have been realloced so
* it could have changed.
*/
struct mclist *
addmclist(list, string)
struct mclist *list;
char *string;
{
int size;
if (list->num > list->size) {
/* Need to alloc more space */
list->size += MCLINIT;
size = sizeof(struct mclist) + (list->size-1)*sizeof(char*);
list = (struct mclist *)realloc((char*)list, (unsigned)size);
if (list == NULL) {
(void) fprintf(stderr, "Out of memory\n");
errexit();
}
}
list->items[list->num++] = mcstrdup(string);
return(list);
}
/*
* Get a list string item.
*/
char *
getmclistitem(list, n)
struct mclist *list;
int n;
{
if (n > list->num)
return((char*)0);
return(list->items[n]);
}
|