Bug 1804489 - Disable browser_dbg-inspector-integration.js on all platforms because...
[gecko.git] / nsprpub / pr / include / gencfg.c
blob3a67e9113e4700e4e79f12c9674b5c2850c9f3b1
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/. */
6 #include <stdio.h>
8 #if defined(__sun)
9 #ifndef SOLARIS
10 error - SOLARIS is not defined
11 #endif
12 #endif
14 #if defined(__hpux)
15 #ifndef HPUX
16 error - HPUX is not defined
17 #endif
18 #endif
20 #if defined(__alpha)
21 #if !(defined(_WIN32)) && !(defined(__linux)) && !(defined(__FreeBSD__))
22 error - None of _WIN32, __linux, or __FreeBSD__ is defined
23 #endif
24 #endif
26 #if defined(_IBMR2)
27 #ifndef AIX
28 error - AIX is not defined
29 #endif
30 #endif
32 #if defined(linux)
33 #ifndef LINUX
34 error - LINUX is not defined
35 #endif
36 #endif
38 #if defined(bsdi)
39 #ifndef BSDI
40 error - BSDI is not defined
41 #endif
42 #endif
44 #if defined(M_UNIX)
45 #ifndef SCO
46 error - SCO is not defined
47 #endif
48 #endif
49 #if !defined(M_UNIX) && defined(_USLC_)
50 #ifndef UNIXWARE
51 error - UNIXWARE is not defined
52 #endif
53 #endif
55 #if defined(__APPLE__)
56 #ifndef DARWIN
57 error - DARWIN is not defined
58 #endif
59 #endif
61 /************************************************************************/
63 /* Generate cpucfg.h */
65 #ifdef XP_PC
66 #ifdef WIN32
67 #define INT64 _PRInt64
68 #else
69 #define INT64 long
70 #endif
71 #else
72 #if defined(HPUX) || defined(SCO) || defined(UNIXWARE)
73 #define INT64 long
74 #else
75 #define INT64 long long
76 #endif
77 #endif
79 struct align_short {
80 char c;
81 short a;
83 struct align_int {
84 char c;
85 int a;
87 struct align_long {
88 char c;
89 long a;
91 struct align_PRInt64 {
92 char c;
93 INT64 a;
95 struct align_fakelonglong {
96 char c;
97 struct {
98 long hi, lo;
99 } a;
101 struct align_float {
102 char c;
103 float a;
105 struct align_double {
106 char c;
107 double a;
109 struct align_pointer {
110 char c;
111 void *a;
114 #define ALIGN_OF(type) \
115 (((char*)&(((struct align_##type *)0)->a)) - ((char*)0))
117 int bpb;
119 /* Used if shell doesn't support redirection. By default, assume it does. */
120 FILE *stream;
122 static int Log2(int n)
124 int log2 = 0;
126 if (n & (n-1)) {
127 log2++;
129 if (n >> 16) {
130 log2 += 16, n >>= 16;
132 if (n >> 8) {
133 log2 += 8, n >>= 8;
135 if (n >> 4) {
136 log2 += 4, n >>= 4;
138 if (n >> 2) {
139 log2 += 2, n >>= 2;
141 if (n >> 1) {
142 log2++;
144 return log2;
147 /* We assume that int's are 32 bits */
148 static void do64(void)
150 union {
151 int i;
152 char c[4];
153 } u;
155 u.i = 0x01020304;
156 if (u.c[0] == 0x01) {
157 fprintf(stream, "#undef IS_LITTLE_ENDIAN\n");
158 fprintf(stream, "#define IS_BIG_ENDIAN 1\n\n");
159 } else {
160 fprintf(stream, "#define IS_LITTLE_ENDIAN 1\n");
161 fprintf(stream, "#undef IS_BIG_ENDIAN\n\n");
165 static void do32(void)
167 union {
168 long i;
169 char c[4];
170 } u;
172 u.i = 0x01020304;
173 if (u.c[0] == 0x01) {
174 fprintf(stream, "#undef IS_LITTLE_ENDIAN\n");
175 fprintf(stream, "#define IS_BIG_ENDIAN 1\n\n");
176 } else {
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)
189 bpb = 8;
192 int main(int argc, char **argv)
194 BitsPerByte();
196 /* If we got a command line argument, try to use it as the stream. */
197 ++argv;
198 if(*argv) {
199 if(!(stream = fopen ( *argv, "wt" ))) {
200 fprintf(stderr, "Could not write to output file %s.\n", *argv);
201 return 1;
203 } else {
204 stream = stdout;
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) {
213 do64();
214 } else {
215 do32();
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));
254 } else {
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");
262 fclose(stream);
264 return 0;