Home
README - scc - simple c99 compiler HTML git clone git://git.simple-cc.org/scc DIR Log DIR Files DIR Refs DIR Submodules DIR README DIR LICENSE --- README (7826B) --- 1 Compiling 2 ========= 3 4 SCC is a portable toolchain that can be compiled on any UNIX system 5 out of the box. It supports several configuration options that 6 can be passed to the command line: 7 8 - PREFIX: Prefix of the path where scc toolchain is going 9 to be installed. /usr/local by default. 10 11 - LIBPREFIX: Prefix of the path where scc searchs for 12 headers and libraries when scc is executed. $PREFIX 13 by default. 14 15 - DESTDIR: Temporary directory prepend to PREFIX used in the 16 install path. It is mainly intended to help package maintainers 17 to install in a specific directory used as base for the package 18 generation. 19 20 - CROSS_COMPILE: 21 Specify a prefix name for the tools called by the Makefile. 22 23 - HOST: 24 Specify the host system to be used. Possible supported 25 values are: 26 27 - unix (by default) 28 - bsd 29 - plan9 30 31 - CONF: Specify which version of libc to build. 32 Once the build process completes only the target specified in 33 CONF will be built. Supported values are: 34 35 - amd64-linux (default) 36 - amd64-darwin 37 - amd64-openbsd 38 - arm64-linux 39 - amd64-dragonfly 40 - amd64-freebsd 41 - amd64-netbsd 42 - arm32-linux 43 - i386-linux 44 45 Not all the configurations have the same level of support in 46 the libc and in some cases the support is minimal. 47 48 - TOOL: Specify the toolchain type to be used. Possible 49 supported values are: 50 51 - unix (by default) 52 - gnu 53 - gnu-darwin 54 - clang 55 - pcc 56 - plan9 57 58 Beware that the default target selects the appropiate value for HOST, 59 CONF and TOOL. In case of being needed, TOOL can be still overloaded 60 in the command line. 61 62 The main targets of the Makefile are: 63 64 - all: 65 Compile the toolchain and the libc. It automatically 66 determines what is the best value for HOST. It sets the 67 value of CONF for the toolchain that is used by the 68 toolchain as the default target. It also compiles the libc 69 for all the available configurations based in the host 70 architecture. 71 72 - config 73 Generate headers supposed to be customized by the user. 74 75 - toolchain 76 Compile the toolchain with the default configuration 77 specified in CONF. Beware that this target is executed without 78 the automatic detection of the host parameters. It makes 79 easier to cross compile. 80 81 - libc: 82 Compile the libc for the target specified in CONF. Beware 83 that this target is executed without the automatic detection 84 of the host parameters. It makes easier to cross compile. 85 86 - install: 87 Installs scc in PREFIX. 88 89 - clean: 90 Remove all the generated files except the one supposed to be edited 91 by the user. 92 93 - distclean 94 Remove all the generated files, including the files generated by the 95 config target that are not removed by the clean target. 96 97 Toolchain configuration 98 ======================= 99 At this moment scc is still using some external tools to generate 100 the final binaries. The toolchain execution is configured in the 101 file `include/bits/scc/sys.h` and it included basically 5 elements: 102 103 - LDBIN: macro with the name of the linker binary. 104 105 - ASBIN: macro with the name of the assembler binary. 106 107 - sysincludes: It is a list of diretories used to locate 108 the system headers 109 110 - ldcmd: It describes how the linker command line is built. 111 112 - ascmd: It describes how the assembler command line is built. 113 114 The definition of sysincludes, ldcmd and ascmd can include wildcards 115 represented by % followed by a single letter: 116 117 - %c: It expands to the full list of input object files of the linker 118 - %a: It expands to the architecture name 119 - %s: It expands to the system name 120 - %p: It expands to the library prefix 121 - %b: It expands too the ABI name 122 - %o: It expands to the output file of the current tool 123 124 Scc includes 3 configuration templates that can be used as base for the 125 configuration of the toolchain: 126 127 - scc: It uses GNU assembler and linker with the scc libc. 128 - scc_clang: It uses clang assembler and linker with the scc libc. 129 - musl: It uses GNU assembler and linker with the musl libc. 130 131 The file `include/bits/scc/sys.h` is automatically created from the scc 132 toolchain configuration with the default make target. The target config 133 can be used to only create the file based on the value of the variable 134 `LIBPROFILE` allowing the user to customize that file as needed. It is 135 important to highlight that the file is not removed by `make clean` 136 because it can contain local user modifications. You should use 137 `make distclean` to remove it. 138 139 Runtime dependencies 140 ==================== 141 142 Some configurations of scc require having the QBE [1] executable in the PATH, 143 whose version must support common storage which was incorporated to it after 144 the commit 8ded7a5, but it is not part of a stable release of QBE yet. 145 146 [1] https://c9x.me/compile/ 147 148 Musl libc support 149 ================= 150 The scc libc is a C99 library and cannot be used to compile POSIX compliant 151 programs. Scc includes a template that can be used to use a musl libc 152 compiled by gcc: 153 154 $ make LIBPROFILE=musl config 155 156 It will generate the files sys.h configured to be used with a musl 157 libc. Beware that it is likely that those files have to be customized to 158 fit your system because the macro GCCLIBPATH used by the musl template 159 depends heavily of the toolchain used to compile musl. As the musl libc 160 is likely installed in a different prefix the scc compilation must be 161 modified to: 162 163 $ make LIBPREFIX=/usr/local/musl # point to the prefix used by your musl 164 165 If the helper scc shell script is used instead of scc-cc then the 166 environment variable SCCLIBPREFIX must be set: 167 168 $ SCCLIBPREFIX=/usr/local/musl scc hello.c 169 170 Deviations from standard C 171 =========================== 172 This compiler aims to be fully compatible with the C99 standard, but 173 it has some differences at this moment: 174 175 - Type qualifiers are accepted but partially ignored. 176 -------------------------------------------------- 177 178 The semantic behind them is not fully implemented, specially in the 179 case of volatile. Be aware that some programs can miswork for this 180 reason. 181 182 - Function type names 183 ------------------- 184 185 C99 allows you to define type names of function types and write something 186 like: 187 188 int f(int (int)); 189 190 Accepting function types in type names (or abstract declarators) makes the 191 grammar ambiguous because it is impossible to differentiate between: 192 193 (int (f)) -> function returning int with one parameter of type f 194 (int (f)) -> integer variable f 195 196 If you don't believe me try this code: 197 198 int 199 f(int g()) 200 { 201 return g(); 202 } 203 204 Function type names seem unnecesary , because they are used as 205 an alias of the function pointer types, but it is weird that something 206 like sizeof(int (int)) is not allowed (because here it should be 207 understood as the size of a function), but f(int (int)) is allowed 208 because it is understood as a parameter of function pointer type. 209 210 - Definition of variables with incomplete type 211 --------------------------------------------- 212 213 C89 allows the definition of variables with incomplete type that 214 have external linkage and file scope. The type of the variable is the 215 composition of all the definitions found in the file. The exact rules 216 are a bit complex (ANSI 3.7.2, or ISO C99 6.2.5p22) so SCC ignores them 217 at this moment by simply not allowing any definition of variables with 218 incomplete type. 219 220 If you don't believe me try this code: 221 222 struct foo x; 223 224 struct foo { 225 int i; 226 }; 227 228 - Variadic function alike macros 229 ------------------------------ 230 231 The standard (C99 6.10.3 c 4) forces passing more parameters than 232 the number of parameters present in the variadic argument list 233 (excluding ...). SCC accepts a parameter list with the same number 234 of arguments. 235 236 #define P(a, ...) a 237 238 P(1) 239 240 C99 libc 241 ======== 242 243 The C99 libc only supports the C locale using UTF-8 for multibyte 244 sequences. It also assumes that the wide character set includes 245 ASCII as a subset.