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