-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathcreateconfiguregpr.ps1
executable file
·337 lines (308 loc) · 12.3 KB
/
createconfiguregpr.ps1
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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
#
# Create "configure.gpr" GPRbuild project file.
#
# Copyright (C) 2020-2025 Gabriele Galeotti
#
# This work is licensed under the terms of the MIT License.
# Please consult the LICENSE.txt file located in the top-level directory.
#
#
# Arguments:
# $1 = configure project
# $2 = configure filename
#
# Environment variables:
# SWEETADA_PATH
# TOOLCHAIN_PREFIX
# GPRBUILD_PREFIX
# TOOLCHAIN_NAME
# GCC_WRAPPER
# GNATADC_FILENAME
# LIBRARY_DIRECTORY
# OBJECT_DIRECTORY
# PLATFORM
# CPU
# CPU_MODEL
# RTS_PATH
# RTS
# PROFILE
# ADA_MODE
# OPTIMIZATION_LEVEL
# STACK_LIMIT
# GNATBIND_SECSTACK
# USE_LIBGCC
# USE_LIBM
# USE_LIBADA
# USE_CLIBRARY
# ADAC_SWITCHES_RTS
# CC_SWITCHES_RTS
# GCC_SWITCHES_PLATFORM
# GCC_SWITCHES_STARTUP
# INCLUDE_DIRECTORIES
# IMPLICIT_ALI_UNITS
#
################################################################################
# Script initialization. #
# #
################################################################################
$scriptname = $MyInvocation.MyCommand.Name
$nl = [Environment]::NewLine
################################################################################
# ExitWithCode() #
# #
################################################################################
function ExitWithCode
{
param($exitcode)
$host.SetShouldExit($exitcode)
exit $exitcode
}
################################################################################
# Write-Stderr() #
# #
################################################################################
function Write-Stderr
{
param([PSObject]$inputobject)
$outf = if ($host.Name -eq "ConsoleHost")
{
[Console]::Error.WriteLine
}
else
{
$host.UI.WriteErrorLine
}
if ($inputobject)
{
[void]$outf.Invoke($inputobject.ToString())
}
else
{
[string[]]$lines = @()
$input | % { $lines += $_.ToString() }
[void]$outf.Invoke($lines -Join $nl)
}
}
################################################################################
# GetEnvVar() #
# #
################################################################################
$GetEnvironmentVariable_signature = @'
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern uint
GetEnvironmentVariable(
string lpName,
System.Text.StringBuilder lpBuffer,
uint nSize
);
'@
Add-Type `
-MemberDefinition $GetEnvironmentVariable_signature `
-Name "Win32GetEnvironmentVariable" `
-Namespace Win32
$gev_buffer_size = 4096
$gev_buffer = [System.Text.StringBuilder]::new($gev_buffer_size)
function GetEnvVar
{
param([string]$varname)
if (-not (Test-Path env:$varname))
{
return [string]::Empty
}
else
{
$nchars = [Win32.Win32GetEnvironmentVariable]::GetEnvironmentVariable(
$varname,
$gev_buffer,
[uint32]$gev_buffer_size
)
if ($nchars -gt $gev_buffer_size)
{
Write-Stderr "$($scriptname): *** Error: GetEnvVar: buffer size < $($nchars)."
ExitWithCode 1
}
return [string]$gev_buffer
}
}
################################################################################
# print_V() #
# #
################################################################################
function print_V
{
return ""
}
################################################################################
# print_I() #
# #
################################################################################
function print_I
{
param([string]$t)
$is = ""
for ($i = 0 ; $i -lt $indentation_level ; $i++)
{
$is += $indentation_Ada
}
return "$is$t"
}
################################################################################
# print_list() #
# #
################################################################################
function print_list
{
param([string]$list, [int]$il, [string]$is)
$return_string = ""
if ($list.Length -gt 0)
{
$list_array = $list -Split "\s+"
$count = 0
foreach ($s in $list_array)
{
$count++
$s = "`"$s`""
if ($count -ne $list_array.Length)
{
$s += ","
}
$return_string += $(print_I "$is$s") + $nl
}
}
return $return_string
}
################################################################################
# LFPL_list() #
# #
# Build a list of the source languages detected in input arguments. #
################################################################################
function LFPL_list
{
param([string]$list)
$LFP_S_files = $false
$LFP_C_files = $false
$LFPL = ""
foreach ($f in $list.Split(" "))
{
if ($f.Trim().EndsWith(".S") -and -not $LFP_S_files)
{
$LFP_S_files = $true
if ($LFPL.Length -gt 0)
{
$LFPL = $LFPL + " "
}
$LFPL = $LFPL + "Asm_Cpp"
}
elseif ($f.Trim().EndsWith(".c") -and -not $LFP_C_files)
{
$LFP_C_files = $true
if ($LFPL.Length -gt 0)
{
$LFPL = $LFPL + " "
}
$LFPL = $LFPL + "C"
}
}
return $LFPL
}
################################################################################
# Main loop. #
# #
################################################################################
#
# Basic input parameters check.
#
$configure_project = $args[0]
if ([string]::IsNullOrEmpty($configure_project))
{
Write-Stderr "$($scriptname): *** Error: no project name specified."
ExitWithCode 1
}
$configure_filename = $args[1]
if ([string]::IsNullOrEmpty($configure_filename))
{
Write-Stderr "$($scriptname): *** Error: no project file specified."
ExitWithCode 1
}
Remove-Item -Path $configure_filename -Force -ErrorAction Ignore
New-Item -Name $configure_filename -ItemType File | Out-Null
$indentation_Ada = " " # Ada 3-space indentation style
$indentation_level = 0
$configuregpr = ""
#
# Initial empty line.
#
$configuregpr += $nl
#
# Declare project.
#
$configuregpr += $(print_I "abstract project $configure_project is") + $nl
$indentation_level++
$configuregpr += $(print_V $configure_filename) + $nl
#
# Configuration declarations.
#
$configuregpr += $(print_I "SweetAda_Path := `"$(GetEnvVar SWEETADA_PATH)`";") + $nl
$configuregpr += $(print_I "Toolchain_Prefix := `"$(GetEnvVar TOOLCHAIN_PREFIX)`";") + $nl
$configuregpr += $(print_I "Gprbuild_Prefix := `"$(GetEnvVar GPRBUILD_PREFIX)`";") + $nl
$configuregpr += $(print_I "Toolchain_Name := `"$(GetEnvVar TOOLCHAIN_NAME)`";") + $nl
$configuregpr += $(print_I "GCC_Wrapper := `"$(GetEnvVar GCC_WRAPPER)`";") + $nl
$configuregpr += $(print_I "GnatAdc_Filename := `"$(GetEnvVar GNATADC_FILENAME)`";") + $nl
$configuregpr += $(print_I "Library_Directory := `"$(GetEnvVar LIBRARY_DIRECTORY)`";") + $nl
$configuregpr += $(print_I "Object_Directory := `"$(GetEnvVar OBJECT_DIRECTORY)`";") + $nl
$configuregpr += $(print_I "Platform := `"$(GetEnvVar PLATFORM)`";") + $nl
$configuregpr += $(print_I "Cpu := `"$(GetEnvVar CPU)`";") + $nl
$configuregpr += $(print_I "Cpu_Model := `"$(GetEnvVar CPU_MODEL)`";") + $nl
$configuregpr += $(print_I "RTS_Path := `"$(GetEnvVar RTS_PATH)`";") + $nl
$configuregpr += $(print_I "RTS := `"$(GetEnvVar RTS)`";") + $nl
$configuregpr += $(print_I "Profile := `"$(GetEnvVar PROFILE)`";") + $nl
$configuregpr += $(print_I "Ada_Mode := `"$(GetEnvVar ADA_MODE)`";") + $nl
$configuregpr += $(print_I "Optimization_Level := `"$(GetEnvVar OPTIMIZATION_LEVEL)`";") + $nl
$configuregpr += $(print_I "Stack_Limit := `"$(GetEnvVar STACK_LIMIT)`";") + $nl
$configuregpr += $(print_I "Gnatbind_SecStack := `"$(GetEnvVar GNATBIND_SECSTACK)`";") + $nl
$configuregpr += $(print_I "Use_LibGCC := `"$(GetEnvVar USE_LIBGCC)`";") + $nl
$configuregpr += $(print_I "Use_Libm := `"$(GetEnvVar USE_LIBM)`";") + $nl
$configuregpr += $(print_I "Use_LibAda := `"$(GetEnvVar USE_LIBADA)`";") + $nl
$configuregpr += $(print_I "Use_CLibrary := `"$(GetEnvVar USE_CLIBRARY)`";") + $nl
$indentl = " "
$configuregpr += $(print_I "ADAC_Switches_RTS := (") + $nl
$configuregpr += $(print_list $(GetEnvVar ADAC_SWITCHES_RTS).Trim(" ") $indentation_level $indentl)
$configuregpr += $(print_I " );") + $nl
$configuregpr += $(print_I "CC_Switches_RTS := (") + $nl
$configuregpr += $(print_list $(GetEnvVar CC_SWITCHES_RTS).Trim(" ") $indentation_level $indentl)
$configuregpr += $(print_I " );") + $nl
$configuregpr += $(print_I "GCC_Switches_Platform := (") + $nl
$configuregpr += $(print_list $(GetEnvVar GCC_SWITCHES_PLATFORM).Trim(" ") $indentation_level $indentl)
$configuregpr += $(print_I " );") + $nl
$configuregpr += $(print_I "Lowlevel_Files_Platform := (") + $nl
$configuregpr += $(print_list $(GetEnvVar LOWLEVEL_FILES_PLATFORM).Trim(" ") $indentation_level $indentl)
$configuregpr += $(print_I " );") + $nl
$configuregpr += $(print_I "Lowlevel_Files_Platform_Languages := (") + $nl
$configuregpr += $(print_list $(LFPL_list $(GetEnvVar LOWLEVEL_FILES_PLATFORM)) $indentation_level $indentl)
$configuregpr += $(print_I " );") + $nl
$configuregpr += $(print_I "GCC_Switches_Lowlevel_Platform := (") + $nl
$configuregpr += $(print_list $(GetEnvVar GCC_SWITCHES_LOWLEVEL_PLATFORM).Trim(" ") $indentation_level $indentl)
$configuregpr += $(print_I " );") + $nl
$configuregpr += $(print_I "Include_Directories := (") + $nl
$configuregpr += $(print_list $(GetEnvVar INCLUDE_DIRECTORIES).Trim(" ") $indentation_level $indentl)
$configuregpr += $(print_I " );") + $nl
$configuregpr += $(print_I "Implicit_ALI_Units := (") + $nl
$configuregpr += $(print_list $(GetEnvVar IMPLICIT_ALI_UNITS).Trim(" ") $indentation_level $indentl)
$configuregpr += $(print_I " );") + $nl
$configuregpr += $(print_V) + $nl
#
# Close the project.
#
$indentation_level--
$configuregpr += $(print_I "end $configure_project;") + $nl
try
{
Add-Content -Path $configure_filename -Value "$configuregpr" -NoNewline
}
catch
{
Write-Stderr "$($scriptname): *** Error: writing $($configure_filename)."
ExitWithCode 1
}
Write-Host "$($scriptname): $($configure_filename): done."
ExitWithCode 0