annotate lib-src/ellcc.c @ 5781:0853e1ec8529

Use alloca_{rawbytes,ibytes} in #'copy-file, #'insert-file-contents-internal src/ChangeLog addition: 2014-01-20 Aidan Kehoe <kehoea@parhasard.net> * fileio.c (Fcopy_file, Finsert_file_contents_internal): Use alloca_{rawbytes,ibytes} here instead of the implicit alloca on the stack; doesn't change where the buffers are allocated for these two functions, but does mean that decisions about alloca vs. malloc based on buffer size are made in the same place (ultimately, the ALLOCA() macro).
author Aidan Kehoe <kehoea@parhasard.net>
date Mon, 20 Jan 2014 17:53:07 +0000
parents 308d34e9f07d
children
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
5402
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 3983
diff changeset
7 XEmacs is free software: you can redistribute it and/or modify it
428
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
5402
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 3983
diff changeset
9 Free Software Foundation, either version 3 of the License, or (at your
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 3983
diff changeset
10 option) any later version.
428
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
5402
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 3983
diff changeset
18 along with XEmacs. If not, see <http://www.gnu.org/licenses/>.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
19 Author: J. Kean Johnston (jkj@sco.com).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
20 Please mail bugs and suggestions to the XEmacs maintainer.
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
23 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
24 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
25 the various Windows platforms don't have reliable scripting that suits
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
26 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
27 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
28 compiler.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
29
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
30 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
31 the module specific documentation and initialization code. We assume we
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
32 are in 'compile' mode unless we encounter an argument which tells us
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
33 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
34 compiler, except for a few which are specific to this program:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
35
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
36 --mode=VALUE This sets the program mode. VALUE can be one of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
37 compile, link, init or verbose.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
38 --mod-name=NAME Sets the module name to the string NAME.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
39 --mod-title=TITLE Sets the module title to the string TITLE.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
40 --mod-version=VER Sets the module version to the string VER.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
41
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
42 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
43 dynamic Emacs modules, and life should be as simple as:
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 make CC=ellcc LD='ellcc --mode=link'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
46
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
47 The only additional requirement is an entry in the Makefile to produce
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
48 the module initialization file, which will usually be something along
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
49 the lines of:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
50
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
51 modinit.c: $(SRCS)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
52 ellcc --mode=init --mod-name=\"$(MODNAME)\" \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
53 --mod-title=\"$(MODTITLE)\" --mod-version=\"$(MODVERSION)\" \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
54 -o $@ $(SRCS)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
55
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
56 See the samples for more details.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
57 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
58
438
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
59 #include <config.h>
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
60 #include <stdio.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
61 #include <stdlib.h>
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
62 #include <stddef.h>
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
63 #include <stdarg.h>
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
64 #include <string.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
65 #include <ctype.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
66 #include <errno.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
67 #include <sys/types.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
68
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
69 #ifdef HAVE_UNISTD_H
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
70 # include <unistd.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
71 #endif /* HAVE_UNISTD_H */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
72
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
73 #define EMODULES_GATHER_VERSION
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
74 #define EXEC_GROW_SIZE 4
438
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
75
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
76 #include <emodules.h>
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
77 #include <ellcc.h> /* Generated files must be included using <...> */
1743
543769b89fed [xemacs-hg @ 2003-10-14 05:02:57 by james]
james
parents: 1706
diff changeset
78 #include "compiler.h"
1506
4d97756f2fbe [xemacs-hg @ 2003-05-29 17:02:31 by james]
james
parents: 1269
diff changeset
79
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
80 #ifndef HAVE_SHLIB
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
81 int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
82 main (int argc, char *argv[])
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
83 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
84 fprintf (stderr, "Dynamic modules not supported on this platform\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
85 return EXIT_FAILURE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
86 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
87 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
88
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
89 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
90 * 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
91 * and how to compile for PIC mode.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
92 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
93
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
94 static char *progname;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
95 static char *mod_name = NULL;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
96 static char *mod_version = NULL;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
97 static char *mod_title = NULL;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
98 static char *mod_output = NULL;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
99 static int exec_argc = 1;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
100 static int exec_length = 0;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
101 static int *exec_args;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
102 static int real_argc = 0;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
103 static char **prog_argv;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
104
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
105 /*
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
106 * 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
107 */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
108 static char *ellcc, *ellld, *ellcflags, *ellldflags, *ellpicflags,
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
109 *elldllflags;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
110
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
111 #define OVERENV(STR,EVAR,DFLT) \
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
112 do { \
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
113 STR = getenv (EVAR); \
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
114 if ((STR) == NULL) { \
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
115 STR = DFLT; \
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
116 } \
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
117 } while(0)
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
118
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
119 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
120 * xnew, xrnew -- allocate, reallocate storage
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
121 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
122 * SYNOPSIS: Type *xnew (int n, Type);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
123 * Type *xrnew (OldPointer, int n, Type);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
124 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
125 #ifdef chkmalloc
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
126 # include "chkmalloc.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
127 # define xnew(n,Type) ((Type *) trace_malloc (__FILE__, __LINE__, \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
128 (n) * sizeof (Type)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
129 # define xrnew(op,n,Type) ((Type *) trace_realloc (__FILE__, __LINE__, \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
130 (op), (n) * sizeof (Type)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
131 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
132 # define xnew(n,Type) ((Type *) xmalloc ((n) * sizeof (Type)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
133 # define xrnew(op,n,Type) ((Type *) xrealloc ((op), (n) * sizeof (Type)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
134 #endif
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
135
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
136 /*
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
137 * Ellcc modes of operation
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
138 */
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 enum mode { ELLCC_COMPILE_MODE, ELLCC_LINK_MODE, ELLCC_INIT_MODE };
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
141
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
142 #ifdef DEBUG
1506
4d97756f2fbe [xemacs-hg @ 2003-05-29 17:02:31 by james]
james
parents: 1269
diff changeset
143 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
144
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
145 static const char *
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
146 ellcc_mode_name (enum mode ellcc_mode)
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
147 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
148 switch (ellcc_mode)
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
149 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
150 case ELLCC_COMPILE_MODE:
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
151 return "compile";
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
152 case ELLCC_LINK_MODE:
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
153 return "link";
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
154 case ELLCC_INIT_MODE:
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
155 return "init";
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
156 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
157 return "";
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 #endif
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
160
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
161 /*
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
162 * Function Prototypes
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
163 */
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
164
1506
4d97756f2fbe [xemacs-hg @ 2003-05-29 17:02:31 by james]
james
parents: 1269
diff changeset
165 static void *xmalloc (size_t size) ATTRIBUTE_MALLOC;
4d97756f2fbe [xemacs-hg @ 2003-05-29 17:02:31 by james]
james
parents: 1269
diff changeset
166 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
167 static char *xstrdup (char *) ATTRIBUTE_MALLOC;
1743
543769b89fed [xemacs-hg @ 2003-10-14 05:02:57 by james]
james
parents: 1706
diff changeset
168 static DECLARE_DOESNT_RETURN (fatal (char *, ...)) PRINTF_ARGS (1, 2);
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
169 static char ** add_string (char **, char *);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
170 static char ** add_to_argv (char **, const char *);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
171 static char ** do_compile_mode (void);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
172 static char ** do_link_mode (void);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
173 static char ** do_init_mode (void);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
174
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
175 #define SSTR(S) ((S) != NULL ? (S) : "")
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
176
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
177 int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
178 main (int argc, char *argv[])
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
179 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
180 char *tmp;
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
181 char ** exec_argv;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
182 int i, done_mode = 0, verbose = 0;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
183 enum mode ellcc_mode;
428
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 if (argc < 2)
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
186 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
187 /* FIXME: Print usage output instead */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
188 fatal ("too few arguments");
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
189 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
190
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
191 prog_argv = argv;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
192
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
193 #if defined(WIN32_NATIVE)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
194 tmp = strrchr (argv[0], '\\');
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
195 if (tmp != NULL)
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
196 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
197 tmp++;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
198 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
199 #elif !defined (VMS)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
200 tmp = strrchr (argv[0], '/');
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
201 if (tmp != NULL)
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
202 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
203 tmp++;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
204 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
205 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
206 tmp = argv[0];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
207 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
208
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
209 progname = (tmp == NULL) ? argv[0] : tmp;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
210
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
211 tmp = &progname[strlen(progname)-2];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
212 if (strcmp (tmp, "cc") == 0)
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
213 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
214 ellcc_mode = ELLCC_COMPILE_MODE;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
215 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
216 else if (strcmp (tmp, "ld") == 0)
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
217 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
218 ellcc_mode = ELLCC_LINK_MODE;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
219 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
220 else if (strcmp (tmp, "it") == 0)
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
221 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
222 ellcc_mode = ELLCC_INIT_MODE;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
223 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
224 else
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 ellcc_mode = ELLCC_COMPILE_MODE;
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
229 exec_args = xnew(argc, int);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
230 exec_args[0] = 0;
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
231 for (i = 1; i < argc; i++)
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
232 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
233 exec_args[i] = -1;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
234 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
235
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
236 for (i = 1; i < argc; i++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
237 {
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
238 if (strncmp (argv[i], "--mode=", (size_t)7) == 0)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
239 {
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
240 char *modeopt = &argv[i][7];
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
241
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
242 if (done_mode && strcmp (modeopt, "verbose") != 0)
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
243 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
244 fatal ("more than one mode specified");
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
245 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
246 if (strcmp (modeopt, "link") == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
247 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
248 done_mode++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
249 ellcc_mode = ELLCC_LINK_MODE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
250 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
251 else if (strcmp (modeopt, "compile") == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
252 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
253 done_mode++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
254 ellcc_mode = ELLCC_COMPILE_MODE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
255 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
256 else if (strcmp (modeopt, "init") == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
257 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
258 done_mode++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
259 ellcc_mode = ELLCC_INIT_MODE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
260 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
261 else if (strcmp (modeopt, "verbose") == 0)
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
262 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
263 verbose++;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
264 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
265 else
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 ("Mode must be link, compile, init, or verbose");
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 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
270 else if (strcmp (argv[i], "--mod-location") == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
271 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
272 printf ("%s\n", ELLCC_MODDIR);
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
273 exit (EXIT_SUCCESS);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
274 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
275 else if (strcmp (argv[i], "--mod-site-location") == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
276 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
277 printf ("%s\n", ELLCC_SITEMODS);
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
278 exit (EXIT_SUCCESS);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
279 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
280 else if (strcmp (argv[i], "--mod-archdir") == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
281 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
282 printf ("%s\n", ELLCC_ARCHDIR);
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
283 exit (EXIT_SUCCESS);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
284 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
285 else if (strcmp (argv[i], "--mod-config") == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
286 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
287 printf ("%s\n", ELLCC_CONFIG);
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
288 exit (EXIT_SUCCESS);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
289 }
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
290 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
291 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
292 mod_name = &argv[i][11];
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
293 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
294 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
295 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
296 mod_title = &argv[i][12];
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
297 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
298 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
299 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
300 mod_version = &argv[i][14];
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
301 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
302 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
303 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
304 mod_output = &argv[i][13];
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
305 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
306 else
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 exec_args[exec_argc] = i;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
309 exec_argc++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
310 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
311 }
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 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
314 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
315 fatal ("must specify --mod-output when linking");
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 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
318 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
319 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
320 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
321 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
322 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
323 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
324 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
325
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
326 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
327 * 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
328 * 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
329 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
330 if (verbose)
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
331 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
332 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
333 ELLCC_EMACS_VER, EMODULES_VERSION, EMODULES_REVISION);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
334 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
335
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
336 #ifdef DEBUG
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
337 if (verbose >= 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
338 {
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
339 printf (" mode = %d (%s)\n", (int)ellcc_mode,
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
340 ellcc_mode_name (ellcc_mode));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
341 printf (" module_name = \"%s\"\n", SSTR(mod_name));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
342 printf (" module_title = \"%s\"\n", SSTR(mod_title));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
343 printf (" module_version = \"%s\"\n", SSTR(mod_version));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
344
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
345 printf (" CC = %s\n", ELLCC_CC);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
346 printf (" CFLAGS = %s\n", ELLCC_CFLAGS);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
347 printf (" CC PIC flags = %s\n", ELLCC_DLL_CFLAGS);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
348 printf (" LD = %s\n", ELLCC_DLL_LD);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
349 printf (" LDFLAGS = %s\n", ELLCC_DLL_LDFLAGS);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
350 printf (" architecture = %s\n", ELLCC_CONFIG);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
351 printf (" Include directory = %s/include\n", ELLCC_ARCHDIR);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
352 printf ("\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
353 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
354 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
355
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
356 if (exec_argc < 2)
996
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 /* FIXME: Print usage output instead */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
359 fatal ("too few arguments");
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
360 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
361
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
362 /*
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
363 * Get the overrides from the environment
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
364 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
365 OVERENV(ellcc, "ELLCC", ELLCC_CC);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
366 OVERENV(ellld, "ELLLD", ELLCC_DLL_LD);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
367 OVERENV(ellcflags, "ELLCFLAGS", ELLCC_CFLAGS);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
368 OVERENV(ellldflags, "ELLLDFLAGS", ELLCC_LDFLAGS);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
369 OVERENV(elldllflags, "ELLDLLFLAGS", ELLCC_DLL_LDFLAGS);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
370 OVERENV(ellpicflags, "ELLPICFLAGS", ELLCC_DLL_CFLAGS);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
371
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
372 switch (ellcc_mode)
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
373 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
374 case ELLCC_COMPILE_MODE:
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
375 exec_argv = do_compile_mode ();
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
376 break;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
377 case ELLCC_LINK_MODE:
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
378 exec_argv = do_link_mode ();
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
379 break;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
380 default:
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
381 exec_argv = do_init_mode ();
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
382 break;
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 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
386 * 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
387 * up and we can run the program.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
388 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
389 if (verbose)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
390 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
391 for (i = 0; i < real_argc; i++)
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
392 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
393 printf ("%s ", exec_argv[i]);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
394 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
395 printf ("\n");
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
396 (void)fflush (stdout);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
397 }
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
398
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
399 /* Terminate argument list. */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
400 exec_argv = add_string (exec_argv, NULL);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
401
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
402 i = execvp (exec_argv[0], exec_argv);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
403 if (verbose)
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
404 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
405 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
406 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
407 exit (i);
428
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
410 /* Like malloc but get fatal error if memory is exhausted. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
411 static void *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
412 xmalloc (size_t size)
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 void *result = malloc (size);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
415 if (result == NULL)
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
416 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
417 fatal ("virtual memory exhausted");
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
418 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
419 return result;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
420 }
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 /* 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
423 static void *
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
424 xrealloc (void *ptr, size_t size)
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
425 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
426 void *result = realloc (ptr, size);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
427 if (result == NULL)
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
428 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
429 fatal ("virtual memory exhausted");
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
430 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
431 return result;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
432 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
433
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
434 /* 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
435 static char *
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
436 xstrdup (char *s)
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
437 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
438 char *result = strdup (s);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
439 if (result == NULL)
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
440 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
441 fatal ("virtual memory exhausted");
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
442 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
443 return result;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
444 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
445
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
446 /* Print error message and exit. */
1743
543769b89fed [xemacs-hg @ 2003-10-14 05:02:57 by james]
james
parents: 1706
diff changeset
447 static DOESNT_RETURN
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
448 fatal (char *format, ...)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
449 {
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
450 va_list ap;
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 va_start (ap, format);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
453 (void)fprintf (stderr, "%s: ", progname);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
454 (void)vfprintf (stderr, format, ap);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
455 (void)fprintf (stderr, "\n");
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
456 va_end (ap);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
457 exit (EXIT_FAILURE);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
458 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
459
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
460 static char **
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
461 add_string (char **exec_argv, char *str)
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
462 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
463 if (real_argc >= exec_length)
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
464 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
465 exec_length = real_argc + EXEC_GROW_SIZE;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
466 exec_argv = xrnew (exec_argv, exec_length, char *);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
467 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
468 exec_argv[real_argc++] = str;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
469 return exec_argv;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
470 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
471
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
472 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
473 * 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
474 * 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
475 * arguments, taking quoting into account.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
476 */
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
477 static char **
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
478 add_to_argv (char **exec_argv, const char *str)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
479 {
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
480 /* Don't add nonexistent strings */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
481 if (str == NULL)
428
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 return exec_argv;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
484 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
485
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
486 /* Skip leading whitespace */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
487 while (isspace (*str))
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
488 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
489 str++;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
490 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
491
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
492 /* Don't add nonexistent strings */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
493 if (*str == '\0')
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
494 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
495 return exec_argv;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
496 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
497
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
498 while (*str != '\0')
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 const char *s;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
501 char *arg;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
502 int l;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
503
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
504 s = str; /* Mark the start of THIS argument */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
505
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
506 /* Find contiguous nonwhitespace characters */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
507 while (*str != '\0' && !isspace(*str))
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
508 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
509 if (*str == '\\') /* Escaped character */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
510 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
511 str++;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
512 if (*str != '\0')
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
513 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
514 str++;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
515 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
516 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
517 else if (*str == '\'')
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
518 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
519 str++;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
520 while (*str != '\0' && *str != '\'')
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
521 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
522 if (str[0] == '\\' && str[1] != '\0')
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
523 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
524 str += 2;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
525 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
526 else
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
527 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
528 str++;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
529 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
530 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
531 if (*str == '\'')
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
532 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
533 str++;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
534 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
535 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
536 else if (*str == '\"')
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
537 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
538 str++;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
539 while (*str != '\0' && *str != '\"')
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
540 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
541 if (str[0] == '\\' && str[1] != '\0')
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
542 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
543 str += 2;
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 else
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++;
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 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
550 if (*str == '\"')
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
551 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
552 str++;
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 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
555 else
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
556 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
557 str++; /* Normal character. Advance the pointer. */
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 }
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 /* Reached the end of the argument. Add it. */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
562 l = str-s;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
563 arg = xnew(l+1, char);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
564 strncpy(arg, s, (size_t)l);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
565 arg[l] = '\0';
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
566 exec_argv = add_string (exec_argv, arg);
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 /* Skip trailing whitespace */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
569 while (isspace (*str))
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
570 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
571 str++;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
572 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
573 }
996
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 return exec_argv;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
576 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
577
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
578 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
579 * 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
580 * 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
581 * that we get all of the required arguments in place.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
582 */
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
583 static char **
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
584 do_compile_mode (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
585 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
586 int i;
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
587 char **exec_argv = xnew (exec_argc + 20, char *);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
588
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
589 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
590 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
591 exec_argv = add_to_argv (exec_argv, ellcflags);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
592 exec_argv = add_to_argv (exec_argv, ellpicflags);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
593 exec_argv = add_to_argv (exec_argv, "-DPIC");
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
594 exec_argv = add_to_argv (exec_argv, "-DEMACS_MODULE");
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
595 #ifdef XEMACS
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
596 /* Cover both cases */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
597 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
598 exec_argv = add_to_argv (exec_argv, "-Dxemacs");
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
599 #endif
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
600 exec_argv = add_to_argv (exec_argv, "-Demacs");
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
601 for (i = 1; i < exec_argc; i++)
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
602 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
603 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
604 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
605 return exec_argv;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
606 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
607
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 * 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
610 * insert the linker commands first, replace any occurrence of ELLSONAME
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
611 * with the desired output file name, insert the output arguments, then
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
612 * all of the provided arguments, then the final post arguments. Once
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
613 * 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
614 */
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
615 static char **
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
616 do_link_mode (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
617 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
618 int i,x;
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
619 char *t, *ts;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
620 char **exec_argv = xnew(exec_argc + 10, char *);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
621
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
622 exec_argv = add_to_argv (exec_argv, ellld);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
623 exec_argv = add_to_argv (exec_argv, ellldflags);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
624 exec_argv = add_to_argv (exec_argv, elldllflags);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
625 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
626 exec_argv = add_to_argv (exec_argv, mod_output);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
627 for (i = 1; i < exec_argc; i++)
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
628 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
629 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
630 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
631 exec_argv = add_to_argv (exec_argv, ELLCC_DLL_POST);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
632
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
633 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
634 * Now go through each argument and replace ELLSONAME with mod_output.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
635 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
636 for (i = 0; i < real_argc; i++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
637 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
638 x = 0;
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
639 ts = xnew (2 * strlen (exec_argv[i]), char);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
640 ts[0] = '\0';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
641
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
642 t = exec_argv[i];
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
643 while (*t != '\0')
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
644 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
645 if (*t == 'E')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
646 {
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
647 if (strncmp (t, "ELLSONAME", (size_t)9) == 0)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
648 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
649 strcat (ts, mod_output);
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
650 x += strlen (mod_output);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
651 t += 8;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
652 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
653 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
654 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
655 ts[x] = *t;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
656 x++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
657 ts[x] = '\0';
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 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
660 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
661 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
662 ts[x] = *t;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
663 x++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
664 ts[x] = '\0';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
665 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
666 t++;
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 free (exec_argv[i]);
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
669 exec_argv[i] = ts;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
670 }
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
671 return exec_argv;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
672 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
673
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
674 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
675 * 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
676 * 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
677 * make-doc program will be processing. We prepare the output file with
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
678 * 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
679 * special dispensation.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
680 */
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
681 static char **
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
682 do_init_mode (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
683 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
684 int i;
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
685 char *ts, *mdocprog;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
686 char **exec_argv = xnew(exec_argc + 8, char *);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
687 FILE *mout = fopen (mod_output, "w");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
688
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
689 if (mout == NULL)
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
690 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
691 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
692 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
693 fprintf (mout, "/* DO NOT EDIT - AUTOMATICALLY GENERATED */\n\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
694 fprintf (mout, "#include <emodules.h>\n\n");
1706
9fc738581a9d [xemacs-hg @ 2003-09-22 03:21:12 by james]
james
parents: 1506
diff changeset
695 fprintf (mout, "#ifdef __cplusplus\n");
9fc738581a9d [xemacs-hg @ 2003-09-22 03:21:12 by james]
james
parents: 1506
diff changeset
696 fprintf (mout, "extern \"C\" {\n");
9fc738581a9d [xemacs-hg @ 2003-09-22 03:21:12 by james]
james
parents: 1506
diff changeset
697 fprintf (mout, "#endif\n");
9fc738581a9d [xemacs-hg @ 2003-09-22 03:21:12 by james]
james
parents: 1506
diff changeset
698 fprintf (mout, "extern const long emodule_compiler;\n");
9fc738581a9d [xemacs-hg @ 2003-09-22 03:21:12 by james]
james
parents: 1506
diff changeset
699 fprintf (mout, "extern const char *emodule_name, *emodule_version, *emodule_title;\n");
9fc738581a9d [xemacs-hg @ 2003-09-22 03:21:12 by james]
james
parents: 1506
diff changeset
700 fprintf (mout, "extern void docs_of_%s (void);\n", SSTR(mod_name));
9fc738581a9d [xemacs-hg @ 2003-09-22 03:21:12 by james]
james
parents: 1506
diff changeset
701 fprintf (mout, "#ifdef __cplusplus\n");
9fc738581a9d [xemacs-hg @ 2003-09-22 03:21:12 by james]
james
parents: 1506
diff changeset
702 fprintf (mout, "}\n");
9fc738581a9d [xemacs-hg @ 2003-09-22 03:21:12 by james]
james
parents: 1506
diff changeset
703 fprintf (mout, "#endif\n\n");
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
704 fprintf (mout, "const long emodule_compiler = %ld;\n", EMODULES_REVISION);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
705 fprintf (mout, "const char *emodule_name = \"%s\";\n", SSTR(mod_name));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
706 fprintf (mout, "const char *emodule_version = \"%s\";\n", SSTR(mod_version));
1706
9fc738581a9d [xemacs-hg @ 2003-09-22 03:21:12 by james]
james
parents: 1506
diff changeset
707 fprintf (mout, "const char *emodule_title = \"%s\";\n\n", SSTR(mod_title));
9fc738581a9d [xemacs-hg @ 2003-09-22 03:21:12 by james]
james
parents: 1506
diff changeset
708 fprintf (mout, "void docs_of_%s ()\n", SSTR(mod_name));
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
709 if (fclose (mout) != 0)
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
710 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
711 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
712 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
713
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
714 mdocprog = getenv ("ELLMAKEDOC");
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
715 if (mdocprog == NULL)
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
716 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
717 mdocprog = xnew (14 + strlen (ELLCC_ARCHDIR), char);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
718 sprintf (mdocprog, "%s/make-docfile", ELLCC_ARCHDIR);
3983
854c88538753 [xemacs-hg @ 2007-05-24 20:18:50 by james]
james
parents: 1743
diff changeset
719 exec_argv = add_to_argv (exec_argv, mdocprog);
854c88538753 [xemacs-hg @ 2007-05-24 20:18:50 by james]
james
parents: 1743
diff changeset
720 free (mdocprog);
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
721 }
3983
854c88538753 [xemacs-hg @ 2007-05-24 20:18:50 by james]
james
parents: 1743
diff changeset
722 else
854c88538753 [xemacs-hg @ 2007-05-24 20:18:50 by james]
james
parents: 1743
diff changeset
723 {
854c88538753 [xemacs-hg @ 2007-05-24 20:18:50 by james]
james
parents: 1743
diff changeset
724 exec_argv = add_to_argv (exec_argv, mdocprog);
854c88538753 [xemacs-hg @ 2007-05-24 20:18:50 by james]
james
parents: 1743
diff changeset
725 }
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
726 ts = xnew (4 + strlen (mod_output), char);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
727 sprintf (ts, "-E %s", mod_output);
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
728 exec_argv = add_to_argv (exec_argv, ts);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
729 free (ts);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
730 for (i = 1; i < exec_argc; i++)
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
731 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
732 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
733 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
734 return exec_argv;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
735 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
736
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
737 #endif /* HAVE_SHLIB */