annotate lib-src/ellcc.c @ 4609:33b8c874b2c8

Correct string offset and arg handling, #'query-coding-string and related. lisp/ChangeLog addition: 2009-02-11 Aidan Kehoe <kehoea@parhasard.net> * coding.el (query-coding-string): Correct the order of arguments passed to #'query-coding-region. (unencodable-char-position): Handle string offsets correctly, they're one less than buffer offsets. Handle START and END correctly if passed a string.
author Aidan Kehoe <kehoea@parhasard.net>
date Wed, 11 Feb 2009 12:11:26 +0000
parents 854c88538753
children 308d34e9f07d
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 <...> */
1743
543769b89fed [xemacs-hg @ 2003-10-14 05:02:57 by james]
james
parents: 1706
diff changeset
81 #include "compiler.h"
1506
4d97756f2fbe [xemacs-hg @ 2003-05-29 17:02:31 by james]
james
parents: 1269
diff changeset
82
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
83 #ifndef HAVE_SHLIB
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
84 int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
85 main (int argc, char *argv[])
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 fprintf (stderr, "Dynamic modules not supported on this platform\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
88 return EXIT_FAILURE;
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 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
91
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 * 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
94 * and how to compile for PIC mode.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
95 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
96
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
97 static char *progname;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
98 static char *mod_name = NULL;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
99 static char *mod_version = NULL;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
100 static char *mod_title = NULL;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
101 static char *mod_output = NULL;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
102 static int exec_argc = 1;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
103 static int exec_length = 0;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
104 static int *exec_args;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
105 static int real_argc = 0;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
106 static char **prog_argv;
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 /*
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
109 * 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
110 */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
111 static char *ellcc, *ellld, *ellcflags, *ellldflags, *ellpicflags,
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
112 *elldllflags;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
113
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
114 #define OVERENV(STR,EVAR,DFLT) \
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
115 do { \
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
116 STR = getenv (EVAR); \
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
117 if ((STR) == NULL) { \
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
118 STR = DFLT; \
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
119 } \
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
120 } while(0)
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
121
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
122 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
123 * xnew, xrnew -- allocate, reallocate storage
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 * SYNOPSIS: Type *xnew (int n, Type);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
126 * Type *xrnew (OldPointer, int n, Type);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
127 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
128 #ifdef chkmalloc
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
129 # include "chkmalloc.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
130 # define xnew(n,Type) ((Type *) trace_malloc (__FILE__, __LINE__, \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
131 (n) * sizeof (Type)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
132 # define xrnew(op,n,Type) ((Type *) trace_realloc (__FILE__, __LINE__, \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
133 (op), (n) * sizeof (Type)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
134 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
135 # define xnew(n,Type) ((Type *) xmalloc ((n) * sizeof (Type)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
136 # define xrnew(op,n,Type) ((Type *) xrealloc ((op), (n) * sizeof (Type)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
137 #endif
996
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 * Ellcc modes of operation
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
141 */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
142
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
143 enum mode { ELLCC_COMPILE_MODE, ELLCC_LINK_MODE, ELLCC_INIT_MODE };
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 #ifdef DEBUG
1506
4d97756f2fbe [xemacs-hg @ 2003-05-29 17:02:31 by james]
james
parents: 1269
diff changeset
146 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
147
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
148 static const char *
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
149 ellcc_mode_name (enum mode ellcc_mode)
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
150 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
151 switch (ellcc_mode)
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
152 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
153 case ELLCC_COMPILE_MODE:
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
154 return "compile";
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
155 case ELLCC_LINK_MODE:
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
156 return "link";
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
157 case ELLCC_INIT_MODE:
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
158 return "init";
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 return "";
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 #endif
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
163
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 * Function Prototypes
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
166 */
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
167
1506
4d97756f2fbe [xemacs-hg @ 2003-05-29 17:02:31 by james]
james
parents: 1269
diff changeset
168 static void *xmalloc (size_t size) ATTRIBUTE_MALLOC;
4d97756f2fbe [xemacs-hg @ 2003-05-29 17:02:31 by james]
james
parents: 1269
diff changeset
169 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
170 static char *xstrdup (char *) ATTRIBUTE_MALLOC;
1743
543769b89fed [xemacs-hg @ 2003-10-14 05:02:57 by james]
james
parents: 1706
diff changeset
171 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
172 static char ** add_string (char **, char *);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
173 static char ** add_to_argv (char **, const char *);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
174 static char ** do_compile_mode (void);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
175 static char ** do_link_mode (void);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
176 static char ** do_init_mode (void);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
177
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
178 #define SSTR(S) ((S) != NULL ? (S) : "")
428
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 int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
181 main (int argc, char *argv[])
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
182 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
183 char *tmp;
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
184 char ** exec_argv;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
185 int i, done_mode = 0, verbose = 0;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
186 enum mode ellcc_mode;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
187
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
188 if (argc < 2)
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 /* FIXME: Print usage output instead */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
191 fatal ("too few arguments");
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
192 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
193
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
194 prog_argv = argv;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
195
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
196 #if defined(WIN32_NATIVE)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
197 tmp = strrchr (argv[0], '\\');
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
198 if (tmp != NULL)
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
199 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
200 tmp++;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
201 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
202 #elif !defined (VMS)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
203 tmp = strrchr (argv[0], '/');
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
204 if (tmp != NULL)
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
205 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
206 tmp++;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
207 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
208 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
209 tmp = argv[0];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
210 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
211
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
212 progname = (tmp == NULL) ? argv[0] : tmp;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
213
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
214 tmp = &progname[strlen(progname)-2];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
215 if (strcmp (tmp, "cc") == 0)
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
216 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
217 ellcc_mode = ELLCC_COMPILE_MODE;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
218 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
219 else if (strcmp (tmp, "ld") == 0)
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
220 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
221 ellcc_mode = ELLCC_LINK_MODE;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
222 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
223 else if (strcmp (tmp, "it") == 0)
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
224 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
225 ellcc_mode = ELLCC_INIT_MODE;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
226 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
227 else
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
228 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
229 ellcc_mode = ELLCC_COMPILE_MODE;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
230 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
231
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
232 exec_args = xnew(argc, int);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
233 exec_args[0] = 0;
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
234 for (i = 1; i < argc; i++)
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
235 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
236 exec_args[i] = -1;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
237 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
238
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
239 for (i = 1; i < argc; i++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
240 {
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
241 if (strncmp (argv[i], "--mode=", (size_t)7) == 0)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
242 {
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
243 char *modeopt = &argv[i][7];
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
244
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
245 if (done_mode && strcmp (modeopt, "verbose") != 0)
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 fatal ("more than one mode specified");
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
248 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
249 if (strcmp (modeopt, "link") == 0)
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 done_mode++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
252 ellcc_mode = ELLCC_LINK_MODE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
253 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
254 else if (strcmp (modeopt, "compile") == 0)
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 done_mode++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
257 ellcc_mode = ELLCC_COMPILE_MODE;
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 else if (strcmp (modeopt, "init") == 0)
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 done_mode++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
262 ellcc_mode = ELLCC_INIT_MODE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
263 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
264 else if (strcmp (modeopt, "verbose") == 0)
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
265 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
266 verbose++;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
267 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
268 else
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
269 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
270 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
271 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
272 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
273 else if (strcmp (argv[i], "--mod-location") == 0)
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 printf ("%s\n", ELLCC_MODDIR);
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
276 exit (EXIT_SUCCESS);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
277 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
278 else if (strcmp (argv[i], "--mod-site-location") == 0)
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 printf ("%s\n", ELLCC_SITEMODS);
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
281 exit (EXIT_SUCCESS);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
282 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
283 else if (strcmp (argv[i], "--mod-archdir") == 0)
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 printf ("%s\n", ELLCC_ARCHDIR);
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
286 exit (EXIT_SUCCESS);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
287 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
288 else if (strcmp (argv[i], "--mod-config") == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
289 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
290 printf ("%s\n", ELLCC_CONFIG);
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
291 exit (EXIT_SUCCESS);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
292 }
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
293 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
294 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
295 mod_name = &argv[i][11];
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
296 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
297 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
298 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
299 mod_title = &argv[i][12];
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
300 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
301 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
302 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
303 mod_version = &argv[i][14];
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
304 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
305 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
306 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
307 mod_output = &argv[i][13];
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
308 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
309 else
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 exec_args[exec_argc] = i;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
312 exec_argc++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
313 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
314 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
315
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
316 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
317 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
318 fatal ("must specify --mod-output when linking");
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
319 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
320 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
321 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
322 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
323 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
324 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
325 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
326 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
327 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
328
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 * 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
331 * 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
332 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
333 if (verbose)
996
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 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
336 ELLCC_EMACS_VER, EMODULES_VERSION, EMODULES_REVISION);
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
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
339 #ifdef DEBUG
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
340 if (verbose >= 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
341 {
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
342 printf (" mode = %d (%s)\n", (int)ellcc_mode,
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
343 ellcc_mode_name (ellcc_mode));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
344 printf (" module_name = \"%s\"\n", SSTR(mod_name));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
345 printf (" module_title = \"%s\"\n", SSTR(mod_title));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
346 printf (" module_version = \"%s\"\n", SSTR(mod_version));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
347
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
348 printf (" CC = %s\n", ELLCC_CC);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
349 printf (" CFLAGS = %s\n", ELLCC_CFLAGS);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
350 printf (" CC PIC flags = %s\n", ELLCC_DLL_CFLAGS);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
351 printf (" LD = %s\n", ELLCC_DLL_LD);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
352 printf (" LDFLAGS = %s\n", ELLCC_DLL_LDFLAGS);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
353 printf (" architecture = %s\n", ELLCC_CONFIG);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
354 printf (" Include directory = %s/include\n", ELLCC_ARCHDIR);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
355 printf ("\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
356 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
357 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
358
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
359 if (exec_argc < 2)
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
360 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
361 /* FIXME: Print usage output instead */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
362 fatal ("too few arguments");
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
363 }
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 /*
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
366 * Get the overrides from the environment
428
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 OVERENV(ellcc, "ELLCC", ELLCC_CC);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
369 OVERENV(ellld, "ELLLD", ELLCC_DLL_LD);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
370 OVERENV(ellcflags, "ELLCFLAGS", ELLCC_CFLAGS);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
371 OVERENV(ellldflags, "ELLLDFLAGS", ELLCC_LDFLAGS);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
372 OVERENV(elldllflags, "ELLDLLFLAGS", ELLCC_DLL_LDFLAGS);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
373 OVERENV(ellpicflags, "ELLPICFLAGS", ELLCC_DLL_CFLAGS);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
374
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
375 switch (ellcc_mode)
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
376 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
377 case ELLCC_COMPILE_MODE:
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
378 exec_argv = do_compile_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 case ELLCC_LINK_MODE:
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
381 exec_argv = do_link_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 default:
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
384 exec_argv = do_init_mode ();
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
385 break;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
386 }
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 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
389 * 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
390 * up and we can run the program.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
391 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
392 if (verbose)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
393 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
394 for (i = 0; i < real_argc; i++)
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
395 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
396 printf ("%s ", exec_argv[i]);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
397 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
398 printf ("\n");
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
399 (void)fflush (stdout);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
400 }
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
401
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
402 /* Terminate argument list. */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
403 exec_argv = add_string (exec_argv, NULL);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
404
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
405 i = execvp (exec_argv[0], exec_argv);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
406 if (verbose)
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
407 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
408 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
409 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
410 exit (i);
428
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
413 /* Like malloc but get fatal error if memory is exhausted. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
414 static void *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
415 xmalloc (size_t size)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
416 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
417 void *result = malloc (size);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
418 if (result == NULL)
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
419 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
420 fatal ("virtual memory exhausted");
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 return result;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
423 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
424
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
425 /* 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
426 static void *
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
427 xrealloc (void *ptr, size_t size)
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 void *result = realloc (ptr, size);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
430 if (result == NULL)
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
431 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
432 fatal ("virtual memory exhausted");
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 return result;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
435 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
436
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
437 /* 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
438 static char *
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
439 xstrdup (char *s)
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 char *result = strdup (s);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
442 if (result == NULL)
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 fatal ("virtual memory exhausted");
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
445 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
446 return result;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
447 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
448
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
449 /* Print error message and exit. */
1743
543769b89fed [xemacs-hg @ 2003-10-14 05:02:57 by james]
james
parents: 1706
diff changeset
450 static DOESNT_RETURN
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
451 fatal (char *format, ...)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
452 {
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
453 va_list ap;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
454
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
455 va_start (ap, format);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
456 (void)fprintf (stderr, "%s: ", progname);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
457 (void)vfprintf (stderr, format, ap);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
458 (void)fprintf (stderr, "\n");
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
459 va_end (ap);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
460 exit (EXIT_FAILURE);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
461 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
462
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
463 static char **
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
464 add_string (char **exec_argv, char *str)
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
465 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
466 if (real_argc >= exec_length)
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_length = real_argc + EXEC_GROW_SIZE;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
469 exec_argv = xrnew (exec_argv, exec_length, char *);
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 exec_argv[real_argc++] = str;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
472 return exec_argv;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
473 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
474
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
475 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
476 * 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
477 * 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
478 * arguments, taking quoting into account.
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 static char **
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
481 add_to_argv (char **exec_argv, const char *str)
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 /* Don't add nonexistent strings */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
484 if (str == NULL)
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 return exec_argv;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
487 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
488
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
489 /* Skip leading whitespace */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
490 while (isspace (*str))
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
491 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
492 str++;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
493 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
494
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
495 /* Don't add nonexistent strings */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
496 if (*str == '\0')
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
497 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
498 return exec_argv;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
499 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
500
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
501 while (*str != '\0')
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 const char *s;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
504 char *arg;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
505 int l;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
506
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
507 s = str; /* Mark the start of THIS argument */
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 /* Find contiguous nonwhitespace characters */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
510 while (*str != '\0' && !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 if (*str == '\\') /* Escaped character */
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 if (*str != '\0')
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 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 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
520 else if (*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 str++;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
523 while (*str != '\0' && *str != '\'')
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
524 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
525 if (str[0] == '\\' && str[1] != '\0')
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 str += 2;
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 else
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 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 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
534 if (*str == '\'')
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 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 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
539 else if (*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 str++;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
542 while (*str != '\0' && *str != '\"')
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
543 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
544 if (str[0] == '\\' && str[1] != '\0')
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
545 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
546 str += 2;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
547 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
548 else
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 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 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
553 if (*str == '\"')
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 str++;
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 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
558 else
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 str++; /* Normal character. Advance the pointer. */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
561 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
562 }
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 /* Reached the end of the argument. Add it. */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
565 l = str-s;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
566 arg = xnew(l+1, char);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
567 strncpy(arg, s, (size_t)l);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
568 arg[l] = '\0';
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
569 exec_argv = add_string (exec_argv, arg);
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 /* Skip trailing whitespace */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
572 while (isspace (*str))
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
573 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
574 str++;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
575 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
576 }
996
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 return exec_argv;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
579 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
580
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
581 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
582 * 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
583 * 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
584 * that we get all of the required arguments in place.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
585 */
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
586 static char **
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
587 do_compile_mode (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
588 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
589 int i;
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
590 char **exec_argv = xnew (exec_argc + 20, char *);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
591
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
592 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
593 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
594 exec_argv = add_to_argv (exec_argv, ellcflags);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
595 exec_argv = add_to_argv (exec_argv, ellpicflags);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
596 exec_argv = add_to_argv (exec_argv, "-DPIC");
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
597 exec_argv = add_to_argv (exec_argv, "-DEMACS_MODULE");
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
598 #ifdef XEMACS
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
599 /* Cover both cases */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
600 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
601 exec_argv = add_to_argv (exec_argv, "-Dxemacs");
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
602 #endif
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
603 exec_argv = add_to_argv (exec_argv, "-Demacs");
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
604 for (i = 1; i < exec_argc; i++)
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
605 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
606 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
607 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
608 return exec_argv;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
609 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
610
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
611 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
612 * 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
613 * insert the linker commands first, replace any occurrence of ELLSONAME
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
614 * with the desired output file name, insert the output arguments, then
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
615 * all of the provided arguments, then the final post arguments. Once
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
616 * 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
617 */
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
618 static char **
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
619 do_link_mode (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
620 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
621 int i,x;
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
622 char *t, *ts;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
623 char **exec_argv = xnew(exec_argc + 10, char *);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
624
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
625 exec_argv = add_to_argv (exec_argv, ellld);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
626 exec_argv = add_to_argv (exec_argv, ellldflags);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
627 exec_argv = add_to_argv (exec_argv, elldllflags);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
628 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
629 exec_argv = add_to_argv (exec_argv, mod_output);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
630 for (i = 1; i < exec_argc; i++)
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
631 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
632 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
633 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
634 exec_argv = add_to_argv (exec_argv, ELLCC_DLL_POST);
428
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 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
637 * Now go through each argument and replace ELLSONAME with mod_output.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
638 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
639 for (i = 0; i < real_argc; i++)
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 x = 0;
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
642 ts = xnew (2 * strlen (exec_argv[i]), char);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
643 ts[0] = '\0';
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 t = exec_argv[i];
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
646 while (*t != '\0')
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
647 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
648 if (*t == 'E')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
649 {
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
650 if (strncmp (t, "ELLSONAME", (size_t)9) == 0)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
651 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
652 strcat (ts, mod_output);
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
653 x += strlen (mod_output);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
654 t += 8;
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 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
657 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
658 ts[x] = *t;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
659 x++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
660 ts[x] = '\0';
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 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
663 else
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 ts[x] = *t;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
666 x++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
667 ts[x] = '\0';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
668 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
669 t++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
670 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
671 free (exec_argv[i]);
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
672 exec_argv[i] = ts;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
673 }
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
674 return exec_argv;
428
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
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 * 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
679 * 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
680 * make-doc program will be processing. We prepare the output file with
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
681 * 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
682 * special dispensation.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
683 */
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
684 static char **
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
685 do_init_mode (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
686 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
687 int i;
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
688 char *ts, *mdocprog;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
689 char **exec_argv = xnew(exec_argc + 8, char *);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
690 FILE *mout = fopen (mod_output, "w");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
691
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
692 if (mout == NULL)
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
693 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
694 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
695 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
696 fprintf (mout, "/* DO NOT EDIT - AUTOMATICALLY GENERATED */\n\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
697 fprintf (mout, "#include <emodules.h>\n\n");
1706
9fc738581a9d [xemacs-hg @ 2003-09-22 03:21:12 by james]
james
parents: 1506
diff changeset
698 fprintf (mout, "#ifdef __cplusplus\n");
9fc738581a9d [xemacs-hg @ 2003-09-22 03:21:12 by james]
james
parents: 1506
diff changeset
699 fprintf (mout, "extern \"C\" {\n");
9fc738581a9d [xemacs-hg @ 2003-09-22 03:21:12 by james]
james
parents: 1506
diff changeset
700 fprintf (mout, "#endif\n");
9fc738581a9d [xemacs-hg @ 2003-09-22 03:21:12 by james]
james
parents: 1506
diff changeset
701 fprintf (mout, "extern const long emodule_compiler;\n");
9fc738581a9d [xemacs-hg @ 2003-09-22 03:21:12 by james]
james
parents: 1506
diff changeset
702 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
703 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
704 fprintf (mout, "#ifdef __cplusplus\n");
9fc738581a9d [xemacs-hg @ 2003-09-22 03:21:12 by james]
james
parents: 1506
diff changeset
705 fprintf (mout, "}\n");
9fc738581a9d [xemacs-hg @ 2003-09-22 03:21:12 by james]
james
parents: 1506
diff changeset
706 fprintf (mout, "#endif\n\n");
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
707 fprintf (mout, "const long emodule_compiler = %ld;\n", EMODULES_REVISION);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
708 fprintf (mout, "const char *emodule_name = \"%s\";\n", SSTR(mod_name));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
709 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
710 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
711 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
712 if (fclose (mout) != 0)
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 close 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
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
717 mdocprog = getenv ("ELLMAKEDOC");
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
718 if (mdocprog == NULL)
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
719 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
720 mdocprog = xnew (14 + strlen (ELLCC_ARCHDIR), char);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
721 sprintf (mdocprog, "%s/make-docfile", ELLCC_ARCHDIR);
3983
854c88538753 [xemacs-hg @ 2007-05-24 20:18:50 by james]
james
parents: 1743
diff changeset
722 exec_argv = add_to_argv (exec_argv, mdocprog);
854c88538753 [xemacs-hg @ 2007-05-24 20:18:50 by james]
james
parents: 1743
diff changeset
723 free (mdocprog);
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
724 }
3983
854c88538753 [xemacs-hg @ 2007-05-24 20:18:50 by james]
james
parents: 1743
diff changeset
725 else
854c88538753 [xemacs-hg @ 2007-05-24 20:18:50 by james]
james
parents: 1743
diff changeset
726 {
854c88538753 [xemacs-hg @ 2007-05-24 20:18:50 by james]
james
parents: 1743
diff changeset
727 exec_argv = add_to_argv (exec_argv, mdocprog);
854c88538753 [xemacs-hg @ 2007-05-24 20:18:50 by james]
james
parents: 1743
diff changeset
728 }
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
729 ts = xnew (4 + strlen (mod_output), char);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
730 sprintf (ts, "-E %s", mod_output);
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
731 exec_argv = add_to_argv (exec_argv, ts);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
732 free (ts);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
733 for (i = 1; i < exec_argc; i++)
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
734 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
735 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
736 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 442
diff changeset
737 return exec_argv;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
738 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
739
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
740 #endif /* HAVE_SHLIB */