3ec19caeede1e6fb0bc476d093441fc5630cd68c
[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 * Annatomy 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 Annatomy 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 dependant 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: Annatomy 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 knows as dynamicaly loadable libraries (DLLs),
99 dynamic shared objects (DSOs) or just simply shared objectcs), 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 availible 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: Annatomy of a Module,  Next: Using ellcc,  Prev: Introduction,  Up: Top
158
159 Annatomy of a Module
160 ********************
161
162    Each dynamically loadable XEmacs extension (hereafter refered to as a
163 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 dependant modules
175
176 \1f
177 File: emodules.info,  Node: Required Header File,  Next: Required Functions,  Prev: Annatomy of a Module,  Up: Annatomy 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 dependant 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: Annatomy 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 dependant modules, and
233 to declare all variables and functions which are to be made visibile 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.
256
257 `modules_of_module'
258      This optional function should be used to load in any modules which
259      your module depends on.  The XEmacs module loading code makes sure
260      that the same module is not loaded twice, so several modules can
261      safely call the module load function for the same module.  Only
262      one copy of each module (at a given version) will ever be loaded.
263
264 `docs_of_module'
265      This is a required function, but not one which you need ever write.
266      This function is created automatically by `ellcc' when the module
267      initialization code is produced.  It is required to document all
268      functions and variables declared in your module.
269
270 \1f
271 File: emodules.info,  Node: Required Variables,  Next: Loading other Modules,  Prev: Required Functions,  Up: Annatomy of a Module
272
273 Required Variables
274 ==================
275
276    Not only does a module need to declare the initialization functions
277 mentioned above, it is also required to provide certain variables which
278 the module loading code searches for in order to determine the viability
279 of a module.  You are _not_ required to provide these variables in your
280 source files.  They are automatically set up in the module
281 initialization file by the `ellcc' compiler.  These variables are
282 discussed here simply for the sake of completeness.
283
284 `emodules_compiler'
285      This is a variable of type `long', and is used to indicate the
286      version of the XEmacs loading technology that was used to produce
287      the module being loaded.  This version number is completely
288      unrelated to the XEmacs version number, as a given module may
289      quite well work regardless of the version of XEmacs that was
290      installed at the time the module was created.
291
292      The XEmacs modules version is used to differentiate between major
293      changes in the module loading technology, not versions of XEmacs.
294
295 `emodules_name'
296      This is a short (typically 10 characters or less) name for the
297      module, and it is used as a suffix for all of the required
298      functions.  This is also the name by which the module is
299      recognised when loading dependant modules.  The name does not
300      necessarily have to be the same as the physical file name,
301      although keeping the two names in sync is a pretty good idea.  The
302      name must not be empty, and it must be a valid part of a C
303      function name.  The value of this variable is appended to the
304      function names `syms_of_', `vars_of_', `modules_of_' and
305      `docs_of_' to form the actual function names that the module
306      loading code looks for when loading a module.
307
308      This variable is set by the `--mod-name' argument to `ellcc'.
309
310 `emodules_version'
311      This string variable is used to load specific versions of a module.
312      Rarely will two or more versions of a module be left lying around,
313      but just in case this does happen, this variable can be used to
314      control exactly which module should be loaded.  See the Lisp
315      function `load-module' for more details.  This variable is set by
316      the `--mod-version' argument to `ellcc'.
317
318 `emodules_title'
319      This is a string which describes the module, and can contain
320      spaces or other special characters.  It is used solely for
321      descriptive purposes, and does not affect the loading of the
322      module.  The value is set by the `--mod-title' argument to `ellcc'.
323
324 \1f
325 File: emodules.info,  Node: Loading other Modules,  Prev: Required Variables,  Up: Annatomy of a Module
326
327 Loading other Modules
328 =====================
329
330    During the loading of a module, it is the responsibility of the
331 function `modules_of_module' to load in any modules which the current
332 module depends on.  If the module is stand-alone, and does not depend
333 on other modules, then this function can be left empty or even
334 undeclared.  However, if it does have dependnacies, it must call
335 `emodules_load':
336
337      int emodules_load (CONST char *module,
338                         CONST char *modname,
339                         CONST char *modver)
340
341    The first argument MODULE is the name of the actual shared object or
342 DLL.  You can omit the `.so', `.ell' or `.dll' extension of you wish.
343 If you do not specify an absolute path name, then the same rules as
344 apply to loading Lisp modules are applied when searching for the
345 module.  If the module cannot be found in any of the standard places,
346 and an absolute path name was not specified, `emodules_load' will
347 signal an error and loading of the module will stop.
348
349    The second argument (MODNAME) is the module name to load, and must
350 match the contents of the variable EMODULE_NAME in the module to be
351 loaded. A mis-match will cause the module load to fail.  If this
352 parameter is `NULL' or empty, then no checks are performed against the
353 target module's EMODULE_NAME variable.
354
355    The last argument, MODVER, is the desired version of the module to
356 load, and is compared to the target module's EMODULE_VERSION value.  If
357 this parameter is not `NULL' or empty, and the match fails, then the
358 load of the module will fail.
359
360    `emodules_load' can be called recursively.  If, at any point during
361 the loading of modules a failure is encountered, then all modules that
362 were loaded since the top level call to `emodules_load' will be
363 unloaded.  This means that if any child modules fail to load, then
364 their parents will also fail to load.  This does not include previous
365 successful calls to `emodules_load' at the top level.
366
367 \1f
368 File: emodules.info,  Node: Using ellcc,  Next: Defining Functions,  Prev: Annatomy of a Module,  Up: Top
369
370 Using `ellcc'
371 *************
372
373    Before discussing the anatomy of a module in greater detail, you
374 should be aware of the steps required in order to correctly compile and
375 link a module for use within XEmacs.  There is little difference between
376 compiling normal C code and compiling a module.  In fact, all that
377 changes is the command used to compile the module, and a few extra
378 arguments to the compiler.
379
380    XEmacs now ships with a new user utility, called `ellcc'.  This is
381 the "Emacs Loadable Library C Compiler".  This is a wrapper program
382 that will invoke the real C compiler with the correct arguments to
383 compile and link your module.  With the exception of a few command line
384 options, this program can be considered a replacement for your C
385 compiler.  It accepts all of the same flags and arguments that your C
386 compiler does, so in many cases you can simply set the `make' variable
387 `CC' to `ellcc' and your code will be compiled as an Emacs module
388 rather than a static C object.
389
390    `ellcc' has three distinct modes of operation.  It can be run in
391 compile, link or initialization mode.  These modes are discussed in more
392 detail below.  If you want `ellcc' to show the commands it is
393 executing, you can specify the option `--mode=verbose' to `ellcc'.
394 Specifying this option twice will enable certain extra debugging
395 messages to be displayed on the standard output.
396
397 * Menu:
398
399 * Compile Mode::                Compiling modules using ellcc
400 * Initialization Mode::         Generating documentation and variables
401 * Link Mode::                   Creating the final loadable module
402 * Other ellcc options::         Other useful options
403 * Environment Variables::       How to control ellcc
404
405 \1f
406 File: emodules.info,  Node: Compile Mode,  Next: Initialization Mode,  Prev: Using ellcc,  Up: Using ellcc
407
408 Compile Mode
409 ============
410
411    By default, `ellcc' is in "compile" mode.  This means that it
412 assumes that all of the command line arguments are C compiler arguments,
413 and that you want to compile the specified source file or files.  You
414 can force compile mode by specifying the `--mode=compile' argument to
415 `ellcc'.
416
417    In this mode, `ellcc' is simply a front-end to the same C compiler
418 that was used to create the XEmacs binary itself.  All `ellcc' does in
419 this mode is insert a few extra command line arguments before the
420 arguments you specify to `ellcc' itself.  `ellcc' will then invoke the
421 C compiler to compile your module, and will return the same exit codes
422 and messages that your C compiler does.
423
424    By far the easiest way to compile modules is to construct a
425 `Makefile' as you would for a normal program, and simply insert, at
426 some appropriate place something similar to:
427
428      CC=ellcc --mode=compile
429      
430      .c.o:
431          $(CC) $(CFLAGS) -c $<
432
433    After this, all you need to do is provide simple `make' rules for
434 compiling your module source files.  Since modules are most useful when
435 they are small and self-contained, most modules will have a single
436 source file, aside from the module specific initialization file (see
437 below for details).
438
439 \1f
440 File: emodules.info,  Node: Initialization Mode,  Next: Link Mode,  Prev: Compile Mode,  Up: Using ellcc
441
442 Initialization Mode
443 ===================
444
445    XEmacs uses a rather bizarre way of documenting variables and
446 functions.  Rather than have the documentation for compiled functions
447 and variables passed as static strings in the source code, the
448 documentation is included as a C comment.  A special program, called
449 `make-docfile', is used to scan the source code files and extract the
450 documentation from these comments, producing the XEmacs `DOC' file,
451 which the internal help engine scans when the documentation for a
452 function or variable is requested.
453
454    Due to the internal construction of Lisp objects, subrs and other
455 such things, adding documentation for a compiled function or variable
456 in a compiled module, at any time after XEmacs has been "dumped" is
457 somewhat problematic.  Fortunately, as a module writer you are insulated
458 from the difficulties thanks to your friend `ellcc' and some internal
459 trickery in the module loading code.  This is all done using the
460 "initialization" mode of `ellcc'.
461
462    The result of running `ellcc' in initialization mode is a C source
463 file which you compile with (you guessed it) `ellcc' in compile mode.
464 Initialization mode is where you set the module name, version, title
465 and gather together all of the documentaion strings for the functions
466 and vairables in your module.  There are several options that you are
467 required to pass `ellcc' in initialization mode, the first of which is
468 the mode switch itself, `--mode=init'.
469
470    Next, you need to specify the name of the C source code file that
471 `ellcc' will produce, and you specify this using the
472 `--mod-output=FILENAME' argument.  FILENAME is the name of the C source
473 code file that will contain the module variables and `docs_of_module'
474 function.
475
476    As discussed previously, each module requires a short "handle" or
477 module name.  This is specified with the `--mod-name=NAME' option,
478 where NAME is the abbreviated module name.  This NAME must consist only
479 of characters that are valid in C function and variable names.
480
481    The module version is specified using `--mod-version=VERSION'
482 argument, with VERSION being any arbitrary version string.  This
483 version can be passed as an optional second argument to the Lisp
484 function `load-module', and as the third argument to the internal
485 module loading command `emodules_load'.  This version string is used to
486 distinguish between different versions of the same module, and to
487 ensure that the module is loaded at a specific version.
488
489    Last, but not least, is the module title.  Specified using the
490 `--mod-title=TITLE' option, the specified TITLE is used when the list
491 of loaded modules is displayed.  The module title serves no purpose
492 other than to inform the user of the function of the module.  This
493 string should be brief, as it has to be formatted to fit the screen.
494
495    Following all of these parameters, you need to provide the list of
496 all source code modules that make up your module.  These are the files
497 which are scanned by `make-docfile', and provide the information
498 required to populate the `docs_of_module' function.  Below is a sample
499 `Makefile' fragment which indicates how all of this is used.
500
501      CC=ellcc --mode=compile
502      LD=ellcc --mode=link
503      MODINIT=ellcc --mode=init
504      CFLAGS=-O2 -DSOME_STUFF
505      
506      .c.o:
507          $(CC) $(CFLAGS) -c $<
508      
509      MODNAME=sample
510      MODVER=1.0.0
511      MODTITLE="Small sample module"
512      
513      SRCS=modfile1.c modfile2.c modfile3.c
514      OBJS=$(SRCS:.c=.o)
515      
516      all: sample.ell
517      clean:
518          rm -f $(OBJS) sample_init.o sample.ell
519      
520      install: all
521          mkdir `ellcc --mod-location`/mymods > /dev/null
522          cp sample.ell `ellcc --mod-location`/mymods/sample.ell
523      
524      sample.ell: $(OBJS) sample_init.o
525          $(LD) --mod-output=$ $(OBJS) sample_init.o
526      
527      sample_init.o: sample_init.c
528      sample_init.c: $(SRCS)
529          $(MODINIT) --mod-name=$(MODNAME) --mod-version=$(MODVER) \
530          --mod-title=$(MODTITLE) --mod-output=$ $(SRCS)
531
532    The above `Makefile' is, in fact, complete, and would compile the
533 sample module, and optionally install it.  The `--mod-location'
534 argument to `ellcc' will produce, on the standard output, the base
535 location of the XEmacs module directory.  Each sub-directory of that
536 directory is automatically searched for for modules when they are loaded
537 with `load-module'.  An alternative location would be
538 `/usr/local/lib/xemacs/site-modules'.  That path can change depending
539 on the options the person who compiled XEmacs chose, so you can always
540 determine the correct site location using the `--mod-site-location'
541 option.  This directory is treated the same way as the main module
542 directory.  Each sub-directory within it is searched for a given module
543 when the user attempts to load it.  The valid extensions that the
544 loader attempts to use are `.so', `.ell' and `.dll'.  You can use any
545 of these extensions, although `.ell' is the prefered extension.
546
547 \1f
548 File: emodules.info,  Node: Link Mode,  Next: Other ellcc options,  Prev: Initialization Mode,  Up: Using ellcc
549
550 Link Mode
551 =========
552
553    Once all of your source code files have been compiled (including the
554 generated init file) you need to link them all together to created the
555 loadable module.  To do this, you invoke `ellcc' in link mode, by
556 pasing the `--mode-link' command.  You need to specify the final output
557 file using the `--mod-output=NAME' command, but other than that all
558 other arguments are passed on directly to the system compiler or
559 linker, along with any other required arguments to create the loadable
560 module.
561
562    The module has complete access to all symbols that were present in
563 the dumped XEmacs, so you do not need to link against libraries that
564 were linked in with the main executable.  If your library uses some
565 other extra libraries, you will need to link with those.  There is
566 nothing particularly complicated about link mode.  All you need to do
567 is make sure you invoke it correctly in the `Makefile'.  See the sample
568 `Makefile' above for an example of a well constructed `Makefile' that
569 invoked the linker correctly.
570
571 \1f
572 File: emodules.info,  Node: Other ellcc options,  Next: Environment Variables,  Prev: Link Mode,  Up: Using ellcc
573
574 Other `ellcc' options
575 =====================
576
577    Aside from the three main `ellcc' modes described above, `ellcc' can
578 accept several other options.  These are typically used in a `Makefile'
579 to determine installation paths.  `ellcc' also allows you to over-ride
580 several of its built-in compiler and linker options using environment
581 variables.  Here is the complete list of options that `ellcc' accepts.
582
583 `--mode=compile'
584      Enables compilation mode.  Use this to compile source modules.
585
586 `--mode=link'
587      Enabled link edit mode.  Use this to create the final module.
588
589 `--mode=init'
590      Used to create the documentation function and to initialize other
591      required variables.  Produces a C source file that must be
592      compiled with `ellcc' in compile mode before linking the final
593      module.
594
595 `--mode=verbose'
596      Enables verbose mode.  This will show you the commands that are
597      being executed, as well as the version number of `ellcc'.  If you
598      specify this option twice, then some extra debugging information
599      is displayed.
600
601 `--mod-name=NAME'
602      Sets the short internaml module NAME to the string specified,
603      which must consist only of valid C identifiers.  Required during
604      initialization mode.
605
606 `--mod-version=VERSION'
607      Sets the internal module VERSION to the specified string.
608      Required during initialization mode.
609
610 `--mod-title=TITLE'
611      Sets the module descriptive TITLE to the string specified.  This
612      string can contain any printable characters, but should not be too
613      long.  It is required during initialization mode.
614
615 `--mod-output=FILENAME'
616      Used to control the output file name.  This is used during
617      initialization mode to set the name of the C source file that will
618      be created to FILENAME.  During link mode, it sets the name of the
619      final loadable module to FILENAME.
620
621 `--mod-location'
622      This will print the name of the standard module installation path
623      on the standard output and immediately exit `ellcc'.  Use this
624      option to determine the directory prefix of where you should
625      install your modules.
626
627 `--mod-site-location'
628      This will print the name of the site specific module location and
629      exit.
630
631 `--mod-archdir'
632      Prints the name of the root of the architecture-dependant
633      directory that XEmacs searches for architecture-dependant files.
634
635 `--mod-config'
636      Prints the name of the configuration for which XEmacs and `ellcc'
637      were compiled.
638
639 \1f
640 File: emodules.info,  Node: Environment Variables,  Prev: Other ellcc options,  Up: Using ellcc
641
642 Environment Variables
643 =====================
644
645    During its normal operation, `ellcc' uses the compiler and linker
646 flags that were determined at the time XEmacs was configured.  In
647 certain rare circumstances you may wish to over-ride the flags passed to
648 the compiler or linker, and you can do so using environment variables.
649 The table below lists all of the environment variables that `ellcc'
650 recognises.
651
652 `ELLCC'
653      This is used to over-ride the name of the C compiler that is
654      invoked by `ellcc'.
655
656 `ELLLD'
657      Sets the name of the link editor to use to created the final
658      module.
659
660 `ELLCFLAGS'
661      Sets the compiler flags passed on when compiling source modules.
662      This only sets the basic C compiler flags.  There are certain
663      hard-coded flags that will always be passed.
664
665 `ELLLDFLAGS'
666      Sets the flags passed on to the linker.  This does *not* include
667      the flags for enabling PIC mode.  This just sets basic linker
668      flags.
669
670 `ELLDLLFLAGS'
671      Sets the flags passed to the linker that are required to created
672      shared and loadable objects.
673
674 `ELLPICFLAGS'
675      Sets the C compiler option required to produce an object file that
676      is suitable for including in a shared library.  This option should
677      turn on PIC mode, or the moral equivalent thereof on the target
678      system.
679
680 `ELLMAKEDOC'
681      Sets the name of the `make-docfile' program to use.  Usually
682      `ellcc' will use the version that was compiled and installed with
683      XEmacs, but this option allows you to specify an alternative path.
684      Used during the compile phase of XEmacs itself.
685
686 \1f
687 File: emodules.info,  Node: Defining Functions,  Next: Defining Variables,  Prev: Using ellcc,  Up: Top
688
689 Defining Functions
690 ******************
691
692    One of the main reasons you would ever write a module is to provide
693 one or more "functions" for the user or the editor to use.  The term
694 "function" is a bit overloaded here, as it refers to both a C function
695 and the way it appears to Lisp, which is a "subroutine", or simply a
696 "subr".  A Lisp subr is also known as a Lisp primitive, but that term
697 applies less to dynamic modules.  *Note Writing Lisp Primitives:
698 (internals)Writing Lisp Primitives, for details on how to declare
699 functions.  You should familiarize yourself with the instructions
700 there.  The format of the function declaration is identical in modules.
701
702    Normal Lisp primitives document the functions they defining by
703 including the documentation as a C comment.  During the build process,
704 a program called `make-docfile' is run, which will extract all of these
705 comments, build up a single large documentation file, and will store
706 pointers to the start of each documentation entry in the dumped XEmacs.
707 This, of course, will not work for dynamic modules, as they are loaded
708 long after XEmacs has been dumped.  For this reason, we require a
709 special means for adding documentation for new subrs.  This is what the
710 macro `CDOCSUBR' is used for, and this is used extensively during
711 `ellcc' initialization mode.
712
713    When using `DEFUN' in normal XEmacs C code, the sixth "parameter" is
714 a C comment which documents the function.  For a dynamic module, we of
715 course need to convert the C comment to a usable string, and we need to
716 set the documentation pointer of the subr to this string.  As a module
717 programmer, you don't actually need to do any work for this to happen.
718 It is all taken care of in the `docs_of_module' function created by
719 `ellcc'.
720
721 * Menu:
722
723 * Using DEFUN::                 Using the DEFUN macro to define functions
724 * Declaring Functions::         Declaring functions to the Lisp reader
725
726 \1f
727 File: emodules.info,  Node: Using DEFUN,  Next: Declaring Functions,  Prev: Defining Functions,  Up: Defining Functions
728
729 Using `DEFUN'
730 =============
731
732    Although the full syntax of a function declaration is discussed in
733 the XEmacs internals manual in greater depth, what follows is a brief
734 description of how to define and implement a new Lisp primitive in a
735 module.  This is done using the `DEFUN' macro.  Here is a small example:
736
737      DEFUN ("my-function", Fmy_function, 1, 1, "FFile name: ", /*
738      Sample Emacs primitive function.
739      
740      The specified FILE is frobricated before it is fnozzled.
741      */
742          (file))
743      {
744        char *filename;
745      
746        if (NILP(file))
747          return Qnil;
748      
749        filename = (char *)XSTRING_DATA(file);
750        frob(filename);
751        return Qt;
752      }
753
754    The first argument is the name of the function as it will appear to
755 the Lisp reader.  This must be provided as a string.  The second
756 argument is the name of the actual C function that will be created.
757 This is typically the Lisp function name with a preceding capital `F',
758 with hyphens converted to underscores.  This must be a valid C function
759 name.  Next come the minimum and maximum number of arguments,
760 respectively.  This is used to ensure that the correct number of
761 arguments are passed to the function.  Next is the `interactive'
762 definition.  If this function is meant to be run by a user
763 interactively, then you need to specify the argument types and prompts
764 in this string.  Please consult the XEmacs Lisp manual for more
765 details.  Next comes a C comment that is the documentation for this
766 function.  This comment *must* exist.  Last comes the list of function
767 argument names, if any.
768
769 \1f
770 File: emodules.info,  Node: Declaring Functions,  Prev: Using DEFUN,  Up: Defining Functions
771
772 Declaring Functions
773 ===================
774
775    Simply writing the code for a function is not enough to make it
776 availible to the Lisp reader.  You have to, during module
777 initialization, let the Lisp reader know about the new function.  This
778 is done by calling `DEFSUBR' with the name of the function.  This is
779 the sole purpose of the initialization function `syms_of_module'.
780 *Note Required Functions::, for more details.
781
782    Each call to `DEFSUBR' takes as its only argument the name of the
783 function, which is the same as the second argument to the call to
784 `DEFUN'.  Using the example function above, you would insert the
785 following code in the `syms_of_module' function:
786
787      DEFSUBR(Fmy_function);
788
789    This call will instruct XEmacs to make the function visible to the
790 Lisp reader and will prepare for the insertion of the documentation into
791 the right place.  Once this is done, the user can call the Lisp
792 function `my-function', if it was defined as an interactive function
793 (which in this case it was).
794
795    Thats all there is to defining and announcing new functions.  The
796 rules for what goes inside the functions, and how to write good
797 modules, is beyond the scope of this document.  Please consult the
798 XEmacs internals manual for more details.
799
800 \1f
801 File: emodules.info,  Node: Defining Variables,  Next: Index,  Prev: Defining Functions,  Up: Top
802
803 Defining Variables
804 ******************
805
806    Rarely will you write a module that only contains functions.  It is
807 common to also provide variables which can be used to control the
808 behaviour of the function, or store the results of the function being
809 executed.  The actual C variable types are the same for modules and
810 internal XEmacs primitives, and the declaration of the variables is
811 identical.
812
813    *Note Adding Global Lisp Variables: (internals)Adding Global Lisp
814 Variables, for more information on variables and naming conventions.
815
816    Once your variables are defined, you need to initialize them and make
817 the Lisp reader aware of them.  This is done in the `vars_of_module'
818 initialization function using special XEmacs macros such as
819 `DEFVAR_LISP', `DEFVAR_BOOL', `DEFVAR_INT' etc.  The best way to see
820 how to use these macros is to look at existing source code, or read the
821 internals manual.
822
823    One _very_ important difference between XEmacs variables and module
824 variables is how you use pure space.  Simply put, you *never* use pure
825 space in XEmacs modules.  The pure space storage is of a limited size,
826 and is initialized propperly during the dumping of XEmacs.  Because
827 variables are being added dynamically to an already running XEmacs when
828 you load a module, you cannot use pure space.  Be warned: *do not use
829 pure space in modules.  Repeat, do not use pure space in modules.*
830 Once again, to remove all doubts: *DO NOT USE PURE SPACE IN MODULES!!!*
831
832    Below is a small example which declares and initializes two
833 variables.  You will note that this code takes into account the fact
834 that this module may very well be compiled into XEmacs itself.  This is
835 a prudent thing to do.
836
837      Lisp_Object Vsample_string;
838      int sample_boolean;
839      
840      void
841      vars_of_module()
842      {
843        DEFVAR_LISP ("sample-string", &Vsample_string /*
844      This is a sample string, declared in a module.
845      
846      Nothing magical about it.
847      */);
848      
849        DEFVAR_BOOL("sample-boolean", &sample_boolean /*
850      *Sample user-settable boolean.
851      */);
852      
853        sample_boolean = 0;
854        Vsample_string = build_string("My string");
855      }
856
857 \1f
858 File: emodules.info,  Node: Index,  Prev: Defining Variables,  Up: Top
859
860 Index
861 *****
862
863 * Menu:
864
865 * annatomy:                              Annatomy of a Module.
866 * compiler:                              Introduction.
867 * compiling:                             Compile Mode.
868 * config.h:                              Required Header File.
869 * defining functions:                    Defining Functions.
870 * defining objects:                      Defining Variables.
871 * defining variables:                    Defining Variables.
872 * DEFSUBR:                               Declaring Functions.
873 * DEFUN:                                 Using DEFUN.
874 * DEFVAR_BOOL:                           Defining Variables.
875 * DEFVAR_INT:                            Defining Variables.
876 * DEFVAR_LISP:                           Defining Variables.
877 * dependancies:                          Loading other Modules.
878 * DLL:                                   Introduction.
879 * docs_of_module:                        Required Functions.
880 * documentation <1>:                     Initialization Mode.
881 * documentation:                         Introduction.
882 * DSO:                                   Introduction.
883 * ELLCC:                                 Environment Variables.
884 * ellcc <1>:                             Using ellcc.
885 * ellcc:                                 Introduction.
886 * ELLCFLAGS:                             Environment Variables.
887 * ELLDLLFLAGS:                           Environment Variables.
888 * ELLLD:                                 Environment Variables.
889 * ELLLDFLAGS:                            Environment Variables.
890 * ELLMAKEDOC:                            Environment Variables.
891 * ELLPICFLAGS:                           Environment Variables.
892 * Emacs Modules:                         Introduction.
893 * emodules.h:                            Required Header File.
894 * emodules_load:                         Loading other Modules.
895 * environment variables:                 Environment Variables.
896 * format, module:                        Annatomy of a Module.
897 * functions, declaring:                  Declaring Functions.
898 * functions, defining:                   Using DEFUN.
899 * functions, Lisp:                       Using DEFUN.
900 * functions, required:                   Required Functions.
901 * header files:                          Introduction.
902 * help:                                  Introduction.
903 * include files:                         Required Header File.
904 * initialization <1>:                    Initialization Mode.
905 * initialization <2>:                    Required Variables.
906 * initialization:                        Required Functions.
907 * linker:                                Introduction.
908 * linking:                               Link Mode.
909 * module compiler:                       Using ellcc.
910 * module format:                         Annatomy of a Module.
911 * module skeleton:                       Annatomy of a Module.
912 * modules_of_module <1>:                 Loading other Modules.
913 * modules_of_module:                     Required Functions.
914 * objects, defining:                     Defining Variables.
915 * objects, Lisp:                         Defining Variables.
916 * paths:                                 Other ellcc options.
917 * required functions:                    Required Functions.
918 * required header:                       Required Header File.
919 * required variables:                    Required Variables.
920 * samples:                               Introduction.
921 * shared object:                         Introduction.
922 * skeleton, module:                      Annatomy of a Module.
923 * subrs:                                 Using DEFUN.
924 * syms_of_module:                        Required Functions.
925 * variables, defining:                   Defining Variables.
926 * variables, Lisp:                       Defining Variables.
927 * variables, required:                   Required Variables.
928 * vars_of_module:                        Required Functions.
929
930
931 \1f
932 Tag Table:
933 Node: Top\7f1536
934 Node: Introduction\7f2884
935 Node: Annatomy of a Module\7f7393
936 Node: Required Header File\7f8209
937 Node: Required Functions\7f10130
938 Node: Required Variables\7f12379
939 Node: Loading other Modules\7f15066
940 Node: Using ellcc\7f17124
941 Node: Compile Mode\7f18919
942 Node: Initialization Mode\7f20287
943 Node: Link Mode\7f25319
944 Node: Other ellcc options\7f26466
945 Node: Environment Variables\7f29046
946 Node: Defining Functions\7f30737
947 Node: Using DEFUN\7f32748
948 Node: Declaring Functions\7f34459
949 Node: Defining Variables\7f35802
950 Node: Index\7f38047
951 \1f
952 End Tag Table