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