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