18a16b7a1SPedro F. Giffuni /*- 28a16b7a1SPedro F. Giffuni * SPDX-License-Identifier: BSD-3-Clause 38a16b7a1SPedro F. Giffuni * 4dea673e9SRodney W. Grimes * Copyright (c) 1980, 1993 5dea673e9SRodney W. Grimes * The Regents of the University of California. All rights reserved. 6dea673e9SRodney W. Grimes * 7dea673e9SRodney W. Grimes * Redistribution and use in source and binary forms, with or without 8dea673e9SRodney W. Grimes * modification, are permitted provided that the following conditions 9dea673e9SRodney W. Grimes * are met: 10dea673e9SRodney W. Grimes * 1. Redistributions of source code must retain the above copyright 11dea673e9SRodney W. Grimes * notice, this list of conditions and the following disclaimer. 12dea673e9SRodney W. Grimes * 2. Redistributions in binary form must reproduce the above copyright 13dea673e9SRodney W. Grimes * notice, this list of conditions and the following disclaimer in the 14dea673e9SRodney W. Grimes * documentation and/or other materials provided with the distribution. 15fbbd9655SWarner Losh * 3. Neither the name of the University nor the names of its contributors 16dea673e9SRodney W. Grimes * may be used to endorse or promote products derived from this software 17dea673e9SRodney W. Grimes * without specific prior written permission. 18dea673e9SRodney W. Grimes * 19dea673e9SRodney W. Grimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 20dea673e9SRodney W. Grimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21dea673e9SRodney W. Grimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22dea673e9SRodney W. Grimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 23dea673e9SRodney W. Grimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24dea673e9SRodney W. Grimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25dea673e9SRodney W. Grimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26dea673e9SRodney W. Grimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27dea673e9SRodney W. Grimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28dea673e9SRodney W. Grimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29dea673e9SRodney W. Grimes * SUCH DAMAGE. 30dea673e9SRodney W. Grimes */ 31dea673e9SRodney W. Grimes 32dea673e9SRodney W. Grimes /* 33dea673e9SRodney W. Grimes * Config. 34dea673e9SRodney W. Grimes */ 35dea673e9SRodney W. Grimes #include <sys/types.h> 36292dd8a8SRuslan Ermilov #include <sys/queue.h> 374edfa908SKyle Evans #include <stdbool.h> 38dea673e9SRodney W. Grimes #include <stdlib.h> 39dea673e9SRodney W. Grimes #include <string.h> 40dea673e9SRodney W. Grimes 4183d7ed8aSKyle Evans #ifdef __cplusplus 4283d7ed8aSKyle Evans #include <string> 4383d7ed8aSKyle Evans 4483d7ed8aSKyle Evans class configword { 4583d7ed8aSKyle Evans private: 4683d7ed8aSKyle Evans std::string cw_word; 4783d7ed8aSKyle Evans bool cw_eof; 4883d7ed8aSKyle Evans bool cw_eol; 4983d7ed8aSKyle Evans public: configword()5083d7ed8aSKyle Evans configword() : cw_word(""), cw_eof(false), cw_eol(false) {} configword(std::string && word)5183d7ed8aSKyle Evans configword(std::string &&word) : cw_word(word), cw_eof(false), cw_eol(false) {} 5283d7ed8aSKyle Evans eof()5383d7ed8aSKyle Evans bool eof() const { 5483d7ed8aSKyle Evans return (cw_eof); 5583d7ed8aSKyle Evans } 5683d7ed8aSKyle Evans eol()5783d7ed8aSKyle Evans bool eol() const { 5883d7ed8aSKyle Evans return (cw_eol); 5983d7ed8aSKyle Evans } 6083d7ed8aSKyle Evans eof(bool eof)6183d7ed8aSKyle Evans configword &eof(bool eof) { 6283d7ed8aSKyle Evans cw_eof = eof; 6383d7ed8aSKyle Evans return (*this); 6483d7ed8aSKyle Evans } 6583d7ed8aSKyle Evans eol(bool eol)6683d7ed8aSKyle Evans configword &eol(bool eol) { 6783d7ed8aSKyle Evans cw_eol = eol; 6883d7ed8aSKyle Evans return (*this); 6983d7ed8aSKyle Evans } 7083d7ed8aSKyle Evans 7183d7ed8aSKyle Evans char operator[](int idx) { 7283d7ed8aSKyle Evans return (cw_word[idx]); 7383d7ed8aSKyle Evans } 7483d7ed8aSKyle Evans 7583d7ed8aSKyle Evans operator const char*() const { 7683d7ed8aSKyle Evans return (cw_word.c_str()); 7783d7ed8aSKyle Evans } 7883d7ed8aSKyle Evans 7983d7ed8aSKyle Evans const std::string &operator*() const { 8083d7ed8aSKyle Evans return (cw_word); 8183d7ed8aSKyle Evans } 8283d7ed8aSKyle Evans 8383d7ed8aSKyle Evans const std::string *operator->() const { 8483d7ed8aSKyle Evans return (&cw_word); 8583d7ed8aSKyle Evans } 8683d7ed8aSKyle Evans }; 8783d7ed8aSKyle Evans 8883d7ed8aSKyle Evans /* 8983d7ed8aSKyle Evans * Is it ugly to limit these to C++ files? Yes. 9083d7ed8aSKyle Evans */ 9183d7ed8aSKyle Evans configword get_word(FILE *); 9283d7ed8aSKyle Evans configword get_quoted_word(FILE *); 9383d7ed8aSKyle Evans #endif 9483d7ed8aSKyle Evans 952ffdc213SKyle Evans __BEGIN_DECLS 962ffdc213SKyle Evans 97744b947eSWojciech A. Koszek struct cfgfile { 98744b947eSWojciech A. Koszek STAILQ_ENTRY(cfgfile) cfg_next; 99744b947eSWojciech A. Koszek char *cfg_path; 100744b947eSWojciech A. Koszek }; 101a33e9864SKyle Evans extern STAILQ_HEAD(cfgfile_head, cfgfile) cfgfiles; 102744b947eSWojciech A. Koszek 103dea673e9SRodney W. Grimes struct file_list { 104292dd8a8SRuslan Ermilov STAILQ_ENTRY(file_list) f_next; 105dea673e9SRodney W. Grimes char *f_fn; /* the name */ 106f37a929cSPeter Wemm int f_type; /* type */ 107dea673e9SRodney W. Grimes u_char f_flags; /* see below */ 108388481c1SPeter Wemm char *f_compilewith; /* special make rule if present */ 109463a577bSEitan Adler char *f_depends; /* additional dependencies */ 110ce584e16SJustin T. Gibbs char *f_clean; /* File list to add to clean rule */ 111e44b832dSPeter Wemm char *f_warn; /* warning message */ 112e4cd31ddSJeff Roberson const char *f_objprefix; /* prefix string for object name */ 1131bf59a71SBryan Drewery const char *f_srcprefix; /* source prefix such as $S/ */ 114dea673e9SRodney W. Grimes }; 115dea673e9SRodney W. Grimes 11643a903c0SOlivier Houchard struct files_name { 11743a903c0SOlivier Houchard char *f_name; 11843a903c0SOlivier Houchard STAILQ_ENTRY(files_name) f_next; 11943a903c0SOlivier Houchard }; 12043a903c0SOlivier Houchard 121dea673e9SRodney W. Grimes /* 122dea673e9SRodney W. Grimes * Types. 123dea673e9SRodney W. Grimes */ 1241b24aa44SPeter Wemm #define NORMAL 1 1251b24aa44SPeter Wemm #define NODEPEND 4 1261b24aa44SPeter Wemm #define LOCAL 5 127cea24a2bSJoerg Wunsch #define DEVDONE 0x80000000 128cea24a2bSJoerg Wunsch #define TYPEMASK 0x7fffffff 129dea673e9SRodney W. Grimes 130dea673e9SRodney W. Grimes /* 131dea673e9SRodney W. Grimes * Attributes (flags). 132dea673e9SRodney W. Grimes */ 133f9f6bfe7SPeter Wemm #define NO_IMPLCT_RULE 1 134f9f6bfe7SPeter Wemm #define NO_OBJ 2 135f9f6bfe7SPeter Wemm #define BEFORE_DEPEND 4 136f37a929cSPeter Wemm #define NOWERROR 16 1375dda1d0bSBryan Drewery #define NO_CTFCONVERT 32 138dea673e9SRodney W. Grimes 139dea673e9SRodney W. Grimes struct device { 140246449f3SPeter Wemm int d_done; /* processed */ 141dea673e9SRodney W. Grimes char *d_name; /* name of device (e.g. rk11) */ 14291221f54SEmmanuel Vadot char *yyfile; /* name of the file that first include the device */ 143dea673e9SRodney W. Grimes #define UNKNOWN -2 /* -2 means not set yet */ 144292dd8a8SRuslan Ermilov STAILQ_ENTRY(device) d_next; /* Next one in list */ 145dea673e9SRodney W. Grimes }; 146dea673e9SRodney W. Grimes 147dea673e9SRodney W. Grimes struct config { 148dea673e9SRodney W. Grimes char *s_sysname; 149dea673e9SRodney W. Grimes }; 150dea673e9SRodney W. Grimes 151dea673e9SRodney W. Grimes /* 152dea673e9SRodney W. Grimes * Config has a global notion of which machine type is 153dea673e9SRodney W. Grimes * being used. It uses the name of the machine in choosing 154e6fbbbe4SPeter Wemm * files and directories. Thus if the name of the machine is ``i386'', 155e6fbbbe4SPeter Wemm * it will build from ``Makefile.i386'' and use ``../i386/inline'' 15651c1297aSWarner Losh * in the makerules, etc. machinearch is the global notion of the 15751c1297aSWarner Losh * MACHINE_ARCH for this MACHINE. 158dea673e9SRodney W. Grimes */ 159a33e9864SKyle Evans extern char *machinename; 160a33e9864SKyle Evans extern char *machinearch; 161dea673e9SRodney W. Grimes 162dea673e9SRodney W. Grimes /* 163dea673e9SRodney W. Grimes * For each machine, a set of CPU's may be specified as supported. 164dea673e9SRodney W. Grimes * These and the options (below) are put in the C flags in the makefile. 165dea673e9SRodney W. Grimes */ 166dea673e9SRodney W. Grimes struct cputype { 167dea673e9SRodney W. Grimes char *cpu_name; 168292dd8a8SRuslan Ermilov SLIST_ENTRY(cputype) cpu_next; 169292dd8a8SRuslan Ermilov }; 170292dd8a8SRuslan Ermilov 171a33e9864SKyle Evans extern SLIST_HEAD(cputype_head, cputype) cputype; 172dea673e9SRodney W. Grimes 173dea673e9SRodney W. Grimes /* 174dea673e9SRodney W. Grimes * A set of options may also be specified which are like CPU types, 175dea673e9SRodney W. Grimes * but which may also specify values for the options. 176dea673e9SRodney W. Grimes * A separate set of options may be defined for make-style options. 177dea673e9SRodney W. Grimes */ 178dea673e9SRodney W. Grimes struct opt { 179dea673e9SRodney W. Grimes char *op_name; 180dea673e9SRodney W. Grimes char *op_value; 1816d41b96fSPeter Wemm int op_ownfile; /* true = own file, false = makefile */ 18291221f54SEmmanuel Vadot char *yyfile; /* name of the file that first include the option */ 183292dd8a8SRuslan Ermilov SLIST_ENTRY(opt) op_next; 1842880daebSAndrew Thompson SLIST_ENTRY(opt) op_append; 185292dd8a8SRuslan Ermilov }; 186292dd8a8SRuslan Ermilov 187a33e9864SKyle Evans extern SLIST_HEAD(opt_head, opt) opt, mkopt, rmopts; 188dea673e9SRodney W. Grimes 1896d41b96fSPeter Wemm struct opt_list { 1906d41b96fSPeter Wemm char *o_name; 1916d41b96fSPeter Wemm char *o_file; 192e1a4e3faSWarner Losh int o_flags; 193e1a4e3faSWarner Losh #define OL_ALIAS 1 194292dd8a8SRuslan Ermilov SLIST_ENTRY(opt_list) o_next; 195292dd8a8SRuslan Ermilov }; 196292dd8a8SRuslan Ermilov 197a33e9864SKyle Evans extern SLIST_HEAD(opt_list_head, opt_list) otab; 1986d41b96fSPeter Wemm 1993b31596dSKyle Evans struct envvar { 2003b31596dSKyle Evans char *env_str; 2014edfa908SKyle Evans bool env_is_file; 2023b31596dSKyle Evans STAILQ_ENTRY(envvar) envvar_next; 2033b31596dSKyle Evans }; 2043b31596dSKyle Evans 205a33e9864SKyle Evans extern STAILQ_HEAD(envvar_head, envvar) envvars; 2063b31596dSKyle Evans 20786418d0cSWarner Losh struct hint { 20886418d0cSWarner Losh char *hint_name; 20986418d0cSWarner Losh STAILQ_ENTRY(hint) hint_next; 21086418d0cSWarner Losh }; 21186418d0cSWarner Losh 212a33e9864SKyle Evans extern STAILQ_HEAD(hint_head, hint) hints; 21386418d0cSWarner Losh 214ae094461SAlan Somers struct includepath { 215ae094461SAlan Somers char *path; 216ae094461SAlan Somers SLIST_ENTRY(includepath) path_next; 217ae094461SAlan Somers }; 218ae094461SAlan Somers 219a33e9864SKyle Evans extern SLIST_HEAD(includepath_head, includepath) includepath; 220ae094461SAlan Somers 221744b947eSWojciech A. Koszek /* 222cc5cd332SNick Hibma * Tag present in the kernconf.tmpl template file. It's mandatory for those 223744b947eSWojciech A. Koszek * two strings to be the same. Otherwise you'll get into trouble. 224744b947eSWojciech A. Koszek */ 225744b947eSWojciech A. Koszek #define KERNCONFTAG "%%KERNCONFFILE%%" 226744b947eSWojciech A. Koszek 227744b947eSWojciech A. Koszek /* 228744b947eSWojciech A. Koszek * Faked option to note, that the configuration file has been taken from the 229744b947eSWojciech A. Koszek * kernel file and inclusion of DEFAULTS etc.. isn't nessesery, because we 230744b947eSWojciech A. Koszek * already have a list of all required devices. 231744b947eSWojciech A. Koszek */ 232744b947eSWojciech A. Koszek #define OPT_AUTOGEN "CONFIG_AUTOGENERATED" 233744b947eSWojciech A. Koszek 234188334f6SPeter Wemm extern char *ident; 235744b947eSWojciech A. Koszek extern char kernconfstr[]; 236188334f6SPeter Wemm extern int do_trace; 237744b947eSWojciech A. Koszek extern int incignore; 238188334f6SPeter Wemm 23968f4fcedSPeter Wemm char *path(const char *); 240f71c01ccSPeter Wemm char *raisestr(char *); 24168f4fcedSPeter Wemm void remember(const char *); 242f71c01ccSPeter Wemm void moveifchanged(const char *, const char *); 243f71c01ccSPeter Wemm int yylex(void); 2442ffdc213SKyle Evans int yyparse(void); 245f71c01ccSPeter Wemm void options(void); 246f71c01ccSPeter Wemm void makefile(void); 24722025511SRuslan Ermilov void makeenv(void); 24822025511SRuslan Ermilov void makehints(void); 249f71c01ccSPeter Wemm void headers(void); 250744b947eSWojciech A. Koszek void cfgfile_add(const char *); 251744b947eSWojciech A. Koszek void cfgfile_removeall(void); 25290aa4f9eSWarner Losh FILE *open_makefile_template(void); 253dea673e9SRodney W. Grimes 254c1f4dd93SWarner Losh extern STAILQ_HEAD(device_head, device) dtab; 255dea673e9SRodney W. Grimes 256188334f6SPeter Wemm extern char errbuf[80]; 257188334f6SPeter Wemm extern int yyline; 2585e06480cSDima Dorfman extern const char *yyfile; 259188334f6SPeter Wemm 260292dd8a8SRuslan Ermilov extern STAILQ_HEAD(file_list_head, file_list) ftab; 261188334f6SPeter Wemm 26243a903c0SOlivier Houchard extern STAILQ_HEAD(files_name_head, files_name) fntab; 26343a903c0SOlivier Houchard 264188334f6SPeter Wemm extern int debugging; 265dfdbf9beSJohn Baldwin extern int found_defaults; 266188334f6SPeter Wemm 267188334f6SPeter Wemm extern int maxusers; 2688e62839eSKyle Evans extern int versreq; 269dea673e9SRodney W. Grimes 270b272cc1eSEivind Eklund extern char *PREFIX; /* Config file name - for error messages */ 271c1454d67SMarcel Moolenaar extern char srcdir[]; /* root of the kernel source tree */ 272b272cc1eSEivind Eklund 2732ffdc213SKyle Evans __END_DECLS; 2742ffdc213SKyle Evans 275dea673e9SRodney W. Grimes #define eq(a,b) (!strcmp(a,b)) 2761c56dc36SPeter Wemm #define ns(s) strdup(s) 277