annotate man/emodules.texi @ 388:aabb7f5b1c81 r21-2-9

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