xref: /onnv-gate/usr/src/cmd/fps/compilercheck/fps_compiler_check.c (revision 10273:84bfc6d78f00)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*
28  * fps_compiler_check verifies if the compiler
29  * and the libsuperf associated with the compiler
30  * are known.
31  *
32  * How To Update the code with details about
33  * a new compiler/libsunperf:
34  * - Add a line that describes the new compiler and libsunperf version
35  * in version_details table.
36  * - Respect the order specified in v_d struct.
37  * - cstyle -p fps_compiler_check.c
38  * - make
39  */
40 
41 #include <stdio.h>
42 #include <stdlib.h>
43 #include <strings.h>
44 #include <sunperf.h>
45 
46 #define	LIM_CI	256
47 
48 typedef struct
49 {
50 	long cc_version;
51 	long lib_version;
52 	long lib_patch;
53 	long lib_update;
54 	char *lib_ver_string;
55 } v_d;
56 
57 v_d version_details[] = {
58 	{0x550, 0x400000000, 0, 0,
59 	"Sun Performance Library 4.1 2003/03/13"}, /* 0 - SOS8 */
60 	{0x570, 0x600000000, 0, 0,
61 	"Sun Performance Library 6 12/13/04"}, /* 1 - SOS10 */
62 	{0x580, 0x600000000, 0, 0,
63 	"Sun Performance Library 6 07/27/2006 Patch_122135-02"}, /* 2-SS11 */
64 	{0x590, 7, 0, 0,
65 	"Sun Performance Library 7 Patch_124870-02"}, /* 3 - SS12 */
66 	{0x590, 7, 124870, 3, /* 4-SS12 QA */
67 	"Sun Performance Library 7 Patch_124870-03 2008/05/28" },
68 	{0x5100, 8, 0, 0,
69 	"Sun Performance Library 8 2008/10/24"}, /* 5 */
70 	{0x5100, 8, 0, 0,
71 	"Sun Performance Library 8 2009/04/28"}, /* 6 - SS12 U1 */
72 	{0, 0, 0, 0, NULL}
73 };
74 
75 
76 #if 0
77 static void printError(
78 char *Uknown, long cc_version, long lib_version,
79 long lib_patch, long lib_update, char *lib_ver_string)
80 {
81 	if ((NULL != Uknown) && (NULL != lib_ver_string))
82 	printf("\n %s \n Compiler = 0x%x \n lib_version = %ld 0x%lx \
83 	\n lib_patch = %ld  0x%lx \n lib_update = %ld  0x%lx \
84 	\n lib_ver_string = %s\n",
85 	    Unknown, cc_version, lib_version, lib_version, lib_patch,
86 	    lib_patch, lib_update, lib_update, lib_ver_string);
87 }
88 #endif
89 
90 
91 int
main()92 main()
93 {
94 	char *lib_ver_string = NULL;
95 	long cc_version, lib_version, lib_patch, lib_update;
96 	int i, k, j, TableElem;
97 	int CompilerIndex[LIM_CI];
98 
99 
100 	/* Initialize */
101 	cc_version = lib_version = lib_patch = lib_update = 0;
102 	TableElem = sizeof (version_details) / sizeof (v_d);
103 	for (i = 0; i < LIM_CI; i++) CompilerIndex[i] = -1;
104 
105 	/* get the info about the current compiler and libsunperf */
106 #ifndef __lint
107 	lib_ver_string =
108 	    sunperf_version_64(&lib_version, &lib_patch, &lib_update);
109 #endif
110 	cc_version = __SUNPRO_C;
111 
112 	for (i = 0; i < TableElem; i++) {
113 		if (version_details[i].cc_version == cc_version) break;
114 	}
115 
116 
117 	/* Check the compiler  __SUNPRO_C  version */
118 	if ((i - TableElem > 0) ||
119 	    (cc_version != version_details[i].cc_version)) {
120 #if 0
121 		printError("Unknown",
122 		    cc_version, lib_version, lib_patch,
123 		    lib_update, lib_ver_string);
124 #endif
125 	return (-1);
126 	}
127 
128 	/*
129 	 * We have at least one line in the table that has info
130 	 * about this compiler. Let's see how many lines with details
131 	 * about this compiler do we have. Store the indexes.
132 	 */
133 	for (k = 0, j = 0; (k < TableElem) && (j < LIM_CI); k++) {
134 		if (version_details[k].cc_version == cc_version) {
135 			CompilerIndex[j++] = k;
136 		}
137 	}
138 
139 
140 	/*
141 	 * We have a  compiler with an known  __SUNPRO_C
142 	 * Check the libsunperf version, patch, update and version string
143 	 */
144 
145 	for (j = 0; (j < LIM_CI) && (-1 != CompilerIndex[j]); j++) {
146 		if (strlen(version_details[CompilerIndex[j]].lib_ver_string) !=
147 		    strlen(lib_ver_string))
148 	continue;
149 		if (
150 		    (0 !=
151 		    strcmp(version_details[CompilerIndex[j]].lib_ver_string,
152 		    lib_ver_string))	||
153 		    (version_details[CompilerIndex[j]].lib_version	!=
154 		    lib_version) 		||
155 		    (version_details[CompilerIndex[j]].lib_patch 	!=
156 		    lib_patch)			||
157 		    (version_details[CompilerIndex[j]].lib_update	!=
158 		    lib_update)) {
159 			continue;
160 		} else {
161 			break;
162 		}
163 	}
164 
165 	if (-1 == CompilerIndex[j]) {
166 #if 0
167 		printError("Uknown Libsunperf ",
168 		    cc_version, lib_version, lib_patch,
169 		    lib_update, lib_ver_string);
170 
171 		for (j = 0; (j < LIM_CI) && (-1 != CompilerIndex[j]); j++) {
172 			printError("Expected one of the following:",
173 			    version_details[CompilerIndex[j]].cc_version,
174 			    version_details[CompilerIndex[j]].lib_version,
175 			    version_details[CompilerIndex[j]].lib_patch,
176 			    version_details[CompilerIndex[j]].lib_update,
177 			    version_details[CompilerIndex[j]].lib_ver_string);
178 		}
179 #endif
180 		return (-1);
181 	}
182 
183 	return (CompilerIndex[j]);
184 }
185