1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is the Netscape Portable Runtime (NSPR).
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998-2000
20 * the Initial Developer. All Rights Reserved.
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
42 error
- IRIX is
not defined
47 #if defined(__svr4) || defined(__svr4__) || defined(__SVR4)
49 error
- SOLARIS is
not defined
53 error
- SUNOS4 is
not defined
60 error
- HPUX is
not defined
65 #if !(defined(_WIN32)) && !(defined(OSF1)) && !(defined(__linux)) && !(defined(__FreeBSD__))
66 error
- None of OSF1
, _WIN32
, __linux
, or __FreeBSD__ is defined
72 error
- AIX is
not defined
78 error
- LINUX is
not defined
84 error
- BSDI is
not defined
90 error
- SCO is
not defined
93 #if !defined(M_UNIX) && defined(_USLC_)
95 error
- UNIXWARE is
not defined
99 #if defined(__APPLE__)
101 error
- DARWIN is
not defined
105 #if defined(__NeXT__)
107 error
- NEXTSTEP is
not defined
111 /************************************************************************/
113 /* Generate cpucfg.h */
117 #define INT64 _PRInt64
122 #if defined(HPUX) || defined(NECSVR4) || defined(SCO) || defined(UNIXWARE) || defined (NCR)
125 #define INT64 long long
141 struct align_PRInt64
{
145 struct align_fakelonglong
{
155 struct align_double
{
159 struct align_pointer
{
164 #define ALIGN_OF(type) \
165 (((char*)&(((struct align_##type *)0)->a)) - ((char*)0))
169 /* Used if shell doesn't support redirection. By default, assume it does. */
172 static int Log2(int n
)
179 log2
+= 16, n
>>= 16;
191 /* We assume that int's are 32 bits */
192 static void do64(void)
200 if (u
.c
[0] == 0x01) {
201 fprintf(stream
, "#undef IS_LITTLE_ENDIAN\n");
202 fprintf(stream
, "#define IS_BIG_ENDIAN 1\n\n");
204 fprintf(stream
, "#define IS_LITTLE_ENDIAN 1\n");
205 fprintf(stream
, "#undef IS_BIG_ENDIAN\n\n");
209 static void do32(void)
217 if (u
.c
[0] == 0x01) {
218 fprintf(stream
, "#undef IS_LITTLE_ENDIAN\n");
219 fprintf(stream
, "#define IS_BIG_ENDIAN 1\n\n");
221 fprintf(stream
, "#define IS_LITTLE_ENDIAN 1\n");
222 fprintf(stream
, "#undef IS_BIG_ENDIAN\n\n");
227 ** Concievably this could actually be used; but there is lots of code out
228 ** there with and's and shift's in it that assumes a byte is 8 bits, so
229 ** forget about porting THIS code to those non 8 bit byte machines.
231 static void BitsPerByte(void)
236 int main(int argc
, char **argv
)
240 /* If we got a command line argument, try to use it as the stream. */
243 if(!(stream
= fopen ( *argv
, "wt" ))) {
244 fprintf(stderr
, "Could not write to output file %s.\n", *argv
);
251 fprintf(stream
, "#ifndef nspr_cpucfg___\n");
252 fprintf(stream
, "#define nspr_cpucfg___\n\n");
254 fprintf(stream
, "/* AUTOMATICALLY GENERATED - DO NOT EDIT */\n\n");
256 if (sizeof(long) == 8) {
261 fprintf(stream
, "#define PR_BYTES_PER_BYTE %d\n", sizeof(char));
262 fprintf(stream
, "#define PR_BYTES_PER_SHORT %d\n", sizeof(short));
263 fprintf(stream
, "#define PR_BYTES_PER_INT %d\n", sizeof(int));
264 fprintf(stream
, "#define PR_BYTES_PER_INT64 %d\n", 8);
265 fprintf(stream
, "#define PR_BYTES_PER_LONG %d\n", sizeof(long));
266 fprintf(stream
, "#define PR_BYTES_PER_FLOAT %d\n", sizeof(float));
267 fprintf(stream
, "#define PR_BYTES_PER_DOUBLE %d\n\n", sizeof(double));
269 fprintf(stream
, "#define PR_BITS_PER_BYTE %d\n", bpb
);
270 fprintf(stream
, "#define PR_BITS_PER_SHORT %d\n", bpb
* sizeof(short));
271 fprintf(stream
, "#define PR_BITS_PER_INT %d\n", bpb
* sizeof(int));
272 fprintf(stream
, "#define PR_BITS_PER_INT64 %d\n", bpb
* 8);
273 fprintf(stream
, "#define PR_BITS_PER_LONG %d\n", bpb
* sizeof(long));
274 fprintf(stream
, "#define PR_BITS_PER_FLOAT %d\n", bpb
* sizeof(float));
275 fprintf(stream
, "#define PR_BITS_PER_DOUBLE %d\n\n",
276 bpb
* sizeof(double));
278 fprintf(stream
, "#define PR_BITS_PER_BYTE_LOG2 %d\n", Log2(bpb
));
279 fprintf(stream
, "#define PR_BITS_PER_SHORT_LOG2 %d\n",
280 Log2(bpb
* sizeof(short)));
281 fprintf(stream
, "#define PR_BITS_PER_INT_LOG2 %d\n",
282 Log2(bpb
* sizeof(int)));
283 fprintf(stream
, "#define PR_BITS_PER_INT64_LOG2 %d\n", 6);
284 fprintf(stream
, "#define PR_BITS_PER_LONG_LOG2 %d\n",
285 Log2(bpb
* sizeof(long)));
286 fprintf(stream
, "#define PR_BITS_PER_FLOAT_LOG2 %d\n",
287 Log2(bpb
* sizeof(float)));
288 fprintf(stream
, "#define PR_BITS_PER_DOUBLE_LOG2 %d\n\n",
289 Log2(bpb
* sizeof(double)));
291 fprintf(stream
, "#define PR_ALIGN_OF_SHORT %d\n", ALIGN_OF(short));
292 fprintf(stream
, "#define PR_ALIGN_OF_INT %d\n", ALIGN_OF(int));
293 fprintf(stream
, "#define PR_ALIGN_OF_LONG %d\n", ALIGN_OF(long));
294 if (sizeof(INT64
) < 8) {
295 /* this machine doesn't actually support PRInt64's */
296 fprintf(stream
, "#define PR_ALIGN_OF_INT64 %d\n",
297 ALIGN_OF(fakelonglong
));
299 fprintf(stream
, "#define PR_ALIGN_OF_INT64 %d\n", ALIGN_OF(PRInt64
));
301 fprintf(stream
, "#define PR_ALIGN_OF_FLOAT %d\n", ALIGN_OF(float));
302 fprintf(stream
, "#define PR_ALIGN_OF_DOUBLE %d\n", ALIGN_OF(double));
303 fprintf(stream
, "#define PR_ALIGN_OF_POINTER %d\n\n", ALIGN_OF(pointer
));
305 fprintf(stream
, "#endif /* nspr_cpucfg___ */\n");