-
Notifications
You must be signed in to change notification settings - Fork 13
/
bmk_make.bmx
1928 lines (1534 loc) · 52.4 KB
/
bmk_make.bmx
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
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
SuperStrict
Import "bmk_modutil.bmx"
Global cc_opts$
Global bcc_opts$
Global cpp_opts$
Global c_opts$
Global asm_opts:String
Function BeginMake()
cc_opts=Null
cpp_opts=Null
c_opts=Null
bcc_opts=Null
asm_opts=Null
app_main=Null
opt_framework=""
End Function
Function ConfigureAndroidPaths()
CheckAndroidPaths()
Local toolchain:String
Local toolchainBin:String
Local arch:String
Local abi:String
Select processor.CPU()
Case "x86"
toolchain = "x86-"
toolchainBin = "i686-linux-android-"
arch = "arch-x86"
abi = "x86"
Case "x64"
toolchain = "x86_64-"
toolchainBin = "x86_64-linux-android-"
arch = "arch-x86_64"
abi = "x86_64"
Case "arm", "armeabi", "armeabiv7a"
toolchain = "arm-linux-androideabi-"
toolchainBin = "arm-linux-androideabi-"
arch = "arch-arm"
If processor.CPU() = "armeabi" Then
abi = "armeabi"
Else
abi = "armeabi-v7a"
End If
Case "arm64v8a"
toolchain = "aarch64-linux-android-"
toolchainBin = "aarch64-linux-android-"
arch = "arch-arm64"
abi = "arm64-v8a"
End Select
Local native:String
?macos
native = "darwin"
?linux
native = "linux"
?win32
native = "windows"
?
Local toolchainDir:String = processor.Option("android.ndk", "") + "/toolchains/" + ..
toolchain + processor.Option("android.toolchain.version", "") + "/prebuilt/" + native
' look for 64 bit build first, then x86, then fallback to no architecture (generally on 32-bit dists)
If FileType(toolchainDir + "-x86_64") = FILETYPE_DIR Then
toolchainDir :+ "-x86_64"
Else If FileType(toolchainDir + "-x86") = FILETYPE_DIR Then
toolchainDir :+ "-x86"
Else If FileType(toolchainDir) <> FILETYPE_DIR Then
Throw "Cannot determine toolchain dir for '" + native + "', at '" + toolchainDir + "'"
End If
Local exe:String
?win32
exe = ".exe"
?
Local gccPath:String = toolchainDir + "/bin/" + toolchainBin + "gcc" + exe
Local gppPath:String = toolchainDir + "/bin/" + toolchainBin + "g++" + exe
Local arPath:String = toolchainDir + "/bin/" + toolchainBin + "ar" + exe
Local libPath:String = toolchainDir + "/lib"
' check paths
If Not FileType(RealPath(gccPath)) Then
Throw "gcc not found at '" + gccPath + "'"
End If
If Not FileType(RealPath(gppPath)) Then
Throw "g++ not found at '" + gppPath + "'"
End If
If Not FileType(RealPath(gccPath)) Then
Throw "ar not found at '" + arPath + "'"
End If
globals.SetVar("android." + processor.CPU() + ".gcc", gccPath)
globals.SetVar("android." + processor.CPU() + ".gpp", gppPath)
globals.SetVar("android." + processor.CPU() + ".ar", arPath)
globals.SetVar("android." + processor.CPU() + ".lib", "-L" + libPath)
' platform
Local platformDir:String = processor.Option("android.ndk", "") + "/platforms/android-" + ..
processor.Option("android.platform", "") + "/" + arch
If Not FileType(platformDir) Then
Throw "Cannot determine platform dir for '" + arch + "' at '" + platformDir + "'"
End If
' platform sysroot
globals.SetVar("android.platform.sysroot", "--sysroot " + platformDir)
globals.AddOption("cc_opts", "android.platform.sysroot", "--sysroot " + platformDir)
' abi
globals.SetVar("android.abi", abi)
' sdk target
Local target:String = GetAndroidSDKTarget()
If Not target Or Not FileType(processor.Option("android.sdk", "") + "/platforms/android-" + target) Then
Local sdkPath:String = processor.Option("android.sdk.target", "")
If sdkPath Then
Throw "Cannot determine SDK target for '" + sdkPath + "'"
Else
Throw "Cannot determine SDK target dir. ANDROID_SDK_TARGET or android.sdk.target option is not set, and auto-lookup failed."
End If
End If
globals.SetVar("android.sdk.target", target)
End Function
Function CheckAndroidPaths()
' check envs and paths
Local androidHome:String = processor.Option("android.home", getenv_("ANDROID_HOME")).Trim()
If Not androidHome Then
Throw "ANDROID_HOME or 'android.home' config option not set"
End If
putenv_("ANDROID_HOME=" + androidHome)
globals.SetVar("android.home", androidHome)
Local androidSDK:String = processor.Option("android.sdk", getenv_("ANDROID_SDK")).Trim()
If Not androidSDK Then
Throw "ANDROID_SDK or 'android.sdk' config option not set"
End If
putenv_("ANDROID_SDK=" + androidSDK)
globals.SetVar("android.sdk", androidSDK)
Local androidNDK:String = processor.Option("android.ndk", getenv_("ANDROID_NDK")).Trim()
If Not androidNDK Then
Throw "ANDROID_NDK or 'android.ndk' config option not set"
End If
putenv_("ANDROID_NDK=" + androidNDK)
globals.SetVar("android.ndk", androidNDK)
Local androidToolchainVersion:String = processor.Option("android.toolchain.version", getenv_("ANDROID_TOOLCHAIN_VERSION")).Trim()
If Not androidToolchainVersion Then
Throw "ANDROID_TOOLCHAIN_VERSION or 'android.toolchain.version' config option not set"
End If
putenv_("ANDROID_TOOLCHAIN_VERSION=" + androidToolchainVersion)
globals.SetVar("android.toolchain.version", androidToolchainVersion)
Local androidPlatform:String = processor.Option("android.platform", getenv_("ANDROID_PLATFORM")).Trim()
If Not androidPlatform Then
Throw "ANDROID_PLATFORM or 'android.platform' config option not set"
End If
putenv_("ANDROID_PLATFORM=" + androidPlatform.Trim())
globals.SetVar("android.platform", androidPlatform)
Local androidSDKTarget:String = processor.Option("android.sdk.target", getenv_("ANDROID_SDK_TARGET")).Trim()
' NOTE : if not set, we'll try to determine the actual target later, and fail if required then.
If androidSDKTarget Then
putenv_("ANDROID_SDK_TARGET=" + androidSDKTarget)
globals.SetVar("android.sdk.target", androidSDKTarget)
End If
Local antHome:String = processor.Option("ant.home", getenv_("ANT_HOME")).Trim()
If Not antHome Then
' as a further fallback, we can use the one from resources folder if it exists.
Local antDir:String = RealPath(BlitzMaxPath() + "/resources/android/apache-ant")
If FileType(antDir) <> FILETYPE_DIR Then
Throw "ANT_HOME or 'ant.home' config option not set, and resources missing apache-ant."
Else
antHome = antDir
globals.SetVar("ant.home", antHome)
End If
End If
putenv_("ANT_HOME=" + antHome)
globals.SetVar("ant.home", antHome)
?Not win32
Local pathSeparator:String = ":"
Local dirSeparator:String = "/"
?win32
Local pathSeparator:String = ";"
Local dirSeparator:String = "\"
?
Local path:String = getenv_("PATH")
path = androidSDK + dirSeparator + "platform-tools" + pathSeparator + path
path = androidSDK + dirSeparator + "tools" + pathSeparator + path
path = androidNDK + pathSeparator + path
path = antHome + dirSeparator + "bin" + pathSeparator + path
putenv_("PATH=" + path)
End Function
Function ConfigureIOSPaths()
Select processor.CPU()
Case "x86", "x64"
Local path:String = "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk"
globals.SetVar("ios." + processor.CPU() + ".sysroot", path)
globals.SetVar("ios." + processor.CPU() + ".syslibroot", path)
Case "armv7", "arm64"
Local path:String = "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk"
globals.SetVar("ios." + processor.CPU() + ".sysroot", path)
globals.SetVar("ios." + processor.CPU() + ".syslibroot", path)
End Select
End Function
Function ConfigureNXPaths()
CheckNXPaths()
Local toolchainBin:String
Select processor.CPU()
Case "arm64"
toolchainBin = "aarch64-none-elf-"
End Select
Local toolchainDir:String = processor.Option("nx.devkitpro", "") + "/devkitA64/"
If FileType(RealPath(toolchainDir)) <> FILETYPE_DIR Then
Throw "Cannot determine toolchain dir for NX, at '" + toolchainDir + "'"
End If
Local exe:String
?win32
exe = ".exe"
?
Local gccPath:String = toolchainDir + "/bin/" + toolchainBin + "gcc" + exe
Local gppPath:String = toolchainDir + "/bin/" + toolchainBin + "g++" + exe
Local arPath:String = toolchainDir + "/bin/" + toolchainBin + "ar" + exe
Local libPath:String = toolchainDir + "/lib"
' check paths
If Not FileType(RealPath(gccPath)) Then
Throw "gcc not found at '" + gccPath + "'"
End If
If Not FileType(RealPath(gppPath)) Then
Throw "g++ not found at '" + gppPath + "'"
End If
If Not FileType(RealPath(gccPath)) Then
Throw "ar not found at '" + arPath + "'"
End If
globals.SetVar("nx." + processor.CPU() + ".gcc", gccPath)
globals.SetVar("nx." + processor.CPU() + ".gpp", gppPath)
globals.SetVar("nx." + processor.CPU() + ".ar", arPath)
globals.SetVar("nx." + processor.CPU() + ".lib", "-L" + libPath)
?Not win32
Local pathSeparator:String = ":"
Local dirSeparator:String = "/"
?win32
Local pathSeparator:String = ";"
Local dirSeparator:String = "\"
?
Local path:String = getenv_("PATH")
path = toolchainDir + dirSeparator + "bin" + pathSeparator + path
putenv_("PATH=" + path)
End Function
Function CheckNXPaths()
' check envs and paths
Local devkitpro:String = processor.Option("nx.devkitpro", getenv_("DEVKITPRO")).Trim()
If Not devkitpro Then
Throw "DEVKITPRO or 'nx.devkitpro' config option not set"
End If
putenv_("DEVKITPRO=" + devkitpro)
globals.SetVar("nx.devkitpro", devkitpro)
End Function
Type TBuildManager Extends TCallback
Field sources:TMap = New TMap
Field buildAll:Int
Field framework_mods:TList
Field app_iface:String
Method New()
' pre build checks
If processor.Platform() = "android" Then
ConfigureAndroidPaths()
Else If processor.Platform() = "ios" Then
ConfigureIOSPaths()
Else If processor.Platform() = "nx" Then
ConfigureNXPaths()
End If
If processor.Platform() = "linux" Or processor.Platform() = "raspberrypi" Then
If opt_nopie Then
globals.SetVar("nopie", "true")
End If
End If
processor.callback = Self
End Method
Method MakeMods(mods:TList, rebuild:Int = False)
For Local m:String = EachIn mods
If (opt_modfilter And ((m).Find(opt_modfilter) = 0)) Or (Not opt_modfilter) Then
GetMod(m, rebuild Or buildAll)
End If
Next
End Method
Method MakeApp(main_path:String, makelib:Int, compileOnly:Int = False)
app_main = main_path
Local source:TSourceFile = GetSourceFile(app_main, False, opt_all)
If Not source Then
Return
End If
Local build_path:String = ExtractDir(main_path) + "/.bmx"
Local appType:String
If Not compileOnly Or source.framewk Then
appType = "." + opt_apptype
End If
source.obj_path = build_path + "/" + StripDir( main_path ) + appType + opt_configmung + processor.CPU() + ".o"
source.obj_time = FileTime(source.obj_path)
source.iface_path = StripExt(source.obj_path) + ".i"
source.iface_time = FileTime(source.iface_path)
app_iface = source.iface_path
Local cc_opts:String
source.AddIncludePath(" -I" + CQuote(ModulePath("")))
If opt_release And Not opt_gdbdebug Then
cc_opts :+ " -DNDEBUG"
End If
If processor.BCCVersion() <> "BlitzMax" Then
If opt_gdbdebug Then
cc_opts :+ " -g"
End If
If opt_gprof Then
cc_opts :+ " -pg"
End If
If opt_coverage Then
cc_opts :+ " -DBMX_COVERAGE"
End If
End If
Local sb:TStringBuffer = New TStringBuffer
sb.Append(" -g ").Append(processor.CPU())
If opt_quiet sb.Append(" -q")
If opt_verbose sb.Append(" -v")
If opt_release sb.Append(" -r")
If opt_threaded sb.Append(" -h")
If opt_framework sb.Append(" -f ").Append(opt_framework)
If processor.BCCVersion() <> "BlitzMax" Then
If opt_gdbdebug Then
sb.Append(" -d")
End If
If Not opt_nostrictupgrade Then
sb.Append(" -s")
End If
If opt_warnover Then
sb.Append(" -w")
End If
If opt_musl Then
sb.Append(" -musl")
End If
If makelib Then
sb.Append(" -makelib")
If opt_nodef Then
sb.append(" -nodef")
End If
If opt_nohead Then
sb.append(" -nohead")
End If
End If
If opt_require_override Then
sb.Append(" -override")
If opt_override_error Then
sb.Append(" -overerr")
End If
End If
Local defs:String = opt_userdefs
If globals.Get("user_defs") Then
If defs Then
defs :+ ","
End If
defs :+ globals.Get("user_defs")
End If
If defs Then
sb.Append(" -ud ").Append(defs)
End If
If opt_standalone Then
sb.Append(" -ib")
End If
If opt_coverage Then
sb.Append(" -cov")
End If
If opt_no_auto_superstrict Then
sb.Append(" -nas")
End If
End If
source.cc_opts :+ cc_opts
source.cpp_opts :+ cpp_opts
source.c_opts :+ c_opts
source.modimports.AddLast("brl.blitz")
source.modimports.AddLast(opt_appstub)
If source.framewk
If opt_framework Then
Throw "Framework already specified on commandline"
End If
opt_framework = source.framewk
sb.Append(" -f ").Append(opt_framework)
source.modimports.AddLast(opt_framework)
Else
framework_mods = New TList
For Local t:String = EachIn EnumModules()
If t.Find("brl.") = 0 Or t.Find("pub.") = 0 Then
If t <> "brl.blitz" And t <> opt_appstub Then
source.modimports.AddLast(t)
framework_mods.AddLast(t)
End If
End If
Next
End If
source.bcc_opts = sb.ToString()
source.SetRequiresBuild(opt_all)
CalculateDependencies(source, False, opt_all)
source.bcc_opts :+ " -t " + opt_apptype
' create bmx stages :
Local gen:TSourceFile
' for osx x86 on legacy, we need to convert asm
If processor.BCCVersion() = "BlitzMax" And processor.CPU() = "x86" And processor.Platform() = "macos" Then
Local fasm2as:TSourceFile = CreateFasm2AsStage(source)
gen = CreateGenStage(fasm2as)
Else
gen = CreateGenStage(source)
End If
If Not compileOnly Then
Local link:TSourceFile = CreateLinkStage(gen, STAGE_APP_LINK)
End If
End Method
Method DoBuild(makelib:Int, app_build:Int = False)
Local arc_order:TList = New TList
Local files:TList = New TList
For Local file:TSourceFile = EachIn sources.Values()
files.AddLast(file)
Next
' get the list of parallelizable batches
' each list of batches has no outstanding dependencies, and therefore
' can be compiled in parallel.
' the last list of batches requires all previous lists to have
' been compiled.
Local batches:TList = CalculateBatches(files)
For Local batch:TList = EachIn batches
Local s:String
For Local m:TSourceFile = EachIn batch
' sort archives for app linkage
If m.modid Then
Local path:String = m.arc_path
If IOS_HAS_MERGE And processor.Platform() = "ios" Then
path = m.merge_path
End If
If Not arc_order.Contains(path) Then
arc_order.AddFirst(path)
End If
End If
Local build_path:String
If m.obj_path Then
build_path = ExtractDir(m.obj_path)
Else
build_path = ExtractDir(m.path) + "/.bmx"
End If
If Not FileType(build_path) Then
CreateDir build_path
End If
If FileType(build_path) <> FILETYPE_DIR Then
Throw "Unable to create temporary directory : " + build_path
End If
' change dir, so relative commands work as expected
' (eg. file processing in BMK-scripts called via pragma)
ChangeDir ExtractDir( m.path )
' bmx file
If Match(m.ext, "bmx") Then
Select m.stage
Case STAGE_GENERATE
If m.requiresBuild Or (m.time > m.gen_time Or m.iface_time < m.MaxIfaceTime() Or Not m.MaxIfaceTime()) Then
If Not opt_quiet Then
Print ShowPct(m.pct) + "Processing:" + StripDir(m.path)
End If
' process pragmas
Local pragma_inDefine:Int, pragma_text:String, pragma_name:String
For Local pragma:String = EachIn m.pragmas
processor.ProcessPragma(pragma, pragma_inDefine, pragma_text, pragma_name)
Next
CompileBMX m.path, m.obj_path, m.bcc_opts
End If
Case STAGE_FASM2AS
For Local s:TSourceFile = EachIn m.depsList
If s.requiresBuild Then
m.SetRequiresBuild(True)
Exit
End If
Next
If m.requiresBuild Or (m.time > m.obj_time Or m.iface_time < m.MaxIfaceTime()) Then
m.SetRequiresBuild(True)
If Not opt_quiet Then
Print ShowPct(m.pct) + "Converting:" + StripDir(StripExt(m.obj_path) + ".s")
End If
Fasm2As m.path, m.obj_path
m.asm_time = time_(Null)
End If
Case STAGE_OBJECT
If m.requiresBuild Or (m.time > m.obj_time Or m.iface_time < m.MaxIfaceTime()) Then
m.SetRequiresBuild(True)
If processor.BCCVersion() <> "BlitzMax" Then
Local csrc_path:String = StripExt(m.obj_path) + ".c"
Local cobj_path:String = StripExt(m.obj_path) + ".o"
If Not opt_quiet Then
Local s:String = ShowPct(m.pct) + "Compiling:" + StripDir(csrc_path)
If opt_standalone And Not opt_nolog processor.PushEcho(FixPct(s))
Print s
End If
If opt_standalone And opt_boot Then
processor.PushSource(csrc_path)
processor.PushSource(StripExt(m.obj_path) + ".h")
End If
CompileC csrc_path,cobj_path, m.GetIncludePaths() + " " + m.cc_opts + " " + m.c_opts
Else
' asm compilation
Local src_path:String = StripExt(m.obj_path) + ".s"
Local obj_path:String = StripExt(m.obj_path) + ".o"
If Not opt_quiet Then
Print ShowPct(m.pct) + "Compiling:" + StripDir(src_path)
End If
Assemble src_path, obj_path
End If
m.obj_time = time_(Null)
End If
Case STAGE_LINK
Local max_obj_time:Int = m.MaxObjTime()
If max_obj_time > m.arc_time And Not m.dontbuild Then
Local objs:TList = New TList
m.GetObjs(objs)
If Not opt_quiet Then
Local s:String = ShowPct(m.pct) + "Archiving:" + StripDir(m.arc_path)
If opt_standalone And Not opt_nolog processor.PushEcho(FixPct(s))
Print s
End If
Local at:TArcTask = New TArcTask.Create(m, m.arc_path, objs)
?threaded
If opt_single Then
at.CreateArc()
Else
processManager.AddTask(TArcTask._CreateArc, at)
End If
?Not threaded
at.CreateArc()
?
End If
Case STAGE_APP_LINK
' this probably should never happen.
' may be a bad module?
If Not opt_outfile Then
Throw "Build Error: Did not expect to link against " + m.path
End If
' an app!
Local max_lnk_time:Int = m.MaxLinkTime()
' include settings and icon times in calculation
If opt_manifest And processor.Platform() = "win32" And opt_apptype="gui" Then
Local settings:String = ExtractDir(opt_infile) + "/" + StripDir(StripExt(opt_outfile)) + ".settings"
If Not FileType(settings) Then
settings = ExtractDir(opt_infile) + "/" + StripDir(StripExt(opt_infile)) + ".settings"
End If
max_lnk_time = Max(FileTime(settings), max_lnk_time)
Local icon:String = ExtractDir(opt_infile) + "/" + StripDir(StripExt(opt_outfile)) + ".ico"
If Not FileType(icon) Then
icon = ExtractDir(opt_infile) + "/" + StripDir(StripExt(opt_infile)) + ".ico"
End If
max_lnk_time = Max(FileTime(icon), max_lnk_time)
End If
If max_lnk_time > FileTime(opt_outfile) Or opt_all Then
' generate manifest for app
If opt_manifest And processor.Platform() = "win32" And opt_apptype="gui" Then
processor.RunCommand("make_win32_resource", Null)
Local res:String = ExtractDir(opt_infile) + "/.bmx/" + StripDir(StripExt(opt_outfile)) + "." + processor.CPU() + ".res.o"
If Not FileType(res) Then
res = ExtractDir(opt_infile) + "/.bmx/" + StripDir(StripExt(opt_infile)) + "." + processor.CPU() + ".res.o"
End If
If FileType(res) = FILETYPE_FILE Then
Local s:TSourceFile = New TSourceFile
s.obj_path = res
s.stage = STAGE_LINK
s.exti = SOURCE_RES
m.depslist.AddLast(s)
End If
End If
If Not opt_quiet Then
Local s:String = ShowPct(m.pct) + "Linking:" + StripDir(opt_outfile)
If opt_standalone And Not opt_nolog processor.PushEcho(FixPct(s))
Print s
End If
Local links:TList = New TList
Local opts:TList = New TList
m.GetLinks(links, opts)
For Local arc:String = EachIn arc_order
links.AddLast(arc)
Next
For Local o:String = EachIn opts
links.AddLast(o)
Next
LinkApp opt_outfile, links, makelib, globals.Get("ld_opts")
m.obj_time = time_(Null)
End If
Case STAGE_MERGE
If IOS_HAS_MERGE Then
' a module?
If m.modid Then
Local max_obj_time:Int = m.MaxObjTime()
If max_obj_time > m.merge_time And Not m.dontbuild Then
If Not opt_quiet Then
Print ShowPct(m.pct) + "Merging:" + StripDir(m.merge_path)
End If
CreateMergeArc m.merge_path, m.arc_path
m.merge_time = time_(Null)
End If
End If
End If
End Select
Else If Match(m.ext, "s") Then
If m.time > m.obj_time Then ' object is older or doesn't exist
m.SetRequiresBuild(True)
End If
If m.requiresBuild Then
If Not opt_quiet Then
Local s:String = ShowPct(m.pct) + "Compiling:" + StripDir(m.path)
If opt_standalone And Not opt_nolog processor.PushEcho(FixPct(s))
Print s
End If
If processor.BCCVersion() = "BlitzMax" Then
Assemble m.path, m.obj_path
Else
CompileC m.path, m.obj_path, m.GetIncludePaths() + " " + m.cc_opts + " " + m.c_opts
End If
End If
Else
If Not m.dontbuild Then
' c/c++ source
If m.time > m.obj_time Then ' object is older or doesn't exist
m.SetRequiresBuild(True)
End If
If m.requiresBuild Then
If Not opt_quiet Then
Local s:String = ShowPct(m.pct) + "Compiling:" + StripDir(m.path)
If opt_standalone And Not opt_nolog processor.PushEcho(FixPct(s))
Print s
End If
If m.path.EndsWith(".cpp") Or m.path.EndsWith(".cc") Or m.path.EndsWith(".mm") Or m.path.EndsWith(".cxx") Then
CompileC m.path, m.obj_path, m.GetIncludePaths() + " " + m.cc_opts + " " + m.cpp_opts
ElseIf m.path.EndsWith(".S") Or m.path.EndsWith("asm") Then
AssembleNative m.path, m.obj_path, m.asm_opts
Else
CompileC m.path, m.obj_path, m.GetIncludePaths() + " " + m.cc_opts + " " + m.c_opts
End If
m.obj_time = time_(Null)
End If
End If
End If
Next
?threaded
If Not opt_single Then
processManager.WaitForTasks()
End If
?
Next
If app_build Then
' global post process
LoadBMK("post.bmk")
' generic post process
LoadBMK(ExtractDir(app_main) + "/post.bmk")
' project-specific post process
LoadBMK(ExtractDir(app_main) + "/" + StripDir( opt_outfile ) + ".post.bmk")
Select processor.Platform()
Case "android"
' create the apk
' copy shared object
Local androidABI:String = processor.Option("android.abi", "")
Local appId:String = StripDir(StripExt(opt_outfile))
If opt_debug And opt_outfile.EndsWith(".debug") Then
appId :+ ".debug"
End If
Local buildDir:String = ExtractDir(opt_outfile)
Local projectDir:String = buildDir + "/android-project-" + appId
Local abiPath:String = projectDir + "/libs/" + androidABI
Local sharedObject:String = "lib" + appId
sharedObject :+ ".so"
CopyFile(buildDir + "/" + sharedObject, abiPath + "/" + sharedObject)
' build the apk :
Local antHome:String = processor.Option("ant.home", "").Trim()
Local cmd:String = "~q" + antHome + "/bin/ant"
?win32
cmd :+ ".bat"
?
cmd :+ "~q debug"
Local dir:String = CurrentDir()
ChangeDir(projectDir)
If opt_dumpbuild Then
Print cmd
End If
If Sys( cmd ) Then
Throw "Error creating apk"
End If
ChangeDir(dir)
'End If
Case "ios"
Local iosSimulator:Int = (processor.CPU() = "x86")
' TODO - other stuff ?
Case "nx"
' TODO - build nro, nso, psf0 and nacp
End Select
End If
End Method
Method CalculateDependencies(source:TSourceFile, isMod:Int = False, rebuildImports:Int = False, isInclude:Int = False)
If source And Not source.processed Then
source.processed = True
For Local m:String = EachIn source.modimports
Local s:TSourceFile = GetMod(m)
If s Then
If Not source.moddeps Then
source.moddeps = New TMap
End If
If Not source.moddeps.ValueForKey(m) Then
source.moddeps.Insert(m, s)
source.deps.Insert(s.GetSourcePath(), s)
source.AddIncludePath(" -I" + CQuote(ExtractDir(s.path)))
End If
End If
Next
Local ib:TSourceFile
If processor.BCCVersion() <> "BlitzMax" And Not source.incbins.IsEmpty() Then
If source.owner_path Then
ib = CreateIncBin(source, source.owner_path)
Else
ib = CreateIncBin(source, source.path)
End If
End If
For Local f:String = EachIn source.imports
If f[0] <> Asc("-") Then
Local path:String = CheckPath(ExtractDir(source.path), f)
Local s:TSourceFile = GetSourceFile(path, isMod)
' imported sourcefile not there? Maybe it's relative to the owner path instead?
' For example, an incbin as part of an included source file.
If Not s Then
Local p:String = CheckPath(ExtractDir(source.owner_path), f)
s = GetSourceFile(p, isMod)
If s Then
path = p
End If
End If
If s Then
If rebuildImports Then
s.SetRequiresBuild(rebuildImports)
End If
If Match(s.ext, "bmx") Then
s.modimports.AddLast("brl.blitz")
' app source files need framework/mod dependencies applied
If Not isMod Then
If opt_framework Then
' add framework as dependency
s.modimports.AddLast(opt_framework)
Else
' add all pub/brl mods as dependency
If framework_mods Then
For Local m:String = EachIn framework_mods
s.modimports.AddLast(m)
Next
End If
End If
End If
s.bcc_opts = source.bcc_opts
s.cc_opts :+ source.cc_opts
s.cpp_opts :+ source.cpp_opts
s.c_opts :+ source.c_opts
s.asm_opts :+ source.asm_opts
s.CopyIncludePaths(source.includePaths)
CalculateDependencies(s, isMod, rebuildImports)
' if file that we generate is missing, we need to rebuild
If processor.BCCVersion() = "BlitzMax" Then
If Not FileType(StripExt(s.obj_path) + ".s") Then
s.SetRequiresBuild(True)
End If
Else
If Not FileType(StripExt(s.obj_path) + ".c") Then
s.SetRequiresBuild(True)
End If
End If
Local gen:TSourceFile
' for osx x86 on legacy, we need to convert asm
If processor.BCCVersion() = "BlitzMax" And processor.CPU() = "x86" And processor.Platform() = "macos" Then
Local fasm2as:TSourceFile = CreateFasm2AsStage(s)
gen = CreateGenStage(fasm2as)
Else
gen = CreateGenStage(s)
End If
source.deps.Insert(gen.GetSourcePath(), gen)
If Not source.depsList Then
source.depsList = New TList
End If
source.depsList.AddLast(gen)
Else
s.cc_opts = source.cc_opts
s.cpp_opts = source.cpp_opts
s.c_opts = source.c_opts
s.asm_opts = source.asm_opts
s.CopyIncludePaths(source.includePaths)
source.deps.Insert(s.GetSourcePath(), s)
If Not source.depsList Then
source.depsList = New TList
End If
source.depsList.AddLast(s)
End If
Else
Local ext:String = ExtractExt(path)
If Match(ext, "h;hpp;hxx") Then ' header?
source.AddIncludePath(" -I" + CQuote(ExtractDir(path)))
Else If Match(ext, "o;a;lib") Then ' object or archive?
Local s:TSourceFile = New TSourceFile
s.time = FileTime(path)
s.obj_time = s.time
s.path = path
s.obj_path = path
s.modid = source.modid