xref: /freebsd/usr.sbin/config/config.h (revision 2a58b312)
1 /*-
2  * SPDX-License-Identifier: BSD-3-Clause
3  *
4  * Copyright (c) 1980, 1993
5  *	The Regents of the University of California.  All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  * 3. Neither the name of the University nor the names of its contributors
16  *    may be used to endorse or promote products derived from this software
17  *    without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29  * SUCH DAMAGE.
30  *
31  *	@(#)config.h	8.1 (Berkeley) 6/6/93
32  * $FreeBSD$
33  */
34 
35 /*
36  * Config.
37  */
38 #include <sys/types.h>
39 #include <sys/queue.h>
40 #include <stdbool.h>
41 #include <stdlib.h>
42 #include <string.h>
43 
44 #ifdef __cplusplus
45 #include <string>
46 
47 class configword {
48 private:
49 	std::string	cw_word;
50 	bool		cw_eof;
51 	bool		cw_eol;
52 public:
53 	configword() : cw_word(""), cw_eof(false), cw_eol(false) {}
54 	configword(std::string &&word) : cw_word(word), cw_eof(false), cw_eol(false) {}
55 
56 	bool eof() const {
57 		return (cw_eof);
58 	}
59 
60 	bool eol() const {
61 		return (cw_eol);
62 	}
63 
64 	configword &eof(bool eof) {
65 		cw_eof = eof;
66 		return (*this);
67 	}
68 
69 	configword &eol(bool eol) {
70 		cw_eol = eol;
71 		return (*this);
72 	}
73 
74 	char operator[](int idx) {
75 		return (cw_word[idx]);
76 	}
77 
78 	operator const char*() const {
79 		return (cw_word.c_str());
80 	}
81 
82 	const std::string &operator*() const {
83 		return (cw_word);
84 	}
85 
86 	const std::string *operator->() const {
87 		return (&cw_word);
88 	}
89 };
90 
91 /*
92  * Is it ugly to limit these to C++ files? Yes.
93  */
94 configword get_word(FILE *);
95 configword get_quoted_word(FILE *);
96 #endif
97 
98 __BEGIN_DECLS
99 
100 struct cfgfile {
101 	STAILQ_ENTRY(cfgfile)	cfg_next;
102 	char	*cfg_path;
103 };
104 extern STAILQ_HEAD(cfgfile_head, cfgfile) cfgfiles;
105 
106 struct file_list {
107 	STAILQ_ENTRY(file_list) f_next;
108 	char	*f_fn;			/* the name */
109 	int     f_type;                 /* type */
110 	u_char	f_flags;		/* see below */
111 	char	*f_compilewith;		/* special make rule if present */
112 	char	*f_depends;		/* additional dependencies */
113 	char	*f_clean;		/* File list to add to clean rule */
114 	char	*f_warn;		/* warning message */
115 	const char *f_objprefix;	/* prefix string for object name */
116 	const char *f_srcprefix;	/* source prefix such as $S/ */
117 };
118 
119 struct files_name {
120 	char *f_name;
121 	STAILQ_ENTRY(files_name) f_next;
122 };
123 
124 /*
125  * Types.
126  */
127 #define NORMAL		1
128 #define NODEPEND	4
129 #define LOCAL		5
130 #define DEVDONE		0x80000000
131 #define TYPEMASK	0x7fffffff
132 
133 /*
134  * Attributes (flags).
135  */
136 #define NO_IMPLCT_RULE	1
137 #define NO_OBJ		2
138 #define BEFORE_DEPEND	4
139 #define NOWERROR	16
140 #define NO_CTFCONVERT	32
141 
142 struct device {
143 	int	d_done;			/* processed */
144 	char	*d_name;		/* name of device (e.g. rk11) */
145 	char	*yyfile;		/* name of the file that first include the device */
146 #define	UNKNOWN -2	/* -2 means not set yet */
147 	STAILQ_ENTRY(device) d_next;	/* Next one in list */
148 };
149 
150 struct config {
151 	char	*s_sysname;
152 };
153 
154 /*
155  * Config has a global notion of which machine type is
156  * being used.  It uses the name of the machine in choosing
157  * files and directories.  Thus if the name of the machine is ``i386'',
158  * it will build from ``Makefile.i386'' and use ``../i386/inline''
159  * in the makerules, etc.  machinearch is the global notion of the
160  * MACHINE_ARCH for this MACHINE.
161  */
162 extern char	*machinename;
163 extern char	*machinearch;
164 
165 /*
166  * For each machine, a set of CPU's may be specified as supported.
167  * These and the options (below) are put in the C flags in the makefile.
168  */
169 struct cputype {
170 	char	*cpu_name;
171 	SLIST_ENTRY(cputype) cpu_next;
172 };
173 
174 extern SLIST_HEAD(cputype_head, cputype) cputype;
175 
176 /*
177  * A set of options may also be specified which are like CPU types,
178  * but which may also specify values for the options.
179  * A separate set of options may be defined for make-style options.
180  */
181 struct opt {
182 	char	*op_name;
183 	char	*op_value;
184 	int	op_ownfile;	/* true = own file, false = makefile */
185 	char	*yyfile;	/* name of the file that first include the option */
186 	SLIST_ENTRY(opt) op_next;
187 	SLIST_ENTRY(opt) op_append;
188 };
189 
190 extern SLIST_HEAD(opt_head, opt) opt, mkopt, rmopts;
191 
192 struct opt_list {
193 	char *o_name;
194 	char *o_file;
195 	int o_flags;
196 #define OL_ALIAS	1
197 	SLIST_ENTRY(opt_list) o_next;
198 };
199 
200 extern SLIST_HEAD(opt_list_head, opt_list) otab;
201 
202 struct envvar {
203 	char	*env_str;
204 	bool	env_is_file;
205 	STAILQ_ENTRY(envvar) envvar_next;
206 };
207 
208 extern STAILQ_HEAD(envvar_head, envvar) envvars;
209 
210 struct hint {
211 	char	*hint_name;
212 	STAILQ_ENTRY(hint) hint_next;
213 };
214 
215 extern STAILQ_HEAD(hint_head, hint) hints;
216 
217 struct includepath {
218 	char	*path;
219 	SLIST_ENTRY(includepath) path_next;
220 };
221 
222 extern SLIST_HEAD(includepath_head, includepath) includepath;
223 
224 /*
225  * Tag present in the kernconf.tmpl template file. It's mandatory for those
226  * two strings to be the same. Otherwise you'll get into trouble.
227  */
228 #define	KERNCONFTAG	"%%KERNCONFFILE%%"
229 
230 /*
231  * Faked option to note, that the configuration file has been taken from the
232  * kernel file and inclusion of DEFAULTS etc.. isn't nessesery, because we
233  * already have a list of all required devices.
234  */
235 #define OPT_AUTOGEN	"CONFIG_AUTOGENERATED"
236 
237 extern char	*ident;
238 extern char	kernconfstr[];
239 extern int	do_trace;
240 extern int	incignore;
241 
242 char	*path(const char *);
243 char	*raisestr(char *);
244 void	remember(const char *);
245 void	moveifchanged(const char *, const char *);
246 int	yylex(void);
247 int	yyparse(void);
248 void	options(void);
249 void	makefile(void);
250 void	makeenv(void);
251 void	makehints(void);
252 void	headers(void);
253 void	cfgfile_add(const char *);
254 void	cfgfile_removeall(void);
255 FILE	*open_makefile_template(void);
256 
257 extern STAILQ_HEAD(device_head, device) dtab;
258 
259 extern char	errbuf[80];
260 extern int	yyline;
261 extern const	char *yyfile;
262 
263 extern STAILQ_HEAD(file_list_head, file_list) ftab;
264 
265 extern STAILQ_HEAD(files_name_head, files_name) fntab;
266 
267 extern int	debugging;
268 extern int	found_defaults;
269 
270 extern int	maxusers;
271 extern int	versreq;
272 
273 extern char *PREFIX;		/* Config file name - for error messages */
274 extern char srcdir[];		/* root of the kernel source tree */
275 
276 __END_DECLS;
277 
278 #define eq(a,b)	(!strcmp(a,b))
279 #define ns(s)	strdup(s)
280