annotate lib-src/ellcc.c @ 388:aabb7f5b1c81 r21-2-9

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