1872b698pfg/*-
2872b698pfg * SPDX-License-Identifier: BSD-3-Clause
3872b698pfg *
4862fdf1rgrimes * Copyright (c) 1980, 1993
5862fdf1rgrimes *	The Regents of the University of California.  All rights reserved.
6862fdf1rgrimes *
7862fdf1rgrimes * Redistribution and use in source and binary forms, with or without
8862fdf1rgrimes * modification, are permitted provided that the following conditions
9862fdf1rgrimes * are met:
10862fdf1rgrimes * 1. Redistributions of source code must retain the above copyright
11862fdf1rgrimes *    notice, this list of conditions and the following disclaimer.
12862fdf1rgrimes * 2. Redistributions in binary form must reproduce the above copyright
13862fdf1rgrimes *    notice, this list of conditions and the following disclaimer in the
14862fdf1rgrimes *    documentation and/or other materials provided with the distribution.
157e6cabdimp * 3. Neither the name of the University nor the names of its contributors
16862fdf1rgrimes *    may be used to endorse or promote products derived from this software
17862fdf1rgrimes *    without specific prior written permission.
18862fdf1rgrimes *
19862fdf1rgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20862fdf1rgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21862fdf1rgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22862fdf1rgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23862fdf1rgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24862fdf1rgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25862fdf1rgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26862fdf1rgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27862fdf1rgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28862fdf1rgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29862fdf1rgrimes * SUCH DAMAGE.
30862fdf1rgrimes *
31862fdf1rgrimes *	@(#)config.h	8.1 (Berkeley) 6/6/93
32b7ec658peter * $FreeBSD$
33862fdf1rgrimes */
34862fdf1rgrimes
35862fdf1rgrimes/*
36862fdf1rgrimes * Config.
37862fdf1rgrimes */
38862fdf1rgrimes#include <sys/types.h>
3961e9b13ru#include <sys/queue.h>
40b77bd81kevans#include <stdbool.h>
41862fdf1rgrimes#include <stdlib.h>
42862fdf1rgrimes#include <string.h>
43862fdf1rgrimes
442e67332wkoszekstruct cfgfile {
452e67332wkoszek	STAILQ_ENTRY(cfgfile)	cfg_next;
462e67332wkoszek	char	*cfg_path;
472e67332wkoszek};
48628db19kevansextern STAILQ_HEAD(cfgfile_head, cfgfile) cfgfiles;
492e67332wkoszek
50862fdf1rgrimesstruct file_list {
5161e9b13ru	STAILQ_ENTRY(file_list) f_next;
52862fdf1rgrimes	char	*f_fn;			/* the name */
531d9abdbpeter	int     f_type;                 /* type */
54862fdf1rgrimes	u_char	f_flags;		/* see below */
55a5edad0peter	char	*f_compilewith;		/* special make rule if present */
5621a3003eadler	char	*f_depends;		/* additional dependencies */
57227859agibbs	char	*f_clean;		/* File list to add to clean rule */
58f10d6e9peter	char	*f_warn;		/* warning message */
592d7d8c0jeff	const char *f_objprefix;	/* prefix string for object name */
604e02326bdrewery	const char *f_srcprefix;	/* source prefix such as $S/ */
61862fdf1rgrimes};
62862fdf1rgrimes
6300e9b04cognetstruct files_name {
6400e9b04cognet	char *f_name;
6500e9b04cognet	STAILQ_ENTRY(files_name) f_next;
6600e9b04cognet};
6700e9b04cognet
68862fdf1rgrimes/*
69862fdf1rgrimes * Types.
70862fdf1rgrimes */
71be40623peter#define NORMAL		1
72be40623peter#define	PROFILING	3
73be40623peter#define NODEPEND	4
74be40623peter#define LOCAL		5
755c37a12joerg#define DEVDONE		0x80000000
765c37a12joerg#define TYPEMASK	0x7fffffff
77862fdf1rgrimes
78862fdf1rgrimes/*
79862fdf1rgrimes * Attributes (flags).
80862fdf1rgrimes */
81b31794bpeter#define NO_IMPLCT_RULE	1
82b31794bpeter#define NO_OBJ		2
83b31794bpeter#define BEFORE_DEPEND	4
841d9abdbpeter#define NOWERROR	16
8549f4465bdrewery#define NO_CTFCONVERT	32
86862fdf1rgrimes
87862fdf1rgrimesstruct device {
884abe344peter	int	d_done;			/* processed */
89862fdf1rgrimes	char	*d_name;		/* name of device (e.g. rk11) */
906bebe8fmanu	char	*yyfile;		/* name of the file that first include the device */
91862fdf1rgrimes#define	UNKNOWN -2	/* -2 means not set yet */
9261e9b13ru	STAILQ_ENTRY(device) d_next;	/* Next one in list */
93862fdf1rgrimes};
94862fdf1rgrimes
95862fdf1rgrimesstruct config {
96862fdf1rgrimes	char	*s_sysname;
97862fdf1rgrimes};
98862fdf1rgrimes
99862fdf1rgrimes/*
100862fdf1rgrimes * Config has a global notion of which machine type is
101862fdf1rgrimes * being used.  It uses the name of the machine in choosing
102e0200a9peter * files and directories.  Thus if the name of the machine is ``i386'',
103e0200a9peter * it will build from ``Makefile.i386'' and use ``../i386/inline''
104245a07aimp * in the makerules, etc.  machinearch is the global notion of the
105245a07aimp * MACHINE_ARCH for this MACHINE.
106862fdf1rgrimes */
107628db19kevansextern char	*machinename;
108628db19kevansextern char	*machinearch;
109862fdf1rgrimes
110862fdf1rgrimes/*
111862fdf1rgrimes * For each machine, a set of CPU's may be specified as supported.
112862fdf1rgrimes * These and the options (below) are put in the C flags in the makefile.
113862fdf1rgrimes */
114862fdf1rgrimesstruct cputype {
115862fdf1rgrimes	char	*cpu_name;
11661e9b13ru	SLIST_ENTRY(cputype) cpu_next;
11761e9b13ru};
11861e9b13ru
119628db19kevansextern SLIST_HEAD(cputype_head, cputype) cputype;
120862fdf1rgrimes
121862fdf1rgrimes/*
122862fdf1rgrimes * A set of options may also be specified which are like CPU types,
123862fdf1rgrimes * but which may also specify values for the options.
124862fdf1rgrimes * A separate set of options may be defined for make-style options.
125862fdf1rgrimes */
126862fdf1rgrimesstruct opt {
127862fdf1rgrimes	char	*op_name;
128862fdf1rgrimes	char	*op_value;
1297a7fb14peter	int	op_ownfile;	/* true = own file, false = makefile */
1306bebe8fmanu	char	*yyfile;	/* name of the file that first include the option */
13161e9b13ru	SLIST_ENTRY(opt) op_next;
1325318a38thompsa	SLIST_ENTRY(opt) op_append;
13361e9b13ru};
13461e9b13ru
135628db19kevansextern SLIST_HEAD(opt_head, opt) opt, mkopt, rmopts;
136862fdf1rgrimes
1377a7fb14peterstruct opt_list {
1387a7fb14peter	char *o_name;
1397a7fb14peter	char *o_file;
1406f9b9b6imp	int o_flags;
1416f9b9b6imp#define OL_ALIAS	1
14261e9b13ru	SLIST_ENTRY(opt_list) o_next;
14361e9b13ru};
14461e9b13ru
145628db19kevansextern SLIST_HEAD(opt_list_head, opt_list) otab;
1467a7fb14peter
147e396020kevansstruct envvar {
148e396020kevans	char	*env_str;
149b77bd81kevans	bool	env_is_file;
150e396020kevans	STAILQ_ENTRY(envvar) envvar_next;
151e396020kevans};
152e396020kevans
153628db19kevansextern STAILQ_HEAD(envvar_head, envvar) envvars;
154e396020kevans
155340936bimpstruct hint {
156340936bimp	char	*hint_name;
157340936bimp	STAILQ_ENTRY(hint) hint_next;
158340936bimp};
159340936bimp
160628db19kevansextern STAILQ_HEAD(hint_head, hint) hints;
161340936bimp
1621b1437fasomersstruct includepath {
1631b1437fasomers	char	*path;
1641b1437fasomers	SLIST_ENTRY(includepath) path_next;
1651b1437fasomers};
1661b1437fasomers
167628db19kevansextern SLIST_HEAD(includepath_head, includepath) includepath;
1681b1437fasomers
1692e67332wkoszek/*
1706d7dddcn_hibma * Tag present in the kernconf.tmpl template file. It's mandatory for those
1712e67332wkoszek * two strings to be the same. Otherwise you'll get into trouble.
1722e67332wkoszek */
1732e67332wkoszek#define	KERNCONFTAG	"%%KERNCONFFILE%%"
1742e67332wkoszek
1752e67332wkoszek/*
1762e67332wkoszek * Faked option to note, that the configuration file has been taken from the
1772e67332wkoszek * kernel file and inclusion of DEFAULTS etc.. isn't nessesery, because we
1782e67332wkoszek * already have a list of all required devices.
1792e67332wkoszek */
1802e67332wkoszek#define OPT_AUTOGEN	"CONFIG_AUTOGENERATED"
1812e67332wkoszek
182911997apeterextern char	*ident;
1832e67332wkoszekextern char	kernconfstr[];
184911997apeterextern int	do_trace;
1852e67332wkoszekextern int	incignore;
186911997apeter
187647ef85peterchar	*get_word(FILE *);
188647ef85peterchar	*get_quoted_word(FILE *);
189b96d955peterchar	*path(const char *);
190647ef85peterchar	*raisestr(char *);
191b96d955petervoid	remember(const char *);
192647ef85petervoid	moveifchanged(const char *, const char *);
193647ef85peterint	yylex(void);
194647ef85petervoid	options(void);
195647ef85petervoid	makefile(void);
1969d1801aruvoid	makeenv(void);
1979d1801aruvoid	makehints(void);
198647ef85petervoid	headers(void);
1992e67332wkoszekvoid	cfgfile_add(const char *);
2002e67332wkoszekvoid	cfgfile_removeall(void);
2011b05a11impFILE	*open_makefile_template(void);
202862fdf1rgrimes
2035907a15impextern STAILQ_HEAD(device_head, device) dtab;
204862fdf1rgrimes
205911997apeterextern char	errbuf[80];
206911997apeterextern int	yyline;
207b5164c6ddextern const	char *yyfile;
208862fdf1rgrimes
20961e9b13ruextern STAILQ_HEAD(file_list_head, file_list) ftab;
210862fdf1rgrimes
21100e9b04cognetextern STAILQ_HEAD(files_name_head, files_name) fntab;
21200e9b04cognet
213911997apeterextern int	profiling;
214911997apeterextern int	debugging;
21536d533djhbextern int	found_defaults;
216862fdf1rgrimes
217911997apeterextern int	maxusers;
2182fbb317kevansextern int	versreq;
219862fdf1rgrimes
220ab0c84aeivindextern char *PREFIX;		/* Config file name - for error messages */
2218024dcbmarcelextern char srcdir[];		/* root of the kernel source tree */
2226c500cceivind
223862fdf1rgrimes#define eq(a,b)	(!strcmp(a,b))
224b7ec658peter#define ns(s)	strdup(s)
225