]> git.sur5r.net Git - cc65/blob - doc/cl65.sgml
Merge remote-tracking branch 'origin' into da65-synclines
[cc65] / doc / cl65.sgml
1 <!doctype linuxdoc system>
2
3 <article>
4 <title>cl65 Users Guide
5 <author><url url="mailto:uz@cc65.org" name="Ullrich von Bassewitz">,<newline>
6 <url url="mailto:greg.king5@verizon.net" name="Greg King">
7 <date>2017-10-16
8
9 <abstract>
10 cl65 is the compile &amp; link utility for cc65, the 6502 C compiler. It was
11 designed as a smart frontend for the C compiler (cc65), the assembler (ca65),
12 the object file converter (co65), and the linker (ld65).
13 </abstract>
14
15 <!-- Table of contents -->
16 <toc>
17
18 <!-- Begin the document -->
19
20 <sect>Overview<p>
21
22 cl65 is a frontend for cc65, ca65, co65 and ld65. While you may not use the
23 full power of the tools when calling them through cl65, most features are
24 available, and the use of cl65 is much simpler.
25
26
27 <sect>Basic Usage<p>
28
29 The cl65 compile and link utility may be used to convert, compile, assemble
30 and link files. While the separate tools do just one step, cl65 knows how to
31 build object files from C files (by calling the compiler, then the assembler)
32 and other things.
33
34 <tscreen><verb>
35 ---------------------------------------------------------------------------
36 Usage: cl65 [options] file [...]
37 Short options:
38   -c                            Compile and assemble but don't link
39   -d                            Debug mode
40   -g                            Add debug info
41   -h                            Help (this text)
42   -l name                       Create an assembler listing file
43   -m name                       Create a map file
44   -mm model                     Set the memory model
45   -o name                       Name the output file
46   -r                            Enable register variables
47   -t sys                        Set the target system
48   -u sym                        Force an import of symbol `sym'
49   -v                            Verbose mode
50   -vm                           Verbose map file
51   -C name                       Use linker config file
52   -Cl                           Make local variables static
53   -D sym[=defn]                 Define a preprocessor symbol
54   -E                            Stop after the preprocessing stage
55   -I dir                        Set a compiler include directory path
56   -L path                       Specify a library search path
57   -Ln name                      Create a VICE label file
58   -O                            Optimize code
59   -Oi                           Optimize code, inline more code
60   -Or                           Optimize code, honour the register keyword
61   -Os                           Optimize code, inline standard funtions
62   -S                            Compile but don't assemble and link
63   -T                            Include source as comment
64   -V                            Print the version number
65   -W name[,...]                 Supress compiler warnings
66   -Wa options                   Pass options to the assembler
67   -Wc options                   Pass options to the compiler
68   -Wl options                   Pass options to the linker
69
70 Long options:
71   --add-source                  Include source as comment
72   --all-cdecl                   Make functions default to __cdecl__
73   --asm-args options            Pass options to the assembler
74   --asm-define sym[=v]          Define an assembler symbol
75   --asm-include-dir dir         Set an assembler include directory
76   --bin-include-dir dir         Set an assembler binary include directory
77   --bss-label name              Define and export a BSS segment label
78   --bss-name seg                Set the name of the BSS segment
79   --cc-args options             Pass options to the compiler
80   --cfg-path path               Specify a config file search path
81   --check-stack                 Generate stack overflow checks
82   --code-label name             Define and export a CODE segment label
83   --code-name seg               Set the name of the CODE segment
84   --codesize x                  Accept larger code by factor x
85   --config name                 Use linker config file
86   --cpu type                    Set cpu type
87   --create-dep name             Create a make dependency file
88   --create-full-dep name        Create a full make dependency file
89   --data-label name             Define and export a DATA segment label
90   --data-name seg               Set the name of the DATA segment
91   --debug                       Debug mode
92   --debug-info                  Add debug info
93   --feature name                Set an emulation feature
94   --force-import sym            Force an import of symbol `sym'
95   --help                        Help (this text)
96   --include-dir dir             Set a compiler include directory path
97   --ld-args options             Pass options to the linker
98   --lib file                    Link this library
99   --lib-path path               Specify a library search path
100   --list-targets                List all available targets
101   --listing name                Create an assembler listing file
102   --list-bytes n                Number of bytes per assembler listing line
103   --mapfile name                Create a map file
104   --memory-model model          Set the memory model
105   --module                      Link as a module
106   --module-id id                Specify a module id for the linker
107   --o65-model model             Override the o65 model
108   --obj file                    Link this object file
109   --obj-path path               Specify an object file search path
110   --print-target-path           Print the target file path
111   --register-space b            Set space available for register variables
112   --register-vars               Enable register variables
113   --rodata-name seg             Set the name of the RODATA segment
114   --signed-chars                Default characters are signed
115   --standard std                Language standard (c89, c99, cc65)
116   --start-addr addr             Set the default start address
117   --static-locals               Make local variables static
118   --target sys                  Set the target system
119   --version                     Print the version number
120   --verbose                     Verbose mode
121   --zeropage-label name         Define and export a ZEROPAGE segment label
122   --zeropage-name seg           Set the name of the ZEROPAGE segment
123 ---------------------------------------------------------------------------
124 </verb></tscreen>
125
126 Most of the options have the same meanings as the corresponding compiler,
127 assembler, and linker options. See the documentation for those tools for an
128 explanation. If an option is available for more than one of the tools, it
129 is set for all tools where it is available. One example for that is <tt/-v/:
130 The compiler, the assembler, and the linker are all called with the <tt/-v/
131 switch.
132
133 There are a few remaining options that control the behaviour of cl65:
134
135 <descrip>
136
137   <tag><tt>-E</tt></tag>
138
139   This option is passed to the cc65 compiler; and, it forces cl65 to stop
140   before the assembly step. That means that C-level preprocessor directives
141   are obeyed; and, macroes are expanded.  But, the C source isn't compiled.
142   If the <tt/-o/ option isn't used, then the C code results are written into
143   files with a ".i" suffix on their base names.  Assembler files, object
144   files, and libraries given on the command line are ignored.
145
146
147   <tag><tt>-S</tt></tag>
148
149   This option forces cl65 to stop before the assembly step. That means that
150   C files are translated into assembler files; but, nothing more is done.
151   Assembler files, object files, and libraries given on the command line
152   are ignored.
153
154
155   <tag><tt>-c</tt></tag>
156
157   This option forces cl65 to stop after the assembly step. That means
158   that C and assembler files given on the command line are translated into
159   object files; but, there is no link step.  Object files and libraries
160   given on the command line are ignored.
161
162
163   <tag><tt>-o name</tt></tag>
164
165   The -o option is used for the target name in the final step. That causes
166   problems if the linker will not be called, and there are several input
167   files on the command line. In that case, the name given with -o will be
168   used for all of them, which makes the option pretty useless. You
169   shouldn't use <tt/-o/ when more than one output file is created.
170
171
172   <tag><tt>--print-target-path</tt></tag>
173
174   This option prints the absolute path of the target file directory, and exits
175   then. It is supposed to be used with shell backquotes or the GNU make shell
176   function. That way, you can write build scripts or Makefiles accessing target
177   files without any assumption about the cc65 installation path.
178
179
180   <tag><tt>-t sys, --target sys</tt></tag>
181
182   The default for this option is different from the compiler and linker, in the
183   case that the option is missing:  While the other tools (compiler, assembler,
184   and linker) will use the "none" system settings by default, cl65 will use
185   "c64" as a target system by default. That was chosen because most people
186   seem to use cc65 to develop for the C64.
187
188
189   <tag><tt>-Wa options, --asm-args options</tt></tag>
190
191   Pass options directly to the assembler. This may be used to pass options
192   that aren't directly supported by cl65. Several options may be separated by
193   commas; the commas are replaced by spaces when passing them to the
194   assembler. Beware: Passing arguments directly to the assembler might interfere
195   with some of the defaults because cl65 doesn't parse the options passed. So,
196   if cl65 supports an option by itself, do not pass that option to the
197   assembler by means of the <tt/-Wa/ switch.
198
199
200   <tag><tt>-Wc options, --cc-args options</tt></tag>
201
202   Pass options directly to the compiler. This may be used to pass options
203   that aren't directly supported by cl65. Several options may be separated by
204   commas; the commas are replaced by spaces when passing them to the
205   compiler. Beware: Passing arguments directly to the compiler might interfere
206   with some of the defaults because cl65 doesn't parse the options passed. So,
207   if cl65 supports an option by itself, do not pass that option to the
208   compiler by means of the <tt/-Wc/ switch.
209
210
211   <tag><tt>-Wl options, --ld-args options</tt></tag>
212
213   Pass options directly to the linker. This may be used to pass options that
214   aren't directly supported by cl65. Several options may be separated by
215   commas; the commas are replaced by spaces when passing them to the linker.
216   Beware: Passing arguments directly to the linker might interfere with some of
217   the defaults because cl65 doesn't parse the options passed. So, if cl65
218   supports an option by itself, do not pass that option to the linker by means
219   of the <tt/-Wl/ switch.
220
221 </descrip>
222
223
224
225 <sect>More usage<p>
226
227 Because cl65 was created to simplify the use of the cc65 development
228 package, it tries to be smart about several things.
229
230 <itemize>
231
232 <item>  If you don't give a target system on the command line, cl65
233         defaults to the C64.
234
235 <item>  When linking, cl65 will supply the name of the library file for
236         the target system to the linker; so, you don't have to do that.
237
238 <item>  If the final step is the linker, and the name of the output file was
239         not explicitly given, cl65 will use the name of the first input file
240         without the extension, provided that the name of that file has an
241         extension. So, you don't need to give the executable name in most
242         cases; just give the name of your "main" file as the first input file.
243 </itemize>
244
245 The command line is parsed from left to right, and the actual processing tool
246 (compiler, assembler, ...) is invoked whenever a file name is encountered.
247 This means that only the options to the left of a file name are in effect when
248 this file is processed. It does also mean that you're able to specify
249 different options for different files on the command line. As an example.
250
251 <tscreen><verb>
252         cl65 -Oirs main.c -O -g module.c
253 </verb></tscreen>
254
255 translates main.c with full optimization and module.c with less optimization
256 and debug info enabled.
257
258 The type of an input file is derived from its extension:
259
260 <itemize>
261 <item>C files: <tt/.c/
262 <item>Assembler files: <tt/.s/, <tt/.asm/, <tt/.a65/
263 <item>Object files: <tt/.o/, <tt/.obj/
264 <item>Libraries: <tt/.a/, <tt/.lib/
265 <item>GEOS resource files: <tt/.grc/
266 <item>o65 files: <tt/.o65/, <tt/.emd/, <tt/.joy/, <tt/.tgi/
267 </itemize>
268
269 Please note that the program cannot handle input files with unknown file
270 extensions.
271
272
273 <sect>Examples<p>
274
275 The morse trainer software, which consists of one C file (morse.c) and one
276 assembler file (irq.s) will need the following separate steps to compile
277 into an executable named morse:
278
279 <tscreen><verb>
280         cc65 -g -Oi -t c64 morse.c
281         ca65 -g morse.s
282         ca65 -g irq.s
283         ld65 -o morse -t c64 c64.o morse.o irq.o c64.lib
284 </verb></tscreen>
285
286 When using cl65, this is simplified to
287
288 <tscreen><verb>
289         cl65 -g -Oi morse.c irq.s
290 </verb></tscreen>
291
292 As a general rule, you may use cl65 instead of cc65 at most times,
293 especially in makefiles to build object files directly from C files. Use
294
295 <tscreen><verb>
296         .c.o:
297                 cl65 -g -Oi $<
298 </verb></tscreen>
299
300 to do this.
301
302
303
304 <sect>Copyright<p>
305
306 cl65 (and all cc65 binutils) are (C) Copyright 1998-2004 Ullrich von
307 Bassewitz. For usage of the binaries and/or sources the following
308 conditions do apply:
309
310 This software is provided 'as-is', without any expressed or implied
311 warranty.  In no event will the authors be held liable for any damages
312 arising from the use of this software.
313
314 Permission is granted to anyone to use this software for any purpose,
315 including commercial applications, and to alter it and redistribute it
316 freely, subject to the following restrictions:
317
318 <enum>
319 <item>  The origin of this software must not be misrepresented; you must not
320         claim that you wrote the original software. If you use this software
321         in a product, an acknowledgment in the product documentation would be
322         appreciated but is not required.
323 <item>  Altered source versions must be plainly marked as such, and must not
324         be misrepresented as being the original software.
325 <item>  This notice may not be removed or altered from any source
326         distribution.
327 </enum>
328
329
330
331 </article>