|
|
1.1 ! root 1: static char *rcsid = "$Header: Mkmf.c,v 1.7 86/01/12 00:48:26 lepreau Exp $"; ! 2: #include "sccsid.h" ! 3: /* ! 4: * mkmf - makefile editor ! 5: * ! 6: * Author: Peter J. Nicklin ! 7: */ ! 8: #include "Mkmf.h" ! 9: #include "getarg.h" ! 10: #include "hash.h" ! 11: #include "null.h" ! 12: #include "path.h" ! 13: #include "target.h" ! 14: #include "slist.h" ! 15: #include "suffix.h" ! 16: #include "system.h" ! 17: #include "yesno.h" ! 18: ! 19: char *L_MAKEFILE = "l.Makefile"; /* default library makefile template */ ! 20: char OBJSFX[SUFFIXSIZE] = ".o"; /* default object suffix */ ! 21: char *P_MAKEFILE = "p.Makefile"; /* default program makefile template */ ! 22: char *PGN = "mkmf"; /* program name */ ! 23: int CFLAG = YES; /* makefile creation message flag */ ! 24: int AFLAG = NO; /* accept src files w/ leading dots? */ ! 25: int DEPEND = 1; /* dependency analysis? */ ! 26: SLIST *HEADLIST; /* header file name list */ ! 27: SLIST *LIBLIST; /* library pathname list */ ! 28: SLIST *SRCLIST; /* source file name list */ ! 29: HASH *MDEFTABLE; /* macro definition table */ ! 30: ! 31: char *DEFRULE[] = /* default preprocessor rules */ ! 32: { ! 33: #include "defaultrul.h" ! 34: NULL ! 35: }; ! 36: ! 37: SUFFIX DEFSFX[] = /* default suffix list */ ! 38: { ! 39: #include "defaultsfx.h" ! 40: NULL, 0 ! 41: }; ! 42: ! 43: main(argc, argv) ! 44: int argc; ! 45: char **argv; ! 46: { ! 47: char *mfname = NULL; /* makefile name */ ! 48: char mfpath[PATHSIZE]; /* makefile template pathname */ ! 49: HASHBLK *htb; /* hash table block */ ! 50: HASHBLK *htinstall(); /* install hash table entry */ ! 51: HASHBLK *htlookup(); /* find hash table entry */ ! 52: int buildliblist(); /* build list of library pathnames */ ! 53: int buildruletable(); /* build table of preprocessor rules */ ! 54: int buildsfxtable(); /* build table of suffixes */ ! 55: int buildsrclist(); /* build list of source file names */ ! 56: int findmf(); /* find makefile */ ! 57: int status = 0; /* exit status */ ! 58: int storemacro(); /* store macro definition */ ! 59: short iflag = NO; /* interactive flag */ ! 60: TARGET target; /* type of makefile target */ ! 61: void answer(); /* install answer in macro def table */ ! 62: void editmf(); /* edit makefile */ ! 63: ! 64: target.type = target.dest = VUNKNOWN; ! 65: ! 66: { ! 67: register char *s; /* option pointer */ ! 68: while (--argc > 0 && **++argv == '-') ! 69: { ! 70: for (s = argv[0]+1; *s != '\0'; s++) ! 71: switch (*s) ! 72: { ! 73: case 'F': ! 74: P_MAKEFILE = L_MAKEFILE = GETARG(s); ! 75: if (P_MAKEFILE==NULL || *P_MAKEFILE=='\0') ! 76: { ! 77: warn("missing template name"); ! 78: status = 1; ! 79: } ! 80: goto endfor; ! 81: case 'a': ! 82: AFLAG = YES; ! 83: break; ! 84: case 'c': ! 85: CFLAG = NO; ! 86: break; ! 87: case 'd': ! 88: /* turn OFF dependency analysis */ ! 89: DEPEND = 0; ! 90: break; ! 91: case 'f': ! 92: mfname = GETARG(s); ! 93: if (mfname == NULL || *mfname == '\0') ! 94: { ! 95: warn("missing makefile name"); ! 96: status = 1; ! 97: } ! 98: goto endfor; ! 99: case 'i': ! 100: iflag = YES; ! 101: break; ! 102: case 'l': ! 103: target.type = VLIBRARY; ! 104: break; ! 105: default: ! 106: badopt(**argv, *s); ! 107: status = 1; ! 108: goto endfor; ! 109: } ! 110: endfor: continue; ! 111: } ! 112: } ! 113: ! 114: /* initialize macro definition table */ ! 115: MDEFTABLE = htinit(MDEFTABLESIZE); ! 116: ! 117: /* get command line macro definitions */ ! 118: for (; argc > 0; argc--, argv++) ! 119: if (storemacro(*argv) == NO) ! 120: { ! 121: warns("%s not a macro definition", *argv); ! 122: status = 1; ! 123: } ! 124: ! 125: if (status == 1) ! 126: { ! 127: usage("[-cdil] [-f makefile] [-F template] [macroname=value...]"); ! 128: exit(1); ! 129: } ! 130: ! 131: ! 132: /* determine the makefile name */ ! 133: if (mfname == NULL) ! 134: if ((htb = htlookup(MMAKEFILE, MDEFTABLE)) != NULL) ! 135: mfname = htb->h_def; ! 136: else if (FILEXIST("makefile")) ! 137: mfname = "makefile"; ! 138: else if (FILEXIST("Makefile")) ! 139: mfname = "Makefile"; ! 140: else ! 141: mfname = "Makefile"; ! 142: if (htinstall(MMAKEFILE, mfname, VREADWRITE, MDEFTABLE) == NULL) ! 143: exit(1); ! 144: ! 145: ! 146: /* find the makefile (template) and load useful macro definitions */ ! 147: if (target.type == VUNKNOWN) ! 148: { ! 149: if (htlookup(MPROGRAM, MDEFTABLE) != NULL) ! 150: target.type = VPROGRAM; ! 151: else if (htlookup(MLIBRARY, MDEFTABLE) != NULL) ! 152: target.type = VLIBRARY; ! 153: } ! 154: if (findmf(mfname, mfpath, &target) == NO) ! 155: exit(1); ! 156: ! 157: ! 158: /* interactive option */ ! 159: if (iflag == YES) ! 160: { ! 161: if (htlookup(MPROGRAM, MDEFTABLE) == NULL && ! 162: htlookup(MLIBRARY, MDEFTABLE) == NULL) ! 163: if (target.type == VPROGRAM) ! 164: { ! 165: printf("program name? "); ! 166: answer(MPROGRAM, VREADWRITE); ! 167: } ! 168: else if (target.type == VLIBRARY) ! 169: { ! 170: printf("library name? "); ! 171: answer(MLIBRARY, VREADWRITE); ! 172: } ! 173: if (htlookup(MDESTDIR, MDEFTABLE) == NULL && target.dest == VDESTDIR) ! 174: { ! 175: printf("destination directory? "); ! 176: answer(MDESTDIR, VREADWRITE); ! 177: } ! 178: } ! 179: ! 180: /* build the suffix table */ ! 181: if (buildsfxtable() == NO) ! 182: exit(1); ! 183: ! 184: /* build the rule table */ ! 185: if (buildruletable() == NO) ! 186: exit(1); ! 187: ! 188: /* build the source code and header file name lists */ ! 189: if (buildsrclist() == NO) ! 190: exit(1); ! 191: ! 192: ! 193: /* build the library pathname list */ ! 194: if (buildliblist() == NO) ! 195: exit(1); ! 196: ! 197: ! 198: /* edit makefile */ ! 199: editmf(mfname, mfpath); ! 200: ! 201: exit(0); ! 202: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.