📄 probe_comp.c
字号:
char *sp; char ln2[2048]; if (NewComp) p = ParseNewCompLine(ln);/* * Should be line of form "'compiler' 'flags'" */ else { sp = CopySingleQuoteString(ln, ln2); assert(sp); i = strlen(ln2) + 1; p->comp = malloc(sizeof(char)*i); assert(p->comp); strcpy(p->comp, ln2); sp = CopySingleQuoteString(sp+1, ln2); i = strlen(ln2) + 1; p->flags = malloc(sizeof(char)*i); assert(p->flags); strcpy(p->flags, ln2); } NewComp = !NewComp; return(p);}COMPNODE *ReadComps(char *file)/* * Reads in a file describing the compilers ATLAS knows about, and returns * a queue of them for later manipulation. */{ char ln[2048]; FILE *fpin; COMPNODE *compq=NULL, *p; fpin = fopen(file, "r"); while (fgets(ln, 2048, fpin)) { if (ln[0] != '#') { KillUselessSpace(ln); if (ln[0] != '#' && ln[0] != '\0') { p = ParseCompLine(ln); if (p != compq) { p->next = compq; compq = p; } } } } fclose(fpin); return(compq);}COMPNODE **GetDefaultComps(enum OSTYPE OS, enum MACHTYPE arch, int verb)/* * This routine reads the file atlcomp.txt, and returns them sorted by * order of priority for each compiler ATLAS needs. This list can then * be matched with the user's input to give final compiler and flags. */{ COMPNODE *q, *p, **comps; comps = malloc(sizeof(COMPNODE)*NCOMP); q = ReadComps("atlcomp.txt"); /* get all compiler lines */ if (verb > 1) PrintCompNodes(stderr, q, "Fresh Read"); q = KillBadArchOS(OS, arch, q); /* discard comps for other platforms */ if (verb > 1) PrintCompNodes(stderr, q, "Targeted"); q = SortCompsByPriority(q); /* q is smallest, bottom is largest */ if (verb > 1) PrintCompNodes(stderr, q, "Sorted"); DivideCompsByComp(q, comps); /* split into individual queues */ return(comps);}int CompTest(int verb, char *targ, int icomp, char *comp, char *flag)/* * Tries to build simple program and run it. * RETURNS: result of system call (0: success, else error code) */{ char ln[1024], res[1024]; int i, iret; if (icomp == ICC_) targ = NULL; if (icomp == F77_) i = sprintf(ln, "make IRunF77Comp F77='%s' F77FLAGS='%s' ", comp, flag); else i = sprintf(ln, "make IRunCComp CC='%s' CCFLAGS='%s' ", comp, flag); if (targ) i += sprintf(ln+i, "atlrun=atlas_runX targ=%s ", targ); i += sprintf(ln+i, "| fgrep SUCCESS"); iret = CmndOneLine(NULL, ln, res); if (verb > 1) fprintf(stderr, "cmnd=%s\n", ln); if (!iret) iret = !strstr(res, "SUCCESS"); if (verb) fprintf(stderr, " %s %s : %s!\n", comp, flag, iret ? "FAILURE":"SUCCESS"); return(iret);}void CompError(int icomp)/* * Prints out informative error message when we die because a compiler doesn't * work */{ fprintf(stderr, "\n\nUnable to find usable compiler for %s; aborting", COMPNAME[icomp]); fprintf(stderr, "Make sure compilers are in your path, and specify good compilers to configure\n"); fprintf(stderr, "(see INSTALL.txt or 'configure --help' for details)"); exit(icomp+1);}char *GetPtrbitsFlag(enum OSTYPE OS, enum MACHTYPE arch, int ptrbits, char *comp)/* * RETURNS: string forcing setting of ptrbits for gcc */{ char *sp = ""; int i, j, k; if (MachIsIA64(arch)) return(sp); if (MachIsMIPS(arch)) sp = (ptrbits == 64) ? "-mabi=64" : "-mabi=n32"; if (!CompIsGcc(comp)) {/* * Add correct 64/32 bit flags for Sun workshop compilers */ if (MachIsUS(arch) && CompIsSunWorkshop(comp)) { if (ptrbits == 64) sp = (arch == SunUSI || arch == SunUSII) ? "-xarch=v9" : "-xarch=v9b"; else sp = (arch == SunUSI || arch == SunUSII) ? "-xarch=v8plusa" : "-xarch=v8plusb"; } else if (CompIsIBMXL(comp)) /* IBM xl compilers */ sp = (ptrbits == 64) ? "-q64" : "-q32"; return(sp); } GetGccVers(comp, &k, &j, &k, &k); if ( !(j >= 3 && (OS != OSOSX || j > 3 || !CompIsAppleGcc(comp))) ) return(sp); else if (OS == OSAIX) sp = (ptrbits == 64) ? "-maix64" : "-maix32"; else if (ptrbits == 64) sp = "-m64"; else if (ptrbits == 32) sp = "-m32"; return(sp);}char *GetStandardCompName(char *comp){ int i, j, k; char *ucomp;/* * Recognize gnu compiler regardless of name string (eg. ev6-gcc-3.2) */ if (CompIsGcc(comp)) { GetGccVers(comp, &k, &j, &k, &k); if (j < 4) { if (i == F77_) ucomp = "g77"; else ucomp = "gcc"; } else if (i == F77_) ucomp = "gfortran"; else ucomp = "gcc"; } else ucomp = NameWithoutPath(comp); return(ucomp);}char *GetWinComp(enum OSTYPE OS, char *comp){ char ln[1024]; char *ucomp; if (!OSIsWin(OS)) return(NULL); ucomp = GetStandardCompName(comp); if (!strcmp(ucomp, "icc") || !strcmp(ucomp, "icl")) ucomp = "ATLwin_icc"; else if (!strcmp(ucomp, "ifort") || !strcmp(ucomp, "ivf")) ucomp = "ATLwin_ifort"; else if (!strcmp(ucomp, "mvc") || !strcmp(ucomp, "cl")) ucomp = "ATLwin_cl"; else /* not a recognized windows compiler that needs wrapping, done */ return(NULL); sprintf(ln, "make wind=/usr/local/bin /usr/local/bin/%s.exe \n", ucomp); if (system(ln)) { fprintf(stderr, "Unable to to build %s, quitting\n", ucomp); fprintf(stderr, "cmnd='%s'\n", ln); exit(-1); } return(ucomp);}void GetComps(enum OSTYPE OS, enum MACHTYPE arch, int verb, char *targ, int ptrbits, char **usrcomps, int nof77)/* * This routine gives config a list of compilers to use. The first NCOMP * entries in usrcomps indicate a user override of the default compiler, * and the next NCOMP entries indicate user override of flags. The next * NCOMP entries indicate that those flags should be appended to prior flags. * A NULL in any entry says the user is happy to use the defaults (or no * appending). Chosen compilers and flags are returned in usrcomps array. */{ COMPNODE **comps, *p; char *ucomp, *dcomp, *flg, *sp, *sp2; char cmnd[256], res[1024]; int i, j, k, h; comps = GetDefaultComps(OS, arch, verb); if (verb > 1) fprintf(stdout, "Finding good compilers:\n"); for (i=0; i < NCOMP; i++) { if (nof77 && i == F77_) continue;/* * If the user has not specified the compiler, look through all available * compilers with one that works (with user flags, if specified) */ if (!usrcomps[i]) { for (p=comps[i]; p; p = p->next) { flg = NewStringCopy(usrcomps[NCOMP+i]?usrcomps[NCOMP+i]:p->flags); if (usrcomps[NCOMP*2+i]) flg = NewAppendedString(flg, usrcomps[NCOMP*2+i]); sp = GetWinComp(OS, p->comp); if (!sp) sp = p->comp; if (ptrbits) flg = NewAppendedString(flg, GetPtrbitsFlag(OS, arch, ptrbits, sp)); if (!CompTest(verb, targ, i, sp, flg)) break; free(flg); } if (!p) CompError(i); else free(flg); usrcomps[i] = p->comp; p->comp = NULL; /* so it isn't deleted by Kill */ if (!usrcomps[NCOMP+i]) { usrcomps[NCOMP+i] = p->flags; p->flags = NULL; /* so it isn't deleted by Kill */ } }/* * If user specified comp w/o flags, get default flags or error */ else if (!usrcomps[NCOMP+i]) { p = comps[i]; ucomp = NameWithoutPath(usrcomps[i]);/* * Recognize gnu compiler regardless of name string (eg. ev6-gcc-3.2) */ if (CompIsGcc(usrcomps[i])) { GetGccVers(usrcomps[i], &k, &j, &k, &k); if (j < 4) { if (i == F77_) ucomp = "g77"; else ucomp = "gcc"; } else if (i == F77_) ucomp = "gfortran"; else ucomp = "gcc"; } for (p=comps[i]; p; p = p->next) { dcomp = NameWithoutPath(p->comp); if (!strcmp(p->comp, ucomp)) break; free(dcomp); } if (!p) { fprintf(stderr, "UNKNOWN COMPILER '%s' for %s: you must also supply flags!\n", usrcomps[i], COMPNAME[i]); exit(i+1); } usrcomps[NCOMP+i] = p->flags; p->flags = NULL; } /* If user specifed both flags and compiler, accept them *//* * On windows, build compiler wrapper for MSVC++ or Intel compilers */ sp = GetWinComp(OS, usrcomps[i]); if (sp) { free(usrcomps[i]); usrcomps[i] = NewStringCopy(sp); }/* * Test selected compiler and flags, and die if they don't work */ flg = NewStringCopy(usrcomps[NCOMP+i]?usrcomps[NCOMP+i]:p->flags); if (usrcomps[NCOMP*2+i]) flg = NewAppendedString(flg, usrcomps[NCOMP*2+i]); if (ptrbits) flg = NewAppendedString(flg, GetPtrbitsFlag(OS, arch, ptrbits,usrcomps[i])); if (CompTest(verb, targ, i, usrcomps[i], flg)) CompError(i); free(flg); } /* end of loop over compilers *//* * modify base flags by appending user flags */ for (i=2*NCOMP; i < 3*NCOMP; i++) { if (usrcomps[i]) /* user has appended flags for compiler i-2*NCOMP */ usrcomps[i-NCOMP] = NewAppendedString(usrcomps[i-NCOMP], usrcomps[i]); }/* * If nof77, set fortran compiler & flags to ICC to avoid linking problems */ if (nof77) { usrcomps[F77_] = NewStringCopy(usrcomps[ICC_]); usrcomps[F77_+NCOMP] = NewStringCopy(usrcomps[ICC_+NCOMP]); }/* * If ptrbits is set to manual override, add -m32/64 to gnu compilers * but not on Itaniums or Apple's munged gcc 3 compiler! */ if (ptrbits && arch != IA64Itan && arch != IA64Itan2) { for (i=0; i < NCOMP; i++) { sp = GetPtrbitsFlag(OS, arch, ptrbits, usrcomps[i]); usrcomps[i+NCOMP] = NewAppendedString(usrcomps[i+NCOMP], sp); } }/* * Need to add target & bitwidth args for MIPSpro compilers on IRIX */ if (OS == OSIRIX) { sprintf(cmnd, "%s -m", FindUname(targ)); assert(!CmndOneLine(NULL, cmnd, res)); sp = strstr(res, "IP"); for (i=2; isdigit(sp[i]); i++); sp[i] = '\0'; sprintf(cmnd, "-TARG:platform=%s", sp);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -