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