static void configfile(void) { FILE *fi, *fo; char *p; int i; fi = fopen(PREFIX, "r"); if (fi == NULL) err(2, "%s", PREFIX); fo = fopen(p = path("config.c.new"), "w"); if (fo == NULL) err(2, "%s", p); fprintf(fo, "#include \"opt_config.h\"\n"); fprintf(fo, "#ifdef INCLUDE_CONFIG_FILE \n"); fprintf(fo, "/* Mark config as used, so gcc doesn't optimize it away. */\n"); fprintf(fo, "#include <sys/types.h>\n"); fprintf(fo, "__used\n"); fprintf(fo, "static const char config[] = \"\\\n"); fprintf(fo, "START CONFIG FILE %s\\n\\\n___", PREFIX); while (EOF != (i = getc(fi))) { if (i == '\n') { fprintf(fo, "\\n\\\n___"); } else if (i == '\"') { fprintf(fo, "\\\""); } else if (i == '\\') { fprintf(fo, "\\\\"); } else { putc(i, fo); } } fprintf(fo, "\\n\\\nEND CONFIG FILE %s\\n\\\n", PREFIX); fprintf(fo, "\";\n"); fprintf(fo, "\n#endif /* INCLUDE_CONFIG_FILE */\n"); fclose(fi); fclose(fo); moveifchanged(path("config.c.new"), path("config.c")); }
/* * Build the makefile from the skeleton */ void makefile(void) { FILE *ifp, *ofp; char line[BUFSIZ]; struct opt *op; int versreq; read_files(); snprintf(line, sizeof(line), "../platform/%s/conf/Makefile", platformname); ifp = fopen(line, "r"); if (ifp == NULL) { snprintf(line, sizeof(line), "Makefile.%s", platformname); ifp = fopen(line, "r"); } if (ifp == NULL) err(1, "%s", line); ofp = fopen(path("Makefile.new"), "w"); if (ofp == NULL) err(1, "%s", path("Makefile.new")); fprintf(ofp, "KERN_IDENT=%s\n", raisestr(ident)); fprintf(ofp, "MACHINE_PLATFORM=%s\n", platformname); fprintf(ofp, "MACHINE=%s\n", machinename); fprintf(ofp, "MACHINE_ARCH=%s\n", machinearchname); fprintf(ofp, ".makeenv MACHINE_PLATFORM\n"); fprintf(ofp, ".makeenv MACHINE\n"); fprintf(ofp, ".makeenv MACHINE_ARCH\n"); fprintf(ofp, "IDENT="); if (profiling) fprintf(ofp, " -DGPROF"); if (cputype == 0) { printf("cpu type must be specified\n"); exit(1); } fprintf(ofp, "\n"); for (op = mkopt; op != NULL; op = op->op_next) fprintf(ofp, "%s=%s\n", op->op_name, op->op_value); if (debugging) fprintf(ofp, "DEBUG=-g\n"); if (profiling) { fprintf(ofp, "PROF=-pg\n"); fprintf(ofp, "PROFLEVEL=%d\n", profiling); } if (*srcdir != '\0') fprintf(ofp,"S=%s\n", srcdir); while (fgets(line, BUFSIZ, ifp) != 0) { if (*line != '%') { fprintf(ofp, "%s", line); continue; } if (strcmp(line, "%BEFORE_DEPEND\n") == 0) do_before_depend(ofp); else if (strcmp(line, "%OBJS\n") == 0) do_objs(ofp); else if (strcmp(line, "%MFILES\n") == 0) do_mfiles(ofp); else if (strcmp(line, "%CFILES\n") == 0) do_cfiles(ofp); else if (strcmp(line, "%SFILES\n") == 0) do_sfiles(ofp); else if (strcmp(line, "%RULES\n") == 0) do_rules(ofp); else if (strcmp(line, "%CLEAN\n") == 0) do_clean(ofp); else if (strncmp(line, "%VERSREQ=", sizeof("%VERSREQ=") - 1) == 0) { versreq = atoi(line + sizeof("%VERSREQ=") - 1); if (versreq != CONFIGVERS) { fprintf(stderr, "ERROR: version of config(8) does not match kernel!\n"); fprintf(stderr, "config version = %d, ", CONFIGVERS); fprintf(stderr, "version required = %d\n\n", versreq); fprintf(stderr, "Make sure that /usr/src/usr.sbin/config is in sync\n"); fprintf(stderr, "with your /usr/src/sys and install a new config binary\n"); fprintf(stderr, "before trying this again.\n\n"); fprintf(stderr, "If running the new config fails check your config\n"); fprintf(stderr, "file against the GENERIC or LINT config files for\n"); fprintf(stderr, "changes in config syntax, or option/device naming\n"); fprintf(stderr, "conventions\n\n"); exit(1); } } else fprintf(stderr, "Unknown %% construct in generic makefile: %s", line); } fclose(ifp); fclose(ofp); moveifchanged(path("Makefile.new"), path("Makefile")); }