forked from lycus/flect
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.exs
230 lines (188 loc) · 7.56 KB
/
config.exs
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
IO.puts("This is the Flect configuration script.")
IO.puts("Some variables will have default values that are based on guesstimations about the current system.")
IO.puts("Simply leave a variable blank to use the default value or specify a different value if needed.")
IO.puts("Note that if the guesstimation leaves a variable blank, it must be filled out manually.")
IO.puts("Some variables (such as FLECT_CC_ARGS and FLECT_LD_ARGS) can be left empty.")
IO.puts("")
IO.puts("Press Enter to start configuring Flect.")
IO.readline()
target = list_to_binary(:erlang.system_info(:system_architecture))
IO.puts("Guesstimated target triple is: #{target}")
IO.puts("")
re = fn(re) -> Regex.match?(re, target) end
{arch, os, abi, fpabi, endian} = cond do
re.(%r/^arm-\w*-linux-gnueabi$/) -> {"arm", "linux", "arm-aapcs", "arm-soft", "little"}
re.(%r/^arm-\w*-linux-gnueabihf$/) -> {"arm", "linux", "arm-aapcs", "arm-hardfp", "little"}
re.(%r/^armv\dh\w-\w*-linux-gnu$/) -> {"arm", "linux", "arm-aapcs", "arm-hardfp", "little"}
re.(%r/^powerpc-\w*-linux-gnu$/) -> {"ppc", "linux", "ppc-ppc64", "ppc-hardfp", "big"}
re.(%r/^i\d86-\w*-linux-gnu$/) -> {"x86", "linux", "x86-sysv32", "x86-x87", "little"}
re.(%r/^x86_64-\w*-linux-gnu$/) -> {"x86", "linux", "x86-sysv64", "x86-sse", "little"}
re.(%r/^i\d86-\w*-darwin/) -> {"x86", "darwin", "x86-sysv32", "x86-x87", "little"}
re.(%r/^x86_64-\w*-darwin/) -> {"x86", "darwin", "x86-sysv64", "x86-sse", "little"}
true -> {"", "", "", "", ""}
end
IO.puts("Guesstimated values:")
IO.puts("")
IO.puts(" FLECT_ARCH = #{arch}")
IO.puts(" FLECT_OS = #{os}")
IO.puts(" FLECT_ABI = #{abi}")
IO.puts(" FLECT_FPABI = #{fpabi}")
IO.puts(" FLECT_ENDIAN = #{endian}")
IO.puts("")
IO.puts("Guesstimation complete. Proceeding to compiler configuration.")
IO.puts("")
get = fn(var, def, empty) ->
cond do
(s = String.strip(list_to_binary(IO.gets("Please enter a value for #{var} [#{def}]: ")))) != "" -> s
def != "" -> def
empty -> ""
true ->
IO.puts("Error: No value for #{var} given.")
System.halt(1)
end
end
get_bool = fn(var, def) ->
s = get.(var, def, false)
if s in ["true", "false"] do
s
else
IO.puts("Error: Value must be true or false.")
System.halt(1)
end
end
arch = get.("FLECT_ARCH", arch, false)
os = get.("FLECT_OS", os, false)
abi = get.("FLECT_ABI", abi, false)
fpabi = get.("FLECT_FPABI", fpabi, false)
endian = get.("FLECT_ENDIAN", endian, false)
unless os in ["none", "aix", "android", "darwin", "dragonflybsd", "freebsd", "haiku", "hpux", "hurd", "ios", "linux", "openbsd", "solaris", "windows"] do
IO.puts("Error: Invalid operating system #{os} (FLECT_OS)")
System.halt(1)
end
arch_valid = case os do
"none" -> arch in ["arm", "ia64", "mips", "ppc", "x86"]
"aix" -> arch in ["ppc"]
"android" -> arch in ["arm", "mips", "x86"]
"darwin" -> arch in ["ppc", "x86"]
"dragonflybsd" -> arch in ["x86"]
"freebsd" -> arch in ["arm", "ia64", "mips", "ppc", "x86"]
"haiku" -> arch in ["x86"]
"hpux" -> arch in ["ia64"]
"hurd" -> arch in ["x86"]
"ios" -> arch in ["arm"]
"linux" -> arch in ["arm", "ia64", "mips", "ppc", "x86"]
"openbsd" -> arch in ["arm", "mips", "ppc", "x86"]
"solaris" -> arch in ["x86"]
"windows" -> arch in ["ia64", "x86"]
end
unless arch_valid do
IO.puts("Error: Invalid architecture #{arch} for operating system #{os} (FLECT_ARCH)")
System.halt(1)
end
abi_valid = case arch do
"arm" -> abi in ["arm-thumb", "arm-thumb2", "arm-aapcs", "arm-aarch64"]
"ia64" -> abi in ["ia64-ilp32", "ia64-lp64"]
"mips" -> abi in ["mips-o32", "mips-n32", "mips-o64", "mips-n64", "mips-eabi32", "mips-eabi64"]
"ppc" -> abi in ["ppc-ppc32", "ppc-ppc64"]
"x86" -> abi in ["x86-ms32", "x86-sysv32", "x86-ms64", "x86-sysv64", "x86-x32"]
end
unless abi_valid do
IO.puts("Error: Invalid ABI #{abi} for architecture #{arch} (FLECT_ABI)")
System.halt(1)
end
fpabi_valid = case arch do
"arm" -> fpabi in ["arm-soft", "arm-softfp", "arm-hardfp"]
"ia64" -> fpabi in ["ia64-hardfp"]
"mips" -> fpabi in ["mips-softfp", "mips-hardfp"]
"ppc" -> fpabi in ["ppc-softfp", "ppc-hardfp"]
"x86" -> fpabi in ["x86-softfp", "x86-x87", "x86-sse"]
end
unless fpabi_valid do
IO.puts("Error: Invalid floating point ABI #{fpabi} for architecture #{arch} (FLECT_FPABI)")
System.halt(1)
end
endian_valid = case arch do
"arm" -> endian in ["big", "little"]
"ia64" -> endian in ["big", "little"]
"mips" -> endian in ["big", "little"]
"ppc" -> endian in ["big", "little"]
"x86" -> endian in ["little"]
end
unless endian_valid do
IO.puts("Error: Invalid endianness #{endian} for architecture #{arch} (FLECT_ENDIAN)")
System.halt(1)
end
cross = get_bool.("FLECT_CROSS", "false")
IO.puts("")
IO.puts("Compiler configuration complete. Proceeding to external tool configuration.")
IO.puts("")
cc = get.("FLECT_CC", "clang", false)
cc_type = get.("FLECT_CC_TYPE", "gcc", false)
unless cc_type in ["gcc"] do
IO.puts("Error: Invalid C99 compiler type #{cc_type} (FLECT_CC_TYPE)")
System.halt(1)
end
cc_args = get.("FLECT_CC_ARGS", "", true)
ld = get.("FLECT_LD", "ld", false)
ld_type = get.("FLECT_LD_TYPE", "ld", false)
unless ld_type in ["ld"] do
IO.puts("Error: Invalid linker type #{ld_type} (FLECT_LD_TYPE)")
System.halt(1)
end
ld_args = get.("FLECT_LD_ARGS", "", true)
IO.puts("")
IO.puts("External tool configuration complete. Proceeding to directory hierarchy configuration.")
IO.puts("")
prefix = get.("FLECT_PREFIX", "/usr/local", false)
bin_dir = get.("FLECT_BIN_DIR", Path.join(prefix, "bin"), false)
lib_dir = get.("FLECT_LIB_DIR", Path.join([prefix, "lib", "flect"]), false)
st_lib_dir = get.("FLECT_ST_LIB_DIR", Path.join(lib_dir, "static"), false)
sh_lib_dir = get.("FLECT_SH_LIB_DIR", Path.join(lib_dir, "shared"), false)
IO.puts("")
IO.puts("Directory hierarchy configuration complete.")
IO.puts("")
IO.puts("Configuration:")
IO.puts("")
IO.puts(" FLECT_ARCH = #{arch}")
IO.puts(" FLECT_OS = #{os}")
IO.puts(" FLECT_ABI = #{abi}")
IO.puts(" FLECT_FPABI = #{fpabi}")
IO.puts(" FLECT_ENDIAN = #{endian}")
IO.puts(" FLECT_CROSS = #{cross}")
IO.puts("")
IO.puts(" FLECT_CC = #{cc}")
IO.puts(" FLECT_CC_TYPE = #{cc_type}")
IO.puts(" FLECT_CC_ARGS = #{cc_args}")
IO.puts(" FLECT_LD = #{ld}")
IO.puts(" FLECT_LD_TYPE = #{ld_type}")
IO.puts(" FLECT_LD_ARGS = #{ld_args}")
IO.puts("")
IO.puts(" FLECT_PREFIX = #{prefix}")
IO.puts(" FLECT_BIN_DIR = #{bin_dir}")
IO.puts(" FLECT_LIB_DIR = #{lib_dir}")
IO.puts(" FLECT_ST_LIB_DIR = #{st_lib_dir}")
IO.puts(" FLECT_SH_LIB_DIR = #{sh_lib_dir}")
IO.puts("")
IO.puts("Press Enter to write the configuration.")
IO.readline()
cfg = "# Generated by config.exs on #{inspect(:erlang.localtime())}.
export FLECT_ARCH ?= #{arch}
export FLECT_OS ?= #{os}
export FLECT_ABI ?= #{abi}
export FLECT_FPABI ?= #{fpabi}
export FLECT_ENDIAN ?= #{endian}
export FLECT_CROSS ?= #{cross}
export FLECT_CC ?= #{cc}
export FLECT_CC_TYPE ?= #{cc_type}
export FLECT_CC_ARGS ?= #{cc_args}
export FLECT_LD ?= #{ld}
export FLECT_LD_TYPE ?= #{ld_type}
export FLECT_LD_ARGS ?= #{ld_args}
export FLECT_PREFIX ?= #{prefix}
export FLECT_BIN_DIR ?= #{bin_dir}
export FLECT_LIB_DIR ?= #{lib_dir}
export FLECT_ST_LIB_DIR ?= #{st_lib_dir}
export FLECT_SH_LIB_DIR ?= #{sh_lib_dir}"
File.write!("config.mak", cfg)
IO.puts("Done.")
System.halt(0)