]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - usr.sbin/config/main.c
Merge ACPICA 20170929.
[FreeBSD/FreeBSD.git] / usr.sbin / config / main.c
1 /*
2  * Copyright (c) 1980, 1993
3  *      The Regents of the University of California.  All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. Neither the name of the University nor the names of its contributors
14  *    may be used to endorse or promote products derived from this software
15  *    without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  */
29
30 #ifndef lint
31 static const char copyright[] =
32 "@(#) Copyright (c) 1980, 1993\n\
33         The Regents of the University of California.  All rights reserved.\n";
34 #endif /* not lint */
35
36 #ifndef lint
37 #if 0
38 static char sccsid[] = "@(#)main.c      8.1 (Berkeley) 6/6/93";
39 #endif
40 static const char rcsid[] =
41   "$FreeBSD$";
42 #endif /* not lint */
43
44 #include <sys/types.h>
45 #include <sys/stat.h>
46 #include <sys/sbuf.h>
47 #include <sys/file.h>
48 #include <sys/mman.h>
49 #include <sys/param.h>
50
51 #include <assert.h>
52 #include <ctype.h>
53 #include <err.h>
54 #include <stdio.h>
55 #include <string.h>
56 #include <sysexits.h>
57 #include <unistd.h>
58 #include <dirent.h>
59 #include "y.tab.h"
60 #include "config.h"
61 #include "configvers.h"
62
63 #ifndef TRUE
64 #define TRUE    (1)
65 #endif
66
67 #ifndef FALSE
68 #define FALSE   (0)
69 #endif
70
71 #define CDIR    "../compile/"
72
73 char *  PREFIX;
74 char    destdir[MAXPATHLEN];
75 char    srcdir[MAXPATHLEN];
76
77 int     debugging;
78 int     profiling;
79 int     found_defaults;
80 int     incignore;
81
82 /*
83  * Preserve old behaviour in INCLUDE_CONFIG_FILE handling (files are included
84  * literally).
85  */
86 int     filebased = 0;
87
88 static void configfile(void);
89 static void get_srcdir(void);
90 static void usage(void);
91 static void cleanheaders(char *);
92 static void kernconfdump(const char *);
93 static void checkversion(void);
94 extern int yyparse(void);
95
96 struct hdr_list {
97         char *h_name;
98         struct hdr_list *h_next;
99 } *htab;
100
101 /*
102  * Config builds a set of files for building a UNIX
103  * system given a description of the desired system.
104  */
105 int
106 main(int argc, char **argv)
107 {
108
109         struct stat buf;
110         int ch, len;
111         char *p;
112         char *kernfile;
113         struct includepath* ipath;
114         int printmachine;
115
116         printmachine = 0;
117         kernfile = NULL;
118         SLIST_INIT(&includepath);
119         while ((ch = getopt(argc, argv, "CI:d:gmpsVx:")) != -1)
120                 switch (ch) {
121                 case 'C':
122                         filebased = 1;
123                         break;
124                 case 'I':
125                         ipath = (struct includepath *) \
126                                 calloc(1, sizeof (struct includepath));
127                         if (ipath == NULL)
128                                 err(EXIT_FAILURE, "calloc");
129                         ipath->path = optarg;
130                         SLIST_INSERT_HEAD(&includepath, ipath, path_next);
131                         break;
132                 case 'm':
133                         printmachine = 1;
134                         break;
135                 case 'd':
136                         if (*destdir == '\0')
137                                 strlcpy(destdir, optarg, sizeof(destdir));
138                         else
139                                 errx(EXIT_FAILURE, "directory already set");
140                         break;
141                 case 'g':
142                         debugging++;
143                         break;
144                 case 'p':
145                         profiling++;
146                         break;
147                 case 's':
148                         if (*srcdir == '\0')
149                                 strlcpy(srcdir, optarg, sizeof(srcdir));
150                         else
151                                 errx(EXIT_FAILURE, "src directory already set");
152                         break;
153                 case 'V':
154                         printf("%d\n", CONFIGVERS);
155                         exit(0);
156                 case 'x':
157                         kernfile = optarg;
158                         break;
159                 case '?':
160                 default:
161                         usage();
162                 }
163         argc -= optind;
164         argv += optind;
165
166         if (kernfile != NULL) {
167                 kernconfdump(kernfile);
168                 exit(EXIT_SUCCESS);
169         }
170
171         if (argc != 1)
172                 usage();
173
174         PREFIX = *argv;
175         if (stat(PREFIX, &buf) != 0 || !S_ISREG(buf.st_mode))
176                 err(2, "%s", PREFIX);
177         if (freopen("DEFAULTS", "r", stdin) != NULL) {
178                 found_defaults = 1;
179                 yyfile = "DEFAULTS";
180         } else {
181                 if (freopen(PREFIX, "r", stdin) == NULL)
182                         err(2, "%s", PREFIX);
183                 yyfile = PREFIX;
184         }
185         if (*destdir != '\0') {
186                 len = strlen(destdir);
187                 while (len > 1 && destdir[len - 1] == '/')
188                         destdir[--len] = '\0';
189                 if (*srcdir == '\0')
190                         get_srcdir();
191         } else {
192                 strlcpy(destdir, CDIR, sizeof(destdir));
193                 strlcat(destdir, PREFIX, sizeof(destdir));
194         }
195
196         SLIST_INIT(&cputype);
197         SLIST_INIT(&mkopt);
198         SLIST_INIT(&opt);
199         SLIST_INIT(&rmopts);
200         STAILQ_INIT(&cfgfiles);
201         STAILQ_INIT(&dtab);
202         STAILQ_INIT(&fntab);
203         STAILQ_INIT(&ftab);
204         STAILQ_INIT(&hints);
205         if (yyparse())
206                 exit(3);
207
208         /*
209          * Ensure that required elements (machine, cpu, ident) are present.
210          */
211         if (machinename == NULL) {
212                 printf("Specify machine type, e.g. ``machine i386''\n");
213                 exit(1);
214         }
215         if (ident == NULL) {
216                 printf("no ident line specified\n");
217                 exit(1);
218         }
219         if (SLIST_EMPTY(&cputype)) {
220                 printf("cpu type must be specified\n");
221                 exit(1);
222         }
223         checkversion();
224
225         if (printmachine) {
226                 printf("%s\t%s\n",machinename,machinearch);
227                 exit(0);
228         }
229
230         /* Make compile directory */
231         p = path((char *)NULL);
232         if (stat(p, &buf)) {
233                 if (mkdir(p, 0777))
234                         err(2, "%s", p);
235         } else if (!S_ISDIR(buf.st_mode))
236                 errx(EXIT_FAILURE, "%s isn't a directory", p);
237
238         configfile();                   /* put config file into kernel*/
239         options();                      /* make options .h files */
240         makefile();                     /* build Makefile */
241         makeenv();                      /* build env.c */
242         makehints();                    /* build hints.c */
243         headers();                      /* make a lot of .h files */
244         cleanheaders(p);
245         printf("Kernel build directory is %s\n", p);
246         printf("Don't forget to do ``make cleandepend && make depend''\n");
247         exit(0);
248 }
249
250 /*
251  * get_srcdir
252  *      determine the root of the kernel source tree
253  *      and save that in srcdir.
254  */
255 static void
256 get_srcdir(void)
257 {
258         struct stat lg, phy;
259         char *p, *pwd;
260         int i;
261
262         if (realpath("../..", srcdir) == NULL)
263                 err(EXIT_FAILURE, "Unable to find root of source tree");
264         if ((pwd = getenv("PWD")) != NULL && *pwd == '/' &&
265             (pwd = strdup(pwd)) != NULL) {
266                 /* Remove the last two path components. */
267                 for (i = 0; i < 2; i++) {
268                         if ((p = strrchr(pwd, '/')) == NULL) {
269                                 free(pwd);
270                                 return;
271                         }
272                         *p = '\0';
273                 }
274                 if (stat(pwd, &lg) != -1 && stat(srcdir, &phy) != -1 &&
275                     lg.st_dev == phy.st_dev && lg.st_ino == phy.st_ino)
276                         strlcpy(srcdir, pwd, MAXPATHLEN);
277                 free(pwd);
278         }
279 }
280
281 static void
282 usage(void)
283 {
284
285         fprintf(stderr,
286             "usage: config [-CgmpV] [-d destdir] [-s srcdir] sysname\n");
287         fprintf(stderr, "       config -x kernel\n");
288         exit(EX_USAGE);
289 }
290
291 /*
292  * get_word
293  *      returns EOF on end of file
294  *      NULL on end of line
295  *      pointer to the word otherwise
296  */
297 char *
298 get_word(FILE *fp)
299 {
300         static char line[80];
301         int ch;
302         char *cp;
303         int escaped_nl = 0;
304
305 begin:
306         while ((ch = getc(fp)) != EOF)
307                 if (ch != ' ' && ch != '\t')
308                         break;
309         if (ch == EOF)
310                 return ((char *)EOF);
311         if (ch == '\\'){
312                 escaped_nl = 1;
313                 goto begin;
314         }
315         if (ch == '\n') {
316                 if (escaped_nl){
317                         escaped_nl = 0;
318                         goto begin;
319                 }
320                 else
321                         return (NULL);
322         }
323         cp = line;
324         *cp++ = ch;
325         /* Negation operator is a word by itself. */
326         if (ch == '!') {
327                 *cp = 0;
328                 return (line);
329         }
330         while ((ch = getc(fp)) != EOF) {
331                 if (isspace(ch))
332                         break;
333                 *cp++ = ch;
334         }
335         *cp = 0;
336         if (ch == EOF)
337                 return ((char *)EOF);
338         (void) ungetc(ch, fp);
339         return (line);
340 }
341
342 /*
343  * get_quoted_word
344  *      like get_word but will accept something in double or single quotes
345  *      (to allow embedded spaces).
346  */
347 char *
348 get_quoted_word(FILE *fp)
349 {
350         static char line[256];
351         int ch;
352         char *cp;
353         int escaped_nl = 0;
354
355 begin:
356         while ((ch = getc(fp)) != EOF)
357                 if (ch != ' ' && ch != '\t')
358                         break;
359         if (ch == EOF)
360                 return ((char *)EOF);
361         if (ch == '\\'){
362                 escaped_nl = 1;
363                 goto begin;
364         }
365         if (ch == '\n') {
366                 if (escaped_nl){
367                         escaped_nl = 0;
368                         goto begin;
369                 }
370                 else
371                         return (NULL);
372         }
373         cp = line;
374         if (ch == '"' || ch == '\'') {
375                 int quote = ch;
376
377                 escaped_nl = 0;
378                 while ((ch = getc(fp)) != EOF) {
379                         if (ch == quote && !escaped_nl)
380                                 break;
381                         if (ch == '\n' && !escaped_nl) {
382                                 *cp = 0;
383                                 printf("config: missing quote reading `%s'\n",
384                                         line);
385                                 exit(2);
386                         }
387                         if (ch == '\\' && !escaped_nl) {
388                                 escaped_nl = 1;
389                                 continue;
390                         }
391                         if (ch != quote && escaped_nl)
392                                 *cp++ = '\\';
393                         *cp++ = ch;
394                         escaped_nl = 0;
395                 }
396         } else {
397                 *cp++ = ch;
398                 while ((ch = getc(fp)) != EOF) {
399                         if (isspace(ch))
400                                 break;
401                         *cp++ = ch;
402                 }
403                 if (ch != EOF)
404                         (void) ungetc(ch, fp);
405         }
406         *cp = 0;
407         if (ch == EOF)
408                 return ((char *)EOF);
409         return (line);
410 }
411
412 /*
413  * prepend the path to a filename
414  */
415 char *
416 path(const char *file)
417 {
418         char *cp = NULL;
419
420         if (file)
421                 asprintf(&cp, "%s/%s", destdir, file);
422         else
423                 cp = strdup(destdir);
424         return (cp);
425 }
426
427 /*
428  * Generate configuration file based on actual settings. With this mode, user
429  * will be able to obtain and build conifguration file with one command.
430  */
431 static void
432 configfile_dynamic(struct sbuf *sb)
433 {
434         struct cputype *cput;
435         struct device *d;
436         struct opt *ol;
437         char *lend;
438         unsigned int i;
439
440         asprintf(&lend, "\\n\\\n");
441         assert(lend != NULL);
442         sbuf_printf(sb, "options\t%s%s", OPT_AUTOGEN, lend);
443         sbuf_printf(sb, "ident\t%s%s", ident, lend);
444         sbuf_printf(sb, "machine\t%s%s", machinename, lend);
445         SLIST_FOREACH(cput, &cputype, cpu_next)
446                 sbuf_printf(sb, "cpu\t%s%s", cput->cpu_name, lend);
447         SLIST_FOREACH(ol, &mkopt, op_next)
448                 sbuf_printf(sb, "makeoptions\t%s=%s%s", ol->op_name,
449                     ol->op_value, lend);
450         SLIST_FOREACH(ol, &opt, op_next) {
451                 if (strncmp(ol->op_name, "DEV_", 4) == 0)
452                         continue;
453                 sbuf_printf(sb, "options\t%s", ol->op_name);
454                 if (ol->op_value != NULL) {
455                         sbuf_putc(sb, '=');
456                         for (i = 0; i < strlen(ol->op_value); i++) {
457                                 if (ol->op_value[i] == '"')
458                                         sbuf_printf(sb, "\\%c",
459                                             ol->op_value[i]);
460                                 else
461                                         sbuf_printf(sb, "%c",
462                                             ol->op_value[i]);
463                         }
464                         sbuf_printf(sb, "%s", lend);
465                 } else {
466                         sbuf_printf(sb, "%s", lend);
467                 }
468         }
469         /*
470          * Mark this file as containing everything we need.
471          */
472         STAILQ_FOREACH(d, &dtab, d_next)
473                 sbuf_printf(sb, "device\t%s%s", d->d_name, lend);
474         free(lend);
475 }
476
477 /*
478  * Generate file from the configuration files.
479  */
480 static void
481 configfile_filebased(struct sbuf *sb)
482 {
483         FILE *cff;
484         struct cfgfile *cf;
485         int i;
486
487         /*
488          * Try to read all configuration files. Since those will be present as
489          * C string in the macro, we have to slash their ends then the line
490          * wraps.
491          */
492         STAILQ_FOREACH(cf, &cfgfiles, cfg_next) {
493                 cff = fopen(cf->cfg_path, "r");
494                 if (cff == NULL) {
495                         warn("Couldn't open file %s", cf->cfg_path);
496                         continue;
497                 }
498                 while ((i = getc(cff)) != EOF) {
499                         if (i == '\n')
500                                 sbuf_printf(sb, "\\n\\\n");
501                         else if (i == '"' || i == '\'')
502                                 sbuf_printf(sb, "\\%c", i);
503                         else
504                                 sbuf_putc(sb, i);
505                 }
506                 fclose(cff);
507         }
508 }
509
510 static void
511 configfile(void)
512 {
513         FILE *fo;
514         struct sbuf *sb;
515         char *p;
516
517         /* Add main configuration file to the list of files to be included */
518         cfgfile_add(PREFIX);
519         p = path("config.c.new");
520         fo = fopen(p, "w");
521         if (!fo)
522                 err(2, "%s", p);
523         sb = sbuf_new(NULL, NULL, 2048, SBUF_AUTOEXTEND);
524         assert(sb != NULL);
525         sbuf_clear(sb);
526         if (filebased) {
527                 /* Is needed, can be used for backward compatibility. */
528                 configfile_filebased(sb);
529         } else {
530                 configfile_dynamic(sb);
531         }
532         sbuf_finish(sb);
533         /* 
534          * We print first part of the template, replace our tag with
535          * configuration files content and later continue writing our
536          * template.
537          */
538         p = strstr(kernconfstr, KERNCONFTAG);
539         if (p == NULL)
540                 errx(EXIT_FAILURE, "Something went terribly wrong!");
541         *p = '\0';
542         fprintf(fo, "%s", kernconfstr);
543         fprintf(fo, "%s", sbuf_data(sb));
544         p += strlen(KERNCONFTAG);
545         fprintf(fo, "%s", p);
546         sbuf_delete(sb);
547         fclose(fo);
548         moveifchanged(path("config.c.new"), path("config.c"));
549         cfgfile_removeall();
550 }
551
552 /*
553  * moveifchanged --
554  *      compare two files; rename if changed.
555  */
556 void
557 moveifchanged(const char *from_name, const char *to_name)
558 {
559         char *p, *q;
560         int changed;
561         size_t tsize;
562         struct stat from_sb, to_sb;
563         int from_fd, to_fd;
564
565         changed = 0;
566
567         if ((from_fd = open(from_name, O_RDONLY)) < 0)
568                 err(EX_OSERR, "moveifchanged open(%s)", from_name);
569
570         if ((to_fd = open(to_name, O_RDONLY)) < 0)
571                 changed++;
572
573         if (!changed && fstat(from_fd, &from_sb) < 0)
574                 err(EX_OSERR, "moveifchanged fstat(%s)", from_name);
575
576         if (!changed && fstat(to_fd, &to_sb) < 0)
577                 err(EX_OSERR, "moveifchanged fstat(%s)", to_name);
578
579         if (!changed && from_sb.st_size != to_sb.st_size)
580                 changed++;
581
582         tsize = (size_t)from_sb.st_size;
583
584         if (!changed) {
585                 p = mmap(NULL, tsize, PROT_READ, MAP_SHARED, from_fd, (off_t)0);
586                 if (p == MAP_FAILED)
587                         err(EX_OSERR, "mmap %s", from_name);
588                 q = mmap(NULL, tsize, PROT_READ, MAP_SHARED, to_fd, (off_t)0);
589                 if (q == MAP_FAILED)
590                         err(EX_OSERR, "mmap %s", to_name);
591
592                 changed = memcmp(p, q, tsize);
593                 munmap(p, tsize);
594                 munmap(q, tsize);
595         }
596         if (changed) {
597                 if (rename(from_name, to_name) < 0)
598                         err(EX_OSERR, "rename(%s, %s)", from_name, to_name);
599         } else {
600                 if (unlink(from_name) < 0)
601                         err(EX_OSERR, "unlink(%s)", from_name);
602         }
603 }
604
605 static void
606 cleanheaders(char *p)
607 {
608         DIR *dirp;
609         struct dirent *dp;
610         struct file_list *fl;
611         struct hdr_list *hl;
612         size_t len;
613
614         remember("y.tab.h");
615         remember("setdefs.h");
616         STAILQ_FOREACH(fl, &ftab, f_next)
617                 remember(fl->f_fn);
618
619         /*
620          * Scan the build directory and clean out stuff that looks like
621          * it might have been a leftover NFOO header, etc.
622          */
623         if ((dirp = opendir(p)) == NULL)
624                 err(EX_OSERR, "opendir %s", p);
625         while ((dp = readdir(dirp)) != NULL) {
626                 len = strlen(dp->d_name);
627                 /* Skip non-headers */
628                 if (len < 2 || dp->d_name[len - 2] != '.' ||
629                     dp->d_name[len - 1] != 'h')
630                         continue;
631                 /* Skip special stuff, eg: bus_if.h, but check opt_*.h */
632                 if (strchr(dp->d_name, '_') &&
633                     strncmp(dp->d_name, "opt_", 4) != 0)
634                         continue;
635                 /* Check if it is a target file */
636                 for (hl = htab; hl != NULL; hl = hl->h_next) {
637                         if (eq(dp->d_name, hl->h_name)) {
638                                 break;
639                         }
640                 }
641                 if (hl)
642                         continue;
643                 printf("Removing stale header: %s\n", dp->d_name);
644                 if (unlink(path(dp->d_name)) == -1)
645                         warn("unlink %s", dp->d_name);
646         }
647         (void)closedir(dirp);
648 }
649
650 void
651 remember(const char *file)
652 {
653         char *s;
654         struct hdr_list *hl;
655
656         if ((s = strrchr(file, '/')) != NULL)
657                 s = ns(s + 1);
658         else
659                 s = ns(file);
660
661         if (strchr(s, '_') && strncmp(s, "opt_", 4) != 0) {
662                 free(s);
663                 return;
664         }
665         for (hl = htab; hl != NULL; hl = hl->h_next) {
666                 if (eq(s, hl->h_name)) {
667                         free(s);
668                         return;
669                 }
670         }
671         hl = calloc(1, sizeof(*hl));
672         if (hl == NULL)
673                 err(EXIT_FAILURE, "calloc");
674         hl->h_name = s;
675         hl->h_next = htab;
676         htab = hl;
677 }
678
679 /*
680  * This one is quick hack. Will be probably moved to elf(3) interface.
681  * It takes kernel configuration file name, passes it as an argument to
682  * elfdump -a, which output is parsed by some UNIX tools...
683  */
684 static void
685 kernconfdump(const char *file)
686 {
687         struct stat st;
688         FILE *fp, *pp;
689         int error, osz, r;
690         unsigned int i, off, size, t1, t2, align;
691         char *cmd, *o;
692
693         r = open(file, O_RDONLY);
694         if (r == -1)
695                 err(EXIT_FAILURE, "Couldn't open file '%s'", file);
696         error = fstat(r, &st);
697         if (error == -1)
698                 err(EXIT_FAILURE, "fstat() failed");
699         if (S_ISDIR(st.st_mode))
700                 errx(EXIT_FAILURE, "'%s' is a directory", file);
701         fp = fdopen(r, "r");
702         if (fp == NULL)
703                 err(EXIT_FAILURE, "fdopen() failed");
704         osz = 1024;
705         o = calloc(1, osz);
706         if (o == NULL)
707                 err(EXIT_FAILURE, "Couldn't allocate memory");
708         /* ELF note section header. */
709         asprintf(&cmd, "/usr/bin/elfdump -c %s | grep -A 8 kern_conf"
710             "| tail -5 | cut -d ' ' -f 2 | paste - - - - -", file);
711         if (cmd == NULL)
712                 errx(EXIT_FAILURE, "asprintf() failed");
713         pp = popen(cmd, "r");
714         if (pp == NULL)
715                 errx(EXIT_FAILURE, "popen() failed");
716         free(cmd);
717         (void)fread(o, osz, 1, pp);
718         pclose(pp);
719         r = sscanf(o, "%d%d%d%d%d", &off, &size, &t1, &t2, &align);
720         free(o);
721         if (r != 5)
722                 errx(EXIT_FAILURE, "File %s doesn't contain configuration "
723                     "file. Either unsupported, or not compiled with "
724                     "INCLUDE_CONFIG_FILE", file);
725         r = fseek(fp, off, SEEK_CUR);
726         if (r != 0)
727                 err(EXIT_FAILURE, "fseek() failed");
728         for (i = 0; i < size; i++) {
729                 r = fgetc(fp);
730                 if (r == EOF)
731                         break;
732                 if (r == '\0') {
733                         assert(i == size - 1 &&
734                             ("\\0 found in the middle of a file"));
735                         break;
736                 }
737                 fputc(r, stdout);
738         }
739         fclose(fp);
740 }
741
742 static void 
743 badversion(int versreq)
744 {
745         fprintf(stderr, "ERROR: version of config(8) does not match kernel!\n");
746         fprintf(stderr, "config version = %d, ", CONFIGVERS);
747         fprintf(stderr, "version required = %d\n\n", versreq);
748         fprintf(stderr, "Make sure that /usr/src/usr.sbin/config is in sync\n");
749         fprintf(stderr, "with your /usr/src/sys and install a new config binary\n");
750         fprintf(stderr, "before trying this again.\n\n");
751         fprintf(stderr, "If running the new config fails check your config\n");
752         fprintf(stderr, "file against the GENERIC or LINT config files for\n");
753         fprintf(stderr, "changes in config syntax, or option/device naming\n");
754         fprintf(stderr, "conventions\n\n");
755         exit(1);
756 }
757
758 static void
759 checkversion(void)
760 {
761         FILE *ifp;
762         char line[BUFSIZ];
763         int versreq;
764
765         ifp = open_makefile_template();
766         while (fgets(line, BUFSIZ, ifp) != 0) {
767                 if (*line != '%')
768                         continue;
769                 if (strncmp(line, "%VERSREQ=", 9) != 0)
770                         continue;
771                 versreq = atoi(line + 9);
772                 if (MAJOR_VERS(versreq) == MAJOR_VERS(CONFIGVERS) &&
773                     versreq <= CONFIGVERS)
774                         continue;
775                 badversion(versreq);
776         }
777         fclose(ifp);
778 }