]> CyberLeo.Net >> Repos - FreeBSD/releng/9.0.git/blob - usr.sbin/config/main.c
Copy stable/9 to releng/9.0 as part of the FreeBSD 9.0-RELEASE release
[FreeBSD/releng/9.0.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                 while ((ch = getc(fp)) != EOF) {
354                         if (ch == quote)
355                                 break;
356                         if (ch == '\n') {
357                                 *cp = 0;
358                                 printf("config: missing quote reading `%s'\n",
359                                         line);
360                                 exit(2);
361                         }
362                         *cp++ = ch;
363                 }
364         } else {
365                 *cp++ = ch;
366                 while ((ch = getc(fp)) != EOF) {
367                         if (isspace(ch))
368                                 break;
369                         *cp++ = ch;
370                 }
371                 if (ch != EOF)
372                         (void) ungetc(ch, fp);
373         }
374         *cp = 0;
375         if (ch == EOF)
376                 return ((char *)EOF);
377         return (line);
378 }
379
380 /*
381  * prepend the path to a filename
382  */
383 char *
384 path(const char *file)
385 {
386         char *cp = NULL;
387
388         if (file)
389                 asprintf(&cp, "%s/%s", destdir, file);
390         else
391                 cp = strdup(destdir);
392         return (cp);
393 }
394
395 /*
396  * Generate configuration file based on actual settings. With this mode, user
397  * will be able to obtain and build conifguration file with one command.
398  */
399 static void
400 configfile_dynamic(struct sbuf *sb)
401 {
402         struct cputype *cput;
403         struct device *d;
404         struct opt *ol;
405         char *lend;
406         unsigned int i;
407
408         asprintf(&lend, "\\n\\\n");
409         assert(lend != NULL);
410         sbuf_printf(sb, "options\t%s%s", OPT_AUTOGEN, lend);
411         sbuf_printf(sb, "ident\t%s%s", ident, lend);
412         sbuf_printf(sb, "machine\t%s%s", machinename, lend);
413         SLIST_FOREACH(cput, &cputype, cpu_next)
414                 sbuf_printf(sb, "cpu\t%s%s", cput->cpu_name, lend);
415         SLIST_FOREACH(ol, &mkopt, op_next)
416                 sbuf_printf(sb, "makeoptions\t%s=%s%s", ol->op_name,
417                     ol->op_value, lend);
418         SLIST_FOREACH(ol, &opt, op_next) {
419                 if (strncmp(ol->op_name, "DEV_", 4) == 0)
420                         continue;
421                 sbuf_printf(sb, "options\t%s", ol->op_name);
422                 if (ol->op_value != NULL) {
423                         sbuf_putc(sb, '=');
424                         for (i = 0; i < strlen(ol->op_value); i++) {
425                                 if (ol->op_value[i] == '"')
426                                         sbuf_printf(sb, "\\%c",
427                                             ol->op_value[i]);
428                                 else
429                                         sbuf_printf(sb, "%c",
430                                             ol->op_value[i]);
431                         }
432                         sbuf_printf(sb, "%s", lend);
433                 } else {
434                         sbuf_printf(sb, "%s", lend);
435                 }
436         }
437         /*
438          * Mark this file as containing everything we need.
439          */
440         STAILQ_FOREACH(d, &dtab, d_next)
441                 sbuf_printf(sb, "device\t%s%s", d->d_name, lend);
442         free(lend);
443 }
444
445 /*
446  * Generate file from the configuration files.
447  */
448 static void
449 configfile_filebased(struct sbuf *sb)
450 {
451         FILE *cff;
452         struct cfgfile *cf;
453         int i;
454
455         /*
456          * Try to read all configuration files. Since those will be present as
457          * C string in the macro, we have to slash their ends then the line
458          * wraps.
459          */
460         STAILQ_FOREACH(cf, &cfgfiles, cfg_next) {
461                 cff = fopen(cf->cfg_path, "r");
462                 if (cff == NULL) {
463                         warn("Couldn't open file %s", cf->cfg_path);
464                         continue;
465                 }
466                 while ((i = getc(cff)) != EOF) {
467                         if (i == '\n')
468                                 sbuf_printf(sb, "\\n\\\n");
469                         else if (i == '"' || i == '\'')
470                                 sbuf_printf(sb, "\\%c", i);
471                         else
472                                 sbuf_putc(sb, i);
473                 }
474                 fclose(cff);
475         }
476 }
477
478 static void
479 configfile(void)
480 {
481         FILE *fo;
482         struct sbuf *sb;
483         char *p;
484
485         /* Add main configuration file to the list of files to be included */
486         cfgfile_add(PREFIX);
487         p = path("config.c.new");
488         fo = fopen(p, "w");
489         if (!fo)
490                 err(2, "%s", p);
491         sb = sbuf_new(NULL, NULL, 2048, SBUF_AUTOEXTEND);
492         assert(sb != NULL);
493         sbuf_clear(sb);
494         if (filebased) {
495                 /* Is needed, can be used for backward compatibility. */
496                 configfile_filebased(sb);
497         } else {
498                 configfile_dynamic(sb);
499         }
500         sbuf_finish(sb);
501         /* 
502          * We print first part of the template, replace our tag with
503          * configuration files content and later continue writing our
504          * template.
505          */
506         p = strstr(kernconfstr, KERNCONFTAG);
507         if (p == NULL)
508                 errx(EXIT_FAILURE, "Something went terribly wrong!");
509         *p = '\0';
510         fprintf(fo, "%s", kernconfstr);
511         fprintf(fo, "%s", sbuf_data(sb));
512         p += strlen(KERNCONFTAG);
513         fprintf(fo, "%s", p);
514         sbuf_delete(sb);
515         fclose(fo);
516         moveifchanged(path("config.c.new"), path("config.c"));
517         cfgfile_removeall();
518 }
519
520 /*
521  * moveifchanged --
522  *      compare two files; rename if changed.
523  */
524 void
525 moveifchanged(const char *from_name, const char *to_name)
526 {
527         char *p, *q;
528         int changed;
529         size_t tsize;
530         struct stat from_sb, to_sb;
531         int from_fd, to_fd;
532
533         changed = 0;
534
535         if ((from_fd = open(from_name, O_RDONLY)) < 0)
536                 err(EX_OSERR, "moveifchanged open(%s)", from_name);
537
538         if ((to_fd = open(to_name, O_RDONLY)) < 0)
539                 changed++;
540
541         if (!changed && fstat(from_fd, &from_sb) < 0)
542                 err(EX_OSERR, "moveifchanged fstat(%s)", from_name);
543
544         if (!changed && fstat(to_fd, &to_sb) < 0)
545                 err(EX_OSERR, "moveifchanged fstat(%s)", to_name);
546
547         if (!changed && from_sb.st_size != to_sb.st_size)
548                 changed++;
549
550         tsize = (size_t)from_sb.st_size;
551
552         if (!changed) {
553                 p = mmap(NULL, tsize, PROT_READ, MAP_SHARED, from_fd, (off_t)0);
554                 if (p == MAP_FAILED)
555                         err(EX_OSERR, "mmap %s", from_name);
556                 q = mmap(NULL, tsize, PROT_READ, MAP_SHARED, to_fd, (off_t)0);
557                 if (q == MAP_FAILED)
558                         err(EX_OSERR, "mmap %s", to_name);
559
560                 changed = memcmp(p, q, tsize);
561                 munmap(p, tsize);
562                 munmap(q, tsize);
563         }
564         if (changed) {
565                 if (rename(from_name, to_name) < 0)
566                         err(EX_OSERR, "rename(%s, %s)", from_name, to_name);
567         } else {
568                 if (unlink(from_name) < 0)
569                         err(EX_OSERR, "unlink(%s)", from_name);
570         }
571 }
572
573 static void
574 cleanheaders(char *p)
575 {
576         DIR *dirp;
577         struct dirent *dp;
578         struct file_list *fl;
579         struct hdr_list *hl;
580         size_t len;
581
582         remember("y.tab.h");
583         remember("setdefs.h");
584         STAILQ_FOREACH(fl, &ftab, f_next)
585                 remember(fl->f_fn);
586
587         /*
588          * Scan the build directory and clean out stuff that looks like
589          * it might have been a leftover NFOO header, etc.
590          */
591         if ((dirp = opendir(p)) == NULL)
592                 err(EX_OSERR, "opendir %s", p);
593         while ((dp = readdir(dirp)) != NULL) {
594                 len = strlen(dp->d_name);
595                 /* Skip non-headers */
596                 if (len < 2 || dp->d_name[len - 2] != '.' ||
597                     dp->d_name[len - 1] != 'h')
598                         continue;
599                 /* Skip special stuff, eg: bus_if.h, but check opt_*.h */
600                 if (strchr(dp->d_name, '_') &&
601                     strncmp(dp->d_name, "opt_", 4) != 0)
602                         continue;
603                 /* Check if it is a target file */
604                 for (hl = htab; hl != NULL; hl = hl->h_next) {
605                         if (eq(dp->d_name, hl->h_name)) {
606                                 break;
607                         }
608                 }
609                 if (hl)
610                         continue;
611                 printf("Removing stale header: %s\n", dp->d_name);
612                 if (unlink(path(dp->d_name)) == -1)
613                         warn("unlink %s", dp->d_name);
614         }
615         (void)closedir(dirp);
616 }
617
618 void
619 remember(const char *file)
620 {
621         char *s;
622         struct hdr_list *hl;
623
624         if ((s = strrchr(file, '/')) != NULL)
625                 s = ns(s + 1);
626         else
627                 s = ns(file);
628
629         if (index(s, '_') && strncmp(s, "opt_", 4) != 0) {
630                 free(s);
631                 return;
632         }
633         for (hl = htab; hl != NULL; hl = hl->h_next) {
634                 if (eq(s, hl->h_name)) {
635                         free(s);
636                         return;
637                 }
638         }
639         hl = calloc(1, sizeof(*hl));
640         if (hl == NULL)
641                 err(EXIT_FAILURE, "calloc");
642         hl->h_name = s;
643         hl->h_next = htab;
644         htab = hl;
645 }
646
647 /*
648  * This one is quick hack. Will be probably moved to elf(3) interface.
649  * It takes kernel configuration file name, passes it as an argument to
650  * elfdump -a, which output is parsed by some UNIX tools...
651  */
652 static void
653 kernconfdump(const char *file)
654 {
655         struct stat st;
656         FILE *fp, *pp;
657         int error, len, osz, r;
658         unsigned int i, off, size, t1, t2, align;
659         char *cmd, *o;
660
661         r = open(file, O_RDONLY);
662         if (r == -1)
663                 err(EXIT_FAILURE, "Couldn't open file '%s'", file);
664         error = fstat(r, &st);
665         if (error == -1)
666                 err(EXIT_FAILURE, "fstat() failed");
667         if (S_ISDIR(st.st_mode))
668                 errx(EXIT_FAILURE, "'%s' is a directory", file);
669         fp = fdopen(r, "r");
670         if (fp == NULL)
671                 err(EXIT_FAILURE, "fdopen() failed");
672         osz = 1024;
673         o = calloc(1, osz);
674         if (o == NULL)
675                 err(EXIT_FAILURE, "Couldn't allocate memory");
676         /* ELF note section header. */
677         asprintf(&cmd, "/usr/bin/elfdump -c %s | grep -A 8 kern_conf"
678             "| tail -5 | cut -d ' ' -f 2 | paste - - - - -", file);
679         if (cmd == NULL)
680                 errx(EXIT_FAILURE, "asprintf() failed");
681         pp = popen(cmd, "r");
682         if (pp == NULL)
683                 errx(EXIT_FAILURE, "popen() failed");
684         free(cmd);
685         len = fread(o, osz, 1, pp);
686         pclose(pp);
687         r = sscanf(o, "%d%d%d%d%d", &off, &size, &t1, &t2, &align);
688         free(o);
689         if (r != 5)
690                 errx(EXIT_FAILURE, "File %s doesn't contain configuration "
691                     "file. Either unsupported, or not compiled with "
692                     "INCLUDE_CONFIG_FILE", file);
693         r = fseek(fp, off, SEEK_CUR);
694         if (r != 0)
695                 err(EXIT_FAILURE, "fseek() failed");
696         for (i = 0; i < size; i++) {
697                 r = fgetc(fp);
698                 if (r == EOF)
699                         break;
700                 /* 
701                  * If '\0' is present in the middle of the configuration
702                  * string, this means something very weird is happening.
703                  * Make such case very visible.  However, some architectures
704                  * pad the length of the section with NULs to a multiple of
705                  * sh_addralign, allow a NUL in that part of the section.
706                  */
707                 if (r == '\0' && (size - i) < align)
708                         break;
709                 assert(r != '\0' && ("Char present in the configuration "
710                     "string mustn't be equal to 0"));
711                 fputc(r, stdout);
712         }
713         fclose(fp);
714 }
715
716 static void 
717 badversion(int versreq)
718 {
719         fprintf(stderr, "ERROR: version of config(8) does not match kernel!\n");
720         fprintf(stderr, "config version = %d, ", CONFIGVERS);
721         fprintf(stderr, "version required = %d\n\n", versreq);
722         fprintf(stderr, "Make sure that /usr/src/usr.sbin/config is in sync\n");
723         fprintf(stderr, "with your /usr/src/sys and install a new config binary\n");
724         fprintf(stderr, "before trying this again.\n\n");
725         fprintf(stderr, "If running the new config fails check your config\n");
726         fprintf(stderr, "file against the GENERIC or LINT config files for\n");
727         fprintf(stderr, "changes in config syntax, or option/device naming\n");
728         fprintf(stderr, "conventions\n\n");
729         exit(1);
730 }
731
732 static void
733 checkversion(void)
734 {
735         FILE *ifp;
736         char line[BUFSIZ];
737         int versreq;
738
739         ifp = open_makefile_template();
740         while (fgets(line, BUFSIZ, ifp) != 0) {
741                 if (*line != '%')
742                         continue;
743                 if (strncmp(line, "%VERSREQ=", 9) != 0)
744                         continue;
745                 versreq = atoi(line + 9);
746                 if (MAJOR_VERS(versreq) == MAJOR_VERS(CONFIGVERS) &&
747                     versreq <= CONFIGVERS)
748                         continue;
749                 badversion(versreq);
750         }
751         fclose(ifp);
752 }