-
Notifications
You must be signed in to change notification settings - Fork 0
/
Make me a Makefile.ps1
521 lines (431 loc) · 23.2 KB
/
Make me a Makefile.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
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
# The MIT License (MIT)
#
# Copyright (c) 2020 Orion 2 CanSat
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
function Is-Numeric ($Value) {
return $Value -match "^[\d\.]+$"
}
$Orion2Logo = [char[]]"MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMWNX0OOkkxk0KXNWWMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMWXOdlc;'.';;..;lodxO0XWWMMMMMMMMMWNXKKXNMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMWNOl,...,'..':c::llllllclox0NMWNKOxollccc:l0MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMWXk:..........',cllllllllcc:,;odolcloxMKXKOc,OMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMW0c.........',;cccllllllllll:,,:::x0kMMMMKo;;dNMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMNk:........,::ccccclllllllllll:,,,:ddcxMNk::okNMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMXkc'..''..,:::cccccclllllllllllc,..,:;l0Oc:dXWWMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMNkl:..:cc:;:ccccccccclllllllllloc;;;:c;clcdKWMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMW0olc,',;:c:;:::cccccllllllllloddl;,,;;;:cdOOMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMNxlllc:,',clc:::ccccllllllllloddc,'''''';cldMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMXdclllll:;;;,',,;:ccllllllllloddc,'''',:clOWMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMXdcllllllc:'......,;:cllllllllc;;:cc:;lxockMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMXXXXNWMMM
MMMMMMMMMNdclllllll;'.........,:clllc;'.,:ldxlcxkdlkMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMc::::lOWMM
MMMMMMMMMWkclooollc,'..........',,,'.';clooddodkkdlMMMMNNNNNNNNNWWMMMWNWWMMMWWNNNNWWMMMMWWWMMMMMMWNNMMMM:;;dNMM
MMMMMMMMMMKl:loooolc;''''''''''.....'coooooodxkOklxMMOddooooooodkXWMkoxKMWKkdoooodxONWMOdxKNMMMXkoxkM;;::MMMMMM
MMMMMMMMMWO:':loooool:;''','......';loooooodxkOkldXMNd::;:cccc::cxNMd:l0MMo:;:ccc::cxXMxcclxKWWKo:okM,;;;;:xNMM
MMMMMMMWOl:odc:looooool:,.....'',,;coooooodxkOxldXMMNd:ccoMMMxoc;oXMo;l0Mx::dXNNNOl;lKMx:;,;lxK0l;l0MOOOOOOKWMM
MMMMMWKl;o0WWKo::lool:,'...'',,;:cloooooodxkxolkNMMMXd;;,,,;;:;;:kWMo;c0Mx;:kWMMMKl;l0Md;:ll;;ldc;lKMMMMMMMMMMM
MMMMNx;cOWMMMMNk:,,''',;,',,;:cloooooddddxdlcdKWMMMMNo;;:oxc,,:oMMMMo,c0Mx;:xKXXXOl;cKMd;:kXOc,;:;lKMMMMMMMMMMM
MMMWx,oXMMWX0kdl:::,,;cl:,;cooddddddddolcclxKWMMMMMMXo,:lMMXx:,;lMMMl,:0MO:,;::::;,,dNMd,;kWMXx:,'cKMMMMMMMMMMM
MMMNo,oxxolccldkKNNXOdlc:,,:ccccccc:::clx0NWMMMMMMMMNkldkKMMWXxlldKMkldXMM0dllccclokNMMOloKMMMWKxldXMMMMMMMMMMM
MMMWKxdddxOKXWMMMMMMMMWX0kxdddoodddxOKNWMMMMMMMMMMMMMWWWWMMMMMWWWWWMWWWMMMMMWWWWWWWMMMMWWWWMMMMMWWWMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMWWMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
"
Clear-Host
foreach ($char in $Orion2Logo)
{
if ($char -eq 'M')
{
Write-Host ' ' -NoNewline
}
elseif ($char -eq "\n$")
{
Write-Host ''
}
elseif ('.,' -match $char)
{
Write-Host $char -ForegroundColor Magenta -NoNewline
}
elseif ('loc' -match $char)
{
Write-Host $char -ForegroundColor Red -NoNewline
}
else
{
Write-Host $char -ForegroundColor DarkRed -NoNewline
}
}
Write-Host "Make me a Makefile
Created by Orion 2 CanSat
"
Write-Host 'Make me a Makefile will ask some questions to prepare your makefile.
'
$ProjectName = Read-Host -Prompt "What is your project Name? "
$BoardName = $null
$BoardID = $null
$BoardProcessor = $null
$CPUType = $null
$CPUSpeed = $null
$FPU = $null
$Defines = $null
Write-Host "Select board.
1) Teensy 3.1
2) Teensy 3.2
3) Teensy 3.5
4) Teensy 3.6
5) Teensy 4.0
6) Teensy 4.1
7) Other
"
$BoardNumber = ""
while (-Not (Is-Numeric $BoardNumber))
{
$BoardNumber = Read-Host -Prompt "Select number of the board you want to complie with"
}
$BoardNumber = $BoardNumber -as [int]
switch ($BoardNumber)
{
1 {
$BoardName = "Teensy 3.1"
$BoardID = "TEENSY33"
$BoardProcessor = "mk20dx256"
$CPUType = "cortex-m4"
$CPUSpeed = "72000000"
$FPU = ""
}
2 {
$BoardName = "Teensy 3.2"
$BoardID = "TEENSY32"
$BoardProcessor = "mk20dx256"
$CPUType = "cortex-m4"
$CPUSpeed = "72000000"
$FPU = ""
}
3 {
$BoardName = "Teensy 3.5"
$BoardID = "TEENSY35"
$BoardProcessor = "mk64fx512"
$CPUType = "cortex-m4"
$CPUSpeed = "120000000"
$FPU = "fpv4-sp-d16"
$Defines = "-D__MK64FX512__ -DTEENSYDUINO=153 -DARDUINO_TEENSY35 -DF_CPU=$CPUSpeed -DUSB_SERIAL -DLAYOUT_US_ENGLISH -DARDUINO"
}
4 {
$BoardName = 'Teensy 3.6'
$BoardID = 'TEENSY36'
$BoardProcessor = 'mk66fx1m0'
$CPUType = 'cortex-m4'
$CPUSpeed = '256000000'
$FPU = 'fpv4-sp-d16'
$Defines = "-D__MK66FX1M0__ -DTEENSYDUINO=153 -DARDUINO_TEENSY36 -DF_CPU=$CPUSpeed -DUSB_SERIAL -DLAYOUT_US_ENGLISH -DARDUINO"
}
5 {
$BoardName = 'Teensy 4.0'
$BoardID = 'TEENSY40'
$BoardProcessor = 'imxrt1062'
$CPUType = 'cortex-m7'
$CPUSpeed = '600000000'
$FPU = 'fpv5-d16'
$Defines = "-D__IMXRT1062__ -DTEENSYDUINO=153 -DARDUINO_TEENSY40 -DF_CPU=$CPUSpeed -DUSB_SERIAL -DLAYOUT_US_ENGLISH -DARDUINO"
}
6 {
$BoardName = 'Teensy 4.1'
$BoardID = 'TEENSY41'
$BoardProcessor = 'imxrt1062_t41'
$CPUType = 'cortex-m7'
$CPUSpeed = '600000000'
$FPU = 'fpv5-d16'
$Defines = "-D__IMXRT1062__ -DTEENSYDUINO=153 -DARDUINO_TEENSY41 -DF_CPU=$CPUSpeed -DUSB_SERIAL -DLAYOUT_US_ENGLISH -DARDUINO"
}
}
if ($BoardName -eq $null)
{
$BoardName = Read-Host -Prompt "What is your project's board Name? "
}
Write-Progress -Id 1 -Activity Updating -Status 'Creating Makefile' -PercentComplete 10 -CurrentOperation OuterLoop
if ($BoardID -eq $null)
{
$BoardID = Read-Host -Prompt "What is your project's board ID? "
}
if ($BoardProcessor -eq $null)
{
$BoardProcessor = Read-Host -Prompt "What is your project's board Processor? "
}
if ($CPUType -eq $null)
{
$CPUType = Read-Host -Prompt "What is your CPU type? "
}
if ($CPUSpeed -eq $null)
{
$CPUSpeed = Read-Host -Prompt "At what speed will your project's board be running? "
}
if ($FPU -eq $null)
{
$FPU = Read-Host -Prompt "What FPU does your processor support? "
}
Write-Progress -Id 1 -Activity Updating -Status 'Creating Makefile' -PercentComplete 20 -CurrentOperation OuterLoop
if ($Defines -eq $null)
{
$Defines = -Read-Host -Prompt "What defines would you like to use? "
}
Write-Progress -Id 1 -Activity Updating -Status 'Creating Makefile' -PercentComplete 30 -CurrentOperation OuterLoop
$Optimization = ""
While (-Not ((Is-Numeric($Optimization) -and ($Optimization -gt '0') -and ($Optimization -lt '3'))-or ($Optimization -eq 's')))
{
Write-Host "What is the level of optimazation that the commpiler will output?`n0: No optimization (the default); generates unoptimized code but has the fastest compilation time.`n1: Moderate optimization; optimizes reasonably well but does not degrade compilation time significantly.`n2: Full optimization; generates highly optimized code and has the slowest compilation time.`n3: Full optimization as in 2; also uses more aggressive automatic inlining of subprograms within a unit (Inlining of Subprograms) and attempts to vectorize loops.`ns: Optimize space usage (code and data) of resulting program."
$Optimization = Read-Host
}
$Optimization = '-O' + $Optimization
Write-Progress -Id 1 -Activity Updating -Status 'Creating Makefile' -PercentComplete 40 -CurrentOperation OuterLoop
$LibraryDir = Read-Host -Prompt "Where are your libraries located in? "
$Libraries = (Get-ChildItem -Path $LibraryDir -Directory)
$CoreLibraryDir = Read-Host -Prompt "Where do you have a core library? (If you do not have a core library leave empty) "
$Date = Get-Date -UFormat "%Y/%m/%d %R"
Write-Progress -Id 1 -Activity Updating -Status 'Creating Makefile' -PercentComplete 50 -CurrentOperation OuterLoop
$OutputString = "#-------------------------------------------------------------------------------------------------------------------------------------------------
# Generated by Make me a Makefile (https://github.com/Orion-CanSat/Make-me-a-Makefile)
#
# Board: $BoardName
# CPU Speed: $CPUSpeed
# Optimization: $Optimization
#
# Time of creation: $Date
#-------------------------------------------------------------------------------------------------------------------------------------------------
#MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
#MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
#MMMMMMMMMMMMMMMMMMMMMMMWNX0OOkkxk0KXNWWMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
#MMMMMMMMMMMMMMMMMMMWXOdlc;'.';;..;lodxO0XWWMMMMMMMMMWNXKKXNMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
#MMMMMMMMMMMMMMMMWNOl,...,'..':c::llllllclox0NMWNKOxollccc:l0MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
#MMMMMMMMMMMMMMWXk:..........',cllllllllcc:,;odolcloxMKXKOc,OMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
#MMMMMMMMMMMMMW0c.........',;cccllllllllll:,,:::x0kMMMMKo;;dNMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
#MMMMMMMMMMMMNk:........,::ccccclllllllllll:,,,:ddcxMNk::okNMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
#MMMMMMMMMMMXkc'..''..,:::cccccclllllllllllc,..,:;l0Oc:dXWWMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
#MMMMMMMMMMNkl:..:cc:;:ccccccccclllllllllloc;;;:c;clcdKWMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
#MMMMMMMMMW0olc,',;:c:;:::cccccllllllllloddl;,,;;;:cdOOMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
#MMMMMMMMMNxlllc:,',clc:::ccccllllllllloddc,'''''';cldMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
#MMMMMMMMMXdclllll:;;;,',,;:ccllllllllloddc,'''',:clOWMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
#MMMMMMMMMXdcllllllc:'......,;:cllllllllc;;:cc:;lxockMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMXXXXNWMMM
#MMMMMMMMMNdclllllll;'.........,:clllc;'.,:ldxlcxkdlkMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMc::::lOWMM
#MMMMMMMMMWkclooollc,'..........',,,'.';clooddodkkdlMMMMNNNNNNNNNWWMMMWNWWMMMWWNNNNWWMMMMWWWMMMMMMWNNMMMM:;;dNMM
#MMMMMMMMMMKl:loooolc;''''''''''.....'coooooodxkOklxMMOddooooooodkXWMkoxKMWKkdoooodxONWMOdxKNMMMXkoxkM;;::MMMMMM
#MMMMMMMMMWO:':loooool:;''','......';loooooodxkOkldXMNd::;:cccc::cxNMd:l0MMo:;:ccc::cxXMxcclxKWWKo:okM,;;;;:xNMM
#MMMMMMMWOl:odc:looooool:,.....'',,;coooooodxkOxldXMMNd:ccoMMMxoc;oXMo;l0Mx::dXNNNOl;lKMx:;,;lxK0l;l0MOOOOOOKWMM
#MMMMMWKl;o0WWKo::lool:,'...'',,;:cloooooodxkxolkNMMMXd;;,,,;;:;;:kWMo;c0Mx;:kWMMMKl;l0Md;:ll;;ldc;lKMMMMMMMMMMM
#MMMMNx;cOWMMMMNk:,,''',;,',,;:cloooooddddxdlcdKWMMMMNo;;:oxc,,:oMMMMo,c0Mx;:xKXXXOl;cKMd;:kXOc,;:;lKMMMMMMMMMMM
#MMMWx,oXMMWX0kdl:::,,;cl:,;cooddddddddolcclxKWMMMMMMXo,:lMMXx:,;lMMMl,:0MO:,;::::;,,dNMd,;kWMXx:,'cKMMMMMMMMMMM
#MMMNo,oxxolccldkKNNXOdlc:,,:ccccccc:::clx0NWMMMMMMMMNkldkKMMWXxlldKMkldXMM0dllccclokNMMOloKMMMWKxldXMMMMMMMMMMM
#MMMWKxdddxOKXWMMMMMMMMWX0kxdddoodddxOKNWMMMMMMMMMMMMMWWWWMMMMMWWWWWMWWWMMMMMWWWWWWWMMMMWWWWMMMMMWWWMMMMMMMMMMMM
#MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMWWMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
#MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
#MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
ifeq (`$(OS),Windows_NT)
`tSHELL := cmd.exe
`texport SHELL
`tDateTime := `$(shell powershell [int](Get-Date -UFormat +%s)[0])
else
`tSHELL := bash
`texport SHELL
`tDateTime := `$(shell date +%s)
endif
TARGET_NAME := $ProjectName
BOARD_ID := $BoardID
MCU := $BoardProcessor
LIBS_DIR := $LibraryDir
LIBS_NAMES := $Libraries
CORE_BASE := $CoreLibraryDir
#-------------------------------------------------------------------------------------------------------------------------------------------------
# Flags
#-------------------------------------------------------------------------------------------------------------------------------------------------
FLAGS_CPU := -mthumb -mcpu=$CPUType -mfloat-abi=hard -mfpu=$FPU -fsingle-precision-constant
FLAGS_OPT := $Optimization
FLAGS_COM := -g -Wall -ffunction-sections -fdata-sections -nostdlib -MMD
FLAGS_LSP :=
FLAGS_CPP := -fno-exceptions -fpermissive -felide-constructors -std=gnu++14 -Wno-error=narrowing -fno-rtti
FLAGS_C :=
FLAGS_S := -x assembler-with-cpp
FLAGS_LD := -Wl,--print-memory-usage,--gc-sections,--relax,--defsym=__rtc_localtime=`$(DateTime) -T`$(CORE_BASE)/$BoardProcessor.ld
LIBS := -larm_cortexM4lf_math -lm -lstdc++
DEFINES := $Defines
CPP_FLAGS := `$(FLAGS_CPU) `$(FLAGS_OPT) `$(FLAGS_COM) `$(DEFINES) `$(FLAGS_CPP)
C_FLAGS := `$(FLAGS_CPU) `$(FLAGS_OPT) `$(FLAGS_COM) `$(DEFINES) `$(FLAGS_C)
S_FLAGS := `$(FLAGS_CPU) `$(FLAGS_OPT) `$(FLAGS_COM) `$(DEFINES) `$(FLAGS_S)
LD_FLAGS := `$(FLAGS_CPU) `$(FLAGS_OPT) `$(FLAGS_LSP) `$(FLAGS_LD)
AR_FLAGS := rcs
#-------------------------------------------------------------------------------------------------------------------------------------------------
# Files & Folders
#-------------------------------------------------------------------------------------------------------------------------------------------------
SRC_SRC := src
LIB_SRC := `$(LIBS_DIR)
CORE_SRC := `$(CORE_BASE)
BIN := bin
SRC_BIN := `$(BIN)/src
CORE_BIN := `$(BIN)/core
LIB_BIN := `$(BIN)/lib
CORE_LIB := `$(BIN)/core.a
TARGET_HEX := `$(BIN)/`$(TARGET_NAME).hex
TARGET_ELF := `$(BIN)/`$(TARGET_NAME).elf
TARGET_LST := `$(BIN)/`$(TARGET_NAME).lst
#-------------------------------------------------------------------------------------------------------------------------------------------------
# Toolchains
#-------------------------------------------------------------------------------------------------------------------------------------------------
CC := arm-none-eabi-gcc
CXX := arm-none-eabi-g++
AR := arm-none-eabi-gcc-ar
OBJCOPY := arm-none-eabi-objcopy
SIZE := arm-none-eabi-size
OBJDUMP := arm-none-eabi-objdump
#-------------------------------------------------------------------------------------------------------------------------------------------------
# Source Files & Library Files
#-------------------------------------------------------------------------------------------------------------------------------------------------
rwildcard =`$(wildcard `$1`$2) `$(foreach d,`$(wildcard `$1*),`$(call rwildcard,`$d/,`$2))
SRC_C_FILES := `$(call rwildcard,`$(SRC_SRC)/,*.c)
SRC_CPP_FILES := `$(call rwildcard,`$(SRC_SRC)/,*.cpp)
SRC_S_FILES := `$(call rwildcard,`$(SRC_SRC)/,*.S)
SRC_OBJ := `$(SRC_S_FILES:`$(SRC_SRC)/%.S=`$(SRC_BIN)/%.o) `$(SRC_C_FILES:`$(SRC_SRC)/%.c=`$(SRC_BIN)/%.o) `$(SRC_CPP_FILES:`$(SRC_SRC)/%.cpp=`$(SRC_BIN)/%.o)
CORE_CPP_FILES := `$(call rwildcard,`$(CORE_SRC)/,*.cpp)
CORE_C_FILES := `$(call rwildcard,`$(CORE_SRC)/,*.c)
CORE_S_FILES := `$(call rwildcard,`$(CORE_SRC)/,*.S)
CORE_OBJ := `$(CORE_S_FILES:`$(CORE_SRC)/%.S=`$(CORE_BIN)/%.o) `$(CORE_C_FILES:`$(CORE_SRC)/%.c=`$(CORE_BIN)/%.o) `$(CORE_CPP_FILES:`$(CORE_SRC)/%.cpp=`$(CORE_BIN)/%.o)
LIB_DIRS := `$(foreach d, `$(LIBS_NAMES), `$(LIBS_DIR)/`$d/ `$(LIBS_DIR)/`$d/utility/ ) # base and /utility
LIB_DIRS += `$(foreach d, `$(LIBS_NAMES), `$(LIBS_DIR)/`$d/src/ `$(dir `$(call rwildcard,`$(LIBS_DIR)/`$d/src/,*/.)))
LIB_CPP_LOCAL := `$(foreach d, `$(LIB_DIRS),`$(call wildcard,`$d/*.cpp))
LIB_C_LOCAL := `$(foreach d, `$(LIB_DIRS_),`$(call wildcard,`$d/*.c))
LIB_S_LOCAL := `$(foreach d, `$(LIB_DIRS),`$(call wildcard,`$d/*.S))
LIB_OBJ := `$(LIB_CPP_LOCAL:`$(LIBS_DIR)/%.cpp=`$(LIB_BIN)/%.o)
LIB_OBJ += `$(LIB_C_LOCAL:`$(LIBS_DIR)/%.c=`$(LIB_BIN)/%.o)
LIB_OBJ += `$(LIB_S_LOCAL:`$(LIBS_DIR)/%.S=`$(LIB_BIN)/%.o)
#-------------------------------------------------------------------------------------------------------------------------------------------------
# Includes
#-------------------------------------------------------------------------------------------------------------------------------------------------
INCLUDE := -I./`$(SRC_SRC) -I`$(CORE_SRC) -Iinclude
INCLUDE += `$(foreach d, `$(LIB_DIRS), -I`$d)
#-------------------------------------------------------------------------------------------------------------------------------------------------
# Creation of Directories
#-------------------------------------------------------------------------------------------------------------------------------------------------
DIRECTORIES := `$(sort `$(dir `$(CORE_OBJ) `$(SRC_OBJ) `$(LIB_OBJ)))
generateDirs := `$(foreach d, `$(DIRECTORIES), `$(shell if not exist `"`$d`" mkdir `"`$d`"))
#-------------------------------------------------------------------------------------------------------------------------------------------------
# Targets
#-------------------------------------------------------------------------------------------------------------------------------------------------
.PHONY: directories all rebuild clean cleanUser cleanCore
all: `$(TARGET_LST) `$(TARGET_HEX)
rebuild: cleanUser all
clean: cleanUser cleanCore cleanLib
`t@echo Cleaning done &&echo.
`$(CORE_BIN)/%.o: `$(CORE_SRC)/%.S
`t@echo CORE [ASM] `$(notdir `$<)
`t@`"`$(CC)`" `$(S_FLAGS) `$(INCLUDE) -o `$@ -c `$<
`$(CORE_BIN)/%.o: `$(CORE_SRC)/%.c
`t@echo CORE [CC] `$(notdir `$<)
`t@`"`$(CC)`" `$(C_FLAGS) `$(INCLUDE) -o `$@ -c `$<
`$(CORE_BIN)/%.o: `$(CORE_SRC)/%.cpp
`t@echo CORE [CPP] `$(notdir `$<)
`t@`"`$(CXX)`" `$(CPP_FLAGS) `$(INCLUDE) -o `$@ -c `$<
`$(CORE_LIB) : `$(CORE_OBJ)
`t@echo CORE [AR] `$@
`t@`$(AR) `$(AR_FLAGS) `$@ `$^
`t@echo Teensy core built successfully &&echo.
`$(LIB_BIN)/%.o: `$(LIBS_DIR)/%.S
`t@echo LIB [ASM] `$(notdir `$<)
`t@`"`$(CC)`" `$(S_FLAGS) `$(INCLUDE) -o `$@ -c `$<
`$(LIB_BIN)/%.o: `$(LIBS_DIR)/%.cpp
`t@echo LIB [CPP] `$(notdir `$<)
`t@`"`$(CXX)`" `$(CPP_FLAGS) `$(INCLUDE) -o `$@ -c `$<
`$(LIB_BIN)/%.o: `$(LIBS_DIR)/%.c
`t@echo LIB [CC] `$(notdir `$<)
`t@`"`$(CC)`" `$(C_FLAGS) `$(INCLUDE) -o `$@ -c `$<
`$(SRC_BIN)/%.o: `$(SRC_SRC)/%.S
`t@echo SRC [ASM] `$<
`t@`"`$(CC)`" `$(S_FLAGS) `$(INCLUDE) -o `$@ -c `$<
`$(SRC_BIN)/%.o: `$(SRC_SRC)/%.c
`t@echo SRC [CC] `$(notdir `$<)
`t@`"`$(CC)`" `$(C_FLAGS) `$(INCLUDE) -o `"`$@`" -c `$<
`$(SRC_BIN)/%.o: `$(SRC_SRC)/%.cpp
`t@echo SRC [CPP] `$(notdir `$<)
`t@`"`$(CXX)`" `$(CPP_FLAGS) `$(INCLUDE) -o `"`$@`" -c `$<
`$(TARGET_ELF): `$(CORE_LIB) `$(LIB_OBJ) `$(SRC_OBJ)
`t@echo [LD] `$@
`t@`$(CC) `$(LD_FLAGS) -o `"`$@`" `$(SRC_OBJ) `$(LIB_OBJ) `$(CORE_LIB)
`t@echo Src code built and linked to libraries &&echo.
%.lst: %.elf
`t@echo [LST] `$@
`t@`$(OBJDUMP) -d -S --demangle --no-show-raw-insn --syms `"`$<`" > `"`$@`"
`t@echo Sucessfully built project &&echo.
%.hex: %.elf
`t@echo [HEX] `$@
`t@`$(OBJCOPY) -O ihex -R.eeprom `"`$<`" `"`$@`"
`t@echo Sucessfully build project HEX file&&echo.
#-------------------------------------------------------------------------------------------------------------------------------------------------
# Cleaning
#-------------------------------------------------------------------------------------------------------------------------------------------------
cleanUser:
`t@echo Cleaning user binaries...
`t@if exist `$(SRC_BIN) rd /s/q `"`$(SRC_BIN)`"
`t@if exist `"`$(TARGET_LST)`" del `$(subst /,\,`$(TARGET_LST))
cleanCore:
`t@echo Cleaning core binaries...
`t@if exist `$(CORE_BIN) rd /s/q `"`$(CORE_BIN)`"
`t@if exist `$(CORE_LIB) del `$(subst /,\,`$(CORE_LIB))
cleanLib:
`t@echo Cleaning user library binaries...
`t@if exist `$(LIB_BIN) rd /s/q `"`$(LIB_BIN)`"
-include `$(CORE_OBJ:.o=.d)
-include `$(SRC_OBJ:.o=.d)
-include `$(LIB_OBJ:.o=.d)
"
Write-Progress -Id 1 -Activity Updating -Status 'Creating Makefile' -PercentComplete 75 -CurrentOperation OuterLoop
try
{
Set-Content -Path "Makefile" -Value $OutputString
New-Item -ItemType Directory -Force -Path "include"
New-Item -ItemType Directory -Force -Path "src"
Set-Content -Path "include/main.hpp" -Value "//-------------------------------------------------------------------------------------------------------------------------------------------------
// Generated by Make me a Makefile (https://github.com/Orion-CanSat/Make-me-a-Makefile)
//
// Board: $BoardName
// CPU Speed: $CPUSpeed
// Optimization: $Optimization
//
// Time of creation: $Date
//-------------------------------------------------------------------------------------------------------------------------------------------------
extern `"C`" int main(void);
"
Set-Content -Path "src/main.cpp" -Value "//-------------------------------------------------------------------------------------------------------------------------------------------------
// Generated by Make me a Makefile (https://github.com/Orion-CanSat/Make-me-a-Makefile)
//
// Board: $BoardName
// CPU Speed: $CPUSpeed
// Optimization: $Optimization
//
// Time of creation: $Date
//-------------------------------------------------------------------------------------------------------------------------------------------------
#include `"main.hpp`"
int main(void)
{
}
"
}
catch
{
Write-Error "Could not write succesfully to path"
}
Write-Progress -Id 1 -Activity Updating -Status 'Creating Makefile' -PercentComplete 100 -CurrentOperation OuterLoop