428
|
1 /* ellcc.c - front-end for compiling Emacs modules
|
|
2 Copyright (C) 1998, 1999 J. Kean Johnston.
|
996
|
3 Copyright (C) 2002 Jerry James.
|
428
|
4
|
|
5 This file is part of XEmacs.
|
|
6
|
|
7 XEmacs is free software; you can redistribute it and/or modify it
|
|
8 under the terms of the GNU General Public License as published by the
|
|
9 Free Software Foundation; either version 2, or (at your option) any
|
|
10 later version.
|
|
11
|
|
12 XEmacs is distributed in the hope that it will be useful, but WITHOUT
|
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
15 for more details.
|
|
16
|
|
17 You should have received a copy of the GNU General Public License
|
|
18 along with XEmacs; see the file COPYING. If not, write to
|
|
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
20 Boston, MA 02111-1307, USA.
|
|
21
|
|
22 Author: J. Kean Johnston (jkj@sco.com).
|
|
23 Please mail bugs and suggestions to the XEmacs maintainer.
|
|
24 */
|
|
25
|
|
26 /*
|
|
27 Here's the scoop. We would really like this to be a shell script, but
|
|
28 the various Windows platforms don't have reliable scripting that suits
|
|
29 our needs. We don't want to rely on perl or some other such language
|
|
30 so we have to roll our own executable to act as a front-end for the
|
|
31 compiler.
|
|
32
|
|
33 This program is used to invoke the compiler, the linker and to generate
|
|
34 the module specific documentation and initialization code. We assume we
|
|
35 are in 'compile' mode unless we encounter an argument which tells us
|
|
36 that we're not. We take all arguments and pass them on directly to the
|
|
37 compiler, except for a few which are specific to this program:
|
|
38
|
|
39 --mode=VALUE This sets the program mode. VALUE can be one of
|
|
40 compile, link, init or verbose.
|
|
41 --mod-name=NAME Sets the module name to the string NAME.
|
|
42 --mod-title=TITLE Sets the module title to the string TITLE.
|
|
43 --mod-version=VER Sets the module version to the string VER.
|
|
44
|
|
45 The idea is that Makefiles will use ellcc as the compiler for making
|
|
46 dynamic Emacs modules, and life should be as simple as:
|
|
47
|
|
48 make CC=ellcc LD='ellcc --mode=link'
|
|
49
|
|
50 The only additional requirement is an entry in the Makefile to produce
|
|
51 the module initialization file, which will usually be something along
|
|
52 the lines of:
|
|
53
|
|
54 modinit.c: $(SRCS)
|
|
55 ellcc --mode=init --mod-name=\"$(MODNAME)\" \
|
|
56 --mod-title=\"$(MODTITLE)\" --mod-version=\"$(MODVERSION)\" \
|
|
57 -o $@ $(SRCS)
|
|
58
|
|
59 See the samples for more details.
|
|
60 */
|
|
61
|
438
|
62 #include <config.h>
|
428
|
63 #include <stdio.h>
|
|
64 #include <stdlib.h>
|
442
|
65 #include <stddef.h>
|
996
|
66 #include <stdarg.h>
|
428
|
67 #include <string.h>
|
|
68 #include <ctype.h>
|
|
69 #include <errno.h>
|
|
70 #include <sys/types.h>
|
|
71
|
|
72 #ifdef HAVE_UNISTD_H
|
|
73 # include <unistd.h>
|
|
74 #endif /* HAVE_UNISTD_H */
|
|
75
|
|
76 #define EMODULES_GATHER_VERSION
|
996
|
77 #define EXEC_GROW_SIZE 4
|
438
|
78
|
|
79 #include <emodules.h>
|
|
80 #include <ellcc.h> /* Generated files must be included using <...> */
|
428
|
81
|
1506
|
82 #ifndef ATTRIBUTE_MALLOC
|
|
83 # if defined(__GNUC__) && (__GNUC__ > 2 || (__GNUC__==2 && __GNUC_MINOR__>=96))
|
|
84 # define ATTRIBUTE_MALLOC __attribute__ ((__malloc__))
|
|
85 # else
|
|
86 # define ATTRIBUTE_MALLOC
|
|
87 # endif /* GCC version >= 2.96 */
|
|
88 #endif /* ATTRIBUTE_MALLOC */
|
|
89
|
|
90 #ifdef __GNUC_
|
|
91 # define ATTRIBUTE_FATAL __attribute__ ((noreturn, format (printf, 1, 2)))
|
|
92 #else
|
|
93 # define ATTRIBUTE_FATAL
|
|
94 #endif /* __GNUC__ */
|
|
95
|
|
96 #if defined(__GNUC__) && (__GNUC__ >= 2 || (__GNUC__==2 && __GNUC_MINOR__>=5))
|
|
97 # define ATTRIBUTE_CONST __attribute__ ((const))
|
|
98 #else
|
|
99 # define ATTRIBUTE_CONST
|
|
100 #endif
|
|
101
|
|
102
|
428
|
103 #ifndef HAVE_SHLIB
|
|
104 int
|
|
105 main (int argc, char *argv[])
|
|
106 {
|
|
107 fprintf (stderr, "Dynamic modules not supported on this platform\n");
|
|
108 return EXIT_FAILURE;
|
|
109 }
|
|
110 #else
|
|
111
|
|
112 /*
|
|
113 * Try to figure out the commands we need to use to create shared objects,
|
|
114 * and how to compile for PIC mode.
|
|
115 */
|
|
116
|
996
|
117 static char *progname;
|
|
118 static char *mod_name = NULL;
|
|
119 static char *mod_version = NULL;
|
|
120 static char *mod_title = NULL;
|
|
121 static char *mod_output = NULL;
|
|
122 static int exec_argc = 1;
|
|
123 static int exec_length = 0;
|
|
124 static int *exec_args;
|
|
125 static int real_argc = 0;
|
|
126 static char **prog_argv;
|
|
127
|
|
128 /*
|
|
129 * We allow the user to override things in the environment
|
|
130 */
|
|
131 static char *ellcc, *ellld, *ellcflags, *ellldflags, *ellpicflags,
|
|
132 *elldllflags;
|
|
133
|
|
134 #define OVERENV(STR,EVAR,DFLT) \
|
|
135 do { \
|
|
136 STR = getenv (EVAR); \
|
|
137 if ((STR) == NULL) { \
|
|
138 STR = DFLT; \
|
|
139 } \
|
|
140 } while(0)
|
|
141
|
428
|
142 /*
|
|
143 * xnew, xrnew -- allocate, reallocate storage
|
|
144 *
|
|
145 * SYNOPSIS: Type *xnew (int n, Type);
|
|
146 * Type *xrnew (OldPointer, int n, Type);
|
|
147 */
|
|
148 #ifdef chkmalloc
|
|
149 # include "chkmalloc.h"
|
|
150 # define xnew(n,Type) ((Type *) trace_malloc (__FILE__, __LINE__, \
|
|
151 (n) * sizeof (Type)))
|
|
152 # define xrnew(op,n,Type) ((Type *) trace_realloc (__FILE__, __LINE__, \
|
|
153 (op), (n) * sizeof (Type)))
|
|
154 #else
|
|
155 # define xnew(n,Type) ((Type *) xmalloc ((n) * sizeof (Type)))
|
|
156 # define xrnew(op,n,Type) ((Type *) xrealloc ((op), (n) * sizeof (Type)))
|
|
157 #endif
|
996
|
158
|
|
159 /*
|
|
160 * Ellcc modes of operation
|
|
161 */
|
|
162
|
|
163 enum mode { ELLCC_COMPILE_MODE, ELLCC_LINK_MODE, ELLCC_INIT_MODE };
|
428
|
164
|
996
|
165 #ifdef DEBUG
|
1506
|
166 static const char *ellcc_mode_name (enum mode ellcc_mode) ATTRIBUTE_CONST;
|
428
|
167
|
996
|
168 static const char *
|
|
169 ellcc_mode_name (enum mode ellcc_mode)
|
|
170 {
|
|
171 switch (ellcc_mode)
|
|
172 {
|
|
173 case ELLCC_COMPILE_MODE:
|
|
174 return "compile";
|
|
175 case ELLCC_LINK_MODE:
|
|
176 return "link";
|
|
177 case ELLCC_INIT_MODE:
|
|
178 return "init";
|
|
179 }
|
|
180 return "";
|
|
181 }
|
|
182 #endif
|
428
|
183
|
|
184 /*
|
996
|
185 * Function Prototypes
|
428
|
186 */
|
996
|
187
|
1506
|
188 static void *xmalloc (size_t size) ATTRIBUTE_MALLOC;
|
|
189 static void *xrealloc (void *ptr, size_t size) ATTRIBUTE_MALLOC;
|
|
190 static char *xstrdup (char *) ATTRIBUTE_MALLOC;
|
|
191 static void fatal (char *, ...) ATTRIBUTE_FATAL;
|
996
|
192 static char ** add_string (char **, char *);
|
|
193 static char ** add_to_argv (char **, const char *);
|
|
194 static char ** do_compile_mode (void);
|
|
195 static char ** do_link_mode (void);
|
|
196 static char ** do_init_mode (void);
|
|
197
|
|
198 #define SSTR(S) ((S) != NULL ? (S) : "")
|
428
|
199
|
|
200 int
|
|
201 main (int argc, char *argv[])
|
|
202 {
|
|
203 char *tmp;
|
996
|
204 char ** exec_argv;
|
|
205 int i, done_mode = 0, verbose = 0;
|
|
206 enum mode ellcc_mode;
|
428
|
207
|
996
|
208 if (argc < 2)
|
|
209 {
|
|
210 /* FIXME: Print usage output instead */
|
|
211 fatal ("too few arguments");
|
|
212 }
|
|
213
|
428
|
214 prog_argv = argv;
|
|
215
|
442
|
216 #if defined(WIN32_NATIVE)
|
428
|
217 tmp = strrchr (argv[0], '\\');
|
996
|
218 if (tmp != NULL)
|
|
219 {
|
|
220 tmp++;
|
|
221 }
|
428
|
222 #elif !defined (VMS)
|
|
223 tmp = strrchr (argv[0], '/');
|
996
|
224 if (tmp != NULL)
|
|
225 {
|
|
226 tmp++;
|
|
227 }
|
428
|
228 #else
|
|
229 tmp = argv[0];
|
|
230 #endif
|
|
231
|
996
|
232 progname = (tmp == NULL) ? argv[0] : tmp;
|
428
|
233
|
|
234 tmp = &progname[strlen(progname)-2];
|
|
235 if (strcmp (tmp, "cc") == 0)
|
996
|
236 {
|
|
237 ellcc_mode = ELLCC_COMPILE_MODE;
|
|
238 }
|
428
|
239 else if (strcmp (tmp, "ld") == 0)
|
996
|
240 {
|
|
241 ellcc_mode = ELLCC_LINK_MODE;
|
|
242 }
|
428
|
243 else if (strcmp (tmp, "it") == 0)
|
996
|
244 {
|
|
245 ellcc_mode = ELLCC_INIT_MODE;
|
|
246 }
|
|
247 else
|
|
248 {
|
|
249 ellcc_mode = ELLCC_COMPILE_MODE;
|
|
250 }
|
428
|
251
|
|
252 exec_args = xnew(argc, int);
|
|
253 exec_args[0] = 0;
|
996
|
254 for (i = 1; i < argc; i++)
|
|
255 {
|
|
256 exec_args[i] = -1;
|
|
257 }
|
428
|
258
|
|
259 for (i = 1; i < argc; i++)
|
|
260 {
|
996
|
261 if (strncmp (argv[i], "--mode=", (size_t)7) == 0)
|
428
|
262 {
|
996
|
263 char *modeopt = &argv[i][7];
|
428
|
264
|
996
|
265 if (done_mode && strcmp (modeopt, "verbose") != 0)
|
|
266 {
|
|
267 fatal ("more than one mode specified");
|
|
268 }
|
428
|
269 if (strcmp (modeopt, "link") == 0)
|
|
270 {
|
|
271 done_mode++;
|
|
272 ellcc_mode = ELLCC_LINK_MODE;
|
|
273 }
|
|
274 else if (strcmp (modeopt, "compile") == 0)
|
|
275 {
|
|
276 done_mode++;
|
|
277 ellcc_mode = ELLCC_COMPILE_MODE;
|
|
278 }
|
|
279 else if (strcmp (modeopt, "init") == 0)
|
|
280 {
|
|
281 done_mode++;
|
|
282 ellcc_mode = ELLCC_INIT_MODE;
|
|
283 }
|
|
284 else if (strcmp (modeopt, "verbose") == 0)
|
996
|
285 {
|
|
286 verbose++;
|
|
287 }
|
|
288 else
|
|
289 {
|
|
290 fatal ("Mode must be link, compile, init, or verbose");
|
|
291 }
|
428
|
292 }
|
|
293 else if (strcmp (argv[i], "--mod-location") == 0)
|
|
294 {
|
|
295 printf ("%s\n", ELLCC_MODDIR);
|
996
|
296 exit (EXIT_SUCCESS);
|
428
|
297 }
|
|
298 else if (strcmp (argv[i], "--mod-site-location") == 0)
|
|
299 {
|
|
300 printf ("%s\n", ELLCC_SITEMODS);
|
996
|
301 exit (EXIT_SUCCESS);
|
428
|
302 }
|
|
303 else if (strcmp (argv[i], "--mod-archdir") == 0)
|
|
304 {
|
|
305 printf ("%s\n", ELLCC_ARCHDIR);
|
996
|
306 exit (EXIT_SUCCESS);
|
428
|
307 }
|
|
308 else if (strcmp (argv[i], "--mod-config") == 0)
|
|
309 {
|
|
310 printf ("%s\n", ELLCC_CONFIG);
|
996
|
311 exit (EXIT_SUCCESS);
|
428
|
312 }
|
996
|
313 else if (strncmp (argv[i], "--mod-name=", (size_t)11) == 0)
|
|
314 {
|
|
315 mod_name = &argv[i][11];
|
|
316 }
|
|
317 else if (strncmp (argv[i], "--mod-title=", (size_t)12) == 0)
|
|
318 {
|
|
319 mod_title = &argv[i][12];
|
|
320 }
|
|
321 else if (strncmp (argv[i], "--mod-version=", (size_t)14) == 0)
|
|
322 {
|
|
323 mod_version = &argv[i][14];
|
|
324 }
|
|
325 else if (strncmp (argv[i], "--mod-output=", (size_t)13) == 0)
|
|
326 {
|
|
327 mod_output = &argv[i][13];
|
|
328 }
|
428
|
329 else
|
|
330 {
|
|
331 exec_args[exec_argc] = i;
|
|
332 exec_argc++;
|
|
333 }
|
|
334 }
|
|
335
|
996
|
336 if (ellcc_mode == ELLCC_LINK_MODE && mod_output == NULL)
|
|
337 {
|
|
338 fatal ("must specify --mod-output when linking");
|
|
339 }
|
|
340 if (ellcc_mode == ELLCC_INIT_MODE && mod_output == NULL)
|
|
341 {
|
|
342 fatal ("must specify --mod-output when creating init file");
|
|
343 }
|
|
344 if (ellcc_mode == ELLCC_INIT_MODE && mod_name == NULL)
|
|
345 {
|
|
346 fatal ("must specify --mod-name when creating init file");
|
|
347 }
|
428
|
348
|
|
349 /*
|
|
350 * We now have the list of arguments to pass to the compiler or
|
996
|
351 * linker (or to process for doc files). We can do the real work now.
|
428
|
352 */
|
|
353 if (verbose)
|
996
|
354 {
|
|
355 printf ("ellcc driver version %s for EMODULES version %s (%ld)\n",
|
|
356 ELLCC_EMACS_VER, EMODULES_VERSION, EMODULES_REVISION);
|
|
357 }
|
|
358
|
428
|
359 #ifdef DEBUG
|
|
360 if (verbose >= 2)
|
|
361 {
|
996
|
362 printf (" mode = %d (%s)\n", (int)ellcc_mode,
|
|
363 ellcc_mode_name (ellcc_mode));
|
428
|
364 printf (" module_name = \"%s\"\n", SSTR(mod_name));
|
|
365 printf (" module_title = \"%s\"\n", SSTR(mod_title));
|
|
366 printf (" module_version = \"%s\"\n", SSTR(mod_version));
|
|
367
|
|
368 printf (" CC = %s\n", ELLCC_CC);
|
|
369 printf (" CFLAGS = %s\n", ELLCC_CFLAGS);
|
|
370 printf (" CC PIC flags = %s\n", ELLCC_DLL_CFLAGS);
|
|
371 printf (" LD = %s\n", ELLCC_DLL_LD);
|
|
372 printf (" LDFLAGS = %s\n", ELLCC_DLL_LDFLAGS);
|
|
373 printf (" architecture = %s\n", ELLCC_CONFIG);
|
|
374 printf (" Include directory = %s/include\n", ELLCC_ARCHDIR);
|
|
375 printf ("\n");
|
|
376 }
|
|
377 #endif
|
|
378
|
|
379 if (exec_argc < 2)
|
996
|
380 {
|
|
381 /* FIXME: Print usage output instead */
|
|
382 fatal ("too few arguments");
|
|
383 }
|
428
|
384
|
|
385 /*
|
996
|
386 * Get the overrides from the environment
|
428
|
387 */
|
|
388 OVERENV(ellcc, "ELLCC", ELLCC_CC);
|
|
389 OVERENV(ellld, "ELLLD", ELLCC_DLL_LD);
|
|
390 OVERENV(ellcflags, "ELLCFLAGS", ELLCC_CFLAGS);
|
|
391 OVERENV(ellldflags, "ELLLDFLAGS", ELLCC_LDFLAGS);
|
|
392 OVERENV(elldllflags, "ELLDLLFLAGS", ELLCC_DLL_LDFLAGS);
|
|
393 OVERENV(ellpicflags, "ELLPICFLAGS", ELLCC_DLL_CFLAGS);
|
|
394
|
996
|
395 switch (ellcc_mode)
|
|
396 {
|
|
397 case ELLCC_COMPILE_MODE:
|
|
398 exec_argv = do_compile_mode ();
|
|
399 break;
|
|
400 case ELLCC_LINK_MODE:
|
|
401 exec_argv = do_link_mode ();
|
|
402 break;
|
|
403 default:
|
|
404 exec_argv = do_init_mode ();
|
|
405 break;
|
|
406 }
|
428
|
407
|
|
408 /*
|
|
409 * The arguments to pass on to the desired program have now been set
|
|
410 * up and we can run the program.
|
|
411 */
|
|
412 if (verbose)
|
|
413 {
|
|
414 for (i = 0; i < real_argc; i++)
|
996
|
415 {
|
|
416 printf ("%s ", exec_argv[i]);
|
|
417 }
|
428
|
418 printf ("\n");
|
996
|
419 (void)fflush (stdout);
|
428
|
420 }
|
996
|
421
|
|
422 /* Terminate argument list. */
|
|
423 exec_argv = add_string (exec_argv, NULL);
|
428
|
424
|
|
425 i = execvp (exec_argv[0], exec_argv);
|
|
426 if (verbose)
|
996
|
427 {
|
|
428 printf ("%s exited with status %d\n", exec_argv[0], i);
|
|
429 }
|
|
430 exit (i);
|
428
|
431 }
|
|
432
|
|
433 /* Like malloc but get fatal error if memory is exhausted. */
|
|
434 static void *
|
|
435 xmalloc (size_t size)
|
|
436 {
|
|
437 void *result = malloc (size);
|
|
438 if (result == NULL)
|
996
|
439 {
|
|
440 fatal ("virtual memory exhausted");
|
|
441 }
|
|
442 return result;
|
|
443 }
|
|
444
|
|
445 /* Like realloc but get fatal error if memory is exhausted. */
|
|
446 static void *
|
|
447 xrealloc (void *ptr, size_t size)
|
|
448 {
|
|
449 void *result = realloc (ptr, size);
|
|
450 if (result == NULL)
|
|
451 {
|
|
452 fatal ("virtual memory exhausted");
|
|
453 }
|
|
454 return result;
|
|
455 }
|
|
456
|
|
457 /* Like strdup but get fatal error if memory is exhausted. */
|
|
458 static char *
|
|
459 xstrdup (char *s)
|
|
460 {
|
|
461 char *result = strdup (s);
|
|
462 if (result == NULL)
|
|
463 {
|
|
464 fatal ("virtual memory exhausted");
|
|
465 }
|
428
|
466 return result;
|
|
467 }
|
|
468
|
|
469 /* Print error message and exit. */
|
|
470 static void
|
996
|
471 fatal (char *format, ...)
|
428
|
472 {
|
996
|
473 va_list ap;
|
|
474
|
|
475 va_start (ap, format);
|
|
476 (void)fprintf (stderr, "%s: ", progname);
|
|
477 (void)vfprintf (stderr, format, ap);
|
|
478 (void)fprintf (stderr, "\n");
|
|
479 va_end (ap);
|
428
|
480 exit (EXIT_FAILURE);
|
|
481 }
|
|
482
|
996
|
483 static char **
|
|
484 add_string (char **exec_argv, char *str)
|
|
485 {
|
|
486 if (real_argc >= exec_length)
|
|
487 {
|
|
488 exec_length = real_argc + EXEC_GROW_SIZE;
|
|
489 exec_argv = xrnew (exec_argv, exec_length, char *);
|
|
490 }
|
|
491 exec_argv[real_argc++] = str;
|
|
492 return exec_argv;
|
|
493 }
|
|
494
|
428
|
495 /*
|
|
496 * Add a string to the argument vector list that will be passed on down
|
|
497 * to the compiler or linker. We need to split individual words into
|
996
|
498 * arguments, taking quoting into account.
|
428
|
499 */
|
996
|
500 static char **
|
|
501 add_to_argv (char **exec_argv, const char *str)
|
428
|
502 {
|
996
|
503 /* Don't add nonexistent strings */
|
|
504 if (str == NULL)
|
428
|
505 {
|
996
|
506 return exec_argv;
|
|
507 }
|
428
|
508
|
996
|
509 /* Skip leading whitespace */
|
|
510 while (isspace (*str))
|
|
511 {
|
|
512 str++;
|
|
513 }
|
428
|
514
|
996
|
515 /* Don't add nonexistent strings */
|
|
516 if (*str == '\0')
|
|
517 {
|
|
518 return exec_argv;
|
428
|
519 }
|
|
520
|
996
|
521 while (*str != '\0')
|
428
|
522 {
|
996
|
523 const char *s;
|
|
524 char *arg;
|
|
525 int l;
|
|
526
|
|
527 s = str; /* Mark the start of THIS argument */
|
|
528
|
|
529 /* Find contiguous nonwhitespace characters */
|
|
530 while (*str != '\0' && !isspace(*str))
|
|
531 {
|
|
532 if (*str == '\\') /* Escaped character */
|
|
533 {
|
|
534 str++;
|
|
535 if (*str != '\0')
|
|
536 {
|
|
537 str++;
|
|
538 }
|
|
539 }
|
|
540 else if (*str == '\'')
|
|
541 {
|
|
542 str++;
|
|
543 while (*str != '\0' && *str != '\'')
|
|
544 {
|
|
545 if (str[0] == '\\' && str[1] != '\0')
|
|
546 {
|
|
547 str += 2;
|
|
548 }
|
|
549 else
|
|
550 {
|
|
551 str++;
|
|
552 }
|
|
553 }
|
|
554 if (*str == '\'')
|
|
555 {
|
|
556 str++;
|
|
557 }
|
|
558 }
|
|
559 else if (*str == '\"')
|
|
560 {
|
|
561 str++;
|
|
562 while (*str != '\0' && *str != '\"')
|
|
563 {
|
|
564 if (str[0] == '\\' && str[1] != '\0')
|
|
565 {
|
|
566 str += 2;
|
|
567 }
|
|
568 else
|
|
569 {
|
|
570 str++;
|
|
571 }
|
|
572 }
|
|
573 if (*str == '\"')
|
|
574 {
|
|
575 str++;
|
|
576 }
|
|
577 }
|
|
578 else
|
|
579 {
|
|
580 str++; /* Normal character. Advance the pointer. */
|
|
581 }
|
|
582 }
|
|
583
|
|
584 /* Reached the end of the argument. Add it. */
|
|
585 l = str-s;
|
|
586 arg = xnew(l+1, char);
|
|
587 strncpy(arg, s, (size_t)l);
|
|
588 arg[l] = '\0';
|
|
589 exec_argv = add_string (exec_argv, arg);
|
|
590
|
|
591 /* Skip trailing whitespace */
|
|
592 while (isspace (*str))
|
|
593 {
|
|
594 str++;
|
|
595 }
|
428
|
596 }
|
996
|
597
|
|
598 return exec_argv;
|
428
|
599 }
|
|
600
|
|
601 /*
|
|
602 * For compile mode, things are pretty straight forward. All we need to do
|
|
603 * is build up the argument vector and exec() it. We must just make sure
|
|
604 * that we get all of the required arguments in place.
|
|
605 */
|
996
|
606 static char **
|
428
|
607 do_compile_mode (void)
|
|
608 {
|
|
609 int i;
|
996
|
610 char **exec_argv = xnew (exec_argc + 20, char *);
|
428
|
611
|
996
|
612 exec_argv = add_to_argv (exec_argv, ellcc);
|
1269
|
613 exec_argv = add_to_argv (exec_argv, ELLCC_CF_ALL);
|
996
|
614 exec_argv = add_to_argv (exec_argv, ellcflags);
|
|
615 exec_argv = add_to_argv (exec_argv, ellpicflags);
|
|
616 exec_argv = add_to_argv (exec_argv, "-DPIC");
|
|
617 exec_argv = add_to_argv (exec_argv, "-DEMACS_MODULE");
|
428
|
618 #ifdef XEMACS
|
996
|
619 /* Cover both cases */
|
|
620 exec_argv = add_to_argv (exec_argv, "-DXEMACS_MODULE");
|
|
621 exec_argv = add_to_argv (exec_argv, "-Dxemacs");
|
428
|
622 #endif
|
996
|
623 exec_argv = add_to_argv (exec_argv, "-Demacs");
|
428
|
624 for (i = 1; i < exec_argc; i++)
|
996
|
625 {
|
|
626 exec_argv = add_string (exec_argv, xstrdup (prog_argv[exec_args[i]]));
|
|
627 }
|
|
628 return exec_argv;
|
428
|
629 }
|
|
630
|
|
631 /*
|
|
632 * For link mode, things are a little bit more complicated. We need to
|
|
633 * insert the linker commands first, replace any occurrence of ELLSONAME
|
|
634 * with the desired output file name, insert the output arguments, then
|
|
635 * all of the provided arguments, then the final post arguments. Once
|
|
636 * all of this has been done, the argument vector is ready to run.
|
|
637 */
|
996
|
638 static char **
|
428
|
639 do_link_mode (void)
|
|
640 {
|
|
641 int i,x;
|
996
|
642 char *t, *ts;
|
|
643 char **exec_argv = xnew(exec_argc + 10, char *);
|
428
|
644
|
996
|
645 exec_argv = add_to_argv (exec_argv, ellld);
|
|
646 exec_argv = add_to_argv (exec_argv, ellldflags);
|
|
647 exec_argv = add_to_argv (exec_argv, elldllflags);
|
|
648 exec_argv = add_to_argv (exec_argv, ELLCC_DLL_LDO);
|
|
649 exec_argv = add_to_argv (exec_argv, mod_output);
|
428
|
650 for (i = 1; i < exec_argc; i++)
|
996
|
651 {
|
|
652 exec_argv = add_string (exec_argv, xstrdup (prog_argv[exec_args[i]]));
|
|
653 }
|
|
654 exec_argv = add_to_argv (exec_argv, ELLCC_DLL_POST);
|
428
|
655
|
|
656 /*
|
|
657 * Now go through each argument and replace ELLSONAME with mod_output.
|
|
658 */
|
|
659 for (i = 0; i < real_argc; i++)
|
|
660 {
|
|
661 x = 0;
|
996
|
662 ts = xnew (2 * strlen (exec_argv[i]), char);
|
428
|
663 ts[0] = '\0';
|
|
664
|
|
665 t = exec_argv[i];
|
996
|
666 while (*t != '\0')
|
428
|
667 {
|
|
668 if (*t == 'E')
|
|
669 {
|
996
|
670 if (strncmp (t, "ELLSONAME", (size_t)9) == 0)
|
428
|
671 {
|
|
672 strcat (ts, mod_output);
|
996
|
673 x += strlen (mod_output);
|
428
|
674 t += 8;
|
|
675 }
|
|
676 else
|
|
677 {
|
|
678 ts[x] = *t;
|
|
679 x++;
|
|
680 ts[x] = '\0';
|
|
681 }
|
|
682 }
|
|
683 else
|
|
684 {
|
|
685 ts[x] = *t;
|
|
686 x++;
|
|
687 ts[x] = '\0';
|
|
688 }
|
|
689 t++;
|
|
690 }
|
|
691 free (exec_argv[i]);
|
996
|
692 exec_argv[i] = ts;
|
428
|
693 }
|
996
|
694 return exec_argv;
|
428
|
695 }
|
|
696
|
|
697 /*
|
|
698 * In init mode, things are a bit easier. We assume that the only things
|
|
699 * passed on the command line are the names of source files which the
|
|
700 * make-doc program will be processing. We prepare the output file with
|
|
701 * the header information first, as make-doc will append to the file by
|
|
702 * special dispensation.
|
|
703 */
|
996
|
704 static char **
|
428
|
705 do_init_mode (void)
|
|
706 {
|
|
707 int i;
|
996
|
708 char *ts, *mdocprog;
|
|
709 char **exec_argv = xnew(exec_argc + 8, char *);
|
428
|
710 FILE *mout = fopen (mod_output, "w");
|
|
711
|
996
|
712 if (mout == NULL)
|
|
713 {
|
|
714 fatal ("Failed to open output file %s", mod_output);
|
|
715 }
|
428
|
716 fprintf (mout, "/* DO NOT EDIT - AUTOMATICALLY GENERATED */\n\n");
|
|
717 fprintf (mout, "#include <emodules.h>\n\n");
|
|
718 fprintf (mout, "const long emodule_compiler = %ld;\n", EMODULES_REVISION);
|
|
719 fprintf (mout, "const char *emodule_name = \"%s\";\n", SSTR(mod_name));
|
|
720 fprintf (mout, "const char *emodule_version = \"%s\";\n", SSTR(mod_version));
|
|
721 fprintf (mout, "const char *emodule_title = \"%s\";\n", SSTR(mod_title));
|
|
722 fprintf (mout, "\n\n");
|
1111
|
723 fprintf (mout, "void docs_of_%s (void);\n", SSTR(mod_name));
|
|
724 fprintf (mout, "void docs_of_%s (void)\n", SSTR(mod_name));
|
996
|
725 if (fclose (mout) != 0)
|
|
726 {
|
|
727 fatal ("Failed to close output file %s", mod_output);
|
|
728 }
|
428
|
729
|
996
|
730 mdocprog = getenv ("ELLMAKEDOC");
|
|
731 if (mdocprog == NULL)
|
|
732 {
|
|
733 mdocprog = xnew (14 + strlen (ELLCC_ARCHDIR), char);
|
|
734 sprintf (mdocprog, "%s/make-docfile", ELLCC_ARCHDIR);
|
|
735 }
|
|
736 exec_argv = add_to_argv (exec_argv, mdocprog);
|
|
737 ts = xnew (4 + strlen (mod_output), char);
|
428
|
738 sprintf (ts, "-E %s", mod_output);
|
996
|
739 exec_argv = add_to_argv (exec_argv, ts);
|
|
740 free (ts);
|
428
|
741 for (i = 1; i < exec_argc; i++)
|
996
|
742 {
|
|
743 exec_argv = add_string (exec_argv, xstrdup (prog_argv[exec_args[i]]));
|
|
744 }
|
|
745 return exec_argv;
|
428
|
746 }
|
|
747
|
|
748 #endif /* HAVE_SHLIB */
|