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