📄 main.c
字号:
/* $OpenBSD: main.c,v 1.20 2000/01/04 14:23:43 angelos Exp $ *//* $NetBSD: main.c,v 1.22 1997/02/02 21:12:33 thorpej Exp $ *//* * Copyright (c) 1992, 1993 * The Regents of the University of California. All rights reserved. * * This software was developed by the Computer Systems Engineering group * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and * contributed to Berkeley. * * All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by the University of * California, Lawrence Berkeley Laboratories. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * from: @(#)main.c 8.1 (Berkeley) 6/6/93 */#ifndef lintstatic char copyright[] ="@(#) Copyright (c) 1992, 1993\n\ The Regents of the University of California. All rights reserved.\n";#endif /* not lint */#include <sys/types.h>#include <sys/stat.h>#include <sys/param.h>#include <ctype.h>#include <errno.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <unistd.h>#include "config.h"#include "common.h"int firstfile(const char *);int yyparse(void);extern char *optarg;extern int optind;static struct hashtab *mkopttab;static struct nvlist **nextopt;static struct nvlist **nextdefopt;static struct nvlist **nextmkopt;static __dead void stop(void);static int do_option(struct hashtab *, struct nvlist ***, const char *, const char *, const char *);static int crosscheck(void);static int badstar(void);static int mksymlinks(void);static int hasparent(struct devi *);static int cfcrosscheck(struct config *, const char *, struct nvlist *);static void optiondelta(void);int madedir = 0;voidusage(char *progname){ fprintf(stderr, "usage: %s [-s srcdir] [-b builddir] [sysname]\n", progname); exit(1);}intmain(argc, argv) int argc; char **argv;{ register char *p; const char *last_component; int ch; while ((ch = getopt(argc, argv, "b:s")) != -1) { switch (ch) { case 'b': builddir = optarg; break; case 's': srcdir = optarg; break; case '?': default: usage(argv[0]); } } argc -= optind; argv += optind; if (argc > 1) usage(argv[0]); conffile = (argc == 1) ? argv[0] : "CONFIG"; if (firstfile(conffile)) { (void)fprintf(stderr, "config: cannot read %s: %s\n", conffile, strerror(errno)); exit(2); } /* * Init variables. */ initintern(); initfiles(); initsem(); devbasetab = ht_new(); devatab = ht_new(); selecttab = ht_new(); needcnttab = ht_new(); opttab = ht_new(); mkopttab = ht_new(); defopttab = ht_new(); nextopt = &options; nextmkopt = &mkoptions; nextdefopt = &defoptions; /* * Handle profiling (must do this before we try to create any * files). */ last_component = strrchr(conffile, '/'); last_component = (last_component) ? last_component + 1 : conffile; p = emalloc(strlen(last_component) + 13); (void)sprintf(p, "../compile/%s", last_component); defbuilddir = (argc == 0) ? "." : p; /* * Parse config file (including machine definitions). */ if (yyparse()) stop(); /* * Fix (as in `set firmly in place') files. */ if (fixfiles()) stop(); /* * Fix objects and libraries. */ if (fixobjects()) stop(); if (crosscheck() || errors) stop(); /* * Squeeze things down and finish cross-checks (STAR checks must * run after packing). */ pack(); if (badstar()) stop(); /* * Ready to go. Build all the various files. */ if (mksymlinks() || mkmakefile() || mkheaders() || mkioconf()) stop(); (void)printf("Don't forget to run \"make depend\"\n"); optiondelta(); exit(0);}/* * Make a symlink for "machine" so that "#include <machine/foo.h>" works, * and for the machine's CPU architecture, so that works as well. */static intmksymlinks(){ int ret; char *p, buf[MAXPATHLEN]; const char *q; sprintf(buf, "Targets/%s/include", machine); p = sourcepath(buf); (void)unlink("target"); ret = symlink(p, "target"); if (ret) (void)fprintf(stderr, "config: symlink(target -> %s): %s\n", p, strerror(errno)); if (machinearch != NULL) { sprintf(buf, "sys/arch/%s/include", machinearch); p = sourcepath(buf); q = "machine"; } else { p = strdup("machine"); q = strdup("target"); } (void)unlink(q); ret = symlink(p, q); if (ret) (void)fprintf(stderr, "config: symlink(%s -> %s): %s\n", q, p, strerror(errno)); free(p); return (ret);}static __dead voidstop(){ (void)fprintf(stderr, "*** Stop.\n"); exit(1);}/* * Define a standard option, for which a header file will be generated. */voiddefoption(name) const char *name;{ register const char *n; register char *p, c; char low[500]; /* * Convert to lower case. The header file name will be * in lower case, so we store the lower case version in * the hash table to detect option name collisions. The * original string will be stored in the nvlist for use * in the header file. */ for (n = name, p = low; (c = *n) != '\0'; n++) *p++ = isupper(c) ? tolower(c) : c; *p = 0; n = intern(low); (void)do_option(defopttab, &nextdefopt, n, name, "defopt"); /* * Insert a verbatum copy of the option name, as well, * to speed lookups when creating the Makefile. */ (void)ht_insert(defopttab, name, (void *)name);}/* * Remove an option. */voidremoveoption(name) const char *name;{ register struct nvlist *nv, *nvt; register const char *n; register char *p, c; char low[500]; if ((nv = ht_lookup(opttab, name)) != NULL) { if (options == nv) { options = nv->nv_next; nvfree(nv); } else { nvt = options; while (nvt->nv_next != NULL) { if (nvt->nv_next == nv) { nvt->nv_next = nvt->nv_next->nv_next; nvfree(nv); break; } else nvt = nvt->nv_next; } } } (void)ht_remove(opttab, name); /* make lowercase, then add to select table */ for (n = name, p = low; (c = *n) != '\0'; n++) *p++ = isupper(c) ? tolower(c) : c; *p = 0; n = intern(low); (void)ht_remove(selecttab, n);}/* * Add an option from "options FOO". Note that this selects things that * are "optional foo". */voidaddoption(name, value) const char *name, *value;{ register const char *n; register char *p, c; char low[500]; if (do_option(opttab, &nextopt, name, value, "options")) return; /* make lowercase, then add to select table */ for (n = name, p = low; (c = *n) != '\0'; n++) *p++ = isupper(c) ? tolower(c) : c; *p = 0; n = intern(low); (void)ht_insert(selecttab, n, (void *)n);}/* * Add a select from "select FOO". This selects things that * are "optional foo". */voidaddselect(name) const char *name;{ register const char *n; register char *p, c; char low[500]; /* make lowercase, then add to select table */ for (n = name, p = low; (c = *n) != '\0'; n++) *p++ = isupper(c) ? tolower(c) : c; *p = 0; n = intern(low); (void)ht_insert(selecttab, n, (void *)n);}/* * Remove a select. */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -