annotate lib-src/ellcc.c @ 872:79c6ff3eef26

[xemacs-hg @ 2002-06-20 21:18:01 by ben] font changes etc.; some 21.4 changes mule/mule-msw-init-late.el: Specify charset->windows-registry conversion. mule/mule-x-init.el: Delete extra mule font additions here. Put them in faces.c. cl-macs.el: Document better. font-lock.el: Move Lisp function regexp to lisp-mode.el. lisp-mode.el: Various indentation fixes: Handle flet functions better. Handle argument lists in defuns and flets. Handle quoted lists, e.g. property lists -- don't indent like function calls. Distinguish between lambdas and other lists. lisp-mode.el: Handle this form. faces.el, font-menu.el, font.el, gtk-faces.el, msw-faces.el, msw-font-menu.el, x-faces.el, x-init.el: Major overhaul of face-handling code: -- Fix lots of bogus code in msw-faces.el, msw-font-menu.el, font-menu.el that was "truenaming" font specs -- i.e. in the process of frobbing a particular field in a general user-specified font spec with wildcarded fields, sticking in particular values for all the remaining wildcarded fields. This bug was rampant everywhere except in x-faces.el (the oldest and only correctly written code). This also means that we need to work with font names at all times and not font instances, because a font instance is essentially a truenamed font. -- Total rewrite of extremely junky code in msw-faces.el. Work with names as well as font instances, and return names; stop truenaming when canonicalizing and frobbing; fix handling of the combined style field, i.e. weight/slant (also fixed in font.el). -- Totally rewrite the frobbing functions in faces.el. This time, we frob all the instantiators rather than just computing a single instance value and working backwards. That way, e.g., `bold' will work for all charsets that have bold available, rather than only for whatever charset was part of the computed font instance (another example of the truename virus). Also fix up code to look at the fallbacks (all of them) when no global value present, so we don't need to put something in the global value. Intelligently handle a request to frob a buffer locale, rather than signalling an error. When frobbing instantiators, try hard to figure out what device type is associated with them, and frob each according to its own proper device type. Correctly handle inheritance vectors given as instantiators. Preserve existing tags when putting back frobbed instantiators. Extract out general specifier-frobbing code into specifier.el. Document everything cleanly. Do lots of other things better, etc. -- Don't duplicatively set a global specification for the default font -- it's already in the fallback and we no longer need a default global specification present. Delete various code in x-faces.el and msw-faces.el that duplicated the lists of fonts in faces.c. -- init-global-faces was not being called at all under MS Windows! Major bogosity. That caused device-specific values to get stuck into all the fonts, making it very hard to change them -- setting global specs caused nothing to happen. -- Correct weight names in font.el. -- Lots more font fixups in objects*.c. Printer.el: Warning fix. specifier.el: Add more args to map-specifier. Add various "heuristic" specifier functions to aid in creation of specifier-munging code such as in faces.el. subr.el: New functions. lwlib.c: Fix warning. config.inc.samp: Clean up, add args to control fastcall (not yet supported! the changes needed are in another ws of mine), profile support, vc6 support, union-type. xemacs.dsp, xemacs.mak: Semi-major overhaul. Fix bug where dump-id was always getting recomputed, forcing a redump even when nothing changed. Add support for fastcall. Support edit-and-continue (on by default) with vc6. Use incremental linking when doing a debug compilation. Add support for profiling. Consolidate the various debug flags. Partial support for "batch-compiling" -- compiling many files on a single invocation of the compiler. Doesn't seem to help that much for me, so it's not finished or enabled by default. Remove HAVE_MSW_C_DIRED, we always do. Correct some sloppy use of directories. s/cygwin32.h: Allow pdump to work under Cygwin (mmap is broken, so need to undefine HAVE_MMAP). s/win32-common.h, s/windowsnt.h: Support for fastcall. Add WIN32_ANY for identifying all Win32 variants (Cygwin, native, MinGW). Both of these are properly used in another ws. alloc.c, balloon-x.c, buffer.c, bytecode.c, callint.c, cm.c, cmdloop.c, cmds.c, console-gtk.c, console-gtk.h, console-msw.c, console-msw.h, console-stream.c, console-stream.h, console-tty.c, console-tty.h, console-x.c, console-x.h, console.c, console.h, device-gtk.c, device-msw.c, device-tty.c, device-x.c, device.c, device.h, devslots.h, dialog-gtk.c, dialog-msw.c, dialog-x.c, dialog.c, dired-msw.c, editfns.c, emacs.c, event-Xt.c, event-gtk.c, event-msw.c, event-stream.c, event-tty.c, event-unixoid.c, events.c, extents.c, extents.h, faces.c, fileio.c, fns.c, frame-gtk.c, frame-msw.c, frame-tty.c, frame-x.c, frame.c, frame.h, glyphs-eimage.c, glyphs-gtk.c, glyphs-msw.c, glyphs-widget.c, glyphs-x.c, glyphs.c, glyphs.h, gui-gtk.c, gui-msw.c, gui-x.c, gui.c, gutter.c, input-method-xlib.c, intl-encap-win32.c, intl-win32.c, keymap.c, lisp.h, macros.c, menubar-gtk.c, menubar-msw.c, menubar-x.c, menubar.c, menubar.h, minibuf.c, mule-charset.c, nt.c, objects-gtk.c, objects-gtk.h, objects-msw.c, objects-msw.h, objects-tty.c, objects-tty.h, objects-x.c, objects-x.h, objects.c, objects.h, postgresql.c, print.c, process.h, redisplay-gtk.c, redisplay-msw.c, redisplay-output.c, redisplay-tty.c, redisplay-x.c, redisplay.c, redisplay.h, scrollbar-gtk.c, scrollbar-msw.c, scrollbar-x.c, scrollbar.c, select-gtk.c, select-msw.c, select-x.c, select.c, signal.c, sound.c, specifier.c, symbols.c, syntax.c, sysdep.c, syssignal.h, syswindows.h, toolbar-common.c, toolbar-gtk.c, toolbar-msw.c, toolbar-x.c, toolbar.c, unicode.c, window.c, window.h: The following are the major changes made: (1) Separation of various header files into an external and an internal version, similar to the existing separation of process.h and procimpl.h. Eventually this should be done for all Lisp objects. The external version has the same name as currently; the internal adds -impl. The external file has XFOO() macros for objects, but the structure is opaque and defined only in the internal file. It's now reasonable to move all prototypes in lisp.h into the appropriate external file, and this should be done. Currently, separation has been done on extents.h, objects*.h, console.h, device.h, frame.h, and window.h. For c/d/f/w, the most basic properties are available in the external header file, with the macros resolving to functions. In the internal header file, the macros are redefined to directly access the structure. Also, the global MARK_FOO_CHANGED macros have been made into functions so that they can be accessed without needing to include lots of -impl headers -- they are used in almost exclusively in non-time-critical functions, and take up enough time that the function overhead will be negligible. Similarly, the function overhead from making the basic properties mentioned above into functions is negligible, and code that does heavy accessing of c/d/f/w structures inevitably ends up needing the internal header files, anyway. (2) More face changes. -- Major rewrite of objects-msw.c. Now handles wildcard specs properly, rather than "truenaming" (or even worse, signalling an error, which previously happened with some of the fallbacks if you tried to use them in make-font-instance!). -- Split charset matching of fonts into two stages -- one to find a font specifically designed for a particular charset (by examining its registry), the second to find a Unicode font that can support the charset. This needs to proceed as two complete, separate instantiations in order to work properly (otherwise many of the fonts in the HELLO page look wrong). This should also make it easy to support iso10646 (Unicode) fonts under X. -- All default values for fonts are now completely specified in the fallbacks. Stuff from mule-x-init.el has all been moved here, merged with the existing specs, and totally rethought so you get sensible results. (HELLO now looks much better!). -- Generalize the "default X/GTK device" stuff into a per-device-type "default device". -- Add mswindows-{set-}charset-registry. In time, charset<->code-page conversion functions will be removed. -- Wrap protective code around calls to compute device specifier tags, and do this computation before calling the face initialization code because the latter may need these tags to be correctly updated. (3) Other changes. EmacsFrame.c, glyphs-msw.c, eval.c, gui-x.c, intl-encap-win32.c, search.c, signal.c, toolbar-msw.c, unicode.c: Warning fixes. config.h.in: #undefs meant to be frobbed by configure *MUST* go inside of #ifndef WIN32_NO_CONFIGURE, and everything else *MUST* go outside! eval.c: Let detailed backtraces be detailed. specifier.c: Don't override user's print-string-length/print-length settings. glyphs.c: New function image-instance-instantiator. config.h.in, sysdep.c: Changes for fastcall. sysdep.c, nt.c: Fix up a previous botched patch that tried to add support for both EEXIST and EACCES. IF THE BOTCHED PATCH WENT INTO 21.4, THIS FIXUP NEEDS TO GO IN, TOO. search.c: Fix *evil* crash due to incorrect synching of syntax-cache code with 21.1. THIS SHOULD GO INTO 21.4.
author ben
date Thu, 20 Jun 2002 21:19:10 +0000
parents abe6d1db359e
children 25e260cb7994
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.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4 This file is part of XEmacs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6 XEmacs is free software; you can redistribute it and/or modify it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7 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
8 Free Software Foundation; either version 2, or (at your option) any
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
9 later version.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
10
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
11 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
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
14 for more details.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
15
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
16 You should have received a copy of the GNU General Public License
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
17 along with XEmacs; see the file COPYING. If not, write to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
19 Boston, MA 02111-1307, USA.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
20
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
21 Author: J. Kean Johnston (jkj@sco.com).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
22 Please mail bugs and suggestions to the XEmacs maintainer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
23 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
24
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 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
27 the various Windows platforms don't have reliable scripting that suits
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
28 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
29 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
30 compiler.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
31
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
32 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
33 the module specific documentation and initialization code. We assume we
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
34 are in 'compile' mode unless we encounter an argument which tells us
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
35 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
36 compiler, except for a few which are specific to this program:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
37
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
38 --mode=VALUE This sets the program mode. VALUE can be one of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
39 compile, link, init or verbose.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
40 --mod-name=NAME Sets the module name to the string NAME.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
41 --mod-title=TITLE Sets the module title to the string TITLE.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
42 --mod-version=VER Sets the module version to the string VER.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
43
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
44 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
45 dynamic Emacs modules, and life should be as simple as:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
46
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
47 make CC=ellcc LD='ellcc --mode=link'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
48
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
49 The only additional requirement is an entry in the Makefile to produce
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
50 the module initialization file, which will usually be something along
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
51 the lines of:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
52
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
53 modinit.c: $(SRCS)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
54 ellcc --mode=init --mod-name=\"$(MODNAME)\" \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
55 --mod-title=\"$(MODTITLE)\" --mod-version=\"$(MODVERSION)\" \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
56 -o $@ $(SRCS)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
57
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
58 See the samples for more details.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
59 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
60
438
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
61 #include <config.h>
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
62 #include <stdio.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
63 #include <stdlib.h>
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
64 #include <stddef.h>
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
65 #include <string.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
66 #include <ctype.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
67 #include <errno.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
68 #include <sys/types.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
69
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
70 #ifdef HAVE_UNISTD_H
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
71 # include <unistd.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
72 #endif /* HAVE_UNISTD_H */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
73
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
74 #define EMODULES_GATHER_VERSION
438
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
75
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
76 #include <emodules.h>
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
77 #include <ellcc.h> /* Generated files must be included using <...> */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
78
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
79 #define DEBUG
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
80
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
81 #ifndef HAVE_SHLIB
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
82 int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
83 main (int argc, char *argv[])
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
84 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
85 fprintf (stderr, "Dynamic modules not supported on this platform\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
86 return EXIT_FAILURE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
87 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
88 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
89
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
90 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
91 * 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
92 * and how to compile for PIC mode.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
93 */
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 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
96 * xnew, xrnew -- allocate, reallocate storage
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
97 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
98 * SYNOPSIS: Type *xnew (int n, Type);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
99 * Type *xrnew (OldPointer, int n, Type);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
100 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
101 #ifdef chkmalloc
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
102 # include "chkmalloc.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
103 # define xnew(n,Type) ((Type *) trace_malloc (__FILE__, __LINE__, \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
104 (n) * sizeof (Type)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
105 # define xrnew(op,n,Type) ((Type *) trace_realloc (__FILE__, __LINE__, \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
106 (op), (n) * sizeof (Type)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
107 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
108 # define xnew(n,Type) ((Type *) xmalloc ((n) * sizeof (Type)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
109 # define xrnew(op,n,Type) ((Type *) xrealloc ((op), (n) * sizeof (Type)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
110 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
111 static void *xmalloc (size_t);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
112 static void fatal (char *, char *);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
113 static void add_to_argv (const char *);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
114 static void do_compile_mode (void);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
115 static void do_link_mode (void);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
116 static void do_init_mode (void);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
117
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
118 #define SSTR(S) ((S)?(S):"")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
119
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
120 #define ELLCC_COMPILE_MODE 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
121 #define ELLCC_LINK_MODE 1
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
122 #define ELLCC_INIT_MODE 2
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
123
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
124 static int ellcc_mode = ELLCC_COMPILE_MODE;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
125 static char *progname;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
126 static char *mod_name = NULL;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
127 static char *mod_version = NULL;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
128 static char *mod_title = NULL;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
129 static char *mod_output = NULL;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
130 static int verbose = 0;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
131 static char **exec_argv;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
132 static int exec_argc = 1;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
133 static int *exec_args;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
134 static int real_argc = 0;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
135 static int prog_argc;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
136 static char **prog_argv;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
137
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
138 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
139 * We allow the user to over-ride things in the environment
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
140 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
141 char *ellcc, *ellld, *ellcflags, *ellldflags, *ellpicflags, *elldllflags;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
142 #define OVERENV(STR,EVAR,DFLT) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
143 STR = getenv(EVAR); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
144 if ((STR) == (char *)0) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
145 STR = DFLT
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
146
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
147 int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
148 main (int argc, char *argv[])
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
149 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
150 char *tmp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
151 int i, done_mode = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
152
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
153 prog_argc = argc;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
154 prog_argv = argv;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
155
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
156 #if defined(WIN32_NATIVE)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
157 tmp = strrchr (argv[0], '\\');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
158 if (tmp != (char *)0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
159 tmp++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
160 #elif !defined (VMS)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
161 tmp = strrchr (argv[0], '/');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
162 if (tmp != (char *)0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
163 tmp++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
164 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
165 tmp = argv[0];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
166 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
167
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
168 if (tmp != (char *)0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
169 progname = tmp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
170 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
171 progname = argv[0];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
172
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
173 tmp = &progname[strlen(progname)-2];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
174 if (strcmp (tmp, "cc") == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
175 ellcc_mode = ELLCC_COMPILE_MODE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
176 else if (strcmp (tmp, "ld") == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
177 ellcc_mode = ELLCC_LINK_MODE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
178 else if (strcmp (tmp, "it") == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
179 ellcc_mode = ELLCC_INIT_MODE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
180
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
181 exec_argv = xnew(argc + 20, char *);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
182 exec_args = xnew(argc, int);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
183 for (i = 0; i < argc; i++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
184 exec_args[i] = -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
185
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
186 if (argc < 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
187 fatal ("too few arguments", (char *)0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
188
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
189 exec_args[0] = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
190
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
191 for (i = 1; i < argc; i++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
192 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
193 if (strncmp (argv[i], "--mode=", 7) == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
194 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
195 char *modeopt = argv[i] + 7;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
196
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
197 if (done_mode && strcmp (modeopt, "verbose"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
198 fatal ("more than one mode specified", (char *) 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
199 if (strcmp (modeopt, "link") == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
200 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
201 done_mode++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
202 ellcc_mode = ELLCC_LINK_MODE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
203 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
204 else if (strcmp (modeopt, "compile") == 0)
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 done_mode++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
207 ellcc_mode = ELLCC_COMPILE_MODE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
208 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
209 else if (strcmp (modeopt, "init") == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
210 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
211 done_mode++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
212 ellcc_mode = ELLCC_INIT_MODE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
213 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
214 else if (strcmp (modeopt, "verbose") == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
215 verbose += 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
216 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
217 else if (strcmp (argv[i], "--mod-location") == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
218 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
219 printf ("%s\n", ELLCC_MODDIR);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
220 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
221 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
222 else if (strcmp (argv[i], "--mod-site-location") == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
223 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
224 printf ("%s\n", ELLCC_SITEMODS);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
225 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
226 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
227 else if (strcmp (argv[i], "--mod-archdir") == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
228 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
229 printf ("%s\n", ELLCC_ARCHDIR);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
230 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
231 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
232 else if (strcmp (argv[i], "--mod-config") == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
233 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
234 printf ("%s\n", ELLCC_CONFIG);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
235 return 0;
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 else if (strncmp (argv[i], "--mod-name=", 11) == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
238 mod_name = argv[i] + 11;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
239 else if (strncmp (argv[i], "--mod-title=", 12) == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
240 mod_title = argv[i] + 12;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
241 else if (strncmp (argv[i], "--mod-version=", 14) == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
242 mod_version = argv[i] + 14;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
243 else if (strncmp (argv[i], "--mod-output=", 13) == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
244 mod_output = argv[i] + 13;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
245 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
246 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
247 exec_args[exec_argc] = i;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
248 exec_argc++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
249 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
250 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
251
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
252 if (ellcc_mode == ELLCC_LINK_MODE && mod_output == (char *)0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
253 fatal ("must specify --mod-output when linking", (char *)0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
254 if (ellcc_mode == ELLCC_INIT_MODE && mod_output == (char *)0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
255 fatal ("must specify --mod-output when creating init file", (char *)0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
256 if (ellcc_mode == ELLCC_INIT_MODE && mod_name == (char *)0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
257 fatal ("must specify --mod-name when creating init file", (char *)0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
258
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
259 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
260 * We now have the list of arguments to pass to the compiler or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
261 * linker (or to process for doc files). We can do the real work
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
262 * now.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
263 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
264 if (verbose)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
265 printf ("ellcc driver version %s for EMODULES version %s (%ld)\n",
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
266 ELLCC_EMACS_VER, EMODULES_VERSION, EMODULES_REVISION);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
267 #ifdef DEBUG
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
268 if (verbose >= 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
269 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
270 printf (" mode = %d (%s)\n", ellcc_mode,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
271 ellcc_mode == ELLCC_COMPILE_MODE ? "compile" :
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
272 ellcc_mode == ELLCC_LINK_MODE ? "link" : "init");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
273 printf (" module_name = \"%s\"\n", SSTR(mod_name));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
274 printf (" module_title = \"%s\"\n", SSTR(mod_title));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
275 printf (" module_version = \"%s\"\n", SSTR(mod_version));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
276
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
277 printf (" CC = %s\n", ELLCC_CC);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
278 printf (" CFLAGS = %s\n", ELLCC_CFLAGS);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
279 printf (" CC PIC flags = %s\n", ELLCC_DLL_CFLAGS);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
280 printf (" LD = %s\n", ELLCC_DLL_LD);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
281 printf (" LDFLAGS = %s\n", ELLCC_DLL_LDFLAGS);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
282 printf (" architecture = %s\n", ELLCC_CONFIG);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
283 printf (" Include directory = %s/include\n", ELLCC_ARCHDIR);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
284 printf ("\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
285 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
286 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
287
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
288 if (exec_argc < 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
289 fatal ("too few arguments", (char *) 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
290
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
291 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
292 * Get the over-rides from the environment
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
293 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
294 OVERENV(ellcc, "ELLCC", ELLCC_CC);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
295 OVERENV(ellld, "ELLLD", ELLCC_DLL_LD);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
296 OVERENV(ellcflags, "ELLCFLAGS", ELLCC_CFLAGS);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
297 OVERENV(ellldflags, "ELLLDFLAGS", ELLCC_LDFLAGS);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
298 OVERENV(elldllflags, "ELLDLLFLAGS", ELLCC_DLL_LDFLAGS);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
299 OVERENV(ellpicflags, "ELLPICFLAGS", ELLCC_DLL_CFLAGS);
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 if (ellcc_mode == ELLCC_COMPILE_MODE)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
302 do_compile_mode();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
303 else if (ellcc_mode == ELLCC_LINK_MODE)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
304 do_link_mode();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
305 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
306 do_init_mode();
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 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
309 * 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
310 * up and we can run the program.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
311 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
312 if (verbose)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
313 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
314 for (i = 0; i < real_argc; i++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
315 printf ("%s ", exec_argv[i]);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
316 printf ("\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
317 fflush (stdout);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
318 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
319 exec_argv[real_argc] = (char *)0; /* Terminate argument list */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
320
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
321 i = execvp (exec_argv[0], exec_argv);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
322 if (verbose)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
323 printf ("%s exited with status %d\n", exec_argv[0], i);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
324 return i;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
325 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
326
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
327 /* Like malloc but get fatal error if memory is exhausted. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
328 static void *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
329 xmalloc (size_t size)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
330 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
331 void *result = malloc (size);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
332 if (result == NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
333 fatal ("virtual memory exhausted", (char *)0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
334 return result;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
335 }
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 /* Print error message and exit. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
338 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
339 fatal (char *s1, char *s2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
340 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
341 fprintf (stderr, "%s: ", progname);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
342 fprintf (stderr, s1, s2);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
343 fprintf (stderr, "\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
344 exit (EXIT_FAILURE);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
345 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
346
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
347 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
348 * 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
349 * to the compiler or linker. We need to split individual words into
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
350 * arguments, taking quoting into account. This can get ugly.
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 static void
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
353 add_to_argv (const char *str)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
354 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
355 int sm = 0;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
356 const char *s = (const char *)0;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
357
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
358 if ((str == (const char *)0) || (str[0] == '\0'))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
359 return;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
360
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
361 while (*str)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
362 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
363 switch (sm)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
364 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
365 case 0: /* Start of case - string leading whitespace */
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
366 if (isspace ((unsigned char) *str))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
367 str++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
368 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
369 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
370 sm = 1; /* Change state to non-whitespace */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
371 s = str; /* Mark the start of THIS argument */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
372 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
373 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
374
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
375 case 1: /* Non-whitespace character. Mark the start */
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
376 if (isspace ((unsigned char) *str))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
377 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
378 /* Reached the end of the argument. Add it. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
379 int l = str-s;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
380 exec_argv[real_argc] = xnew (l+2, char);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
381 strncpy (exec_argv[real_argc], s, l);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
382 exec_argv[real_argc][l] = '\0';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
383 real_argc++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
384 sm = 0; /* Back to start state */
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
385 s = (const char *)0;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
386 break;
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 else if (*str == '\\')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
389 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
390 sm = 2; /* Escaped character */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
391 str++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
392 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
393 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
394 else if (*str == '\'')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
395 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
396 /* Start of quoted string (single quotes) */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
397 sm = 3;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
398 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
399 else if (*str == '"')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
400 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
401 /* Start of quoted string (double quotes) */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
402 sm = 4;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
403 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
404 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
405 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
406 /* This was just a normal character. Advance the pointer. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
407 str++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
408 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
409 break;
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 case 2: /* Escaped character */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
412 str++; /* Preserve the quoted character */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
413 sm = 1; /* Go back to gathering state */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
414 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
415
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
416 case 3: /* Inside single quoted string */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
417 if (*str == '\'')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
418 sm = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
419 str++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
420 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
421
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
422 case 4: /* inside double quoted string */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
423 if (*str == '"')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
424 sm = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
425 str++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
426 break;
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 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
429
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
430 if (s != (const char *)0)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
431 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
432 int l = str-s;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
433 exec_argv[real_argc] = xnew (l+2, char);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
434 strncpy (exec_argv[real_argc], s, l);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
435 exec_argv[real_argc][l] = '\0';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
436 real_argc++;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
437 s = (const char *)0;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
438 }
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
441 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
442 * 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
443 * 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
444 * that we get all of the required arguments in place.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
445 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
446 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
447 do_compile_mode (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
448 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
449 int i;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
450 char ts[4096]; /* Plenty big enough */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
451
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
452 add_to_argv (ellcc);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
453 add_to_argv (ellcflags);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
454 add_to_argv (ellpicflags);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
455 add_to_argv ("-DPIC");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
456 add_to_argv ("-DEMACS_MODULE");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
457 #ifdef XEMACS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
458 add_to_argv ("-DXEMACS_MODULE"); /* Cover both cases */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
459 add_to_argv ("-Dxemacs");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
460 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
461 add_to_argv ("-Demacs");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
462 sprintf (ts, "-I%s/include", ELLCC_ARCHDIR);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
463 add_to_argv (ts);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
464 add_to_argv (ELLCC_CF_ALL);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
465 for (i = 1; i < exec_argc; i++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
466 exec_argv[real_argc++] = strdup (prog_argv[exec_args[i]]);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
467 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
468
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
469 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
470 * 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
471 * insert the linker commands first, replace any occurrence of ELLSONAME
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
472 * with the desired output file name, insert the output arguments, then
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
473 * all of the provided arguments, then the final post arguments. Once
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
474 * 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
475 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
476 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
477 do_link_mode (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
478 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
479 int i,x;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
480 char *t, ts[4096]; /* Plenty big enough */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
481
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
482 add_to_argv (ellld);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
483 add_to_argv (ellldflags);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
484 add_to_argv (elldllflags);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
485 add_to_argv (ELLCC_DLL_LDO);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
486 add_to_argv (mod_output);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
487 for (i = 1; i < exec_argc; i++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
488 exec_argv[real_argc++] = strdup (prog_argv[exec_args[i]]);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
489 add_to_argv (ELLCC_DLL_POST);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
490
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
491 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
492 * Now go through each argument and replace ELLSONAME with mod_output.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
493 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
494 for (i = 0; i < real_argc; i++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
495 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
496 x = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
497 ts[0] = '\0';
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 t = exec_argv[i];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
500 while (*t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
501 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
502 if (*t == 'E')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
503 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
504 if (strncmp (t, "ELLSONAME", 9) == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
505 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
506 strcat (ts, mod_output);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
507 t += 8;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
508 x += strlen (mod_output);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
509 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
510 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
511 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
512 ts[x] = *t;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
513 x++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
514 ts[x] = '\0';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
515 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
516 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
517 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
518 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
519 ts[x] = *t;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
520 x++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
521 ts[x] = '\0';
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 t++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
524 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
525 free (exec_argv[i]);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
526 exec_argv[i] = strdup (ts);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
527 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
528 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
529
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
530 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
531 * 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
532 * 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
533 * make-doc program will be processing. We prepare the output file with
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
534 * 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
535 * special dispensation.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
536 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
537 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
538 do_init_mode (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
539 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
540 int i;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
541 char ts[4096]; /* Plenty big enough */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
542 char *mdocprog;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
543 FILE *mout = fopen (mod_output, "w");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
544
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
545 if (mout == (FILE *)0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
546 fatal ("failed to open output file", mod_output);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
547 fprintf (mout, "/* DO NOT EDIT - AUTOMATICALLY GENERATED */\n\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
548 fprintf (mout, "#include <emodules.h>\n\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
549 fprintf (mout, "const long emodule_compiler = %ld;\n", EMODULES_REVISION);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
550 fprintf (mout, "const char *emodule_name = \"%s\";\n", SSTR(mod_name));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
551 fprintf (mout, "const char *emodule_version = \"%s\";\n", SSTR(mod_version));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
552 fprintf (mout, "const char *emodule_title = \"%s\";\n", SSTR(mod_title));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
553 fprintf (mout, "\n\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
554 fprintf (mout, "void docs_of_%s()\n", SSTR(mod_name));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
555 fclose (mout);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
556
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
557 sprintf (ts, "%s/make-docfile", ELLCC_ARCHDIR);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
558 OVERENV(mdocprog, "ELLMAKEDOC", ts);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
559 add_to_argv (mdocprog);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
560 sprintf (ts, "-E %s", mod_output);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
561 add_to_argv (ts);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
562 for (i = 1; i < exec_argc; i++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
563 exec_argv[real_argc++] = strdup (prog_argv[exec_args[i]]);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
564 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
565
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
566 #endif /* HAVE_SHLIB */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
567