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