Mercurial > hg > xemacs-beta
comparison lib-src/ellcc.c @ 424:11054d720c21 r21-2-20
Import from CVS: tag r21-2-20
author | cvs |
---|---|
date | Mon, 13 Aug 2007 11:26:11 +0200 |
parents | 697ef44129c6 |
children |
comparison
equal
deleted
inserted
replaced
423:28d9c139be4c | 424:11054d720c21 |
---|---|
22 Please mail bugs and suggestions to the XEmacs maintainer. | 22 Please mail bugs and suggestions to the XEmacs maintainer. |
23 */ | 23 */ |
24 | 24 |
25 /* | 25 /* |
26 Here's the scoop. We would really like this to be a shell script, but | 26 Here's the scoop. We would really like this to be a shell script, but |
27 the various Windows platforms dont have reliable scripting that suits | 27 the various Windows platforms don't have reliable scripting that suits |
28 our needs. We dont want to reply on perl or some other such language | 28 our needs. We don't want to rely on perl or some other such language |
29 so we have to roll our own executable to act as a front-end for the | 29 so we have to roll our own executable to act as a front-end for the |
30 compiler. | 30 compiler. |
31 | 31 |
32 This program is used to invoke the compiler, the linker and to generate | 32 This program is used to invoke the compiler, the linker and to generate |
33 the module specific documentation and initialization code. We assume we | 33 the module specific documentation and initialization code. We assume we |
56 -o $@ $(SRCS) | 56 -o $@ $(SRCS) |
57 | 57 |
58 See the samples for more details. | 58 See the samples for more details. |
59 */ | 59 */ |
60 | 60 |
61 #include <../src/config.h> | |
61 #include <stdio.h> | 62 #include <stdio.h> |
62 #include <stdlib.h> | 63 #include <stdlib.h> |
63 | |
64 #ifdef MSDOS | |
65 # include <fcntl.h> | |
66 # include <sys/param.h> | |
67 # include <io.h> | |
68 # ifndef HAVE_CONFIG_H | |
69 # define DOS_NT | |
70 # include <sys/config.h> | |
71 # endif | |
72 #endif /* MSDOS */ | |
73 | |
74 #ifdef WINDOWSNT | |
75 # include <stdlib.h> | |
76 # include <fcntl.h> | |
77 # include <string.h> | |
78 # include <io.h> | |
79 # define MAXPATHLEN _MAX_PATH | |
80 # ifdef HAVE_CONFIG_H | |
81 # undef HAVE_NTGUI | |
82 # else | |
83 # define DOS_NT | |
84 # define HAVE_GETCWD | |
85 # endif /* not HAVE_CONFIG_H */ | |
86 #endif /* WINDOWSNT */ | |
87 | |
88 #ifdef HAVE_CONFIG_H | |
89 # include <config.h> | |
90 /* On some systems, Emacs defines static as nothing for the sake | |
91 of unexec. We don't want that here since we don't use unexec. */ | |
92 # undef static | |
93 #endif /* HAVE_CONFIG_H */ | |
94 | |
95 #if !defined (WINDOWSNT) && defined (STDC_HEADERS) | |
96 #include <stdlib.h> | |
97 #include <string.h> | 64 #include <string.h> |
98 #endif | 65 #include <ctype.h> |
66 #include <errno.h> | |
67 #include <sys/types.h> | |
99 | 68 |
100 #ifdef HAVE_UNISTD_H | 69 #ifdef HAVE_UNISTD_H |
101 # include <unistd.h> | 70 # include <unistd.h> |
102 #else | |
103 # ifdef HAVE_GETCWD | |
104 extern char *getcwd (); | |
105 # endif | |
106 #endif /* HAVE_UNISTD_H */ | 71 #endif /* HAVE_UNISTD_H */ |
107 | |
108 #include <stdio.h> | |
109 #include <ctype.h> | |
110 #include <errno.h> | |
111 #ifndef errno | |
112 extern int errno; | |
113 #endif | |
114 #include <sys/types.h> | |
115 #include <sys/stat.h> | |
116 | 72 |
117 #define EMODULES_GATHER_VERSION | 73 #define EMODULES_GATHER_VERSION |
118 #include "emodules.h" | 74 #include "emodules.h" |
119 #include "ellcc.h" | 75 #include "ellcc.h" |
120 | 76 |
121 #if !defined (S_ISREG) && defined (S_IFREG) | |
122 # define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) | |
123 #endif | |
124 | |
125 /* Exit codes for success and failure. */ | |
126 #ifdef VMS | |
127 # define GOOD 1 | |
128 # define BAD 0 | |
129 #else | |
130 # define GOOD 0 | |
131 # define BAD 1 | |
132 #endif | |
133 | |
134 #define DEBUG | 77 #define DEBUG |
135 | 78 |
136 #ifndef HAVE_SHLIB | 79 #ifndef HAVE_SHLIB |
137 int | 80 int |
138 main() | 81 main (int argc, char *argv[]) |
139 { | 82 { |
140 fprintf (stderr, "Dynamic modules not supported on this platform\n"); | 83 fprintf (stderr, "Dynamic modules not supported on this platform\n"); |
141 return (BAD); | 84 return EXIT_FAILURE; |
142 } | 85 } |
143 #else | 86 #else |
144 | 87 |
145 /* | 88 /* |
146 * Try to figure out the commands we need to use to create shared objects, | 89 * Try to figure out the commands we need to use to create shared objects, |
161 (op), (n) * sizeof (Type))) | 104 (op), (n) * sizeof (Type))) |
162 #else | 105 #else |
163 # define xnew(n,Type) ((Type *) xmalloc ((n) * sizeof (Type))) | 106 # define xnew(n,Type) ((Type *) xmalloc ((n) * sizeof (Type))) |
164 # define xrnew(op,n,Type) ((Type *) xrealloc ((op), (n) * sizeof (Type))) | 107 # define xrnew(op,n,Type) ((Type *) xrealloc ((op), (n) * sizeof (Type))) |
165 #endif | 108 #endif |
166 long *xmalloc (), *xrealloc (); | 109 static void *xmalloc (size_t); |
167 void fatal (), pfatal (); | 110 static void fatal (char *, char *); |
168 char *ellcc_strchr (), *ellcc_strrchr (); | 111 static void add_to_argv (CONST char *); |
169 void add_to_argv (); | 112 static void do_compile_mode (void); |
170 void do_compile_mode(), do_link_mode(), do_init_mode(); | 113 static void do_link_mode (void); |
114 static void do_init_mode (void); | |
171 | 115 |
172 #define SSTR(S) ((S)?(S):"") | 116 #define SSTR(S) ((S)?(S):"") |
173 | 117 |
174 #define ELLCC_COMPILE_MODE 0 | 118 #define ELLCC_COMPILE_MODE 0 |
175 #define ELLCC_LINK_MODE 1 | 119 #define ELLCC_LINK_MODE 1 |
194 STR = getenv(EVAR); \ | 138 STR = getenv(EVAR); \ |
195 if ((STR) == (char *)0) \ | 139 if ((STR) == (char *)0) \ |
196 STR = DFLT | 140 STR = DFLT |
197 | 141 |
198 int | 142 int |
199 main (argc, argv) | 143 main (int argc, char *argv[]) |
200 int argc; | |
201 char *argv[]; | |
202 { | 144 { |
203 char *tmp; | 145 char *tmp; |
204 int i, done_mode = 0; | 146 int i, done_mode = 0; |
205 | 147 |
206 prog_argc = argc; | 148 prog_argc = argc; |
207 prog_argv = argv; | 149 prog_argv = argv; |
208 | 150 |
209 #if defined(MSDOS) || defined(WINDOWSNT) | 151 #if defined(MSDOS) || defined(WINDOWSNT) |
210 tmp = ellcc_strrchr (argv[0], '\\'); | 152 tmp = strrchr (argv[0], '\\'); |
211 if (tmp != (char *)0) | 153 if (tmp != (char *)0) |
212 tmp++; | 154 tmp++; |
213 #elif !defined (VMS) | 155 #elif !defined (VMS) |
214 tmp = ellcc_strrchr (argv[0], '/'); | 156 tmp = strrchr (argv[0], '/'); |
215 if (tmp != (char *)0) | 157 if (tmp != (char *)0) |
216 tmp++; | 158 tmp++; |
217 #else | 159 #else |
218 tmp = argv[0]; | 160 tmp = argv[0]; |
219 #endif | 161 #endif |
246 if (strncmp (argv[i], "--mode=", 7) == 0) | 188 if (strncmp (argv[i], "--mode=", 7) == 0) |
247 { | 189 { |
248 char *modeopt = argv[i] + 7; | 190 char *modeopt = argv[i] + 7; |
249 | 191 |
250 if (done_mode && strcmp (modeopt, "verbose")) | 192 if (done_mode && strcmp (modeopt, "verbose")) |
251 fatal ("more than one mode specified"); | 193 fatal ("more than one mode specified", (char *) 0); |
252 if (strcmp (modeopt, "link") == 0) | 194 if (strcmp (modeopt, "link") == 0) |
253 { | 195 { |
254 done_mode++; | 196 done_mode++; |
255 ellcc_mode = ELLCC_LINK_MODE; | 197 ellcc_mode = ELLCC_LINK_MODE; |
256 } | 198 } |
285 else if (strcmp (argv[i], "--mod-config") == 0) | 227 else if (strcmp (argv[i], "--mod-config") == 0) |
286 { | 228 { |
287 printf ("%s\n", ELLCC_CONFIG); | 229 printf ("%s\n", ELLCC_CONFIG); |
288 return 0; | 230 return 0; |
289 } | 231 } |
290 else if (strncmp (argv[i], "--mod-name=", 10) == 0) | 232 else if (strncmp (argv[i], "--mod-name=", 11) == 0) |
291 mod_name = argv[i] + 11; | 233 mod_name = argv[i] + 11; |
292 else if (strncmp (argv[i], "--mod-title=", 11) == 0) | 234 else if (strncmp (argv[i], "--mod-title=", 12) == 0) |
293 mod_title = argv[i] + 12; | 235 mod_title = argv[i] + 12; |
294 else if (strncmp (argv[i], "--mod-version=", 13) == 0) | 236 else if (strncmp (argv[i], "--mod-version=", 14) == 0) |
295 mod_version = argv[i] + 14; | 237 mod_version = argv[i] + 14; |
296 else if (strncmp (argv[i], "--mod-output=", 12) == 0) | 238 else if (strncmp (argv[i], "--mod-output=", 13) == 0) |
297 mod_output = argv[i] + 13; | 239 mod_output = argv[i] + 13; |
298 else | 240 else |
299 { | 241 { |
300 exec_args[exec_argc] = i; | 242 exec_args[exec_argc] = i; |
301 exec_argc++; | 243 exec_argc++; |
337 printf ("\n"); | 279 printf ("\n"); |
338 } | 280 } |
339 #endif | 281 #endif |
340 | 282 |
341 if (exec_argc < 2) | 283 if (exec_argc < 2) |
342 fatal ("too few arguments"); | 284 fatal ("too few arguments", (char *) 0); |
343 | 285 |
344 /* | 286 /* |
345 * Get the over-rides from the environment | 287 * Get the over-rides from the environment |
346 */ | 288 */ |
347 OVERENV(ellcc, "ELLCC", ELLCC_CC); | 289 OVERENV(ellcc, "ELLCC", ELLCC_CC); |
376 printf ("%s exited with status %d\n", exec_argv[0], i); | 318 printf ("%s exited with status %d\n", exec_argv[0], i); |
377 return i; | 319 return i; |
378 } | 320 } |
379 | 321 |
380 /* Like malloc but get fatal error if memory is exhausted. */ | 322 /* Like malloc but get fatal error if memory is exhausted. */ |
381 long * | 323 static void * |
382 xmalloc (size) | 324 xmalloc (size_t size) |
383 unsigned int size; | 325 { |
384 { | 326 void *result = malloc (size); |
385 long *result = (long *) malloc (size); | |
386 if (result == NULL) | 327 if (result == NULL) |
387 fatal ("virtual memory exhausted", (char *)NULL); | 328 fatal ("virtual memory exhausted", (char *)0); |
388 return result; | 329 return result; |
389 } | 330 } |
390 | 331 |
391 long * | |
392 xrealloc (ptr, size) | |
393 char *ptr; | |
394 unsigned int size; | |
395 { | |
396 long *result = (long *) realloc (ptr, size); | |
397 if (result == NULL) | |
398 fatal ("virtual memory exhausted", (char *)NULL); | |
399 return result; | |
400 } | |
401 | |
402 /* Print error message and exit. */ | 332 /* Print error message and exit. */ |
403 void | 333 static void |
404 fatal (s1, s2) | 334 fatal (char *s1, char *s2) |
405 char *s1, *s2; | |
406 { | 335 { |
407 fprintf (stderr, "%s: ", progname); | 336 fprintf (stderr, "%s: ", progname); |
408 fprintf (stderr, s1, s2); | 337 fprintf (stderr, s1, s2); |
409 fprintf (stderr, "\n"); | 338 fprintf (stderr, "\n"); |
410 exit (BAD); | 339 exit (EXIT_FAILURE); |
411 } | |
412 | |
413 void | |
414 pfatal (s1) | |
415 char *s1; | |
416 { | |
417 perror (s1); | |
418 exit (BAD); | |
419 } | |
420 | |
421 /* | |
422 * Return the ptr in sp at which the character c last | |
423 * appears; NULL if not found | |
424 * | |
425 * Identical to System V strrchr, included for portability. | |
426 */ | |
427 char * | |
428 ellcc_strrchr (sp, c) | |
429 register char *sp, c; | |
430 { | |
431 register char *r; | |
432 | |
433 r = NULL; | |
434 do | |
435 { | |
436 if (*sp == c) | |
437 r = sp; | |
438 } while (*sp++); | |
439 return r; | |
440 } | |
441 | |
442 /* | |
443 * Return the ptr in sp at which the character c first | |
444 * appears; NULL if not found | |
445 * | |
446 * Identical to System V strchr, included for portability. | |
447 */ | |
448 char * | |
449 ellcc_strchr (sp, c) | |
450 register char *sp, c; | |
451 { | |
452 do | |
453 { | |
454 if (*sp == c) | |
455 return sp; | |
456 } while (*sp++); | |
457 return NULL; | |
458 } | 340 } |
459 | 341 |
460 /* | 342 /* |
461 * Add a string to the argument vector list that will be passed on down | 343 * Add a string to the argument vector list that will be passed on down |
462 * to the compiler or linker. We need to split individual words into | 344 * to the compiler or linker. We need to split individual words into |
463 * arguments, taking quoting into account. This can get ugly. | 345 * arguments, taking quoting into account. This can get ugly. |
464 */ | 346 */ |
465 void | 347 static void |
466 add_to_argv (str) | 348 add_to_argv (CONST char *str) |
467 CONST char *str; | |
468 { | 349 { |
469 int sm = 0; | 350 int sm = 0; |
470 CONST char *s = (CONST char *)0; | 351 CONST char *s = (CONST char *)0; |
471 | 352 |
472 if ((str == (CONST char *)0) || (str[0] == '\0')) | 353 if ((str == (CONST char *)0) || (str[0] == '\0')) |
555 /* | 436 /* |
556 * For compile mode, things are pretty straight forward. All we need to do | 437 * For compile mode, things are pretty straight forward. All we need to do |
557 * is build up the argument vector and exec() it. We must just make sure | 438 * is build up the argument vector and exec() it. We must just make sure |
558 * that we get all of the required arguments in place. | 439 * that we get all of the required arguments in place. |
559 */ | 440 */ |
560 void | 441 static void |
561 do_compile_mode() | 442 do_compile_mode (void) |
562 { | 443 { |
563 int i; | 444 int i; |
564 char ts[4096]; /* Plenty big enough */ | 445 char ts[4096]; /* Plenty big enough */ |
565 | 446 |
566 add_to_argv (ellcc); | 447 add_to_argv (ellcc); |
585 * insert the linker commands first, replace any occurrence of ELLSONAME | 466 * insert the linker commands first, replace any occurrence of ELLSONAME |
586 * with the desired output file name, insert the output arguments, then | 467 * with the desired output file name, insert the output arguments, then |
587 * all of the provided arguments, then the final post arguments. Once | 468 * all of the provided arguments, then the final post arguments. Once |
588 * all of this has been done, the argument vector is ready to run. | 469 * all of this has been done, the argument vector is ready to run. |
589 */ | 470 */ |
590 void | 471 static void |
591 do_link_mode() | 472 do_link_mode (void) |
592 { | 473 { |
593 int i,x; | 474 int i,x; |
594 char *t, ts[4096]; /* Plenty big enough */ | 475 char *t, ts[4096]; /* Plenty big enough */ |
595 | 476 |
596 add_to_argv (ellld); | 477 add_to_argv (ellld); |
646 * passed on the command line are the names of source files which the | 527 * passed on the command line are the names of source files which the |
647 * make-doc program will be processing. We prepare the output file with | 528 * make-doc program will be processing. We prepare the output file with |
648 * the header information first, as make-doc will append to the file by | 529 * the header information first, as make-doc will append to the file by |
649 * special dispensation. | 530 * special dispensation. |
650 */ | 531 */ |
651 void | 532 static void |
652 do_init_mode() | 533 do_init_mode (void) |
653 { | 534 { |
654 int i; | 535 int i; |
655 char ts[4096]; /* Plenty big enough */ | 536 char ts[4096]; /* Plenty big enough */ |
656 char *mdocprog; | 537 char *mdocprog; |
657 FILE *mout = fopen (mod_output, "w"); | 538 FILE *mout = fopen (mod_output, "w"); |