changelog shortlog tags changeset manifest revisions annotate raw

README

changeset 500: f2c405afb91a
parent:085680cd701d
author: Rob Landley <rob@landley.net>
date: Sun Nov 04 22:52:43 2007 -0600 (12 months ago)
permissions: -rw-r--r--
description: New readme.
1What is tinycc:
2---------------
3
4Tinycc is a small, simple, and fast single-pass C compiler. It converts
5ISO C99 source directly to machine language, with only the most basic
6optimizations. Tinycc can produce native ELF executables and libraries as
7fast as Perl or Python interpreters produce bytecode, and the result is a
8real executable which requires no interpreter.
9
10Tinycc can be used to turn C into a scripting language: simply add the line
11"#!/usr/bin/tinycc -run" to the start of a C source file, set the executable
12bit, and run your source code directly from the command line. (You can even
13add libraries to link against after -run, to use things like zlib or x11.
14For an example of this, see ex4.c in the examples directory.)
15
16Tinycc is a single self-contained executable, acting as both a C99 compiler and
17ELF linker, totalling about 100k. When paired with a small C library (such as
18uClibc or klibc) a complete development environment can fit in under a megabyte.
19This means that resource constrained environments (such as embedded systems,
20rescue disks, and initramfs) can afford to include a C compiler.
21
22Tinycc is a fully functional C compiler, supporting C99 and several gcc
23extensions, plus full debug info (-g) and an optional memory and bounds
24checker. Developing C code with tinycc doesn't even require a makefile,
25because recompiling most projects from scratch takes (at most) a few seconds.
26
27Tinycc can currently produce Linux executables for i386 and ARM targets,
28Windows executables for i386, and COFF executables for C67 (TMS320C67x).
29More are planned.
30
31Installation:
32-------------
33
34To build and install tinycc on a Linux host:
35
36 Compile: ./make
37 Test: ./make --test
38 Install: ./make --install /usr/bin
39 More options: ./make --help
40
41To build on a Windows host, read win32/readme.txt
42
43Using tinycc:
44-------------
45
46Run tinycc with no arguments to see built-in help. A web page with more
47extensive documentation is available as www/tinycc-docs.html in this tarball.
48
49Tinycc compiles ANSI C programs, based on the ISO C99 standard with some
50extensions for compatability with gcc. The command line arguments are
51specified by Posix for the "c99" utility.
52
53This means the options -c, -o, -E, -I, -D, -U, -L, -l, -shared, -static, -g,
54-W, -f, and more usually work like you'd expect. For compatability with other
55compilers, unknown options to -O, -W, and -f are ignored by default. Many
56packages will build just by specifying the environment variable "CC=tinycc".
57
58The include file <tinyinc.h> contains small basic libc include support without
59copying the entire /usr/include directory.
60
61Note that the -run option (for C scripting) only compiles a single C file.
62Any additional arguments after that wind up in argc and argv[] as command line
63arguments to main().
64
65Several example programs are available in the examples directory.
66
67Standards:
68----------
69
70A more or less final draft of the ISO C99 standard is available at:
71
72 http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1124.pdf
73
74The Open Group Base Specifications Issue 6 (also known as Single Unix
75Specification version 3, also known as POSIX) definition for the c99
76command:
77
78 http://www.opengroup.org/onlinepubs/000095399/utilities/c99.html
79
80Cross compiling:
81----------------
82
83Tinycc treats cross compiling as nothing special, because it isn't.
84
85A compiler is a program that reads input files and produces output files.
86So is a docbook to pdf converter. In addition to the files listed on the
87command line, a compiler takes lots of implicit input from various search
88paths (#include files, libraries, etc). Again, so does a docbook to pdf
89converter (fonts, style sheets, etc).
90
91Compilers produce runnable programs. So do text processing utilities like
92sed, awk, and vi when they create shell scripts (or perl, or python).
93
94Selecting the various target platforms tinycc can produce output for is
95about as important as telling a program that reads docbook whether it
96should produce html, pdf, or man page output. It's not a big deal.
97
98Some insane build systems force you to specify what host the resulting program
99should run on. That's none of its business. The compiler you build the
100project with determines where the output runs, and everything else (word
101size, endianness, etc) of the running program can be determined from that.
102
103If you want to build a compiler that runs on a different system than you're
104building on, build twice. First build a cross compiler that targets the
105system it should run on, and then build the compiler with that cross compiler.
106
107 ./make
108 ./make --install
109 ./make --clean
110 CC=arm-tinycc ./make
111
112The "arm-tinycc" in the
113
114When you build tinycc, the host machine the compiler runs on
115
116are not the only programs that produce executable code that runs
117on the s
118Whether or not the output of the compiler runs on the same machine as the
119compiler itself does is a coincidence.
120
121Tinycc treats cross compiling as normal.
122
123A compiler that outputs code that runs on the same machine as the compiler is
124a native compiler. This is essentially a coincidence.
125
126License:
127-------
128
129Tinycc is distributed under GPL version 2. (This is a specific version of
130the GPL, included in the file LICENSE in this tarball. It may not be
131distributed under later versions.)
132
133The license on tinycc does not apply to output files produced by tinycc (which
134are under whatever licenses the corresponding source files were under), nor
135does it affect the header files in the include directory (look up "Scenes a
136Faire" and the merger doctrine).
137
138History:
139--------
140
141http://fabrice.bellard.free.fr/otcc
142
143In 2002, Fabrice Bellard created the Obfuscated Tiny C Compiler (otcc)
144as an entry into the Obfuscated C Code contest. His entry was a compiler for
145a subset of C that could recompile itself, and which fit in 2048 bytes of
146source code. (He won "best abuse of the rules".)
147
148http://fabrice.bellard.free.fr/tcc/
149
150After the contest, Fabrice un-obfuscated OTCC and fleshed it out
151towards full ISO C99 compliance. This was TCC, the Tiny C Compiler. TCC
152remained an active project for over two years, producing several interesting
153results such as tccboot (http://fabrice.bellard.free.fr/tcc/tccboot.html).
154
155The TCC project stalled in early 2005, when another project of Fabrice's (qemu)
156began to take up all of Fabrice's time.
157
158http://landley.net/code/tinycc
159
160In late 2006, Rob Landley cloned the dormant TCC repository in Mercurial,
161and started collecting unapplied patches and fixing outstanding bugs. This
162was an unofficial fork of the TCC project, because although Fabrice recognized
163the stalled nature of TCC and offered to hand it off to a new maintainer, he
164insisted development remain centered around the old CVS repository.
165
166After a year of maintaining a fork, Rob decided to make it a real project.
167This involved changing the name (from tcc to tinycc), setting up a new mailing
168list (tinycc@landley.net), and taking advantage of the LGPL v2.1's relicensing
169clause to convert the project's license to GPL version 2.