xref: /freebsd/usr.sbin/config/config.h (revision 6ef644f5889afbd0f681b08ed1a2f369524af83e)
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  */
33 
34 /*
35  * Config.
36  */
37 #include <sys/types.h>
38 #include <sys/queue.h>
39 #include <stdbool.h>
40 #include <stdlib.h>
41 #include <string.h>
42 
43 #ifdef __cplusplus
44 #include <string>
45 
46 class configword {
47 private:
48 	std::string	cw_word;
49 	bool		cw_eof;
50 	bool		cw_eol;
51 public:
52 	configword() : cw_word(""), cw_eof(false), cw_eol(false) {}
53 	configword(std::string &&word) : cw_word(word), cw_eof(false), cw_eol(false) {}
54 
55 	bool eof() const {
56 		return (cw_eof);
57 	}
58 
59 	bool eol() const {
60 		return (cw_eol);
61 	}
62 
63 	configword &eof(bool eof) {
64 		cw_eof = eof;
65 		return (*this);
66 	}
67 
68 	configword &eol(bool eol) {
69 		cw_eol = eol;
70 		return (*this);
71 	}
72 
73 	char operator[](int idx) {
74 		return (cw_word[idx]);
75 	}
76 
77 	operator const char*() const {
78 		return (cw_word.c_str());
79 	}
80 
81 	const std::string &operator*() const {
82 		return (cw_word);
83 	}
84 
85 	const std::string *operator->() const {
86 		return (&cw_word);
87 	}
88 };
89 
90 /*
91  * Is it ugly to limit these to C++ files? Yes.
92  */
93 configword get_word(FILE *);
94 configword get_quoted_word(FILE *);
95 #endif
96 
97 __BEGIN_DECLS
98 
99 struct cfgfile {
100 	STAILQ_ENTRY(cfgfile)	cfg_next;
101 	char	*cfg_path;
102 };
103 extern STAILQ_HEAD(cfgfile_head, cfgfile) cfgfiles;
104 
105 struct file_list {
106 	STAILQ_ENTRY(file_list) f_next;
107 	char	*f_fn;			/* the name */
108 	int     f_type;                 /* type */
109 	u_char	f_flags;		/* see below */
110 	char	*f_compilewith;		/* special make rule if present */
111 	char	*f_depends;		/* additional dependencies */
112 	char	*f_clean;		/* File list to add to clean rule */
113 	char	*f_warn;		/* warning message */
114 	const char *f_objprefix;	/* prefix string for object name */
115 	const char *f_srcprefix;	/* source prefix such as $S/ */
116 };
117 
118 struct files_name {
119 	char *f_name;
120 	STAILQ_ENTRY(files_name) f_next;
121 };
122 
123 /*
124  * Types.
125  */
126 #define NORMAL		1
127 #define NODEPEND	4
128 #define LOCAL		5
129 #define DEVDONE		0x80000000
130 #define TYPEMASK	0x7fffffff
131 
132 /*
133  * Attributes (flags).
134  */
135 #define NO_IMPLCT_RULE	1
136 #define NO_OBJ		2
137 #define BEFORE_DEPEND	4
138 #define NOWERROR	16
139 #define NO_CTFCONVERT	32
140 
141 struct device {
142 	int	d_done;			/* processed */
143 	char	*d_name;		/* name of device (e.g. rk11) */
144 	char	*yyfile;		/* name of the file that first include the device */
145 #define	UNKNOWN -2	/* -2 means not set yet */
146 	STAILQ_ENTRY(device) d_next;	/* Next one in list */
147 };
148 
149 struct config {
150 	char	*s_sysname;
151 };
152 
153 /*
154  * Config has a global notion of which machine type is
155  * being used.  It uses the name of the machine in choosing
156  * files and directories.  Thus if the name of the machine is ``i386'',
157  * it will build from ``Makefile.i386'' and use ``../i386/inline''
158  * in the makerules, etc.  machinearch is the global notion of the
159  * MACHINE_ARCH for this MACHINE.
160  */
161 extern char	*machinename;
162 extern char	*machinearch;
163 
164 /*
165  * For each machine, a set of CPU's may be specified as supported.
166  * These and the options (below) are put in the C flags in the makefile.
167  */
168 struct cputype {
169 	char	*cpu_name;
170 	SLIST_ENTRY(cputype) cpu_next;
171 };
172 
173 extern SLIST_HEAD(cputype_head, cputype) cputype;
174 
175 /*
176  * A set of options may also be specified which are like CPU types,
177  * but which may also specify values for the options.
178  * A separate set of options may be defined for make-style options.
179  */
180 struct opt {
181 	char	*op_name;
182 	char	*op_value;
183 	int	op_ownfile;	/* true = own file, false = makefile */
184 	char	*yyfile;	/* name of the file that first include the option */
185 	SLIST_ENTRY(opt) op_next;
186 	SLIST_ENTRY(opt) op_append;
187 };
188 
189 extern SLIST_HEAD(opt_head, opt) opt, mkopt, rmopts;
190 
191 struct opt_list {
192 	char *o_name;
193 	char *o_file;
194 	int o_flags;
195 #define OL_ALIAS	1
196 	SLIST_ENTRY(opt_list) o_next;
197 };
198 
199 extern SLIST_HEAD(opt_list_head, opt_list) otab;
200 
201 struct envvar {
202 	char	*env_str;
203 	bool	env_is_file;
204 	STAILQ_ENTRY(envvar) envvar_next;
205 };
206 
207 extern STAILQ_HEAD(envvar_head, envvar) envvars;
208 
209 struct hint {
210 	char	*hint_name;
211 	STAILQ_ENTRY(hint) hint_next;
212 };
213 
214 extern STAILQ_HEAD(hint_head, hint) hints;
215 
216 struct includepath {
217 	char	*path;
218 	SLIST_ENTRY(includepath) path_next;
219 };
220 
221 extern SLIST_HEAD(includepath_head, includepath) includepath;
222 
223 /*
224  * Tag present in the kernconf.tmpl template file. It's mandatory for those
225  * two strings to be the same. Otherwise you'll get into trouble.
226  */
227 #define	KERNCONFTAG	"%%KERNCONFFILE%%"
228 
229 /*
230  * Faked option to note, that the configuration file has been taken from the
231  * kernel file and inclusion of DEFAULTS etc.. isn't nessesery, because we
232  * already have a list of all required devices.
233  */
234 #define OPT_AUTOGEN	"CONFIG_AUTOGENERATED"
235 
236 extern char	*ident;
237 extern char	kernconfstr[];
238 extern int	do_trace;
239 extern int	incignore;
240 
241 char	*path(const char *);
242 char	*raisestr(char *);
243 void	remember(const char *);
244 void	moveifchanged(const char *, const char *);
245 int	yylex(void);
246 int	yyparse(void);
247 void	options(void);
248 void	makefile(void);
249 void	makeenv(void);
250 void	makehints(void);
251 void	headers(void);
252 void	cfgfile_add(const char *);
253 void	cfgfile_removeall(void);
254 FILE	*open_makefile_template(void);
255 
256 extern STAILQ_HEAD(device_head, device) dtab;
257 
258 extern char	errbuf[80];
259 extern int	yyline;
260 extern const	char *yyfile;
261 
262 extern STAILQ_HEAD(file_list_head, file_list) ftab;
263 
264 extern STAILQ_HEAD(files_name_head, files_name) fntab;
265 
266 extern int	debugging;
267 extern int	found_defaults;
268 
269 extern int	maxusers;
270 extern int	versreq;
271 
272 extern char *PREFIX;		/* Config file name - for error messages */
273 extern char srcdir[];		/* root of the kernel source tree */
274 
275 __END_DECLS;
276 
277 #define eq(a,b)	(!strcmp(a,b))
278 #define ns(s)	strdup(s)
279