/*-1* SPDX-License-Identifier: BSD-3-Clause2*3* Copyright (c) 1980, 19934* The Regents of the University of California. All rights reserved.5*6* Redistribution and use in source and binary forms, with or without7* modification, are permitted provided that the following conditions8* are met:9* 1. Redistributions of source code must retain the above copyright10* notice, this list of conditions and the following disclaimer.11* 2. Redistributions in binary form must reproduce the above copyright12* notice, this list of conditions and the following disclaimer in the13* documentation and/or other materials provided with the distribution.14* 3. Neither the name of the University nor the names of its contributors15* may be used to endorse or promote products derived from this software16* without specific prior written permission.17*18* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND19* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE20* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE21* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE22* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL23* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS24* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)25* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT26* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY27* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF28* SUCH DAMAGE.29*/3031/*32* Config.33*/34#include <sys/types.h>35#include <sys/queue.h>36#include <stdbool.h>37#include <stdlib.h>38#include <string.h>3940#ifdef __cplusplus41#include <string>4243class configword {44private:45std::string cw_word;46bool cw_eof;47bool cw_eol;48public:49configword() : cw_word(""), cw_eof(false), cw_eol(false) {}50configword(std::string &&word) : cw_word(word), cw_eof(false), cw_eol(false) {}5152bool eof() const {53return (cw_eof);54}5556bool eol() const {57return (cw_eol);58}5960configword &eof(bool eof) {61cw_eof = eof;62return (*this);63}6465configword &eol(bool eol) {66cw_eol = eol;67return (*this);68}6970char operator[](int idx) {71return (cw_word[idx]);72}7374operator const char*() const {75return (cw_word.c_str());76}7778const std::string &operator*() const {79return (cw_word);80}8182const std::string *operator->() const {83return (&cw_word);84}85};8687/*88* Is it ugly to limit these to C++ files? Yes.89*/90configword get_word(FILE *);91configword get_quoted_word(FILE *);92#endif9394__BEGIN_DECLS9596struct cfgfile {97STAILQ_ENTRY(cfgfile) cfg_next;98char *cfg_path;99};100extern STAILQ_HEAD(cfgfile_head, cfgfile) cfgfiles;101102struct file_list {103STAILQ_ENTRY(file_list) f_next;104char *f_fn; /* the name */105int f_type; /* type */106u_char f_flags; /* see below */107char *f_compilewith; /* special make rule if present */108char *f_depends; /* additional dependencies */109char *f_clean; /* File list to add to clean rule */110char *f_warn; /* warning message */111const char *f_objprefix; /* prefix string for object name */112const char *f_srcprefix; /* source prefix such as $S/ */113};114115struct files_name {116char *f_name;117STAILQ_ENTRY(files_name) f_next;118};119120/*121* Types.122*/123#define NORMAL 1124#define NODEPEND 4125#define LOCAL 5126#define DEVDONE 0x80000000127#define TYPEMASK 0x7fffffff128129/*130* Attributes (flags).131*/132#define NO_IMPLCT_RULE 1133#define NO_OBJ 2134#define BEFORE_DEPEND 4135#define NOWERROR 16136#define NO_CTFCONVERT 32137138struct device {139int d_done; /* processed */140char *d_name; /* name of device (e.g. rk11) */141char *yyfile; /* name of the file that first include the device */142#define UNKNOWN -2 /* -2 means not set yet */143STAILQ_ENTRY(device) d_next; /* Next one in list */144};145146struct config {147char *s_sysname;148};149150/*151* Config has a global notion of which machine type is152* being used. It uses the name of the machine in choosing153* files and directories. Thus if the name of the machine is ``i386'',154* it will build from ``Makefile.i386'' and use ``../i386/inline''155* in the makerules, etc. machinearch is the global notion of the156* MACHINE_ARCH for this MACHINE.157*/158extern char *machinename;159extern char *machinearch;160161/*162* For each machine, a set of CPU's may be specified as supported.163* These and the options (below) are put in the C flags in the makefile.164*/165struct cputype {166char *cpu_name;167SLIST_ENTRY(cputype) cpu_next;168};169170extern SLIST_HEAD(cputype_head, cputype) cputype;171172/*173* A set of options may also be specified which are like CPU types,174* but which may also specify values for the options.175* A separate set of options may be defined for make-style options.176*/177struct opt {178char *op_name;179char *op_value;180int op_ownfile; /* true = own file, false = makefile */181char *yyfile; /* name of the file that first include the option */182SLIST_ENTRY(opt) op_next;183SLIST_ENTRY(opt) op_append;184};185186extern SLIST_HEAD(opt_head, opt) opt, mkopt, rmopts;187188struct opt_list {189char *o_name;190char *o_file;191int o_flags;192#define OL_ALIAS 1193SLIST_ENTRY(opt_list) o_next;194};195196extern SLIST_HEAD(opt_list_head, opt_list) otab;197198struct envvar {199char *env_str;200bool env_is_file;201STAILQ_ENTRY(envvar) envvar_next;202};203204extern STAILQ_HEAD(envvar_head, envvar) envvars;205206struct hint {207char *hint_name;208STAILQ_ENTRY(hint) hint_next;209};210211extern STAILQ_HEAD(hint_head, hint) hints;212213struct includepath {214char *path;215SLIST_ENTRY(includepath) path_next;216};217218extern SLIST_HEAD(includepath_head, includepath) includepath;219220/*221* Tag present in the kernconf.tmpl template file. It's mandatory for those222* two strings to be the same. Otherwise you'll get into trouble.223*/224#define KERNCONFTAG "%%KERNCONFFILE%%"225226/*227* Faked option to note, that the configuration file has been taken from the228* kernel file and inclusion of DEFAULTS etc.. isn't nessesery, because we229* already have a list of all required devices.230*/231#define OPT_AUTOGEN "CONFIG_AUTOGENERATED"232233extern char *ident;234extern char kernconfstr[];235extern int do_trace;236extern int incignore;237238char *path(const char *);239char *raisestr(char *);240void remember(const char *);241void moveifchanged(const char *, const char *);242int yylex(void);243int yyparse(void);244void options(void);245void makefile(void);246void makeenv(void);247void makehints(void);248void headers(void);249void cfgfile_add(const char *);250void cfgfile_removeall(void);251FILE *open_makefile_template(void);252253extern STAILQ_HEAD(device_head, device) dtab;254255extern char errbuf[80];256extern int yyline;257extern const char *yyfile;258259extern STAILQ_HEAD(file_list_head, file_list) ftab;260261extern STAILQ_HEAD(files_name_head, files_name) fntab;262extern STAILQ_HEAD(options_files_name_head, files_name) optfntab;263264extern int debugging;265extern int found_defaults;266extern int verbose;267268extern int maxusers;269extern int versreq;270271extern char *PREFIX; /* Config file name - for error messages */272extern char srcdir[]; /* root of the kernel source tree */273274__END_DECLS;275276#define eq(a,b) (!strcmp(a,b))277#define ns(s) strdup(s)278279280