annotate lib-src/ellcc.c @ 1559:9bf5135fc04f

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