Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
att
GitHub Repository: att/ast
Path: blob/master/src/cmd/nmake/archive.c
1808 views
1
/***********************************************************************
2
* *
3
* This software is part of the ast package *
4
* Copyright (c) 1984-2011 AT&T Intellectual Property *
5
* and is licensed under the *
6
* Eclipse Public License, Version 1.0 *
7
* by AT&T Intellectual Property *
8
* *
9
* A copy of the License is available at *
10
* http://www.eclipse.org/org/documents/epl-v10.html *
11
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
12
* *
13
* Information and Software Systems Research *
14
* AT&T Research *
15
* Florham Park NJ *
16
* *
17
* Glenn Fowler <[email protected]> *
18
* *
19
***********************************************************************/
20
#pragma prototyped
21
/*
22
* Glenn Fowler
23
* AT&T Research
24
*
25
* make archive access routines
26
*/
27
28
#include "make.h"
29
30
#include <ardir.h>
31
32
static int ntouched; /* count of touched members */
33
34
/*
35
* return the update command for the named archive
36
*/
37
38
char*
39
arupdate(char* name)
40
{
41
Ardir_t* ar;
42
char* update;
43
44
update = "$(RANLIB) $(<)";
45
if (!state.regress)
46
{
47
if (!(ar = ardiropen(name, NiL, ARDIR_LOCAL)))
48
return 0;
49
if (streq(ar->meth->name, "local"))
50
update = "($(RANLIB|\":\") $(<)) >/dev/null 2>&1 || true";
51
else if (!(ar->flags & ARDIR_RANLIB))
52
update = 0;
53
ardirclose(ar);
54
}
55
return update;
56
}
57
58
/*
59
* walk through an archive
60
* d==0 updates the modify time of preselected members (see artouch())
61
* else each member is recorded using addfile()
62
*/
63
64
static int
65
walkar(register Ardir_t* ar, Dir_t* d, char* name)
66
{
67
register Ardirent_t* ent;
68
register Rule_t* r;
69
70
if (d)
71
{
72
putar(d->name, d);
73
d->truncate = ar->truncate;
74
}
75
while (ent = ardirnext(ar))
76
{
77
if (d)
78
{
79
if ((Seconds_t)ent->mtime > (Seconds_t)ar->st.st_mtime)
80
message((-1, "member %s is newer than archive %s", ent->name, name));
81
addfile(d, ent->name, ((r = staterule(RULE, NiL, ent->name, -1)) && ent->mtime == tmxsec(r->time)) ? r->time : tmxsns(ent->mtime, 0));
82
}
83
else if ((r = getrule(ent->name)) && r->status == TOUCH)
84
{
85
ent->mtime = CURSECS;
86
ardirchange(ar, ent);
87
r->status = EXISTS;
88
staterule(RULE, r, NiL, 1)->time = r->time = tmxsns(ent->mtime, 0);
89
state.savestate = 1;
90
if (!state.silent)
91
error(0, "touch %s/%s", name, ent->name);
92
ntouched--;
93
}
94
}
95
return 0;
96
}
97
98
/*
99
* check for any untouched r->status==TOUCH members
100
*/
101
102
static int
103
chktouch(const char* s, char* v, void* h)
104
{
105
Rule_t* r = (Rule_t*)v;
106
107
NoP(s);
108
NoP(h);
109
if (r->status == TOUCH)
110
{
111
r->status = FAILED;
112
error(1, "archive member %s not touched", r->name);
113
}
114
return 0;
115
}
116
117
/*
118
* touch the modify time of an archive member (and the archive itself!)
119
*/
120
121
void
122
artouch(char* name, register char* member)
123
{
124
register Rule_t* r;
125
Ardir_t* ar;
126
127
if (member)
128
{
129
if (!(r = getrule(member)))
130
error(PANIC, "%s[%s] not scanned", name, member);
131
else
132
{
133
r->status = TOUCH;
134
ntouched++;
135
}
136
}
137
else if (ar = ardiropen(name, NiL, ARDIR_LOCAL|ARDIR_UPDATE))
138
{
139
walkar(ar, NiL, name);
140
if (ardirclose(ar))
141
error(1, "error touching archive %s", name);
142
if (ntouched > 0)
143
{
144
message((-2, "checking %d untouched members in %s", ntouched, name));
145
hashwalk(table.rule, 0, chktouch, NiL);
146
}
147
ntouched = 0;
148
}
149
}
150
151
/*
152
* scan archive r and record all its entries
153
*/
154
155
void
156
arscan(Rule_t* r)
157
{
158
Ardir_t* ar;
159
Dir_t* d;
160
161
if (r->dynamic & D_scanned)
162
return;
163
r->dynamic |= D_scanned;
164
if (r->property & P_state)
165
r->dynamic &= ~D_entries;
166
else if (!(d = unique(r)))
167
r->dynamic |= D_entries;
168
else if (r->scan >= SCAN_USER)
169
{
170
debug((-5, "scan aggregate %s", r->name));
171
d->archive = 1;
172
state.archive = d;
173
scan(r, NiL);
174
state.archive = 0;
175
r->dynamic |= D_entries;
176
}
177
else if (ar = ardiropen(r->name, NiL, ARDIR_LOCAL))
178
{
179
debug((-5, "scan archive %s", r->name));
180
d->archive = 1;
181
if (walkar(ar, d, r->name))
182
r->dynamic |= D_entries;
183
else
184
r->dynamic &= ~D_entries;
185
if (ardirclose(ar))
186
error(1, "%s: archive scan error", r->name);
187
}
188
else
189
debug((-5, "arscan(%s) failed", r->name));
190
}
191
192