1# Configuration file for the Nim Compiler.
2# (c) 2017 Andreas Rumpf
3
4# Feel free to edit the default values as you need.
5
6# You may set environment variables with
7# @putenv "key" "val"
8# Environment variables can be accessed like so:
9#  gcc.path %= "$CC_PATH"
10
11cc = gcc
12gcc.exe = "gcc"
13
14# additional options always passed to the compiler:
15--parallel_build: "0" # 0 to auto-detect number of processors
16
17hint[LineTooLong]=off
18#hint[XDeclaredButNotUsed]=off
19
20# Examples of how to setup a cross-compiler:
21
22# Cross-compiling for Raspberry Pi.
23# (This compiler is available in gcc-arm-linux-gnueabihf package on Ubuntu)
24arm.linux.gcc.exe = "arm-linux-gnueabihf-gcc"
25arm.linux.gcc.linkerexe = "arm-linux-gnueabihf-gcc"
26
27# For OpenWRT, you will also need to adjust PATH to point to your toolchain.
28mips.linux.gcc.exe = "mips-openwrt-linux-gcc"
29mips.linux.gcc.linkerexe = "mips-openwrt-linux-gcc"
30
31
32path="$lib/deprecated/core"
33path="$lib/deprecated/pure"
34path="$lib/pure/collections"
35path="$lib/pure/concurrency"
36path="$lib/impure"
37path="$lib/wrappers"
38path="$lib/wrappers/linenoise"
39path="$lib/windows"
40path="$lib/posix"
41path="$lib/js"
42path="$lib/pure/unidecode"
43path="$lib/arch"
44path="$lib/core"
45path="$lib/pure"
46
47@if not windows:
48  nimblepath="/opt/nimble/pkgs2/"
49  nimblepath="/opt/nimble/pkgs/"
50@else:
51  # TODO:
52@end
53nimblepath="$home/.nimble/pkgs2/"
54nimblepath="$home/.nimble/pkgs/"
55
56# Syncronize with compiler/commands.specialDefine
57@if danger or quick:
58  obj_checks:off
59  field_checks:off
60  range_checks:off
61  bound_checks:off
62  overflow_checks:off
63  assertions:off
64  stacktrace:off
65  linetrace:off
66  debugger:off
67  line_dir:off
68@end
69
70# Syncronize with compiler/commands.specialDefine
71@if release or danger:
72  stacktrace:off
73  excessiveStackTrace:off
74  linetrace:off
75  debugger:off
76  line_dir:off
77  opt:speed
78  define:release
79@end
80
81@if false: # not danger: # this does not work yet.
82  clang.options.always %= "${clang.options.always} -fsanitize=null -fsanitize-undefined-trap-on-error"
83  gcc.options.always %= "${gcc.options.always} -fsanitize=null -fsanitize-undefined-trap-on-error"
84@end
85
86@if unix and mingw:
87  # Cross compile for Windows from Linux/OSX using MinGW
88  i386.windows.gcc.exe = "i686-w64-mingw32-gcc"
89  i386.windows.gcc.linkerexe = "i686-w64-mingw32-gcc"
90  i386.windows.gcc.cpp.exe = "i686-w64-mingw32-g++"
91  i386.windows.gcc.cpp.linkerexe = "i686-w64-mingw32-g++"
92
93  amd64.windows.gcc.exe = "x86_64-w64-mingw32-gcc"
94  amd64.windows.gcc.linkerexe = "x86_64-w64-mingw32-gcc"
95  amd64.windows.gcc.cpp.exe = "x86_64-w64-mingw32-g++"
96  amd64.windows.gcc.cpp.linkerexe = "x86_64-w64-mingw32-g++"
97
98  @if macosx:
99    i386.windows.gcc.path = "/usr/local/bin"
100    amd64.windows.gcc.path = "/usr/local/bin"
101  @else:
102    i386.windows.gcc.path = "/usr/bin"
103    amd64.windows.gcc.path = "/usr/bin"
104  @end
105
106  os = windows
107
108  gcc.options.linker = ""
109  gcc.cpp.options.linker = ""
110@end
111
112@if unix:
113  @if haiku:
114    gcc.options.linker = "-Wl,--as-needed -lnetwork"
115    gcc.cpp.options.linker = "-Wl,--as-needed -lnetwork"
116    clang.options.linker = "-Wl,--as-needed -lnetwork"
117    clang.cpp.options.linker = "-Wl,--as-needed -lnetwork"
118    tcc.options.linker = "-Wl,--as-needed -lnetwork"
119  @elif not genode:
120    # -fopenmp
121    gcc.options.linker = "-ldl"
122    gcc.cpp.options.linker = "-ldl"
123    clang.options.linker = "-ldl"
124    clang.cpp.options.linker = "-ldl"
125    tcc.options.linker = "-ldl"
126  @end
127@end
128
129@if android:
130  cc = gcc
131  @if termux:
132    gcc.options.linker = "-landroid-glob"
133    gcc.cpp.options.linker = "-landroid-glob"
134    clang.options.linker = "-landroid-glob"
135    clang.cpp.options.linker = "-landroid-glob"
136    tcc.options.linker = "-landroid-glob"
137  @end
138@end
139
140@if nintendoswitch:
141  cc = "switch_gcc"
142  switch_gcc.options.linker = "-g -march=armv8-a -mtune=cortex-a57 -mtp=soft -fPIE"
143  switch_gcc.cpp.options.linker = "-g -march=armv8-a -mtune=cortex-a57 -mtp=soft -fPIE"
144  switch_gcc.options.always = "-g -Wall -O2 -ffunction-sections -march=armv8-a -mtune=cortex-a57 -mtp=soft -fPIE -D__SWITCH__"
145  switch_gcc.cpp.options.always = "-g -Wall -O2 -ffunction-sections -march=armv8-a -mtune=cortex-a57 -mtp=soft -fPIE -D__SWITCH__ -fno-rtti -fno-exceptions -std=gnu++11"
146@end
147
148# Configuration for the Intel C/C++ compiler:
149@if windows:
150  icl.options.speed = "/Ox /arch:SSE2"
151  icl.options.always = "/nologo"
152@end
153
154# Configuration for the GNU C/C++ compiler:
155@if windows:
156  #gcc.path = r"$nim\dist\mingw\bin"
157@end
158
159gcc.maxerrorsimpl = "-fmax-errors=3"
160
161@if macosx or freebsd or openbsd:
162  cc = gcc
163  gcc.options.always %= "-w ${gcc.maxerrorsimpl}"
164  gcc.cpp.options.always %= "-w ${gcc.maxerrorsimpl} -fpermissive"
165@elif windows:
166  gcc.options.always %= "-w ${gcc.maxerrorsimpl} -mno-ms-bitfields"
167  gcc.cpp.options.always %= "-w ${gcc.maxerrorsimpl} -fpermissive -mno-ms-bitfields"
168@else:
169  gcc.options.always %= "-w ${gcc.maxerrorsimpl}"
170  gcc.cpp.options.always %= "-w ${gcc.maxerrorsimpl} -fpermissive"
171@end
172
173# Configuration for Objective-C compiler:
174#
175# Options for GNUStep. GNUStep configuration varies wildly, so you'll probably
176# have to add additional compiler and linker flags on a per-project basis.
177gcc.objc.options.linker = "-lobjc -lgnustep-base"
178llvm_gcc.objc.options.linker = "-lobjc -lgnustep-base"
179clang.objc.options.linker = "-lobjc -lgnustep-base"
180
181# Options for Mac OS X. Mac OS X uses its own Objective-C stack that is
182# totally different from GNUStep.
183@if macosx:
184  gcc.objc.options.linker = "-framework Foundation"
185  llvm_gcc.objc.options.linker = "-framework Foundation"
186  clang.objc.options.linker = "-framework Foundation"
187@end
188
189# Options for FreeBSD, OpenBSD, NetBSD linker to add locations for searching
190# shared libraries.
191@if freebsd or openbsd or netbsd:
192  gcc.options.linker = "-Wl,-rpath=.:/usr/local/lib:/usr/pkg/lib:/usr/X11R6/lib"
193  gcc.cpp.options.linker = "-Wl,-rpath=.:/usr/local/lib:/usr/pkg/lib:/usr/X11R6/lib"
194  llvm_gcc.options.linker = "-Wl,-rpath=.:/usr/local/lib:/usr/pkg/lib:/usr/X11R6/lib"
195  llvm_gcc.cpp.options.linker = "-Wl,-rpath=.:/usr/local/lib:/usr/pkg/lib:/usr/X11R6/lib"
196  clang.options.linker = "-Wl,-rpath=.:/usr/local/lib:/usr/pkg/lib:/usr/X11R6/lib"
197  clang.cpp.options.linker = "-Wl,-rpath=.:/usr/local/lib:/usr/pkg/lib:/usr/X11R6/lib"
198
199  cincludes: "/usr/local/include"
200  clibdir: "/usr/local/lib"
201@end
202
203@if freebsd or openbsd:
204  cincludes: "/usr/local/include"
205  clibdir: "/usr/local/lib"
206@elif netbsd:
207  cincludes: "/usr/pkg/include"
208  clibdir: "/usr/pkg/lib"
209@end
210
211# Configuration for the VxWorks
212# This has been tested with VxWorks 6.9 only
213@if vxworks:
214  # For now we only support compiling RTPs applications (i.e. no DKMs)
215  gcc.options.always = "-mrtp -fno-strict-aliasing -D_C99 -D_HAS_C9X -std=c99 -fasm -Wall -Wno-write-strings"
216  # The linker config must add the VxWorks common library for the selected
217  # processor which is usually found in:
218  # "$WIND_BASE/target/lib/usr/lib/PROCESSOR_FAMILY/PROCESSOR_TYPE/common",
219  # where PROCESSOR_FAMILY and PROCESSOR_TYPE are those supported by the VxWorks
220  # compiler (e.g. ppc/PPC32 or mips/MIPSI64, etc)
221  # For now we only support the PowerPC CPU
222  gcc.options.linker %= "-L $WIND_BASE/target/lib/usr/lib/ppc/PPC32/common -mrtp -fno-strict-aliasing -D_C99 -D_HAS_C9X -std=c99 -fasm -Wall -Wno-write-strings"
223@end
224
225gcc.options.speed = "-O3 -fno-strict-aliasing -fno-ident"
226gcc.options.size = "-Os -fno-ident"
227@if windows:
228  gcc.options.debug = "-g3 -Og -gdwarf-3"
229@else:
230  gcc.options.debug = "-g3 -Og"
231@end
232gcc.cpp.options.speed = "-O3 -fno-strict-aliasing -fno-ident"
233gcc.cpp.options.size = "-Os -fno-ident"
234gcc.cpp.options.debug = "-g3 -Og"
235#passl = "-pg"
236
237# Configuration for the LLVM GCC compiler:
238llvm_gcc.options.debug = "-g"
239llvm_gcc.options.always = "-w"
240llvm_gcc.options.speed = "-O2"
241llvm_gcc.options.size = "-Os"
242
243# Configuration for the LLVM CLang compiler:
244clang.options.debug = "-g"
245clang.cpp.options.debug = "-g"
246clang.options.always = "-w -ferror-limit=3"
247clang.options.speed = "-O3"
248clang.options.size = "-Os"
249
250@if windows:
251  clang_cl.cpp.options.always %= "${clang_cl.options.always} /EHsc"
252  @if not release and not safety and not danger:
253    clang_cl.options.linker = "/Z7"
254    clang_cl.cpp.options.linker = "/Z7"
255  @end
256  clang.options.debug = "-g -gcodeview"
257  clang.cpp.options.debug = "-g -gcodeview"
258  @if not release and not safety and not danger:
259    clang.options.linker = "-g"
260    clang.cpp.options.linker = "-g"
261  @end
262@end
263
264# Configuration for the Visual C/C++ compiler:
265# VCCEXE is a tool that invokes the Visual Studio Developer Command Prompt
266# before calling the compiler.
267# Please make sure either Visual Studio or C++ Build SKU is installed when using the vcc compiler backend.
268
269vcc.exe = "vccexe.exe"
270vcc.cpp.exe = "vccexe.exe"
271vcc.linkerexe = "vccexe.exe"
272vcc.cpp.linkerexe = "vccexe.exe"
273
274vcc.options.always =  "/nologo"
275vcc.cpp.options.always = "/nologo /EHsc"
276vcc.options.debug = "/Zi /FS /Od"
277vcc.cpp.options.debug = "/Zi /FS /Od"
278vcc.options.speed = "/O2"
279vcc.cpp.options.speed = "/O2"
280vcc.options.size = "/O1"
281vcc.cpp.options.size = "/O1"
282
283# Configuration for the Tiny C Compiler:
284tcc.options.always = "-w"
285
286@if arm or arm64:
287  --define:nimEmulateOverflowChecks
288@end
289
290@if nimv019:
291  --multimethods:on
292  --define:nimOldCaseObjects
293  --define:nimOldShiftRight
294@end
295
296@if lto or lto_incremental:
297  @if lto_incremental:
298   vcc.options.always%= "${vcc.options.always} /GL /Gw /Gy"
299   vcc.cpp.options.always%= "${vcc.cpp.options.always} /GL /Gw /Gy"
300   vcc.options.linker %= "${vcc.options.linker} /link /LTCG:incremental"
301   vcc.cpp.options.linker %= "${vcc.cpp.options.linker} /link /LTCG:incremental"
302  @else:
303   vcc.options.always%= "${vcc.options.always} /GL"
304   vcc.cpp.options.always%= "${vcc.cpp.options.always} /GL"
305   vcc.options.linker %= "${vcc.options.linker} /link /LTCG"
306   vcc.cpp.options.linker %= "${vcc.cpp.options.linker} /link /LTCG"
307  @end
308  clang_cl.options.always%= "${clang_cl.options.always} -flto"
309  clang_cl.cpp.options.always%= "${clang.cpp.options.always} -flto"
310  clang.options.always%= "${clang.options.always} -flto"
311  clang.cpp.options.always%= "${clang.cpp.options.always} -flto"
312  icl.options.always %= "${icl.options.always} /Qipo"
313  icl.cpp.options.always %= "${icl.cpp.options.always} /Qipo"
314  gcc.options.always %= "${gcc.options.always} -flto"
315  gcc.cpp.options.always %= "${gcc.cpp.options.always} -flto"
316  clang.options.linker %= "${clang.options.linker} -fuse-ld=lld -flto"
317  clang.cpp.options.linker %= "${clang.cpp.options.linker} -fuse-ld=lld -flto"
318  gcc.options.linker %= "${gcc.options.linker} -flto"
319  gcc.cpp.options.linker %= "${gcc.cpp.options.linker} -flto"
320@end
321@if strip:
322  gcc.options.linker %= "${gcc.options.linker} -s"
323  gcc.cpp.options.linker %= "${gcc.cpp.options.linker} -s"
324  clang.options.linker %= "${clang.options.linker} -s"
325  clang.cpp.options.linker %= "${clang.cpp.options.linker} -s"
326@end
327