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