1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
10 error
- SOLARIS is
not defined
16 error
- HPUX is
not defined
21 #if !(defined(_WIN32)) && !(defined(__linux)) && !(defined(__FreeBSD__))
22 error
- None of _WIN32
, __linux
, or __FreeBSD__ is defined
28 error
- AIX is
not defined
34 error
- LINUX is
not defined
40 error
- BSDI is
not defined
46 error
- SCO is
not defined
49 #if !defined(M_UNIX) && defined(_USLC_)
51 error
- UNIXWARE is
not defined
55 #if defined(__APPLE__)
57 error
- DARWIN is
not defined
61 /************************************************************************/
63 /* Generate cpucfg.h */
67 #define INT64 _PRInt64
72 #if defined(HPUX) || defined(SCO) || defined(UNIXWARE)
75 #define INT64 long long
91 struct align_PRInt64
{
95 struct align_fakelonglong
{
105 struct align_double
{
109 struct align_pointer
{
114 #define ALIGN_OF(type) \
115 (((char*)&(((struct align_##type *)0)->a)) - ((char*)0))
119 /* Used if shell doesn't support redirection. By default, assume it does. */
122 static int Log2(int n
)
130 log2
+= 16, n
>>= 16;
147 /* We assume that int's are 32 bits */
148 static void do64(void)
156 if (u
.c
[0] == 0x01) {
157 fprintf(stream
, "#undef IS_LITTLE_ENDIAN\n");
158 fprintf(stream
, "#define IS_BIG_ENDIAN 1\n\n");
160 fprintf(stream
, "#define IS_LITTLE_ENDIAN 1\n");
161 fprintf(stream
, "#undef IS_BIG_ENDIAN\n\n");
165 static void do32(void)
173 if (u
.c
[0] == 0x01) {
174 fprintf(stream
, "#undef IS_LITTLE_ENDIAN\n");
175 fprintf(stream
, "#define IS_BIG_ENDIAN 1\n\n");
177 fprintf(stream
, "#define IS_LITTLE_ENDIAN 1\n");
178 fprintf(stream
, "#undef IS_BIG_ENDIAN\n\n");
183 ** Concievably this could actually be used; but there is lots of code out
184 ** there with and's and shift's in it that assumes a byte is 8 bits, so
185 ** forget about porting THIS code to those non 8 bit byte machines.
187 static void BitsPerByte(void)
192 int main(int argc
, char **argv
)
196 /* If we got a command line argument, try to use it as the stream. */
199 if(!(stream
= fopen ( *argv
, "wt" ))) {
200 fprintf(stderr
, "Could not write to output file %s.\n", *argv
);
207 fprintf(stream
, "#ifndef nspr_cpucfg___\n");
208 fprintf(stream
, "#define nspr_cpucfg___\n\n");
210 fprintf(stream
, "/* AUTOMATICALLY GENERATED - DO NOT EDIT */\n\n");
212 if (sizeof(long) == 8) {
217 fprintf(stream
, "#define PR_BYTES_PER_BYTE %d\n", sizeof(char));
218 fprintf(stream
, "#define PR_BYTES_PER_SHORT %d\n", sizeof(short));
219 fprintf(stream
, "#define PR_BYTES_PER_INT %d\n", sizeof(int));
220 fprintf(stream
, "#define PR_BYTES_PER_INT64 %d\n", 8);
221 fprintf(stream
, "#define PR_BYTES_PER_LONG %d\n", sizeof(long));
222 fprintf(stream
, "#define PR_BYTES_PER_FLOAT %d\n", sizeof(float));
223 fprintf(stream
, "#define PR_BYTES_PER_DOUBLE %d\n\n", sizeof(double));
225 fprintf(stream
, "#define PR_BITS_PER_BYTE %d\n", bpb
);
226 fprintf(stream
, "#define PR_BITS_PER_SHORT %d\n", bpb
* sizeof(short));
227 fprintf(stream
, "#define PR_BITS_PER_INT %d\n", bpb
* sizeof(int));
228 fprintf(stream
, "#define PR_BITS_PER_INT64 %d\n", bpb
* 8);
229 fprintf(stream
, "#define PR_BITS_PER_LONG %d\n", bpb
* sizeof(long));
230 fprintf(stream
, "#define PR_BITS_PER_FLOAT %d\n", bpb
* sizeof(float));
231 fprintf(stream
, "#define PR_BITS_PER_DOUBLE %d\n\n",
232 bpb
* sizeof(double));
234 fprintf(stream
, "#define PR_BITS_PER_BYTE_LOG2 %d\n", Log2(bpb
));
235 fprintf(stream
, "#define PR_BITS_PER_SHORT_LOG2 %d\n",
236 Log2(bpb
* sizeof(short)));
237 fprintf(stream
, "#define PR_BITS_PER_INT_LOG2 %d\n",
238 Log2(bpb
* sizeof(int)));
239 fprintf(stream
, "#define PR_BITS_PER_INT64_LOG2 %d\n", 6);
240 fprintf(stream
, "#define PR_BITS_PER_LONG_LOG2 %d\n",
241 Log2(bpb
* sizeof(long)));
242 fprintf(stream
, "#define PR_BITS_PER_FLOAT_LOG2 %d\n",
243 Log2(bpb
* sizeof(float)));
244 fprintf(stream
, "#define PR_BITS_PER_DOUBLE_LOG2 %d\n\n",
245 Log2(bpb
* sizeof(double)));
247 fprintf(stream
, "#define PR_ALIGN_OF_SHORT %d\n", ALIGN_OF(short));
248 fprintf(stream
, "#define PR_ALIGN_OF_INT %d\n", ALIGN_OF(int));
249 fprintf(stream
, "#define PR_ALIGN_OF_LONG %d\n", ALIGN_OF(long));
250 if (sizeof(INT64
) < 8) {
251 /* this machine doesn't actually support PRInt64's */
252 fprintf(stream
, "#define PR_ALIGN_OF_INT64 %d\n",
253 ALIGN_OF(fakelonglong
));
255 fprintf(stream
, "#define PR_ALIGN_OF_INT64 %d\n", ALIGN_OF(PRInt64
));
257 fprintf(stream
, "#define PR_ALIGN_OF_FLOAT %d\n", ALIGN_OF(float));
258 fprintf(stream
, "#define PR_ALIGN_OF_DOUBLE %d\n", ALIGN_OF(double));
259 fprintf(stream
, "#define PR_ALIGN_OF_POINTER %d\n\n", ALIGN_OF(pointer
));
261 fprintf(stream
, "#endif /* nspr_cpucfg___ */\n");