xref: /onnv-gate/usr/src/cmd/fps/compilercheck/fps_compiler_check.c (revision 9271:d16e1d723aba)
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 - SS13 */
70 	{0, 0, 0, 0, NULL}
71 };
72 
73 
74 #if 0
75 static void printError(
76 char *Uknown, long cc_version, long lib_version,
77 long lib_patch, long lib_update, char *lib_ver_string)
78 {
79 	if ((NULL != Uknown) && (NULL != lib_ver_string))
80 	printf("\n %s \n Compiler = 0x%x \n lib_version = %ld 0x%lx \
81 	\n lib_patch = %ld  0x%lx \n lib_update = %ld  0x%lx \
82 	\n lib_ver_string = %s\n",
83 	    Unknown, cc_version, lib_version, lib_version, lib_patch,
84 	    lib_patch, lib_update, lib_update, lib_ver_string);
85 }
86 #endif
87 
88 
89 int
90 main()
91 {
92 	char *lib_ver_string = NULL;
93 	long cc_version, lib_version, lib_patch, lib_update;
94 	int i, k, j, TableElem;
95 	int CompilerIndex[LIM_CI];
96 
97 
98 	/* Initialize */
99 	cc_version = lib_version = lib_patch = lib_update = 0;
100 	TableElem = sizeof (version_details) / sizeof (v_d);
101 	for (i = 0; i < LIM_CI; i++) CompilerIndex[i] = -1;
102 
103 	/* get the info about the current compiler and libsunperf */
104 #ifndef __lint
105 	lib_ver_string =
106 	    sunperf_version_64(&lib_version, &lib_patch, &lib_update);
107 #endif
108 	cc_version = __SUNPRO_C;
109 
110 	for (i = 0; i < TableElem; i++) {
111 		if (version_details[i].cc_version == cc_version) break;
112 	}
113 
114 
115 	/* Check the compiler  __SUNPRO_C  version */
116 	if ((i - TableElem > 0) ||
117 	    (cc_version != version_details[i].cc_version)) {
118 #if 0
119 		printError("Unknown",
120 		    cc_version, lib_version, lib_patch,
121 		    lib_update, lib_ver_string);
122 #endif
123 	return (-1);
124 	}
125 
126 	/*
127 	 * We have at least one line in the table that has info
128 	 * about this compiler. Let's see how many lines with details
129 	 * about this compiler do we have. Store the indexes.
130 	 */
131 	for (k = 0, j = 0; (k < TableElem) && (j < LIM_CI); k++) {
132 		if (version_details[k].cc_version == cc_version) {
133 			CompilerIndex[j++] = k;
134 		}
135 	}
136 
137 
138 	/*
139 	 * We have a  compiler with an known  __SUNPRO_C
140 	 * Check the libsunperf version, patch, update and version string
141 	 */
142 
143 	for (j = 0; (j < LIM_CI) && (-1 != CompilerIndex[j]); j++) {
144 		if (strlen(version_details[CompilerIndex[j]].lib_ver_string) !=
145 		    strlen(lib_ver_string))
146 	continue;
147 		if (
148 		    (0 !=
149 		    strcmp(version_details[CompilerIndex[j]].lib_ver_string,
150 		    lib_ver_string))	||
151 		    (version_details[CompilerIndex[j]].lib_version	!=
152 		    lib_version) 		||
153 		    (version_details[CompilerIndex[j]].lib_patch 	!=
154 		    lib_patch)			||
155 		    (version_details[CompilerIndex[j]].lib_update	!=
156 		    lib_update)) {
157 			continue;
158 		} else {
159 			break;
160 		}
161 	}
162 
163 	if (-1 == CompilerIndex[j]) {
164 #if 0
165 		printError("Uknown Libsunperf ",
166 		    cc_version, lib_version, lib_patch,
167 		    lib_update, lib_ver_string);
168 
169 		for (j = 0; (j < LIM_CI) && (-1 != CompilerIndex[j]); j++) {
170 			printError("Expected one of the following:",
171 			    version_details[CompilerIndex[j]].cc_version,
172 			    version_details[CompilerIndex[j]].lib_version,
173 			    version_details[CompilerIndex[j]].lib_patch,
174 			    version_details[CompilerIndex[j]].lib_update,
175 			    version_details[CompilerIndex[j]].lib_ver_string);
176 		}
177 #endif
178 		return (-1);
179 	}
180 
181 	return (CompilerIndex[j]);
182 }
183