Initial revision
[sw-tools] / src / sw_arch.h
1 /* -*-c-*-
2 *
3 * $Id: sw_arch.h,v 1.1 1999/06/02 16:53:35 mdw Exp $
4 *
5 * Messing with architectures
6 *
7 * (c) 1999 EBI
8 */
9
10 /*----- Licensing notice --------------------------------------------------*
11 *
12 * This file is part of sw-tools.
13 *
14 * sw-tools is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
18 *
19 * sw-tools is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with sw-tools; if not, write to the Free Software Foundation,
26 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 */
28
29 /*----- Revision history --------------------------------------------------*
30 *
31 * $Log: sw_arch.h,v $
32 * Revision 1.1 1999/06/02 16:53:35 mdw
33 * Initial revision
34 *
35 */
36
37 #ifndef SW_ARCH_H
38 #define SW_ARCH_H
39
40 #ifdef __cplusplus
41 extern "C" {
42 #endif
43
44 /*----- Header files ------------------------------------------------------*/
45
46 #include <mLib/dstr.h>
47
48 /*----- Data structures ---------------------------------------------------*/
49
50 /* --- @archcons@ --- *
51 *
52 * Links architectures into a list. It's done like this so that we can have
53 * multiple lists all referring to the same data.
54 */
55
56 typedef struct archcons {
57 struct archent *car;
58 struct archcons *cdr;
59 } archcons;
60
61 /* --- @archent@ --- *
62 *
63 * Records information extracted from the `archtab' file, together with some
64 * other data used at run-time for the parallel build stuff.
65 */
66
67 typedef struct archent {
68 struct archcons cons; /* Cons for linking these together */
69 char *arch; /* The architecture name */
70 char *host; /* The architecture representative */
71 int status; /* Exit status from build process */
72 struct sw_remote *r; /* Remote command control block */
73 void *pres; /* Data for presentation handler */
74 unsigned flags; /* Various other flags */
75 } archent;
76
77 /* --- Flags --- */
78
79 enum {
80 archFlag_touched = 1, /* Unique flag: see @arch_filter@ */
81 archFlag_built = 2, /* This architecture is up-to-date */
82 archFlag_home = 4 /* This is the current arch */
83 };
84
85 /*----- Functions provided ------------------------------------------------*/
86
87 /* --- @arch_readtab@ --- *
88 *
89 * Arguments: ---
90 *
91 * Returns: The address of the archtab list.
92 *
93 * Use: Reads the archtab file (if necessary) and returns a list of
94 * its contents.
95 */
96
97 extern archcons *arch_readtab(void);
98
99 /* --- @arch_lookup@ --- *
100 *
101 * Arguments: @const char *arch@ = pointer to archtecture name
102 * @int abbrev@ = whether abbreviations are OK
103 *
104 * Returns: Pointer to archtab block, or null.
105 *
106 * Use: Translates an architecture name into the name of a host
107 * supporting that architecture.
108 */
109
110 extern archent *arch_lookup(const char */*arch*/, int /*abbrev*/);
111
112 /* --- @arch_filter@ --- *
113 *
114 * Arguments: @archcons *a@ = input list to filter
115 * @const char *p@ = pointer to a textual list of architectures
116 * @unsigned and@, @unsigned xor@ = flags to look for
117 *
118 * Returns: A newly constructed architecture list containing only the
119 * listed architectures.
120 *
121 * Use: Filters the architecture list down to a few interesting
122 * architectures.
123 *
124 * If @p@ is non-null, it is a textual list of architecture
125 * names (possibly abbreviated), and separated by whitespace
126 * and/or commas: only the named architectures are included in
127 * the resulting list. If @p@ is null, all architectures are
128 * considered.
129 *
130 * The list is further trimmed down by examining the flags words
131 * in each entry. Only entries with flags @f@ where @(f ^ xor)
132 * & and@ is zero are left in the resulting list. (To include
133 * all entries, clear @and@ to zero. To require a flag to be
134 * clear, set the corresponding bit in @and@. To require a flag
135 * to be set, set the corresponding bit in both @and@ and @xor@.
136 *
137 * (Don't try to filter on the @archFlag_touched@ flag. That
138 * flag is for the internal use of this routine.)
139 */
140
141 extern archcons *arch_filter(archcons */*a*/, const char */*p*/,
142 unsigned /*and*/, unsigned /*xor*/);
143
144 /* --- @arch_free@ --- *
145 *
146 * Arguments: @archcons *a@ = pointer to a list
147 *
148 * Returns: ---
149 *
150 * Use: Contrary to anything you might have expected from the Lispy
151 * naming, old architecture lists don't get garbage collected.
152 * This routine throws away an old list when you don't want it
153 * any more. Don't call this on the main list! It will fail
154 * miserably, because the cons cells in the main list are
155 * faked.
156 */
157
158 extern void arch_free(archcons */*a*/);
159
160 /* --- @arch_toText@ --- *
161 *
162 * Arguments: @dstr *d@ = pointer to dynamic string to build result in
163 * @archcons *a@ = list to write into the string
164 * @unsigned and@, @unsigned xor@ = flags to look for
165 *
166 * Returns: ---
167 *
168 * Use: Writes a textual list of architectures to a string. This can
169 * then be used (for example) as the `only-arch' list in the
170 * info file, by filling it into a skeleton and calling
171 * @swinfo_update@. The @and@ and @xor@ arguments work in the
172 * same way as with @arch_filter@.
173 */
174
175 extern void arch_toText(dstr */*d*/, archcons */*a*/,
176 unsigned /*and*/, unsigned /*xor*/);
177
178 /* --- Subcommands --- */
179
180 extern int sw_arch(int /*argc*/, char */*argv*/[]);
181 extern int sw_listarch(int /*argc*/, char */*argv*/[]);
182 extern int sw_host(int /*argc*/, char */*argv*/[]);
183 extern int sw_only(int /*argc*/, char */*argv*/[]);
184 extern int sw_all(int /*argc*/, char */*argv*/[]);
185
186 #ifdef CMD_LINK
187 static cmd cmd_only = {
188 CMD_LINK, "only-arch", sw_only,
189 "only-arch ARCH,...\n\
190 Restrict builds to a selection of architectures. (This option is\n\
191 persistent. An `--arch' command-line option takes precedence,\n\
192 though.)\n"
193 };
194 static cmd cmd_all = {
195 &cmd_only, "all-arch", sw_all,
196 "all-arch\n\
197 Clears the `only-arch' list. Subsequent builds occur across all\n\
198 architectures.\n"
199 };
200 static cmd cmd_host = {
201 &cmd_all, "host", sw_host,
202 "host ARCH\n\
203 Display the name of a host supporting architecture ARCH.\n"
204 };
205 static cmd cmd_listarch = {
206 &cmd_host, "listarch", sw_listarch,
207 "listarch\n\
208 Display a list of all architectures known.\n"
209 };
210 static cmd cmd_arch = {
211 &cmd_listarch, "arch", sw_arch,
212 "arch\tDisplay the architecture name of the current host.\n"
213 };
214 # undef CMD_LINK
215 # define CMD_LINK &cmd_arch
216 #endif
217
218 /*----- That's all, folks -------------------------------------------------*/
219
220 #ifdef __cplusplus
221 }
222 #endif
223
224 #endif