-
Notifications
You must be signed in to change notification settings - Fork 559
/
config.nims
133 lines (122 loc) · 4.01 KB
/
config.nims
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
############################################################################
# apps/config.nims
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
############################################################################
import std/os
import std/strutils
switch "os", "nuttx"
switch "mm", "orc"
switch "arm.nuttx.gcc.exe", "arm-none-eabi-gcc"
switch "arm64.nuttx.gcc.exe", "aarch64-none-elf-gcc"
switch "riscv32.nuttx.gcc.exe", "riscv64-unknown-elf-gcc"
switch "riscv64.nuttx.gcc.exe", "riscv64-unknown-elf-gcc"
switch "amd64.nuttx.gcc.exe", "x86_64-linux-gnu-gcc"
switch "nimcache", ".nimcache"
switch "d", "useStdLib"
switch "d", "useMalloc"
switch "d", "nimAllocPagesViaMalloc"
switch "d", "noSignalHandler"
switch "threads", "off"
switch "noMain", "on"
switch "compileOnly", "on"
switch "noLinking", "on"
# TODO: need OpenSSL-mbedTLS wrapper library.
#switch "d", "ssl"
#swich "dynlibOverride", "ssl"
type
OptFlag = enum
oNone
oSize
DotConfig = object
arch: string
opt: OptFlag
debugSymbols: bool
ramSize: int
isSim: bool
proc killoBytes(bytes: int): int =
result = (bytes / 1024).int
proc read_config(cfg: string): DotConfig =
for line in cfg.readFile.splitLines:
if not line.startsWith("CONFIG_"):
continue
let keyval = line.replace("CONFIG_", "").split("=")
if keyval.len != 2:
continue
case keyval[0]
of "ARCH":
let arch = keyval[1].strip(chars = {'"'})
case arch
of "arm", "arm64":
result.arch = arch
of "sim":
if defined(amd64):
result.arch = "amd64"
elif defined(aarch64):
result.arch = "arm64"
result.isSim = true
of "ARCH_FAMILY":
let arch = keyval[1].strip(chars = {'"'})
case arch
of "rv32":
result.arch = "riscv32"
of "rv64":
result.arch = "riscv64"
of "DEBUG_NOOPT":
result.opt = oNone
of "DEBUG_FULLOPT":
result.opt = oSize
of "DEBUG_SYMBOLS":
result.debugSymbols = true
of "RAM_SIZE":
result.ramSize = keyval[1].parseInt
echo "* arch: " & result.arch
echo "* opt: " & $result.opt
echo "* debug: " & $result.debugSymbols
echo "* ramSize: " & $result.ramSize
func bool2onoff(b: bool): string =
result = if b: "on" else: "off"
proc setup_cfg(cfg: DotConfig) =
switch("cpu", cfg.arch)
if cfg.opt == oSize:
switch("define", "release")
switch("define", "danger")
switch("opt", "size")
if cfg.debugSymbols:
# use native debugger (gdb)
switch("debugger", "native")
let debug_onoff = cfg.debugSymbols.bool2onoff
switch("lineDir", debug_onoff)
switch("stackTrace", debug_onoff)
switch("lineTrace", debug_onoff)
if not cfg.isSim:
# Adjust the page size for Nim's GC allocator.
let ramKilloBytes = cfg.ramSize.killoBytes
if ramKilloBytes < 32:
switch("define", "nimPage256")
elif ramKilloBytes < 512:
switch("define", "nimPage512")
elif ramKilloBytes < 2048:
switch("define", "nimPage1k")
if ramKilloBytes < 512:
# Sets MemAlign to 4 bytes which reduces the memory alignment
# to better match some embedded devices.
switch("define", "nimMemAlignTiny")
const key = "TOPDIR"
let topdir = if existsEnv(key): getEnv(key) else: thisDir() & "/../nuttx"
let cfg = read_config(topdir & "/.config")
cfg.setup_cfg()