annotate lib-src/ellcc.c @ 1111:184461bc8de4

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