XEmacs 21.2.42 "Poseidon".
[chise/xemacs-chise.git.1] / info / emodules.info
1 This is ../info/emodules.info, produced by makeinfo version 4.0 from
2 emodules.texi.
3
4    This file documents the module loading technology of XEmacs.
5
6    Copyright (C) 1998 J. Kean Johnston.
7
8    Permission is granted to make and distribute verbatim copies of this
9 manual provided the copyright notice and this permission notice are
10 preserved on all copies.
11
12    Permission is granted to copy and distribute modified versions of
13 this manual under the conditions for verbatim copying, provided that the
14 entire resulting derived work is distributed under the terms of a
15 permission notice identical to this one.
16
17    Permission is granted to copy and distribute translations of this
18 manual into another language, under the above conditions for modified
19 versions, except that this permission notice may be stated in a
20 translation approved by the Foundation.
21
22    Permission is granted to copy and distribute modified versions of
23 this manual under the conditions for verbatim copying, provided also
24 that the section entitled "GNU General Public License" is included
25 exactly as in the original, and provided that the entire resulting
26 derived work is distributed under the terms of a permission notice
27 identical to this one.
28
29    Permission is granted to copy and distribute translations of this
30 manual into another language, under the above conditions for modified
31 versions, except that the section entitled "GNU General Public License"
32 may be included in a translation approved by the Free Software
33 Foundation instead of in the original English.
34
35 \1f
36 File: emodules.info,  Node: Top,  Next: Introduction,  Prev: (dir),  Up: (dir)
37
38    This Info file contains v1.0 of the XEmacs dynamic loadable module
39 support documentation.
40
41 * Menu:
42
43 * Introduction::                Introducing Emacs Modules
44 * Anatomy of a Module::         Basic module layout and technology
45 * Using ellcc::                 How to use the module compiler
46 * Defining Functions::          Creating new Lisp primitives
47 * Defining Variables::          Creating new Lisp variables
48 * Index::                       Concept Index
49
50  --- The Detailed Node Listing ---
51
52 Anatomy of a Module
53
54 * Required Header File::        Always include <emodules.h>
55 * Required Functions::          Functions you must always provide
56 * Required Variables::          Variables whose values you must provide
57 * Loading other Modules::       How to load dependent modules
58
59 Using `ellcc'
60
61 * Compile Mode::                Compiling modules using ellcc
62 * Initialization Mode::         Generating documentation and variables
63 * Link Mode::                   Creating the final loadable module
64 * Other ellcc options::         Other useful options
65 * Environment Variables::       How to control ellcc
66
67 Defining Functions
68
69 * Using DEFUN::                 Using the DEFUN macro to define functions
70 * Declaring Functions::         Declaring functions to the Lisp reader
71
72 \1f
73 File: emodules.info,  Node: Introduction,  Next: Anatomy of a Module,  Prev: Top,  Up: Top
74
75 Introduction
76 ************
77
78    XEmacs is a powerful, extensible editor.  The traditional way of
79 extending the functionality of XEmacs is to use its built-in Lisp
80 language (called Emacs Lisp, or Elisp for short).  However, while Elisp
81 is a full programming language and capable of extending XEmacs in more
82 ways than you can imagine, it does have its short-comings.
83
84    Firstly, Elisp is an interpreted language, and this has serious speed
85 implications.  Like all other interpreted languages (like Java), Elisp
86 is often suitable only for certain types of application or extension.
87 So although Elisp is a general purpose language, and very high level,
88 there are times when it is desirable to descend to a lower level
89 compiled language for speed purposes.
90
91    Secondly, Elisp (or Lisp in general) is not a very common language
92 any more, except for certain circles in the computer industry.  C is a
93 far more commonly known language, and because it is compiled, more
94 suited to a wider range of applications, especially those that require
95 low level access to a system or need to be as quick as possible.
96
97    This manual describes a new way of extending XEmacs, by using dynamic
98 loadable modules (also known as dynamically loadable libraries (DLLs),
99 dynamic shared objects (DSOs) or just simply shared objects), which can
100 be written in C or C++ and loaded into XEmacs at any time.  I sometimes
101 refer to this technology as "CEmacs", which is short for "C Extensible
102 Emacs".
103
104    XEmacs modules are configured into and installed with XEmacs by
105 default on all systems that support loading of shared objects.  From a
106 users perspective, the internals of XEmacs modules are irrelevant.  All
107 a user will ever need to know about shared objects is the name of the
108 shared object when they want to load a given module.  From a developers
109 perspective though, a lot more is provided.
110
111    *   Of primary interest is the `ellcc' program.  This program is
112      created during compile time, and is intended to abstract compiler
113      specific characteristics from the developer.  This program is
114      called to compile and link all objects that will make up the final
115      shared object, and accepts all common C compiler flags.  `ellcc'
116      also sets up the correct environment for compiling modules by
117      enabling any special compiler modes (such as PIC mode), setting
118      the correct include paths for the location of XEmacs internal
119      header files etc.  The program will also invoke the linker
120      correctly to created the final shared object which is loaded into
121      XEmacs.
122
123    *   CEmacs also makes all of the relevant XEmacs internal header
124      files available for module authors to use.  This is often required
125      to get data structure definitions and external variable
126      declarations.  The header files installed include the module
127      specific header file `emodules.h'.  Due to the nature of dynamic
128      modules, most of the internals of XEmacs are exposed.  *Note Top:
129      (internals)Top, for a more complete discussion on how to extend
130      and understand XEmacs.  All of the rules for C modules are
131      discussed there.
132
133    *   Part of the XEmacs distribution is a set of sample modules.
134      These are not installed when XEmacs is, but remain in the XEmacs
135      source tree.  These modules live in the directory `modules', which
136      is a sub-directory of the main XEmacs source code directory.
137      Please look at the samples carefully, and maybe even use them as a
138      basis for making your own modules.  Most of the concepts required
139      for writing extension modules are covered in the samples.
140
141    *   Last, but not least is this manual.  This can be viewed from
142      within XEmacs, and it can be printed out as well.  It is the
143      intention of this document that it will describe everything you
144      need to know about extending XEmacs in C.  If you do not find this
145      to be the case, please contact the author(s).
146
147    The rest of this document will discuss the actual mechanics of
148 XEmacs modules and work through several of the samples.  Please be sure
149 that you have read the XEmacs Internals Manual and understand
150 everything in it.  The concepts there apply to all modules.  This
151 document may have some overlap, but it is the internals manual which
152 should be considered the final authority.  It will also help a great
153 deal to look at the actual XEmacs source code to see how things are
154 done.
155
156 \1f
157 File: emodules.info,  Node: Anatomy of a Module,  Next: Using ellcc,  Prev: Introduction,  Up: Top
158
159 Anatomy of a Module
160 *******************
161
162    Each dynamically loadable XEmacs extension (hereafter referred to as
163 a module) has a certain compulsory format, and must contain several
164 pieces of information and several mandatory functions.  This chapter
165 describes the basic layout of a module, and provides a very simple
166 sample.  The source for this sample can be found in the file
167 `modules/simple/sample.c' in the main XEmacs source code tree.
168
169 * Menu:
170
171 * Required Header File::        Always include <emodules.h>
172 * Required Functions::          Functions you must always provide
173 * Required Variables::          Variables whose values you must provide
174 * Loading other Modules::       How to load dependent modules
175
176 \1f
177 File: emodules.info,  Node: Required Header File,  Next: Required Functions,  Prev: Anatomy of a Module,  Up: Anatomy of a Module
178
179 Required Header File
180 ====================
181
182    Every module must include the file `<emodules.h>'.  This will
183 include several other XEmacs internal header files, and will set up
184 certain vital macros.  One of the most important files included by
185 `emodules.h' is the generated `config.h' file, which contains all of
186 the required system abstraction macros and definitions.  Most modules
187 will probably require some pre-processor conditionals based on
188 constants defined in `config.h'.  Please read that file to familiarize
189 yourself with the macros defined there.
190
191    Depending on exactly what your module will be doing, you will
192 probably need to include one or more of the XEmacs internal header
193 files.  When you `#include <emodules.h>', you will get a few of the
194 most important XEmacs header files included automatically for you.  The
195 files included are:
196
197 `lisp.h'
198      This file contains most of the macros required for declaring Lisp
199      object types, macros for accessing Lisp objects, and global
200      variable declarations.
201
202 `sysdep.h'
203      All system dependent declarations and abstraction macros live
204      here.  You should never call low level system functions directly.
205      Rather, you should use the abstraction macros provided in this
206      header file.
207
208 `window.h'
209      This header file defines the window structures and Lisp types, and
210      provides functions and macros for manipulating multiple XEmacs
211      windows.
212
213 `buffer.h'
214      All macros and function declarations for manipulating internal and
215      user visible buffers appear in this file.
216
217 `insdel.h'
218      This header provides the information required for performing text
219      insertion and deletion.
220
221 `frame.h'
222      Provides the required structure, macro and function definitions for
223      manipulating XEmacs frames.
224
225 \1f
226 File: emodules.info,  Node: Required Functions,  Next: Required Variables,  Prev: Required Header File,  Up: Anatomy of a Module
227
228 Required Functions
229 ==================
230
231    Every module requires several initialization functions.  It is the
232 responsibility of these functions to load in any dependent modules, and
233 to declare all variables and functions which are to be made visible to
234 the XEmacs Lisp reader.  Each of these functions performs a very
235 specific task, and they are executed in the correct order by XEmacs.
236 All of these functions are `void' functions which take no arguments.
237 Here, briefly, are the required module functions.  Note that the actual
238 function names do not end with the string `_module', but rather they
239 end with the abbreviated module name by which the module is known.
240 More on the module name and its importance later.  Just bear in mind
241 that the text `_module' in the functions below is simply a
242 place-holder, not an actual function name.
243
244 `syms_of_module'
245      This required function is responsible for introducing to the Lisp
246      reader all functions that you have defined in your module using
247      `DEFUN()'.  Note that _only_ functions are declared here, using
248      the `DEFSUBR()' macro.  No variables are declared.
249
250 `vars_of_module'
251      This required function contains calls to macros such as
252      `DEFVAR_LISP()', `DEFVAR_BOOL()' etc, and its purpose is to
253      declare and initialize all and any variables that your module
254      defines.  They syntax for declaring variables is identical to the
255      syntax used for all internal XEmacs source code.  If the module is
256      intended to be usable statically linked into XEmacs, the actions
257      of this function are severely restricted.  *Note General Coding
258      Rules: (internals)General Coding Rules.  Also see the comments in
259      `src/emacs.c' (`main_1').  Modules which perform initializations
260      not permitted by these rules will probably work, but dual-use
261      (dynamic loading and static linking) modules will require very
262      careful, and possibly fragile, coding.
263
264 `modules_of_module'
265      This optional function should be used to load in any modules which
266      your module depends on.  The XEmacs module loading code makes sure
267      that the same module is not loaded twice, so several modules can
268      safely call the module load function for the same module.  Only
269      one copy of each module (at a given version) will ever be loaded.
270
271 `docs_of_module'
272      This is a required function, but not one which you need ever write.
273      This function is created automatically by `ellcc' when the module
274      initialization code is produced.  It is required to document all
275      functions and variables declared in your module.
276
277 \1f
278 File: emodules.info,  Node: Required Variables,  Next: Loading other Modules,  Prev: Required Functions,  Up: Anatomy of a Module
279
280 Required Variables
281 ==================
282
283    Not only does a module need to declare the initialization functions
284 mentioned above, it is also required to provide certain variables which
285 the module loading code searches for in order to determine the viability
286 of a module.  You are _not_ required to provide these variables in your
287 source files.  They are automatically set up in the module
288 initialization file by the `ellcc' compiler.  These variables are
289 discussed here simply for the sake of completeness.
290
291 `emodules_compiler'
292      This is a variable of type `long', and is used to indicate the
293      version of the XEmacs loading technology that was used to produce
294      the module being loaded.  This version number is completely
295      unrelated to the XEmacs version number, as a given module may
296      quite well work regardless of the version of XEmacs that was
297      installed at the time the module was created.
298
299      The XEmacs modules version is used to differentiate between major
300      changes in the module loading technology, not versions of XEmacs.
301
302 `emodules_name'
303      This is a short (typically 10 characters or less) name for the
304      module, and it is used as a suffix for all of the required
305      functions.  This is also the name by which the module is
306      recognized when loading dependent modules.  The name does not
307      necessarily have to be the same as the physical file name,
308      although keeping the two names in sync is a pretty good idea.  The
309      name must not be empty, and it must be a valid part of a C
310      function name.  The value of this variable is appended to the
311      function names `syms_of_', `vars_of_', `modules_of_' and
312      `docs_of_' to form the actual function names that the module
313      loading code looks for when loading a module.
314
315      This variable is set by the `--mod-name' argument to `ellcc'.
316
317 `emodules_version'
318      This string variable is used to load specific versions of a module.
319      Rarely will two or more versions of a module be left lying around,
320      but just in case this does happen, this variable can be used to
321      control exactly which module should be loaded.  See the Lisp
322      function `load-module' for more details.  This variable is set by
323      the `--mod-version' argument to `ellcc'.
324
325 `emodules_title'
326      This is a string which describes the module, and can contain
327      spaces or other special characters.  It is used solely for
328      descriptive purposes, and does not affect the loading of the
329      module.  The value is set by the `--mod-title' argument to `ellcc'.
330
331 \1f
332 File: emodules.info,  Node: Loading other Modules,  Prev: Required Variables,  Up: Anatomy of a Module
333
334 Loading other Modules
335 =====================
336
337    During the loading of a module, it is the responsibility of the
338 function `modules_of_module' to load in any modules which the current
339 module depends on.  If the module is stand-alone, and does not depend
340 on other modules, then this function can be left empty or even
341 undeclared.  However, if it does have dependencies, it must call
342 `emodules_load':
343
344      int emodules_load (const char *module,
345                         const char *modname,
346                         const char *modver)
347
348    The first argument MODULE is the name of the actual shared object or
349 DLL.  You can omit the `.so', `.ell' or `.dll' extension of you wish.
350 If you do not specify an absolute path name, then the same rules as
351 apply to loading Lisp modules are applied when searching for the
352 module.  If the module cannot be found in any of the standard places,
353 and an absolute path name was not specified, `emodules_load' will
354 signal an error and loading of the module will stop.
355
356    The second argument (MODNAME) is the module name to load, and must
357 match the contents of the variable EMODULE_NAME in the module to be
358 loaded. A mis-match will cause the module load to fail.  If this
359 parameter is `NULL' or empty, then no checks are performed against the
360 target module's EMODULE_NAME variable.
361
362    The last argument, MODVER, is the desired version of the module to
363 load, and is compared to the target module's EMODULE_VERSION value.  If
364 this parameter is not `NULL' or empty, and the match fails, then the
365 load of the module will fail.
366
367    `emodules_load' can be called recursively.  If, at any point during
368 the loading of modules a failure is encountered, then all modules that
369 were loaded since the top level call to `emodules_load' will be
370 unloaded.  This means that if any child modules fail to load, then
371 their parents will also fail to load.  This does not include previous
372 successful calls to `emodules_load' at the top level.
373
374 \1f
375 File: emodules.info,  Node: Using ellcc,  Next: Defining Functions,  Prev: Anatomy of a Module,  Up: Top
376
377 Using `ellcc'
378 *************
379
380    Before discussing the anatomy of a module in greater detail, you
381 should be aware of the steps required in order to correctly compile and
382 link a module for use within XEmacs.  There is little difference between
383 compiling normal C code and compiling a module.  In fact, all that
384 changes is the command used to compile the module, and a few extra
385 arguments to the compiler.
386
387    XEmacs now ships with a new user utility, called `ellcc'.  This is
388 the "Emacs Loadable Library C Compiler".  This is a wrapper program
389 that will invoke the real C compiler with the correct arguments to
390 compile and link your module.  With the exception of a few command line
391 options, this program can be considered a replacement for your C
392 compiler.  It accepts all of the same flags and arguments that your C
393 compiler does, so in many cases you can simply set the `make' variable
394 `CC' to `ellcc' and your code will be compiled as an Emacs module
395 rather than a static C object.
396
397    `ellcc' has three distinct modes of operation.  It can be run in
398 compile, link or initialization mode.  These modes are discussed in more
399 detail below.  If you want `ellcc' to show the commands it is
400 executing, you can specify the option `--mode=verbose' to `ellcc'.
401 Specifying this option twice will enable certain extra debugging
402 messages to be displayed on the standard output.
403
404 * Menu:
405
406 * Compile Mode::                Compiling modules using ellcc
407 * Initialization Mode::         Generating documentation and variables
408 * Link Mode::                   Creating the final loadable module
409 * Other ellcc options::         Other useful options
410 * Environment Variables::       How to control ellcc
411
412 \1f
413 File: emodules.info,  Node: Compile Mode,  Next: Initialization Mode,  Prev: Using ellcc,  Up: Using ellcc
414
415 Compile Mode
416 ============
417
418    By default, `ellcc' is in "compile" mode.  This means that it
419 assumes that all of the command line arguments are C compiler arguments,
420 and that you want to compile the specified source file or files.  You
421 can force compile mode by specifying the `--mode=compile' argument to
422 `ellcc'.
423
424    In this mode, `ellcc' is simply a front-end to the same C compiler
425 that was used to create the XEmacs binary itself.  All `ellcc' does in
426 this mode is insert a few extra command line arguments before the
427 arguments you specify to `ellcc' itself.  `ellcc' will then invoke the
428 C compiler to compile your module, and will return the same exit codes
429 and messages that your C compiler does.
430
431    By far the easiest way to compile modules is to construct a
432 `Makefile' as you would for a normal program, and simply insert, at
433 some appropriate place something similar to:
434
435      CC=ellcc --mode=compile
436      
437      .c.o:
438          $(CC) $(CFLAGS) -c $<
439
440    After this, all you need to do is provide simple `make' rules for
441 compiling your module source files.  Since modules are most useful when
442 they are small and self-contained, most modules will have a single
443 source file, aside from the module specific initialization file (see
444 below for details).
445
446 \1f
447 File: emodules.info,  Node: Initialization Mode,  Next: Link Mode,  Prev: Compile Mode,  Up: Using ellcc
448
449 Initialization Mode
450 ===================
451
452    XEmacs uses a rather bizarre way of documenting variables and
453 functions.  Rather than have the documentation for compiled functions
454 and variables passed as static strings in the source code, the
455 documentation is included as a C comment.  A special program, called
456 `make-docfile', is used to scan the source code files and extract the
457 documentation from these comments, producing the XEmacs `DOC' file,
458 which the internal help engine scans when the documentation for a
459 function or variable is requested.
460
461    Due to the internal construction of Lisp objects, subrs and other
462 such things, adding documentation for a compiled function or variable
463 in a compiled module, at any time after XEmacs has been "dumped" is
464 somewhat problematic.  Fortunately, as a module writer you are insulated
465 from the difficulties thanks to your friend `ellcc' and some internal
466 trickery in the module loading code.  This is all done using the
467 "initialization" mode of `ellcc'.
468
469    The result of running `ellcc' in initialization mode is a C source
470 file which you compile with (you guessed it) `ellcc' in compile mode.
471 Initialization mode is where you set the module name, version, title
472 and gather together all of the documentation strings for the functions
473 and variables in your module.  There are several options that you are
474 required to pass `ellcc' in initialization mode, the first of which is
475 the mode switch itself, `--mode=init'.
476
477    Next, you need to specify the name of the C source code file that
478 `ellcc' will produce, and you specify this using the
479 `--mod-output=FILENAME' argument.  FILENAME is the name of the C source
480 code file that will contain the module variables and `docs_of_module'
481 function.
482
483    As discussed previously, each module requires a short "handle" or
484 module name.  This is specified with the `--mod-name=NAME' option,
485 where NAME is the abbreviated module name.  This NAME must consist only
486 of characters that are valid in C function and variable names.
487
488    The module version is specified using `--mod-version=VERSION'
489 argument, with VERSION being any arbitrary version string.  This
490 version can be passed as an optional second argument to the Lisp
491 function `load-module', and as the third argument to the internal
492 module loading command `emodules_load'.  This version string is used to
493 distinguish between different versions of the same module, and to
494 ensure that the module is loaded at a specific version.
495
496    Last, but not least, is the module title.  Specified using the
497 `--mod-title=TITLE' option, the specified TITLE is used when the list
498 of loaded modules is displayed.  The module title serves no purpose
499 other than to inform the user of the function of the module.  This
500 string should be brief, as it has to be formatted to fit the screen.
501
502    Following all of these parameters, you need to provide the list of
503 all source code modules that make up your module.  These are the files
504 which are scanned by `make-docfile', and provide the information
505 required to populate the `docs_of_module' function.  Below is a sample
506 `Makefile' fragment which indicates how all of this is used.
507
508      CC=ellcc --mode=compile
509      LD=ellcc --mode=link
510      MODINIT=ellcc --mode=init
511      CFLAGS=-O2 -DSOME_STUFF
512      
513      .c.o:
514          $(CC) $(CFLAGS) -c $<
515      
516      MODNAME=sample
517      MODVER=1.0.0
518      MODTITLE="Small sample module"
519      
520      SRCS=modfile1.c modfile2.c modfile3.c
521      OBJS=$(SRCS:.c=.o)
522      
523      all: sample.ell
524      clean:
525          rm -f $(OBJS) sample_init.o sample.ell
526      
527      install: all
528          mkdir `ellcc --mod-location`/mymods > /dev/null
529          cp sample.ell `ellcc --mod-location`/mymods/sample.ell
530      
531      sample.ell: $(OBJS) sample_init.o
532          $(LD) --mod-output=$ $(OBJS) sample_init.o
533      
534      sample_init.o: sample_init.c
535      sample_init.c: $(SRCS)
536          $(MODINIT) --mod-name=$(MODNAME) --mod-version=$(MODVER) \
537          --mod-title=$(MODTITLE) --mod-output=$ $(SRCS)
538
539    The above `Makefile' is, in fact, complete, and would compile the
540 sample module, and optionally install it.  The `--mod-location'
541 argument to `ellcc' will produce, on the standard output, the base
542 location of the XEmacs module directory.  Each sub-directory of that
543 directory is automatically searched for for modules when they are loaded
544 with `load-module'.  An alternative location would be
545 `/usr/local/lib/xemacs/site-modules'.  That path can change depending
546 on the options the person who compiled XEmacs chose, so you can always
547 determine the correct site location using the `--mod-site-location'
548 option.  This directory is treated the same way as the main module
549 directory.  Each sub-directory within it is searched for a given module
550 when the user attempts to load it.  The valid extensions that the
551 loader attempts to use are `.so', `.ell' and `.dll'.  You can use any
552 of these extensions, although `.ell' is the preferred extension.
553
554 \1f
555 File: emodules.info,  Node: Link Mode,  Next: Other ellcc options,  Prev: Initialization Mode,  Up: Using ellcc
556
557 Link Mode
558 =========
559
560    Once all of your source code files have been compiled (including the
561 generated init file) you need to link them all together to create the
562 loadable module.  To do this, you invoke `ellcc' in link mode, by
563 passing the `--mode=link' option.  You need to specify the final output
564 file using the `--mod-output=NAME' option, but other than that all
565 other arguments are passed on directly to the system compiler or
566 linker, along with any other required arguments to create the loadable
567 module.
568
569    The module has complete access to all symbols that were present in
570 the dumped XEmacs, so you do not need to link against libraries that
571 were linked in with the main executable.  If your library uses some
572 other extra libraries, you will need to link with those.  There is
573 nothing particularly complicated about link mode.  All you need to do
574 is make sure you invoke it correctly in the `Makefile'.  See the sample
575 `Makefile' above for an example of a well constructed `Makefile' that
576 invoked the linker correctly.
577
578 \1f
579 File: emodules.info,  Node: Other ellcc options,  Next: Environment Variables,  Prev: Link Mode,  Up: Using ellcc
580
581 Other `ellcc' options
582 =====================
583
584    Aside from the three main `ellcc' modes described above, `ellcc' can
585 accept several other options.  These are typically used in a `Makefile'
586 to determine installation paths.  `ellcc' also allows you to over-ride
587 several of its built-in compiler and linker options using environment
588 variables.  Here is the complete list of options that `ellcc' accepts.
589
590 `--mode=compile'
591      Enables compilation mode.  Use this to compile source modules.
592
593 `--mode=link'
594      Enabled link edit mode.  Use this to create the final module.
595
596 `--mode=init'
597      Used to create the documentation function and to initialize other
598      required variables.  Produces a C source file that must be
599      compiled with `ellcc' in compile mode before linking the final
600      module.
601
602 `--mode=verbose'
603      Enables verbose mode.  This will show you the commands that are
604      being executed, as well as the version number of `ellcc'.  If you
605      specify this option twice, then some extra debugging information
606      is displayed.
607
608 `--mod-name=NAME'
609      Sets the short internal module NAME to the string specified, which
610      must consist only of valid C identifiers.  Required during
611      initialization mode.
612
613 `--mod-version=VERSION'
614      Sets the internal module VERSION to the specified string.
615      Required during initialization mode.
616
617 `--mod-title=TITLE'
618      Sets the module descriptive TITLE to the string specified.  This
619      string can contain any printable characters, but should not be too
620      long.  It is required during initialization mode.
621
622 `--mod-output=FILENAME'
623      Used to control the output file name.  This is used during
624      initialization mode to set the name of the C source file that will
625      be created to FILENAME.  During link mode, it sets the name of the
626      final loadable module to FILENAME.
627
628 `--mod-location'
629      This will print the name of the standard module installation path
630      on the standard output and immediately exit `ellcc'.  Use this
631      option to determine the directory prefix of where you should
632      install your modules.
633
634 `--mod-site-location'
635      This will print the name of the site specific module location and
636      exit.
637
638 `--mod-archdir'
639      Prints the name of the root of the architecture-dependent
640      directory that XEmacs searches for architecture-dependent files.
641
642 `--mod-config'
643      Prints the name of the configuration for which XEmacs and `ellcc'
644      were compiled.
645
646 \1f
647 File: emodules.info,  Node: Environment Variables,  Prev: Other ellcc options,  Up: Using ellcc
648
649 Environment Variables
650 =====================
651
652    During its normal operation, `ellcc' uses the compiler and linker
653 flags that were determined at the time XEmacs was configured.  In
654 certain rare circumstances you may wish to over-ride the flags passed to
655 the compiler or linker, and you can do so using environment variables.
656 The table below lists all of the environment variables that `ellcc'
657 recognizes.
658
659 `ELLCC'
660      This is used to over-ride the name of the C compiler that is
661      invoked by `ellcc'.
662
663 `ELLLD'
664      Sets the name of the link editor to use to created the final
665      module.
666
667 `ELLCFLAGS'
668      Sets the compiler flags passed on when compiling source modules.
669      This only sets the basic C compiler flags.  There are certain
670      hard-coded flags that will always be passed.
671
672 `ELLLDFLAGS'
673      Sets the flags passed on to the linker.  This does *not* include
674      the flags for enabling PIC mode.  This just sets basic linker
675      flags.
676
677 `ELLDLLFLAGS'
678      Sets the flags passed to the linker that are required to created
679      shared and loadable objects.
680
681 `ELLPICFLAGS'
682      Sets the C compiler option required to produce an object file that
683      is suitable for including in a shared library.  This option should
684      turn on PIC mode, or the moral equivalent thereof on the target
685      system.
686
687 `ELLMAKEDOC'
688      Sets the name of the `make-docfile' program to use.  Usually
689      `ellcc' will use the version that was compiled and installed with
690      XEmacs, but this option allows you to specify an alternative path.
691      Used during the compile phase of XEmacs itself.
692
693 \1f
694 File: emodules.info,  Node: Defining Functions,  Next: Defining Variables,  Prev: Using ellcc,  Up: Top
695
696 Defining Functions
697 ******************
698
699    One of the main reasons you would ever write a module is to provide
700 one or more "functions" for the user or the editor to use.  The term
701 "function" is a bit overloaded here, as it refers to both a C function
702 and the way it appears to Lisp, which is a "subroutine", or simply a
703 "subr".  A Lisp subr is also known as a Lisp primitive, but that term
704 applies less to dynamic modules.  *Note Writing Lisp Primitives:
705 (internals)Writing Lisp Primitives, for details on how to declare
706 functions.  You should familiarize yourself with the instructions
707 there.  The format of the function declaration is identical in modules.
708
709    Normal Lisp primitives document the functions they defining by
710 including the documentation as a C comment.  During the build process,
711 a program called `make-docfile' is run, which will extract all of these
712 comments, build up a single large documentation file, and will store
713 pointers to the start of each documentation entry in the dumped XEmacs.
714 This, of course, will not work for dynamic modules, as they are loaded
715 long after XEmacs has been dumped.  For this reason, we require a
716 special means for adding documentation for new subrs.  This is what the
717 macro `CDOCSUBR' is used for, and this is used extensively during
718 `ellcc' initialization mode.
719
720    When using `DEFUN' in normal XEmacs C code, the sixth "parameter" is
721 a C comment which documents the function.  For a dynamic module, we of
722 course need to convert the C comment to a usable string, and we need to
723 set the documentation pointer of the subr to this string.  As a module
724 programmer, you don't actually need to do any work for this to happen.
725 It is all taken care of in the `docs_of_module' function created by
726 `ellcc'.
727
728 * Menu:
729
730 * Using DEFUN::                 Using the DEFUN macro to define functions
731 * Declaring Functions::         Declaring functions to the Lisp reader
732
733 \1f
734 File: emodules.info,  Node: Using DEFUN,  Next: Declaring Functions,  Prev: Defining Functions,  Up: Defining Functions
735
736 Using `DEFUN'
737 =============
738
739    Although the full syntax of a function declaration is discussed in
740 the XEmacs internals manual in greater depth, what follows is a brief
741 description of how to define and implement a new Lisp primitive in a
742 module.  This is done using the `DEFUN' macro.  Here is a small example:
743
744      DEFUN ("my-function", Fmy_function, 1, 1, "FFile name: ", /*
745      Sample Emacs primitive function.
746      
747      The specified FILE is frobnicated before it is fnozzled.
748      */
749          (file))
750      {
751        char *filename;
752      
753        if (NILP(file))
754          return Qnil;
755      
756        filename = (char *)XSTRING_DATA(file);
757        frob(filename);
758        return Qt;
759      }
760
761    The first argument is the name of the function as it will appear to
762 the Lisp reader.  This must be provided as a string.  The second
763 argument is the name of the actual C function that will be created.
764 This is typically the Lisp function name with a preceding capital `F',
765 with hyphens converted to underscores.  This must be a valid C function
766 name.  Next come the minimum and maximum number of arguments,
767 respectively.  This is used to ensure that the correct number of
768 arguments are passed to the function.  Next is the `interactive'
769 definition.  If this function is meant to be run by a user
770 interactively, then you need to specify the argument types and prompts
771 in this string.  Please consult the XEmacs Lisp manual for more
772 details.  Next comes a C comment that is the documentation for this
773 function.  This comment *must* exist.  Last comes the list of function
774 argument names, if any.
775
776 \1f
777 File: emodules.info,  Node: Declaring Functions,  Prev: Using DEFUN,  Up: Defining Functions
778
779 Declaring Functions
780 ===================
781
782    Simply writing the code for a function is not enough to make it
783 available to the Lisp reader.  You have to, during module
784 initialization, let the Lisp reader know about the new function.  This
785 is done by calling `DEFSUBR' with the name of the function.  This is
786 the sole purpose of the initialization function `syms_of_module'.
787 *Note Required Functions::, for more details.
788
789    Each call to `DEFSUBR' takes as its only argument the name of the
790 function, which is the same as the second argument to the call to
791 `DEFUN'.  Using the example function above, you would insert the
792 following code in the `syms_of_module' function:
793
794      DEFSUBR(Fmy_function);
795
796    This call will instruct XEmacs to make the function visible to the
797 Lisp reader and will prepare for the insertion of the documentation into
798 the right place.  Once this is done, the user can call the Lisp
799 function `my-function', if it was defined as an interactive function
800 (which in this case it was).
801
802    Thats all there is to defining and announcing new functions.  The
803 rules for what goes inside the functions, and how to write good
804 modules, is beyond the scope of this document.  Please consult the
805 XEmacs internals manual for more details.
806
807 \1f
808 File: emodules.info,  Node: Defining Variables,  Next: Index,  Prev: Defining Functions,  Up: Top
809
810 Defining Variables
811 ******************
812
813    Rarely will you write a module that only contains functions.  It is
814 common to also provide variables which can be used to control the
815 behavior of the function, or store the results of the function being
816 executed.  The actual C variable types are the same for modules and
817 internal XEmacs primitives, and the declaration of the variables is
818 identical.
819
820    *Note Adding Global Lisp Variables: (internals)Adding Global Lisp
821 Variables, for more information on variables and naming conventions.
822
823    Once your variables are defined, you need to initialize them and make
824 the Lisp reader aware of them.  This is done in the `vars_of_module'
825 initialization function using special XEmacs macros such as
826 `DEFVAR_LISP', `DEFVAR_BOOL', `DEFVAR_INT' etc.  The best way to see
827 how to use these macros is to look at existing source code, or read the
828 internals manual.
829
830    One _very_ important difference between XEmacs variables and module
831 variables is how you use pure space.  Simply put, you *never* use pure
832 space in XEmacs modules.  The pure space storage is of a limited size,
833 and is initialized properly during the dumping of XEmacs.  Because
834 variables are being added dynamically to an already running XEmacs when
835 you load a module, you cannot use pure space.  Be warned: *do not use
836 pure space in modules.  Repeat, do not use pure space in modules.*
837 Once again, to remove all doubts: *DO NOT USE PURE SPACE IN MODULES!!!*
838
839    Below is a small example which declares and initializes two
840 variables.  You will note that this code takes into account the fact
841 that this module may very well be compiled into XEmacs itself.  This is
842 a prudent thing to do.
843
844      Lisp_Object Vsample_string;
845      int sample_boolean;
846      
847      void
848      vars_of_module()
849      {
850        DEFVAR_LISP ("sample-string", &Vsample_string /*
851      This is a sample string, declared in a module.
852      
853      Nothing magical about it.
854      */);
855      
856        DEFVAR_BOOL("sample-boolean", &sample_boolean /*
857      *Sample user-settable boolean.
858      */);
859      
860        sample_boolean = 0;
861        Vsample_string = build_string("My string");
862      }
863
864 \1f
865 File: emodules.info,  Node: Index,  Prev: Defining Variables,  Up: Top
866
867 Index
868 *****
869
870 * Menu:
871
872 * anatomy:                               Anatomy of a Module.
873 * compiler:                              Introduction.
874 * compiling:                             Compile Mode.
875 * config.h:                              Required Header File.
876 * defining functions:                    Defining Functions.
877 * defining objects:                      Defining Variables.
878 * defining variables:                    Defining Variables.
879 * DEFSUBR:                               Declaring Functions.
880 * DEFUN:                                 Using DEFUN.
881 * DEFVAR_BOOL:                           Defining Variables.
882 * DEFVAR_INT:                            Defining Variables.
883 * DEFVAR_LISP:                           Defining Variables.
884 * dependencies:                          Loading other Modules.
885 * DLL:                                   Introduction.
886 * docs_of_module:                        Required Functions.
887 * documentation <1>:                     Initialization Mode.
888 * documentation:                         Introduction.
889 * DSO:                                   Introduction.
890 * ELLCC:                                 Environment Variables.
891 * ellcc <1>:                             Using ellcc.
892 * ellcc:                                 Introduction.
893 * ELLCFLAGS:                             Environment Variables.
894 * ELLDLLFLAGS:                           Environment Variables.
895 * ELLLD:                                 Environment Variables.
896 * ELLLDFLAGS:                            Environment Variables.
897 * ELLMAKEDOC:                            Environment Variables.
898 * ELLPICFLAGS:                           Environment Variables.
899 * Emacs Modules:                         Introduction.
900 * emodules.h:                            Required Header File.
901 * emodules_load:                         Loading other Modules.
902 * environment variables:                 Environment Variables.
903 * format, module:                        Anatomy of a Module.
904 * functions, declaring:                  Declaring Functions.
905 * functions, defining:                   Using DEFUN.
906 * functions, Lisp:                       Using DEFUN.
907 * functions, required:                   Required Functions.
908 * header files:                          Introduction.
909 * help:                                  Introduction.
910 * include files:                         Required Header File.
911 * initialization <1>:                    Initialization Mode.
912 * initialization <2>:                    Required Variables.
913 * initialization:                        Required Functions.
914 * linker:                                Introduction.
915 * linking:                               Link Mode.
916 * module compiler:                       Using ellcc.
917 * module format:                         Anatomy of a Module.
918 * module skeleton:                       Anatomy of a Module.
919 * modules_of_module <1>:                 Loading other Modules.
920 * modules_of_module:                     Required Functions.
921 * objects, defining:                     Defining Variables.
922 * objects, Lisp:                         Defining Variables.
923 * paths:                                 Other ellcc options.
924 * required functions:                    Required Functions.
925 * required header:                       Required Header File.
926 * required variables:                    Required Variables.
927 * samples:                               Introduction.
928 * shared object:                         Introduction.
929 * skeleton, module:                      Anatomy of a Module.
930 * subrs:                                 Using DEFUN.
931 * syms_of_module:                        Required Functions.
932 * variables, defining:                   Defining Variables.
933 * variables, Lisp:                       Defining Variables.
934 * variables, required:                   Required Variables.
935 * vars_of_module:                        Required Functions.
936
937
938 \1f
939 Tag Table:
940 Node: Top\7f1536
941 Node: Introduction\7f2883
942 Node: Anatomy of a Module\7f7391
943 Node: Required Header File\7f8205
944 Node: Required Functions\7f10124
945 Node: Required Variables\7f12848
946 Node: Loading other Modules\7f15534
947 Node: Using ellcc\7f17591
948 Node: Compile Mode\7f19385
949 Node: Initialization Mode\7f20753
950 Node: Link Mode\7f25787
951 Node: Other ellcc options\7f26932
952 Node: Environment Variables\7f29511
953 Node: Defining Functions\7f31202
954 Node: Using DEFUN\7f33213
955 Node: Declaring Functions\7f34924
956 Node: Defining Variables\7f36267
957 Node: Index\7f38510
958 \1f
959 End Tag Table