-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathbmk_util.bmx
2089 lines (1618 loc) · 53.2 KB
/
bmk_util.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_config.bmx"
Import "bmk_ng.bmx"
Import "file_util.c"
Import "hash.c"
'OS X Nasm doesn't work? Used to produce incorrect reloc offsets - haven't checked for a while
Const USE_NASM:Int=False
Const CC_WARNINGS:Int=False'True
Const IOS_HAS_MERGE:Int = False
Type TModOpt ' BaH
Field cc_opts:String = ""
Field ld_opts:TList = New TList
Field cpp_opts:String = ""
Field c_opts:String = ""
Field asm_opts:String = ""
Method addOption(qval:String, path:String)
If qval.startswith("CC_OPTS") Then
cc_opts:+ " " + setPath(ReQuote(qval[qval.find(":") + 1..].Trim()), path)
ElseIf qval.startswith("CPP_OPTS") Then
cpp_opts:+ " " + setPath(ReQuote(qval[qval.find(":") + 1..].Trim()), path)
ElseIf qval.startswith("C_OPTS") Then
c_opts:+ " " + setPath(ReQuote(qval[qval.find(":") + 1..].Trim()), path)
ElseIf qval.startswith("ASM_OPTS") Then
asm_opts:+ " " + setPath(ReQuote(qval[qval.find(":") + 1..].Trim()), path)
ElseIf qval.startswith("LD_OPTS") Then
Local opt:String = ReQuote(qval[qval.find(":") + 1..].Trim())
If opt.startsWith("-L") Then
opt = "-L" + CQuote(opt[2..])
End If
ld_opts.addLast opt
ElseIf qval.startswith("CC_VOPT") Then
setOption("cc_opts", qval)
ElseIf qval.startswith("CPP_VOPT") Then
setOption("cpp_opts", qval)
ElseIf qval.startswith("C_VOPT") Then
setOption("c_opts", qval)
ElseIf qval.startswith("ASM_VOPT") Then
setOption("asm_opts", qval)
ElseIf qval.startswith("LD_VOPT") Then
setOption("ld_opts", qval)
End If
End Method
Function setOption(option:String, qval:String)
Local opt:String = qval[qval.find(":") + 1..].Trim()
Local parts:String[] = opt.Split("|")
If parts.length = 2 Then
globals.SetOption(option, parts[0].trim(), parts[1].Trim())
End If
End Function
Method hasCCopt:Int(value:String)
Return cc_opts.find(value) >= 0
End Method
Method hasCPPopt:Int(value:String)
Return cpp_opts.find(value) >= 0
End Method
Method hasCopt:Int(value:String)
Return c_opts.find(value) >= 0
End Method
Method hasASMopt:Int(value:String)
Return asm_opts.find(value) >= 0
End Method
Method hasLDopt:Int(value:String)
For Local opt:String = EachIn ld_opts
If opt.find(value) >= 0 Then
Return True
End If
Next
Return False
End Method
Function setPath:String(value:String, path:String)
If value.Contains("%PWD%") Then
If FileType(path) = FILETYPE_FILE Then
path = ExtractDir(path)
End If
Return value.Replace("%PWD%", path)
End If
' var replace
Local s:Int = value.Find("%")
If s >= 0 Then
Local e:Int = value.Find("%", s + 1)
If e >= 0 Then
Local v:String = value[s+1..e]
value = value[..s] + processor.option(v, "NA") + value[e+1..]
End If
End If
Return value
End Function
End Type
Global mod_opts:TModOpt ' BaH
Function Match:Int( ext$,pat$ )
Return (";"+pat+";").Find( ";"+ext+";" )<>-1
End Function
Function HTTPEsc$( t$ )
t=t.Replace( " ","%20" )
Return t
End Function
Function Sys:Int( cmd$ )
If opt_verbose
Print cmd
Else If opt_dumpbuild
Local p$=cmd
p=p.Replace( BlitzMaxPath()+"/","./" )
WriteStdout p+"~n"
Local t$="mkdir "
If cmd.StartsWith( t ) And FileType( cmd[t.length..] ) Return 0
EndIf
Return system_( cmd )
End Function
Function Ranlib( dir$ )
'
?MacOS
If macos_version>=$1040 Return
?
'
For Local f$=EachIn LoadDir( dir )
Local p$=dir+"/"+f
Select FileType( p )
Case FILETYPE_DIR
Ranlib p
Case FILETYPE_FILE
If ExtractExt(f).ToLower()="a" Sys "ranlib "+p
End Select
Next
End Function
Function Assemble( src$,obj$ )
processor.RunCommand("assemble", [src, obj])
End Function
Function AssembleNative( src$, obj$, opts:String )
processor.RunCommand("assembleNative", [src, obj, opts])
End Function
Function Fasm2As( src$,obj$ )
processor.RunCommand("fasm2as", [src, obj])
End Function
Function CompileC( src$,obj$,opts$ )
processor.RunCommand("CompileC", [src, obj, opts])
End Function
Function CompileBMX( src$,obj$,opts$ )
If processor.BCCVersion() <> "BlitzMax" Then
opts :+ " -p " + processor.Platform()
End If
If opt_standalone opt_nolog = True
processor.RunCommand("CompileBMX", [src, obj, opts])
If opt_standalone opt_nolog = False
End Function
Function CreateMergeArc( path$ , arc_path:String )
Local cmd$
If processor.Platform() = "ios" Then
Local proc:String = processor.CPU()
Local opp:String
Select proc
Case "x86"
proc = "i386"
opp = "x86_64"
Case "x64"
proc = "x86_64"
opp = "i386"
Case "armv7"
opp = "arm64"
Case "arm64"
opp = "armv7"
End Select
cmd = "lipo "
If Not FileType(path) Then
cmd :+ "-create -arch_blank " + opp + " -arch "
Else
cmd :+ CQuote(path)
cmd :+ " -replace "
End If
cmd :+ proc + " " + CQuote(arc_path)
cmd :+ " -output " + CQuote(path)
End If
If cmd And processor.MultiSys( cmd, path, Null, Null )
DeleteFile path
Throw "Build Error: Failed to merge archive " + path
EndIf
End Function
Function LinkApp( path$,lnk_files:TList,makelib:Int,opts$ )
If processor.Platform() = "ios" Then
PackageIOSApp(path, lnk_files, opts)
Return
End If
DeleteFile path
Local cmd$
Local files$
Local tmpfile$=BlitzMaxPath()+"/tmp/ld.tmp"
Local sb:TStringBuffer = New TStringBuffer
Local fb:TStringBuffer = New TStringBuffer
If opt_standalone tmpfile = String(globals.GetRawVar("EXEPATH")) + "/ld." + processor.AppDet() + ".txt.tmp"
If processor.Platform() = "macos" Or processor.Platform() = "osx" Then
sb.Append(processor.Option(processor.BuildName("gpp"), "g++"))
Select processor.CPU()
Case "ppc"
sb.Append(" -arch ppc" )
Case "x86"
sb.Append(" -arch i386 -read_only_relocs suppress")
Case "x64"
sb.Append(" -arch x86_64")
Case "arm64"
sb.Append(" -arch arm64")
End Select
If processor.Option(processor.BuildName("sysroot"), "") Then
sb.Append(" -isysroot ").Append(processor.Option(processor.BuildName("sysroot"), ""))
End If
sb.Append(" -o ").Append(CQuote( path ))
If opt_debug Or opt_gdbdebug Then
sb.Append(" -g")
End If
If processor.BCCVersion() = "BlitzMax" Then
sb.Append(" ").Append(CQuote("-L" +CQuote( BlitzMaxPath()+"/lib" ) ))
End If
If Not opt_dumpbuild Then
sb.Append(" -filelist ").Append(CQuote( tmpfile ))
End If
For Local t$=EachIn lnk_files
If opt_dumpbuild Or (t[..1]="-") Or (t[..1]="`")
sb.Append(" ").Append(t)
Else
fb.Append(t).Append(Chr(10))
EndIf
Next
sb.Append(" -lSystem -framework CoreServices -framework CoreFoundation")
If opts Then
sb.Append(" ").Append(opts)
End If
If processor.CPU() = "ppc"
sb.Append(" -lc -lgcc_eh")
End If
End If
If processor.Platform() = "win32"
Local ext:String = ""
?win32
ext = ".exe"
?
Local version:Int = Int(processor.GCCVersion(True))
Local usingLD:Int = False
Local options:TStringBuffer = fb
If processor.HasClang() Then
options = sb
End If
' always use g++ instead of LD...
' uncomment if we want to change to only use LD for GCC's < 4.x
'If version < 40000 Then
' usingLD = True
'End If
' or we can override in the config...
If globals.Get("link_with_ld") Or (version >= 40600 And version < 60000) Then
usingLD = True
End If
Local blitzMaxLibDir:String = "/lib"
If processor.CPU()="x64" Then
blitzMaxLibDir = "/lib64"
End If
If usingLD Then
sb.Append(CQuote(processor.Option("path_to_ld", processor.MinGWBinPath()+ "/ld" + ext))).Append(" -stack 4194304")
If Not opt_debug And Not opt_gdbdebug Then
sb.Append(processor.option("strip.debug", " -s "))
End If
If opt_apptype="gui" Then
sb.Append(" -subsystem windows")
End If
Else
Local prefix:String = processor.MinGWExePrefix()
sb.Append(CQuote(processor.Option("path_to_gpp", processor.MinGWBinPath() + "/" + prefix + "g++" + ext)))
If Not processor.HasClang() Then
If version < 60000 Then
sb.Append(" --stack=4194304")
Else
sb.Append(" -Wl,--stack,4194304")
End If
End If
If Not opt_debug And Not opt_gdbdebug Then
sb.Append(processor.option("strip.debug", " -s "))
End If
If opt_apptype="gui"
If version < 60000 Then
sb.Append(" --subsystem,windows -mwindows")
Else
sb.Append(" -Wl,--subsystem,windows -mwindows")
End If
Else
If Not makelib
sb.Append(" -mconsole")
End If
End If
If opt_threaded Then
If version < 60000 Then
sb.Append(" -mthread")
Else
sb.Append(" -mthreads")
End If
End If
End If
If makelib Then
sb.Append(" -shared")
If processor.Platform() = "win32" Then
sb.Append(" -static-libgcc")
End If
Else
sb.Append(" -static")
If opt_gprof Then
sb.Append(" -pg")
End If
End If
sb.Append(" -o ").Append(CQuote( path ))
If usingLD Then
If processor.CPU()="x86"
sb.Append(" ").Append(processor.MinGWLinkPaths()) ' the BlitzMax lib folder
' linking for x86 when using mingw64 binaries
If processor.HasTarget("x86_64") Then
sb.Append(" -mi386pe")
End If
Else
sb.Append(" ").Append(processor.MinGWLinkPaths()) ' the BlitzMax lib folder
End If
If globals.Get("path_to_mingw_lib") Then
sb.Append(" ").Append(CQuote( "-L"+CQuote( RealPath(processor.Option("path_to_mingw_lib", BlitzMaxPath()+"/lib") ) ) ))
End If
If globals.Get("path_to_mingw_lib2") Then
sb.Append(" ").Append(CQuote( "-L"+CQuote( RealPath(processor.Option("path_to_mingw_lib2", BlitzMaxPath()+"/lib") ) ) ))
End If
If globals.Get("path_to_mingw_lib3") Then
sb.Append(" ").Append(CQuote( "-L"+CQuote( RealPath(processor.Option("path_to_mingw_lib3", BlitzMaxPath()+"/lib") ) ) ))
End If
End If
If makelib
Local def$=StripExt(path)+".def"
Local imp$=StripExt(path)+".a"
If FileType( def )<>FILETYPE_FILE Then
Print "Warning: Cannot locate .def file (" + def + "). Exporting ALL symbols."
Else
sb.Append(" ").Append(CQuote( def ))
End If
If version < 60000 Then
sb.Append(" --out-implib ").Append(CQuote( imp ))
If usingLD Then
options.Append(" ").Append(CQuote( RealPath(processor.Option("path_to_mingw_lib", processor.MinGWDLLCrtPath()) + "/dllcrt2.o" ) ))
End If
Else
sb.Append(" -Wl,--out-implib,").Append(CQuote( imp ))
End If
Else
If usingLD
fb.Append(" ").Append(CQuote( RealPath(processor.Option("path_to_mingw_lib2", processor.MinGWCrtPath()) + "/crtbegin.o" ) ))
fb.Append(" ").Append(CQuote( RealPath(processor.Option("path_to_mingw_lib", processor.MinGWDLLCrtPath()) + "/crt2.o" ) ))
End If
EndIf
Local xpmanifest$
For Local f$=EachIn lnk_files
Local t$=CQuote( f )
If processor.HasClang() Then
If f.StartsWith("-l") Then
f = f.Replace(" ", "~n")
End If
t = f.Replace("\", "/").Replace(" ", "\ ").Replace("'", "\'")
End If
If opt_dumpbuild Or (t[..1]="-" And t[..2]<>"-l")
sb.Append(" ").Append(t)
Else
If f.EndsWith( "/win32maxguiex.mod/xpmanifest.o" )
xpmanifest=t
Else
If processor.HasClang() Then
fb.Append("~n").Append(t)
Else
fb.Append(" ").Append(t)
End If
EndIf
EndIf
Next
If xpmanifest Then
If processor.HasClang() Then
fb.Append("~n").Append(xpmanifest)
Else
fb.Append(" ").Append(xpmanifest)
End If
End If
sb.Append(" ")
If processor.HasClang() Then
sb.Append("@")
End If
sb.Append(CQuote( tmpfile ))
options.Append(" -lgdi32 -lwsock32 -lwinmm -ladvapi32")
' add any user-defined linker options
options.Append(" ").Append(opts)
If usingLD
If opts.Find("stdc++") = -1 Then
options.Append(" -lstdc++")
End If
options.Append(" -lmingwex")
' for a native Win32 runtiime of mingw 3.4.5, this needs to appear early.
'If Not processor.Option("path_to_mingw", "") Then
options.Append(" -lmingw32")
'End If
If opts.Find("gcc") = -1 Then
options.Append(" -lgcc")
End If
' if using 4.8+ or mingw64, we need to link to pthreads
If version >= 40800 Or processor.HasTarget("x86_64") Or processor.HasClang() Then
options.Append(" -lwinpthread ")
If processor.CPU()="x86" Then
options.Append(" -lgcc")
End If
End If
options.Append(" -lmoldname -lmsvcrt ")
End If
options.Append(" -luser32 -lkernel32 ")
'If processor.Option("path_to_mingw", "") Then
' for a non-native Win32 runtime, this needs to appear last.
' (Actually, also for native gcc 4.x, but I dunno how we'll handle that yet!)
If usingLD
options.Append(" -lmingw32 ")
End If
' add any user-defined linker options, again - just to cover whether we missed dependencies before.
options.Append(" ").Append(opts)
'End If
If Not makelib
If usingLD
options.Append(" ").Append(CQuote( processor.Option("path_to_mingw_lib2", processor.MinGWCrtPath()) + "/crtend.o" ))
End If
EndIf
If Not processor.HasClang() Then
fb.Insert(0,"INPUT(").Append(")")
End If
End If
If processor.Platform() = "linux" Or processor.Platform() = "raspberrypi" Or processor.Platform() = "haiku"
sb.Append(processor.Option(processor.BuildName("gpp"), "g++"))
'cmd:+" -m32 -s -Os -pthread"
If processor.Platform() <> "raspberrypi" And processor.Platform() <> "haiku" Then
If processor.CPU() = "x86" Or processor.CPU() = "arm" Then
sb.Append(" -m32")
End If
If processor.CPU() = "x64" Then
sb.Append(" -m64")
End If
End If
If opt_static Then
sb.Append(" -static")
End If
If processor.Platform() <> "haiku" And Not opt_nopie Then
sb.Append(" -no-pie -fpie")
End If
If opt_gprof Then
sb.Append(" -pg")
End If
If processor.Platform() <> "haiku" Then
sb.Append(" -pthread")
Else
sb.Append(" -lpthread")
End If
sb.Append(" -o ").Append(CQuote( path ))
sb.Append(" ").Append(CQuote( tmpfile ))
If processor.Platform() <> "haiku" Then
If processor.CPU() = "x86" Then
sb.Append(" -L").Append(processor.Option(processor.BuildName("lib32"), "/usr/lib32"))
End If
sb.Append(" -L").Append(processor.Option(processor.BuildName("x11lib"), "/usr/X11R6/lib"))
sb.Append(" -L").Append(processor.Option(processor.BuildName("lib"), "/usr/lib"))
Else
sb.Append(" -L").Append(CQuote( "/boot/system/develop/lib" ))
sb.Append(" -L").Append(CQuote( BlitzMaxPath()+"/lib" ))
End If
For Local t$=EachIn lnk_files
t=CQuote(t)
If opt_dumpbuild Or (t[..1]="-" And t[..2]<>"-l") Or (t[..1]="`")
sb.Append(" ").Append(t)
Else
fb.Append(" ").Append(t)
EndIf
Next
fb.Insert(0,"INPUT(").Append(")")
End If
If processor.Platform() = "android" Then
sb.Append(processor.Option(processor.BuildName("gpp"), "g++"))
Local libso:String = StripDir(path)
sb.Append(" -fPIC -shared ")
' for stlport shared lib
sb.Append(" -L").Append(AndroidSTLPortDir())
sb.Append(" -Wl,-soname,lib").Append(libso).Append(".so ")
sb.Append(" -Wl,--export-dynamic -rdynamic ")
sb.Append(" -o ").Append(CQuote( ExtractDir(path) + "/lib" + libso + ".so" ))
sb.Append(" ").Append(CQuote( tmpfile ))
sb.Append(" ").Append(processor.Option("android.platform.sysroot", ""))
For Local t$=EachIn lnk_files
t=CQuote(t)
If opt_dumpbuild Or (t[..1]="-" And t[..2]<>"-l")
sb.Append(" ").Append(t)
Else
fb.Append(" ").Append(t)
EndIf
Next
sb.Append(" -Wl,-Bdynamic -lGLESv2 -lGLESv1_CM ")
' libstlport
sb.Append(" -lstlport_shared")
sb.Append(" -llog -ldl -landroid ")
fb.Insert(0,"INPUT(").Append(")")
End If
If processor.Platform() = "emscripten"
sb.Append(processor.Option(processor.BuildName("gpp"), "em++"))
' cmd:+" -pthread" ' No threading support yet...
sb.Append(" -o ").Append(CQuote( path ))
'cmd:+" -filelist "+CQuote( tmpfile )
sb.Append(" ").Append(opts)
For Local t$=EachIn lnk_files
t=CQuote(t)
'If opt_dumpbuild Or (t[..1]="-" And t[..2]<>"-l")
sb.Append(" ").Append(t)
'Else
' files:+" "+t
'EndIf
Next
fb.Insert(0,"INPUT(").Append(")")
End If
If processor.Platform() = "nx" Then
sb.Append(processor.Option(processor.BuildName("gpp"), "g++"))
Local libso:String = StripDir(path)
sb.Append(" -MMD -MP -MF ")
sb.Append(" -march=armv8-a -mtune=cortex-a57 -mtp=soft -fPIE ")
sb.Append(" -specs=").Append(processor.Option("nx.devkitpro", "")).Append("/libnx/switch.specs")
sb.Append(" -g")
'sb.Append(" -Wl,-Map,").Append(StripExt(path)).Append(".map")
sb.Append(" -L").Append(NXLibDir())
sb.Append(" -o ").Append(CQuote( path ))
sb.Append(" ").Append(CQuote( tmpfile ))
Local endLinks:TList = New TList
For Local t$=EachIn lnk_files
t=CQuote(t)
If opt_dumpbuild Or (t[..1]="-" And t[..2]<>"-l") Or (t[..1]="`")
sb.Append(" ").Append(t)
Else
If t.Contains("appstub") Or t.Contains("blitz.mod") Then
endLinks.AddLast(t)
Continue
End If
fb.Append(" ").Append(t)
EndIf
Next
fb.Append(" -lnx -lm")
For Local t:String = EachIn endLinks
fb.Append(" ").Append(t)
Next
fb.Insert(0,"INPUT(").Append(")")
End If
Local t$=getenv_( "BMK_LD_OPTS" )
If t
sb.Append(" ").Append(t)
EndIf
cmd = sb.ToString()
files = fb.ToString()
If Not opt_standalone Then
Local stream:TStream=WriteStream( tmpfile )
stream.WriteBytes files.ToCString(),files.length
stream.Close
End If
If processor.Sys( cmd ) Throw "Build Error: Failed to link "+path
If opt_standalone
Local stream:TStream=WriteStream( StripExt(tmpfile) )
Local f:String = processor.FixPaths(files)
stream.WriteBytes f.ToCString(),f.length
stream.Close
End If
End Function
Function MergeApp(file1:String, file2:String, outputFile:String)
If Not opt_quiet Print "[100%] Merging:"+StripDir(file1) + " + " + StripDir(file2) + " > " + StripDir(outputFile)
Local cmd:String = "lipo -create ~q" + file1 + "~q ~q" + file2 + "~q -output ~q" + outputFile + "~q"
If processor.Sys( cmd ) Throw "Merge Error: Failed to merge " + file1 + " and " + file2 + " into " + outputFile
DeleteFile file1
DeleteFile file2
End Function
Function DeployAndroidProject()
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)
' eg. android-project-test_01
Local projectDir:String = buildDir + "/android-project-" + appId '+ "-" + processor.CPU()
' check for dir
If Not FileType(projectDir) Then
' doesn't exist. create it
Local resourceProject:String = BlitzMaxPath() + "/resources/android/android-project"
If Not FileType(resourceProject) Then
Throw "Missing resources folder for Android build : " + resourceProject
End If
CopyDir(resourceProject, projectDir)
End If
' check for valid dir
If FileType(projectDir) <> FILETYPE_DIR Then
Throw "Error creating project dir '" + projectDir + "'"
End If
' create assets dir if missing
Local assetsDir:String = projectDir + "/assets"
If opt_all Then
' remove assets if we are doing a full build
DeleteDir(assetsDir, True)
End If
If FileType(assetsDir) <> FILETYPE_DIR Then
CreateDir(assetsDir)
If FileType(assetsDir) <> FILETYPE_DIR Then
Throw "Error creating assests dir '" + assetsDir + "'"
End If
End If
' create libs/abi dir if missing
Local abiDir:String = projectDir + "/libs"
If FileType(abiDir) <> FILETYPE_DIR Then
CreateDir(abiDir)
If FileType(abiDir) <> FILETYPE_DIR Then
Throw "Error creating libs dir '" + abiDir + "'"
End If
End If
abiDir :+ "/" + GetAndroidArch()
If FileType(abiDir) <> FILETYPE_DIR Then
CreateDir(abiDir)
If FileType(abiDir) <> FILETYPE_DIR Then
Throw "Error creating libs abi dir '" + abiDir + "'"
End If
End If
' copy stlport
Local stlportDest:String = abiDir + "/libstlport_shared.so"
If opt_all Or Not FileType(stlportDest) Then
Local stlportSrc:String = AndroidSTLPortDir() + "/libstlport_shared.so"
CopyFile(stlportSrc, stlportDest)
If Not FileType(stlportDest) Then
Throw "Error copying libstlport_shared.so from '" + stlportSrc + "'"
End If
End If
Local projectSettings:TMap = ParseApplicationIniFile()
Local appPackage:String = String(projectSettings.ValueForKey("app.package"))
Local packagePath:String = projectDir + "/src/" + PathFromPackage(appPackage)
' create the package
If Not FileType(packagePath) Then
CreateDir(packagePath, True)
If FileType(packagePath) <> FILETYPE_DIR Then
Throw "Error creating package '" + packagePath + "'"
End If
End If
' copy/create java
Local gameClassFile:String = packagePath+ "/BlitzMaxApp.java"
If Not FileType(gameClassFile) Then
CopyFile(projectDir + "/BlitzMaxApp.java", gameClassFile)
If Not FileType(gameClassFile) Then
Throw "Error creating class file '" + gameClassFile + "'"
End If
End If
' merge project data
' update AndroidManifest.xml
MergeFile(projectDir, "AndroidManifest.xml", projectSettings)
' update BlitzMaxApp.java
MergeFile(packagePath, "BlitzMaxApp.java", projectSettings)
Local javaApp:String = LoadString( gameClassFile )
' set the package
javaApp = ReplaceBlock( javaApp, "app.package","package " + appPackage + ";" )
' lib imports
javaApp = ReplaceBlock( javaApp, "lib.imports", GetAndroidLibImports() )
SaveString(javaApp, gameClassFile)
' update strings.xml
MergeFile(projectDir + "/res/values", "strings.xml", projectSettings)
' update build.xml
MergeFile(projectDir, "build.xml", projectSettings)
' set the sdk target
Local projectPropertiesFile:String = projectDir + "/project.properties"
Local projectProperties:String = LoadString( projectPropertiesFile )
projectProperties = ReplaceBlock( projectProperties, "sdk.target","target=android-" + processor.option("android.sdk.target", ""), "~n#")
SaveString(projectProperties, projectPropertiesFile)
' copy resources to assets
CopyAndroidResources(buildDir, assetsDir)
End Function
Function GetAndroidLibImports:String()
Local imports:String
imports = "System.loadLibrary( ~qstlport_shared~q);~n"
' TODO : others imported via project...
Return imports
End Function
Function GetAndroidArch:String()
Local arch:String
Select processor.CPU()
Case "x86"
arch = "x86"
Case "x64"
arch = "x86_64"
Case "arm"
arch = "armeabi-v7a"
Case "armeabi"
arch = "armeabi"
Case "armeabiv7a"
arch = "armeabi-v7a"
Case "arm64v8a"
arch = "arm64-v8a"
Default
Throw "Not a valid architecture '" + processor.CPU() + "'"
End Select
Return arch
End Function
Function AndroidSTLPortDir:String()
Return processor.Option("android.ndk", "") + "/sources/cxx-stl/stlport/libs/" + GetAndroidArch()
End Function
Function CopyAndroidResources(buildDir:String, assetsDir:String)
Local paths:String[] = SplitPaths(String(globals.GetRawVar("resource_path")))
If paths Then
For Local dir:String = EachIn paths
Local resourceDir:String = buildDir + "/" + dir
If Not FileType(resourceDir) Then
Print "Warning : Defined resource_path '" + dir + "' not found"
End If
If FileType(resourceDir) = FILETYPE_DIR Then
CopyDir assetsDir + "/" + dir, resourceDir
End If
Next
End If
End Function
Function GetAndroidSDKTarget:String()
Local sdkPath:String = processor.Option("android.sdk", "") + "/platforms"
Local target:String = processor.Option("android.sdk.target", "")
Local targetPath:String
If target Then
targetPath = sdkPath + "/android-" + target
If FileType(targetPath) = FILETYPE_DIR Then
Return target
End If
End If
' find highest numbered target platform dir
Local dirs:String[] = LoadDir(sdkPath, True)
Local high:Int
For Local dir:String = EachIn dirs
Local index:Int = dir.Find("android-")
If index >= 0 Then
Local value:Int = dir[index + 8..].ToInt()
high = Max(value, high)
End If
Next
If high > 0 Then
Return high
End If
End Function
Function NXLibDir:String()
Return processor.Option("nx.devkitpro", "") + "/libnx/lib"
End Function
Function NxToolsDir:String()
Return processor.Option("nx.devkitpro", "") + "/tools/bin"
End Function
Function BuildNxDependencies()
BuildNxNso()
BuildNxNacp()
BuildNxNro()
End Function
Function BuildNxNso()
If Not opt_quiet Print "Building:" + StripDir(StripExt(opt_outfile)) + ".nso"
Local elf2nso:String = NxToolsDir() + "/elf2nso"
?win32
elf2nso :+ ".exe"
?
If Not FileType(elf2nso) Then
Throw "elf2nso tool not present at " + elf2nso
End If
Local app:String = StripExt(opt_outfile)
Local cmd:String = elf2nso + " " + CQuote(app + ".elf")
cmd :+ " " + CQuote(app + ".nso")
Sys(cmd)
End Function
Function BuildNxNacp()
If Not opt_quiet Print "Building:" + StripDir(StripExt(opt_outfile)) + ".nacp"
Local nacptool:String = NxToolsDir() + "/nacptool"
?win32
nacptool :+ ".exe"
?
If Not FileType(nacptool) Then
Throw "nacptool tool not present at " + nacptool
End If
Local app:String = StripExt(opt_outfile)
Local cmd:String = nacptool + " --create"
Local name:String = processor.AppSetting("app.name")
If Not name Then
name = StripDir(StripExt(opt_outfile))
End If
cmd :+ " " + CQuote(name)
Local auth:String = processor.AppSetting("app.company")
If Not auth Then
auth = "Unspecified Author"
End If
cmd :+ " " + CQuote(auth)
Local ver:String = processor.AppSetting("app.version.name")
If Not ver Then
ver = "1.0.0"
End If
cmd :+ " " + CQuote(ver)
cmd :+ " " + CQuote(app + ".nacp")
Sys(cmd)