297
char *CmndResults(char *targ, char *cmnd)
299
static char tnam[128];
300
static int FirstTime=1;
306
assert(tmpnam(tnam));
308
if (targ) sprintf(ln, "ssh %s \"%s\" > %s 2>&1 \n", targ, cmnd, tnam);
309
else sprintf(ln, "%s > %s 2>&1\n", cmnd, tnam);
310
if (!system(ln)) return(tnam);
314
int CmndOneLine(char *targ, char *cmnd, char *ln)
316
* executes a system call with contents of cmnd, returns the output in ln;
317
* Returns value returned by system call
318
* if targ is set, we ssh to that machine
326
tnam = CmndResults(targ, cmnd);
329
fp = fopen(tnam, "r");
331
if (!fgets(ln, 2048, fp)) ln[0] = '\0';
339
332
int GetIntBeforeWord(char *word, char *ln)
641
650
* comp: 0: gcc; 1: egcs; 2: pgcc, 3: apple's gcc
644
char ln[512], ln2[512];
647
656
*comp = *major = *minor = *patch = -1;
648
sprintf(ln, "%s --version", gcc);
649
if (CmndOneLine(NULL, ln, ln2) == 0)
657
i = strlen(gcc) + 12;
658
cmnd = malloc(i * sizeof(char));
660
sprintf(cmnd, "%s --version", gcc);
661
res = atlsys_1L(NULL, cmnd, 0, 0);
651
if (strstr(ln2, "Apple Computer"))
665
if (strstr(res, "Apple Computer") || strstr(res, "Apple Inc"))
654
668
* Skip compiler name, which may have digits in it
656
for (i=0; ln2[i] && !isspace(ln2[i]); i++);
657
*major = GetIntVers(ln2+i, &j); j += i;
670
for (i=0; res[i] && !isspace(res[i]); i++);
671
*major = GetIntVers(res+i, &j); j += i;
658
672
if (*major != -1)
660
*minor = GetIntVers(ln2+j, &i); j += i;
674
*minor = GetIntVers(res+j, &i); j += i;
661
675
if (*minor != -1)
663
*patch = GetIntVers(ln2+j, &i); j += i;
664
if (strstr(ln2, "egcs")) *comp = 1;
665
else if (strstr(ln2, "pgcc")) *comp = 2;
677
*patch = GetIntVers(res+j, &i); j += i;
678
if (strstr(res, "egcs")) *comp = 1;
679
else if (strstr(res, "pgcc")) *comp = 2;
680
else if (*comp == -1) *comp = 0;
687
char *GetPathEnvVar(void)
689
* returns users path with inter-name spaces replaced by "\ "
690
* and dirs separated by spaces
696
path = getenv("PATH");
701
p = pp = malloc((2*n+1)*sizeof(char));
703
for (i=0; i < n; i++)
707
else if (path[i] == ' ')
672
720
int CompIsGcc(char *comp)
674
722
* Tries to detect if compiler is gcc w/o scoping name of compiler
723
* However, rejects compilers with c89 and c90 in name, since these
724
* guys turn off inline assembly, which hurts the ATLAS install on performance.
677
char cmnd[1024], res[1024];
731
cmpname = NameWithoutPath(comp);
732
if (strstr(cmpname, "c89") || strstr(cmpname, "c90"))
738
i = strlen(comp) + 16;
739
cmnd = malloc(i*sizeof(char));
679
741
sprintf(cmnd, "%s --version", comp);
680
if (CmndOneLine(NULL, cmnd, res) == 0)
742
res = atlsys_1L(NULL, cmnd, 0, 0);
683
747
* The direct comps added because Ubuntu stopped printing (GCC) in the
684
748
* version line. Don't want to search for just "gcc", since that will
685
749
* match with pgcc
687
if (strstr(res, "(GCC)") || strstr(res, " GCC ") ||
688
strstr(res, "GNU Fortran") || strstr(res, "(GCC ") ||
689
(res[0] == 'g' && res[1] == 'c' && res[2] == 'c' && res[3] == ' ')
751
if (strstr(res, "(GCC)") || strstr(res, " GCC ") ||
752
strstr(res, "gcc-mp") || strstr(res, "(GCC ") ||
753
strstr(res, "GNU Fortran") ||
754
(res[0] == 'g' && res[1] == 'c' && res[2] == 'c' &&
755
(res[3] == ' ' || res[3] == '-'))
766
int CompIsMinGW(char *comp)
768
* Tries to detect if compiler is MinGW compiler
775
i = strlen(comp) + 24;
776
cmnd = malloc(sizeof(char)*i);
778
sprintf(cmnd, "%s -v 2>&1 | fgrep mingw", comp);
779
res = atlsys_1L(NULL, cmnd, 0, 0);
783
if (strstr(res, "mingw"))
695
794
int CompIsAppleGcc(char *comp)
697
796
* Tries to detect if compiler is Apple's funked-up gcc
700
char cmnd[1024], res[1024];
702
801
if (CompIsGcc(comp))
804
i = strlen(comp) + 24;
805
cmnd = malloc(sizeof(char)*i);
705
807
sprintf(cmnd, "%s -v 2>&1 | fgrep Apple", comp);
706
CmndOneLine(NULL, cmnd, res);
707
if (strstr(res, "Apple"))
808
res = atlsys_1L(NULL, cmnd, 0, 0);
812
if (strstr(res, "Apple"))
715
825
* RETURNS: 1 if compiler is MIPSpro compiler, 0 otherwise
718
char cmnd[1024], res[1024];
831
i = strlen(comp) + 4;
832
cmnd = malloc(sizeof(char)*i);
720
834
sprintf(cmnd, "%s -v", comp);
721
if (CmndOneLine(NULL, cmnd, res) == 0)
835
res = atlsys_1L(NULL, cmnd, 0, 0);
723
839
if (strstr(res, "MIPSpro Compiler"))
849
int CompIsPathScale(char *comp)
854
i = strlen(comp) + 4;
855
cmnd = malloc(sizeof(char)*i);
857
sprintf(cmnd, "%s -v", comp);
858
res = atlsys_1L(NULL, cmnd, 0, 0);
862
if (strstr(res, "PathScale"))
747
900
* RETURNS: 1 if compiler is an IBM XL compiler, 0 otherwise
750
char cmnd[1024], res[1024];
906
i = strlen(comp) + 11;
907
cmnd = malloc(sizeof(char)*i);
752
909
sprintf(cmnd, "%s -qversion", comp);
753
if (CmndOneLine(NULL, cmnd, res) == 0)
910
res = atlsys_1L(NULL, cmnd, 0, 0);
755
914
if (strstr(res, "IBM XL"))
761
char *NewStringCopy(char *old)
763
* RETURNS: newly allocates string containing copy of string old
767
new = malloc(sizeof(char)*(strlen(old)+1));
771
char *NewAppendedString(char *old, char *app)
773
* RETURNS: string holding : old + " " + app
774
* NOTE: frees old string after copy
781
new = malloc(sizeof(char)*(strlen(app)+1));
787
new = malloc(sizeof(char)*(strlen(old) + strlen(app)+2));
924
char **GetLinesFromFile
926
FILE *fpin, /* stream to read from */
927
char **curlns /* NULL-termed list of lines to prepend to file list ret */
930
* Read all lines from file fnam, suffix them to lines in curlns, delete
931
* curlns, and return them as NULL-terminated array of strings
939
for (n=0; fgets(ln, 2048, fpin); n++); /* count number of lines in file */
942
for (nc=0; curlns[nc]; nc++);
946
lns = malloc((N+1)*sizeof(char*));
950
for (i=0; i < nc; i++)
954
for (i=0; i < n; i++)
958
assert(fgets(ln, 2048, fpin));
960
lns[i+nc] = sp = malloc(k*sizeof(char));
964
* Get rid of whitespace on end of line
966
for (k -= 2; isspace(sp[k]); k--) sp[k] = '\0';
972
void PrintAllStringsInList
975
char **strs /* NULL terminated arrayof strings to be printed */
981
printf("%s: NULL\n", exp);
984
printf("%s:\n", exp);
985
for (i=0; strs[i]; i++)
986
printf(" '%s'\n", strs[i]);
988
void KillAllStringsInList
990
char **strs /* NULL terminated arrayof strings to be freed */
996
for (i=0; strs[i]; i++)
1001
char *FreeListGetString
1003
char **strs, /* NULL-terminated array of strings to be freed */
1004
int n /* only string you want to retain from array (returned) */
1013
for (i=0; strs[i]; i++)
1022
char **NewOneStringList
1024
char **strs, /* NULL-terminated array of strings to be freed */
1025
int n /* only string you want to retain from array (returned) */
1029
nstrs = malloc(2*sizeof(char*));
1031
nstrs[0] = FreeListGetString(strs, n);