-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathandroidndk_project.lua
More file actions
1743 lines (1633 loc) · 84.2 KB
/
androidndk_project.lua
File metadata and controls
1743 lines (1633 loc) · 84.2 KB
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
-- premake-androidndk - a multi-ABI, multi-language ndk-build Android.mk generator for Premake.
-- Originally written by Vitaliy <Triang3l> Kuzmin.
-- See README.md for detailed usage and design information.
-- Available under the Unlicense (see UNLICENSE.txt) or the BSD 3-Clause "New" or "Revised" License (see LICENSE.txt).
local p = premake;
local androidndk = p.modules.androidndk;
androidndk.kindScripts = {
[p.CONSOLEAPP] = "BUILD_EXECUTABLE",
[p.SHAREDLIB] = "BUILD_SHARED_LIBRARY",
[p.STATICLIB] = "BUILD_STATIC_LIBRARY",
};
androidndk.prebuiltKinds = {
[p.SHAREDLIB] = {
extension = ".so",
script = "PREBUILT_SHARED_LIBRARY",
},
[p.STATICLIB] = {
extension = ".a",
script = "PREBUILT_STATIC_LIBRARY",
},
};
function androidndk.isProjectSupported(project, reportWarnings)
-- Not allowing references or escaped $ in project names as they complicate path building as well as including project Android.mk files.
-- Premake treats any path beginning with $ as absolute.
-- LOCAL_MODULE and LOCAL_STATIC_LIBRARIES sweeping result:
-- Allowed directly on Linux: !+,-./@[]^_{}~
-- Allowed if \-escaped on Linux: "`
-- Allowed if \-escaped on Linux, misleadingly displayed with \ in the terminal: &'()*<>?
-- Allowed if \\-escaped on Linux: \
-- Disallowed: whitespaces, #$%:;=|
-- Stricter than LOCAL_MODULE_FILENAME derived from it by default for : and = (no action required).
-- However, more relaxed for / - to avoid issues, disallowing / too.
if string.find(project.name, "%$") ~= nil or androidndk.staticallyHasPatternPostEsc(p.esc(project.name), "[%s#%$%%/:;=|]") then
if reportWarnings then
p.warn(
"Skipping workspace '%s' project '%s' with name containing GNU make references, " ..
"whitespaces or characters disallowed in an ndk-build module name #$%%/:;=|",
project.workspace.name, project.name);
end
return false;
end
return true;
end
function androidndk.getConfigCondition(buildcfg, platform, abi)
-- All requirements must be met by what is provided by ndk-build and the user for a configuration to be selected.
-- This is done by removing (filtering out) the current state from the set of the requirements.
-- If the resulting set is empty, the current state matches all the requirements.
-- It's important that either all requirements are checked at once (like here), or the ABI check is the outermost ifeq.
-- PREMAKE_ANDROIDNDK_CONFIGURATIONS and _PLATFORMS include _all_ needed configurations and are the same throughout the ndk-build execution.
-- With nested buildcfg > platform > ABI conditionals, all ABIs would be entering the same buildcfg, and then the same platform within it.
-- However, the ABI is the primary criteria for selecting the platform (and the buildcfg if it depends on it).
-- The ABI should be narrowing down the selection either to one config, or to skipping the module.
-- The result for multiple configurations for one ABI is undefined.
local state = {};
local requirements = {};
-- Configs in projects are usually sorted by ABI (so ABI-agnostic fallbacks can be provided), then (by Premake) buildcfg, then platform.
-- So, using this order as well for better readability of generated makefiles.
-- ABI filtering is done only when the ABI specified.
if abi ~= nil then
if abi ~= androidndk.ABI_ALL then
table.insert(state, "ABI=$(TARGET_ARCH_ABI)");
table.insert(requirements, "ABI=" .. abi);
end
end
-- At least one build configuration is required by Premake.
table.insert(state, "$(PREMAKE_ANDROIDNDK_CONFIGURATIONS_PREFIXED)");
table.insert(requirements, "CONFIGURATION=" .. p.esc(buildcfg));
-- Platforms may be unspecified, in this case, configurations will have a nil platform.
if platform ~= nil then
table.insert(state, "$(PREMAKE_ANDROIDNDK_PLATFORMS_PREFIXED)");
table.insert(requirements, "PLATFORM=" .. p.esc(platform));
end
return "ifeq ($(filter-out " .. table.concat(state, " ") .. "," .. table.concat(requirements, " ") .. "),)";
end
function androidndk.configUsesA32(config)
-- LOCAL_ARM_MODE and the .arm suffix have no effect on ABIs where they're not relevant - no need to check the ABI.
-- NDK uses T32 by default, and always switches to A32 for debug builds, but it's handled implicitly in it.
return config.armisa == "A32";
end
function androidndk.configUsesNeon(config)
-- LOCAL_ARM_NEON and the .neon suffix have no effect on ABIs where they're not relevant - no need to check the ABI.
-- On NDK r21, NEON is enabled by default.
-- Requiring setting vectorextensions to "ARMv7" (similar to "IA32") explicitly for disabling.
return config.vectorextensions ~= "ARMv7";
end
function androidndk.shellEscapePreQuotesPostEsc(argument, temporaryVariables)
if androidndk.hasNonEmptyMakeReferencesPostEsc(argument) then
-- Escape while building, after expanding variable and function references.
-- Can't use the text directly in a function call because it may contain brackets.
return "$(call " .. androidndk.shellEscapePreQuotesMakeCall .. "," .. androidndk.getTemporaryVariableReference(temporaryVariables, argument) .. ")";
end
-- Unescape comment characters, which have \ in their escape sequence.
argument = string.gsub(argument, androidndk.commentUnescapePattern, "#");
-- Pre-escape.
argument = string.gsub(string.gsub(argument, "\\", "\\\\"), "\"", "\\\"");
-- Re-escape comment characters.
argument = string.gsub(argument, "#", androidndk.commentEscapeString);
return argument;
end
-- For calling with unescaped paths, otherwise paths starting with # will be considered absolute due to $()\# escaping.
-- In addition, may need to escape characters inserted by path.getrelative itself.
-- Unfortunately, if path.getrelative inserts any $ by itself while joining, they will be treated as references.
-- They wouldn't be able to be distinguished from references specified in the project itself.
function androidndk.getEscapedProjectRelativePath(project, file, joinWithLocalPath)
-- Must be synchronized with LOCAL_PATH setting.
-- Based on p.filename logic (relative to the location of the project's Android.mk).
-- If a path starts with a GNU make variable or function reference, it's assumed to be absolute, to allow using paths like $(NDK_ROOT).
-- Premake already treats paths starting with $ as absolute in path.getrelative, among other functions.
-- Relative paths starting with $ must be prefixed with ./.
local relativePath = path.getrelative(project.location or project.basedir, file);
-- For something like ./$(VARIABLE) (relative), path.getrelative can possibly return $(VARIABLE), which will be treated as absolute.
-- Premake treats all paths beginning with $ as absolute.
-- In this case, the path must still be written as relative to $(LOCAL_PATH), but path.join won't work.
-- path.join doesn't even work if the trailing part begins with ./$(VARIABLE).
-- Using concatenation for this purpose instead.
if joinWithLocalPath and (not path.isabsolute(relativePath) or (string.sub(relativePath, 1, 1) == "$" and string.sub(file, 1, 1) ~= "$")) then
relativePath = "$(LOCAL_PATH)/" .. relativePath;
end
return p.esc(relativePath);
end
-- Excluding the .arm and .neon suffixes.
androidndk.asmExtension = ".asm";
androidndk.cExtension = ".c";
androidndk.sourceExtensions = { androidndk.asmExtension, androidndk.cExtension };
androidndk.compilerFlagsVariables = {
[androidndk.asmExtension] = "ASMFLAGS",
[androidndk.cExtension] = "CONLYFLAGS",
};
-- NDK r23 default-c++-extensions.
-- Strictly broader than path.iscppfile as of premake-core v5.0.0-alpha16.
-- path.iscppfile is not usable directly conveniently, however, as it also includes assembly and Objective-C/C++.
-- Do not use path.hasextension (or path.iscppfile) as it's case-insensitive unlike ndk-build, and will treat .C as C instead of C++.
-- Indexed for concatenation purposes.
androidndk.cppExtensions = { ".cc", ".cp", ".cxx", ".cpp", ".CPP", ".c++", ".C" };
table.foreachi(androidndk.cppExtensions, function(extension)
-- Build a hash set for lookup in cppExtensions.
androidndk.cppExtensions[extension] = extension;
-- Register the extension as a C++ one.
table.insert(androidndk.sourceExtensions, extension);
androidndk.compilerFlagsVariables[extension] = "CPPFLAGS";
end);
-- NDK r23 default-rs-extensions.
androidndk.rsExtensions = { ".rs", ".fs" };
table.foreachi(androidndk.rsExtensions, function(extension)
-- Build a hash set for lookup in rsExtensions.
androidndk.rsExtensions[extension] = extension;
-- Register the extension as a RenderScript one.
table.insert(androidndk.sourceExtensions, extension);
androidndk.compilerFlagsVariables[extension] = "RENDERSCRIPT_FLAGS";
end);
androidndk.asExtensions = { ".s", ".S" };
table.foreachi(androidndk.asExtensions, function(extension)
-- Build a hash set for lookup in asExtensions.
androidndk.asExtensions[extension] = extension;
-- Register the extension as a GAS one.
table.insert(androidndk.sourceExtensions, extension);
androidndk.compilerFlagsVariables[extension] = "ASFLAGS";
end);
-- Build a hash set for lookup in sourceExtensions.
table.foreachi(androidndk.sourceExtensions, function(extension)
androidndk.sourceExtensions[extension] = extension;
end);
-- Define variables usable by projects for language filtering via extension filters.
-- Lowercase because it's the public interface for projects.
androidndk.filefilters = {};
function androidndk.buildExtensionFileFilterTerms(extensions)
local extensionsCaseInsensitive = {};
-- Premake filters are case-insensitive - don't add the same extension twice.
for i, extension in ipairs(extensions) do
table.insertkeyed(extensionsCaseInsensitive, string.lower(extension));
end
-- Build filters including subdirectories, adding all possible ARM suffixes.
local extensionFilters = {};
for i, extension in ipairs(extensionsCaseInsensitive) do
local extensionFilter = "**" .. extension;
table.insert(extensionFilters, extensionFilter);
table.insert(extensionFilters, extensionFilter .. ".arm");
table.insert(extensionFilters, extensionFilter .. ".neon");
table.insert(extensionFilters, extensionFilter .. ".arm.neon");
end
return extensionFilters;
end
-- Initializing public helpers (and thus lowercase names) - don't remove even though they are not referenced within the module itself!
(function()
local languageFilterVariables = {
{
language = "as",
extensions = androidndk.asExtensions,
},
{
language = "asm",
extensions = { androidndk.asmExtension },
},
{
language = "c",
extensions = { androidndk.cExtension },
},
{
language = "cpp",
-- Premake filters are case-insensitive, so C sources would pass **.C as well - skip it in the C++ filter.
-- It's not recommended to use the .C extension at all for this reason.
extensions = table.filter(
androidndk.cppExtensions,
function(extension)
return extension ~= ".C";
end),
},
{
language = "rs",
extensions = androidndk.rsExtensions,
},
};
for i, languageFilterVariable in ipairs(languageFilterVariables) do
local extensionsCaseInsensitive = {};
-- Premake filters are case-insensitive - don't add the same extension twice.
for i2, extension in ipairs(languageFilterVariable.extensions) do
table.insertkeyed(extensionsCaseInsensitive, string.lower(extension));
end
-- Build arrays of raw extensions with all possible ARM suffixes:
-- androidndk.prefixfilefilterextensions = { ".ext", ".ext.arm", ".ext.neon", ".ext.arm.neon"... }
-- This allows arbitrary usage of table.translate, including to prepend a specific file name.
local extensionsWithSuffixes = {};
for i2, extension in ipairs(extensionsCaseInsensitive) do
table.insert(extensionsWithSuffixes, extension);
table.insert(extensionsWithSuffixes, extension .. ".arm");
table.insert(extensionsWithSuffixes, extension .. ".neon");
table.insert(extensionsWithSuffixes, extension .. ".arm.neon");
end
androidndk.filefilters[languageFilterVariable.language .. "extensions"] = extensionsWithSuffixes;
-- Build inclusive filters for all subdirectories as a string.
-- androidndk.filefilters.language = "files:**.ext or files:**.ext.arm or files:**.ext.neon or files:**.ext.arm.neon..."
androidndk.filefilters[languageFilterVariable.language] =
table.concat(
table.translate(
extensionsWithSuffixes,
function(extension)
return "files:**" .. extension;
end),
" or ");
-- Build exclusive filters for all subdirectories as a table.
-- androidndk.filefilters.notlanguage = { "files:not **.ext", "files:not **.ext.arm", "files:not **.ext.neon", "files:not **.ext.arm.neon"... }
androidndk.filefilters["not" .. languageFilterVariable.language] =
table.translate(
extensionsWithSuffixes,
function(extension)
return "files:not **" .. extension;
end);
end
end)();
-- In this module, flags are gathered from both the project configuration and per-file configuration.
-- ndk-build, however, doesn't support per-file flags.
-- Per-file configuration is needed though because compilers for different languages may need different flags.
-- The `language` setting is a whole-project setting, it alone can't be used in a filter to specify which compiler should receive the flags.
-- Therefore, the file extension must be used as a filter.
-- This leads of a lot of duplication - every file in the project has project-level flags as well as extension-specific flags.
-- For this reason, each flag is added only once.
-- Because of this, a flag may contain one or multiple whitespace-separated compiler argument.
-- "-include a.h -include b.h -include \"c d.h\" -include \"c d.h\"" must NOT be deduplicated as:
-- { "-include", "a.h", "b.h", "\"c d.h\"" }
-- or as:
-- { "-include", "a.h", "b.h", "\"c", "d.h\"" }
-- It must be:
-- { "-include a.h", "-include b.h", "-include \"c d.h\"" }
-- Built-in flags (derived from from boolean or enumeration settings) here are added to the flags table directly as p.esc(value).
-- Most shell characters in them will be escaped at build time, however, " and \ will not.
-- So, it's possible to have built-in flags corresponding to one (possibly with quoted whitespaces) or multiple (with unquoted whitespaces) compiler arguments.
-- If a double quote character or a backslash needs to be used as a raw character, it needs to be pre-escaped manually in the flag literal here.
-- GNU make variable and function references should be used in built-in flags very carefully for the same reason.
-- Ordering of the flags is preserved only for their first occurrences in each of the LOCAL_languageFLAGS.
-- In Clang, if there are conflicting flags (such as -f and -fno), the ones later in the list take precedence.
-- Per-extension flags are therefore added after project-scope flags so the former can override the latter.
-- Makes the value a single command line arguments passed to the compiler with a prefix, which may be in the same or in a separate argument.
-- The value must be pre-escaped with p.esc.
-- The prefix (not pre-escaped) will be handled similar to built-in flags, and may contain unquoted whitespaces for separate command line arguments.
-- Examples of the output:
-- * -DCSTRING=\"Hello\"
-- * -D"CSTRING=\"Hello, world!\""
-- * -D "YASMSTRING=\"Hello, world!\""
-- * -include header.h
-- * -include "header file.h"
-- * PREMAKE_ANDROIDNDK_TEMPORARY_1 := $(ENVIRONMENT_VARIABLE)/New folder (2)/header file.h
-- -include "$(call PREMAKE_ANDROIDNDK_SHELL_ESCAPE_PRE_QUOTES,$(PREMAKE_ANDROIDNDK_TEMPORARY_1))"
function androidndk.getSingleArgumentPrefixedFlagPostValueEsc(value, prefix, temporaryVariables)
local flagParts = { p.esc(prefix) };
-- While it's completely safe to add excessive quotes in general, in some cases ndk-build doesn't expect them.
-- One example being LOCAL_LDLIBS, which is designed only for linking to Android system libraries.
-- ndk-build checks each entry against a list of known Android system libraries, and throws a warning if any non-system ones are specified.
-- The intended usage pattern of LOCAL_LDLIBS `LOCAL_LDLIBS := -landroid -llog`, not ``LOCAL_LDLIBS := -l"android" -l"log"`.
-- So, adding quotes only if there are whitespaces or references (for which it's not known whether they will be expanded to something containing whitespaces).
local isQuoted = androidndk.hasNonEmptyMakeReferencesPostEsc(value) or androidndk.staticallyHasPatternPostEsc(value, "%s");
if isQuoted then
table.insert(flagParts, "\"");
end
table.insert(flagParts, androidndk.shellEscapePreQuotesPostEsc(value, temporaryVariables));
if isQuoted then
table.insert(flagParts, "\"");
end
return table.concat(flagParts);
end
-- System include directories are normally placed after the local ones, including in ndk-build itself.
androidndk.includeDirsConfigSettings = { "includedirs", "sysincludedirs" };
function androidndk.addIncludeDirs(includeDirs, config)
-- In LOCAL_C_INCLUDES (tested on it, but LOCAL_RENDERSCRIPT_INCLUDES goes to the host-c-includes call too):
-- Allowed directly on Linux: !%*+,-./:=?@[]^_{}~
-- Allowed if \-escaped on Linux: "&'();<>\`|
-- Escaped UNC paths (beginning with \\\\) are supported on Windows.
-- Disallowed: whitespaces, #$
-- In the NDK itself, either absolute or relative to the NDK root, not to the local path - need $(LOCAL_PATH) explicitly.
for i, settingName in ipairs(androidndk.includeDirsConfigSettings) do
local settingOutput = includeDirs[settingName];
if settingOutput == nil then
settingOutput = {};
includeDirs[settingName] = settingOutput;
end
local settingInput = config[settingName];
for i2, includeDir in ipairs(settingInput) do
local includeDirPath = androidndk.getEscapedProjectRelativePath(config.project, includeDir, true);
if androidndk.staticallyHasPatternPostEsc(includeDirPath, "[%s#%$]") then
p.warn(
"Skipping workspace '%s' project '%s' configuration '%s' include directory '%s' with whitespaces or disallowed characters #$",
config.workspace.name, config.project.name, config.name, includeDir);
else
table.insert(settingOutput, includeDirPath);
end
end
end
end
function androidndk.writeProjectIncludeDirs(includeDirsForAllVariables, variable, escapeShellCharacters)
local includeDirsForVariable = includeDirsForAllVariables[variable];
if includeDirsForVariable == nil then
return false;
end
-- Merge all config settings the include directories are gathered from in the correct order.
local includeDirsForVariableMerged = {};
for i, configSettingName in ipairs(androidndk.includeDirsConfigSettings) do
if includeDirsForVariable[configSettingName] ~= nil then
for i2, includeDir in ipairs(includeDirsForVariable[configSettingName]) do
table.insertkeyed(includeDirsForVariableMerged, includeDir);
end
end
end
local localVariable = "LOCAL_" .. variable;
if androidndk.assignToVariablePostEsc(localVariable, includeDirsForVariableMerged, true, androidndk.shellEscapeChecker) then
if escapeShellCharacters then
androidndk.writePostProcessCall(localVariable, androidndk.shellEscapeMakeCall);
end
return true;
end
return false;
end
-- Assuming Clang - GCC was removed in NDK r13.
-- RenderScript is based on C99, but for writing compute kernels.
-- Supported values are built-in flags as single strings and tables of strings (will be separate flags table elements).
androidndk.asmFlagsSettingFlags = {
{ key = "FatalCompileWarnings", value = "-Werror" },
};
androidndk.cCppFlagsSettingFlags = {
{ key = "FatalCompileWarnings", value = "-Werror" },
-- LinkTimeOptimization is per-project, not per-extension, as it needs to be easily queryable in static library dependency analysis.
-- NoBufferSecurityCheck is C++-only in p.clang, but nothing precludes its usage in C.
-- Android uses -fstack-protector-strong by default as of NDK r23.
{ key = "NoBufferSecurityCheck", value = "-fno-stack-protector" },
{ key = "ShadowedVariables", value = "-Wshadow" },
{ key = "UndefinedIdentifiers", value = "-Wundef" },
};
androidndk.rsFlagsSettingFlags = {
{ key = "FatalCompileWarnings", value = "-Werror" },
{ key = "ShadowedVariables", value = "-Wshadow" },
{ key = "UndefinedIdentifiers", value = "-Wundef" },
};
-- Instead of using p.clang and mapFlags (with all its complexity), listing only what's relevant to ndk-build.
-- Supported keys are only strings and booleans (as p.OFF and p.ON), no tables (to avoid the complexity of keeping a deterministic order).
-- Supported values are built-in flags as single strings and tables of strings (will be separate flags table elements).
-- Values may contain unquoted (for multiple options) or quoted whitespaces, or \-escaped " and \, but p.esc will be done before writing.
androidndk.asmSettingValueFlags = {
{
key = "warnings",
values = {
[p.OFF] = "-w",
},
},
};
androidndk.cCppSettingValueFlags = {
-- architecture is chosen via APP_ABI.
-- flags are handled separately to avoid ensuring deterministic table ordering.
{
key = "floatingpoint",
values = {
Fast = "-ffast-math",
},
},
-- floatingpointexceptions not present in p.clang as of v5.0.0-alpha16, added here.
{
key = "floatingpointexceptions",
values = {
[p.ON] = "-ftrapping-math",
[p.OFF] = "-fno-trapping-math",
},
},
{
key = "strictaliasing",
values = {
[p.OFF] = "-fno-strict-aliasing",
Level1 = { "-fstrict-aliasing", "-Wstrict-aliasing=1" },
Level2 = { "-fstrict-aliasing", "-Wstrict-aliasing=2" },
Level3 = { "-fstrict-aliasing", "-Wstrict-aliasing=3" },
},
},
-- optimize is chosen via APP_OPTIM.
-- pic is always enabled by ndk-build and is required on Android.
-- vectorextensions are per-architecture.
-- isaextensions are per-architecture.
{
key = "warnings",
values = {
[p.OFF] = "-w",
High = "-Wall",
Extra = { "-Wall", "-Wextra" },
Everything = "-Weverything",
},
},
-- symbols are chosen via APP_DEBUG.
{
key = "unsignedchar",
values = {
[p.ON] = "-funsigned-char",
[p.OFF] = "-fno-unsigned-char",
},
},
-- omitframepointer Off is needed for the Address Sanitizer, so exposed here.
-- More info about omitframepointer on Android: https://github.com/android/ndk/issues/824
{
key = "omitframepointer",
values = {
[p.ON] = "-fomit-frame-pointer",
[p.OFF] = "-fno-omit-frame-pointer",
},
},
-- visibility and inlinesvisibility are C++-only in p.clang in v5.0.0-alpha16, but nothing precludes their usage in C.
{
key = "visibility",
values = {
Default = "-fvisibility=default",
Hidden = "-fvisibility=hidden",
Internal = "-fvisibility=internal",
Protected = "-fvisibility=protected",
},
},
{
key = "inlinesvisibility",
values = {
Hidden = "-fvisibility-inlines-hidden",
},
},
};
androidndk.cSettingValueFlags = {
{
key = "cdialect",
values = {
["C89"] = "-std=c89",
["C90"] = "-std=c90",
["C99"] = "-std=c99",
["C11"] = "-std=c11",
["gnu89"] = "-std=gnu89",
["gnu90"] = "-std=gnu90",
["gnu99"] = "-std=gnu99",
["gnu11"] = "-std=gnu11",
},
},
}
androidndk.cppSettingValueFlags = {
-- exceptionhandling is chosen via LOCAL_CPP_FEATURES.
{
key = "cppdialect",
values = {
["C++98"] = "-std=c++98",
["C++0x"] = "-std=c++0x",
["C++11"] = "-std=c++11",
["C++1y"] = "-std=c++1y",
["C++14"] = "-std=c++14",
["C++1z"] = "-std=c++1z",
["C++17"] = "-std=c++17",
["C++2a"] = "-std=c++2a",
["C++20"] = "-std=c++20",
["gnu++98"] = "-std=gnu++98",
["gnu++0x"] = "-std=gnu++0x",
["gnu++11"] = "-std=gnu++11",
["gnu++1y"] = "-std=gnu++1y",
["gnu++14"] = "-std=gnu++14",
["gnu++1z"] = "-std=gnu++1z",
["gnu++17"] = "-std=gnu++17",
["gnu++2a"] = "-std=gnu++2a",
["gnu++20"] = "-std=gnu++20",
["C++latest"] = "-std=c++20",
},
},
-- rtti is chosen via LOCAL_CPP_FEATURES.
};
androidndk.rsSettingValueFlags = {
{
key = "warnings",
values = {
[p.OFF] = "-w",
High = "-Wall",
Extra = { "-Wall", "-Wextra" },
Everything = "-Weverything",
},
},
-- No other cCppFlagsSettingFlags and cSettingValueFlags are supported.
};
androidndk.asmWarningFlags = {
{ key = "enablewarnings", prefix = "-W" },
{ key = "disablewarnings", prefix = "-Wno-" },
-- No -Werror= on YASM, pick the closest to the intention.
{ key = "fatalwarnings", prefix = "-W" },
};
androidndk.cCppWarningFlags = {
{ key = "enablewarnings", prefix = "-W" },
{ key = "disablewarnings", prefix = "-Wno-" },
{ key = "fatalwarnings", prefix = "-Werror=" },
};
function androidndk.addCompilerFlagsForExtension(flagsForExtension, extension, config, temporaryVariables)
-- Make sure the table for generic flags exists.
if flagsForExtension.buildoptions == nil then
flagsForExtension.buildoptions = {};
end
local isCCpp = extension == androidndk.cExtension or androidndk.cppExtensions[extension] ~= nil;
local languageDefinesPrefix = nil;
local languageUndefinesPrefix = nil;
local languageFlagsSettingFlags = nil;
local languageSettingValueFlagsTables = {};
local languageWarningFlags = nil;
if extension == androidndk.asmExtension then
-- The defines prefix is separated into a different argument.
languageDefinesPrefix = "-D ";
languageUndefinesPrefix = "-U ";
languageFlagsSettingFlags = androidndk.asmFlagsSettingFlags;
table.insert(languageSettingValueFlagsTables, androidndk.asmSettingValueFlags);
languageWarningFlags = androidndk.asmWarningFlags;
elseif isCCpp then
-- The defines prefix is in the same argument (though separation also works, but ndk-build itself doesn't separate).
languageDefinesPrefix = "-D";
languageUndefinesPrefix = "-U";
-- Currently only shared between C and C++.
languageFlagsSettingFlags = androidndk.cCppFlagsSettingFlags;
table.insert(languageSettingValueFlagsTables, androidndk.cCppSettingValueFlags);
if androidndk.cppExtensions[extension] ~= nil then
table.insert(languageSettingValueFlagsTables, androidndk.cppSettingValueFlags);
else
table.insert(languageSettingValueFlagsTables, androidndk.cSettingValueFlags);
end
languageWarningFlags = androidndk.cCppWarningFlags;
elseif androidndk.rsExtensions[extension] ~= nil then
-- -D and -U are not supported.
languageFlagsSettingFlags = androidndk.rsFlagsSettingFlags;
table.insert(languageSettingValueFlagsTables, androidndk.rsSettingValueFlags);
languageWarningFlags = androidndk.cCppWarningFlags;
end
-- Preprocessor definitions (not supported by the GNU assembler).
-- Potentially with whitespaces, but need to go to a single (quoted) argument.
-- Defines before undefines for consistency with other Premake actions such as Visual Studio.
-- Placing them in separate tables so they're not mixed if both defines are undefines are provided by both the project and the extension filter.
-- Not doing the same for -D and -U provided via raw buildoptions though to avoid interfering with the project-provided order.
if languageDefinesPrefix ~= nil then
if flagsForExtension.defines == nil then
flagsForExtension.defines = {};
end
for i, define in ipairs(config.defines) do
table.insertkeyed(
flagsForExtension.defines,
androidndk.getSingleArgumentPrefixedFlagPostValueEsc(p.esc(define), languageDefinesPrefix, temporaryVariables));
end
end
if languageUndefinesPrefix ~= nil then
if flagsForExtension.undefines == nil then
flagsForExtension.undefines = {};
end
for i, undefine in ipairs(config.undefines) do
table.insertkeyed(
flagsForExtension.undefines,
androidndk.getSingleArgumentPrefixedFlagPostValueEsc(p.esc(undefine), languageUndefinesPrefix, temporaryVariables));
end
end
-- Forced include paths (not supported by the GNU assembler).
if extension == androidndk.asmExtension then
for i, forceInclude in ipairs(config.forceincludes) do
local forceIncludePath = androidndk.getEscapedProjectRelativePath(config.project, forceInclude, true);
if androidndk.staticallyHasPatternPostEsc(forceIncludePath, "[\"';]") then
p.warn(
"Skipping workspace '%s' project '%s' configuration '%s' Yasm force include '%s' with path containing disallowed characters \"';",
config.workspace.name, config.project.name, config.name, forceInclude);
else
table.insertkeyed(
flagsForExtension.buildoptions,
androidndk.getSingleArgumentPrefixedFlagPostValueEsc(forceIncludePath, "-P ", temporaryVariables));
end
end
elseif isCCpp then
-- -include is not supported by RenderScript.
for i, forceInclude in ipairs(config.forceincludes) do
local forceIncludePath = androidndk.getEscapedProjectRelativePath(config.project, forceInclude, true);
-- -include %s becomes #include "%s", the inner " is considered a string terminator.
if androidndk.staticallyHasPatternPostEsc(forceIncludePath, "[\"]") then
p.warn(
"Skipping workspace '%s' project '%s' configuration '%s' C/C++ force include '%s' with path containing a disallowed double quote character",
config.workspace.name, config.project.name, config.name, forceInclude);
else
table.insertkeyed(
flagsForExtension.buildoptions,
androidndk.getSingleArgumentPrefixedFlagPostValueEsc(forceIncludePath, "-include ", temporaryVariables));
end
end
end
-- Flags for configuration flags setting.
if languageFlagsSettingFlags ~= nil then
for i, flagsSettingKeyValue in ipairs(languageFlagsSettingFlags) do
if config.flags[flagsSettingKeyValue.key] then
local flagsSettingValue = flagsSettingKeyValue.value;
if type(flagsSettingValue) ~= "table" then
flagsSettingValue = { flagsSettingValue };
end
for i2, flagsSettingValueBuildOption in ipairs(flagsSettingValue) do
table.insertkeyed(flagsForExtension.buildoptions, p.esc(flagsSettingValueBuildOption));
end
end
end
end
-- Flags for setting values.
for i, languageSettingValueFlags in ipairs(languageSettingValueFlagsTables) do
for i2, languageSettingValueKeyValues in ipairs(languageSettingValueFlags) do
local settingValue = config[languageSettingValueKeyValues.key];
if settingValue ~= nil then
-- Convert boolean to off/on.
if settingValue == false then
settingValue = p.OFF;
elseif settingValue == true then
settingValue = p.ON;
end
local settingValueFlags = languageSettingValueKeyValues.values[settingValue];
if settingValueFlags ~= nil then
if type(settingValueFlags) ~= "table" then
settingValueFlags = { settingValueFlags };
end
for i3, settingValueFlag in ipairs(settingValueFlags) do
table.insertkeyed(flagsForExtension.buildoptions, p.esc(settingValueFlag));
end
end
end
end
end
-- Individual warnings.
-- After generic setting flags which include the default warning behavior so -Wname can override -w.
if languageWarningFlags ~= nil then
for i, warningKeyPrefix in ipairs(languageWarningFlags) do
for i2, warning in ipairs(config[warningKeyPrefix.key]) do
table.insertkeyed(
flagsForExtension.buildoptions,
androidndk.getSingleArgumentPrefixedFlagPostValueEsc(p.esc(warning), warningKeyPrefix.prefix, temporaryVariables));
end
end
end
-- Add raw project-specified flags, as single or multiple arguments, after everything (so they can cancel internal flags).
-- Quoting, or escaping of quotes, must be done by the project instead, as a single build option may contain multiple arguments.
-- Build options are platform-dependent anyway - the module is free to establish any rules.
for i, buildOption in ipairs(config.buildoptions) do
local buildOptionEscaped = p.esc(buildOption);
table.insertkeyed(flagsForExtension.buildoptions, buildOptionEscaped);
if isCCpp and androidndk.isFltoOption(buildOptionEscaped) then
-- Store the last (thus the highest-priority) -flto type used by the language.
-- RenderScript doesn't support -flto.
flagsForExtension.flto = buildOptionEscaped;
end
end
end
-- Defines before undefines for consistency with other Premake actions such as Visual Studio.
-- Everything special before everything generic (including raw project buildoptions) for the same reason.
-- Separate to make sure -D -U -D -U instead of -D -D -U -U doesn't happen if both are provided by both the project and the extension filter.
androidndk.projectCompilerFlagsOrder = { "defines", "undefines", "buildoptions" };
function androidndk.writeProjectCompilerFlags(flagsForAllVariables, variable, escapeShellCharacters)
local flagsForVariable = flagsForAllVariables[variable];
if flagsForVariable == nil then
return false;
end
local flagsForVariableMerged = {};
-- Merge all sources of flags in the correct order.
for i, flagsTableName in ipairs(androidndk.projectCompilerFlagsOrder) do
if flagsForVariable[flagsTableName] ~= nil then
for i2, flag in ipairs(flagsForVariable[flagsTableName]) do
table.insertkeyed(flagsForVariableMerged, flag);
end
end
end
local localVariable = "LOCAL_" .. variable;
if androidndk.assignToVariablePostEsc(localVariable, flagsForVariableMerged, true, androidndk.shellEscapePostQuotesChecker) then
if escapeShellCharacters then
androidndk.writePostProcessCall(localVariable, androidndk.shellEscapePostQuotesMakeCall);
end
return true;
end
return false;
end
-- Built-in flags for ISA and vector extensions.
androidndk.abiIsaExtensions = {
["x86"] = {
MOVBE = "-mmovbe",
POPCNT = "-mpopcnt",
PCLMUL = "-mpclmul",
LZCNT = "-mlzcnt",
BMI = "-mbmi",
BMI2 = "-mbmi2",
F16C = "-mf16c",
AES = "-maes",
FMA = "-mfma",
FMA4 = "-mfma4",
RDRND = "-mrdrnd",
},
};
androidndk.abiIsaExtensions["x86_64"] = androidndk.abiIsaExtensions["x86"];
androidndk.abiVectorExtensions = {
["x86"] = {
-- Up to SSSE3 are required.
["SSE4.1"] = "-msse4.1",
["SSE4.2"] = "-msse4.2",
["AVX"] = "-mavx",
["AVX2"] = "-mavx2",
},
["x86_64"] = {
-- Up to SSE4.2 are required.
["AVX"] = "-mavx",
["AVX2"] = "-mavx2",
},
};
-- Escaped or not doesn't matter.
function androidndk.isFltoOption(option)
-- Remove quotes (so "-flto..." is handled like -flto...).
-- Escaped or not doesn't matter as the pattern being checked doesn't include a backslash.
option = string.gsub(option, "\"", "");
-- Let -flto alone, or -flto=..., pass.
return string.find(option, "^%s*%-flto%s$") ~= nil or string.find(option, "^%s*%-flto=") ~= nil;
end
-- ldFlagsUndefined receives -u and --undefined from `linkoptions`.
-- ldLibsDirFlags receives -L from `linkoptions` and -L for `links`.
-- ldLibsSysDirFlags receives -L for `syslibdirs`.
-- ldLibsLibFlags receives -l from `linkoptions` and -l for `links`.
-- ldFlags receives the rest of `linkoptions`.
-- Any output table can be nil.
-- In this case, only libraries to link to will be obtained and written to ldLibs*Flags.
-- Returns the last encountered (thus highest-priority) -flto option if any is passed (so non-default LTO types can be used with transitivity).
function androidndk.addSingleConfigLinkerFlags(config, ldFlagsUndefined, ldFlags, ldLibsDirFlags, ldLibsSysDirFlags, ldLibsLibFlags, temporaryVariables)
-- NDK passes LDFLAGS before LDLIBS.
-- It also placed local LDLIBS before imported LDLIBS.
-- Entries for the system libraries (`syslibdirs` here specifically) should be the last according to this ordering also.
-- The system can be considered the deepest import of everything.
-- For LDFLAGS, it's the reverse, however - imported LDFLAGS are before local LDFLAGS.
-- This module also distributes `linkoptions` between LDFLAGS and LDLIBS instead of passing all to LDFLAGS.
-- LDLIBS is what's designed to hold the -l flags for the system libraries to link to.
-- While LDFLAGS can contain -l too, it's not the intended way of passing them.
-- The reason why this is taken into consideration, and `linkoptions` are parsed at all, is the special case of name collision resolution.
-- A workspace may contain its own project, for example, named "log", and in this case a "log" link would be considered a sibling link, not a system one.
-- An alternative would be to link to ":liblog.so".
-- However, this will result in a warning as ndk-build uses simpler logic for checking whether only system libraries are specified which fails for that.
-- Therefore, this module offers a way to pass "-llog" via `linkoptions`.
-- Normally though -l should be used only for a small fixed set of Android NDK system libraries.
-- All this logic is therefore a massive overkill.
-- Prebuilt library projects normally should be used instead of -L and -l.
-- However, for the ease of porting, and to avoid adding constraints, letting projects link directly to libraries via raw linker arguments anyway.
-- Specifying anything but -l would throw a warning though.
-- Search paths (-L) apply to all -l options regardless of the order.
-- They can be written to either LDFLAGS or LDLIBS.
-- This module implements dependency transitivity a custom way, stopping iterating at shared libraries (unlike NDK's internal exports).
-- For this purpose, it only imports everything that goes to LDLIBS, but not to LDFLAGS - assuming it contains everything needed for library linkage.
-- So, always writing search paths to LDLIBS here, not to LDFLAGS.
-- Handling `linkoptions` before `links` and `syslibdirs` because the latter is conceptually closer to LDFLAGS, and the latter two to LDLIBS.
-- Considering -L specified in `linkoptions` as the more generic `links` (which are placed before `syslibdirs`) for the same reason as well.
local flto = nil;
local longLinkOptions = {
{
name = "--library",
destination = ldLibsLibFlags,
},
{
name = "--library-path",
destination = ldLibsDirFlags,
},
{
name = "--undefined",
destination = ldFlagsUndefined,
},
};
for i, linkOptionUnescaped in ipairs(config.linkoptions) do
local linkOption = p.esc(linkOptionUnescaped);
-- Check which output table should receive the option.
local linkOptionDestination = ldFlags;
-- -flto is a Clang++ option, not an LLD one - don't check it if there's -Wl.
-- Also, it's either a full option, or an option with a value - check it in a special way for this reason as well.
if androidndk.isFltoOption(linkOption) then
flto = linkOption;
else
-- Trim whitespaces (until the first quote if present).
local linkOptionFirstNonWhitespace = string.find(linkOption, "[%S]");
if linkOptionFirstNonWhitespace ~= nil then
-- Remove quotes (so "-l..." is handled like -l...).
-- Escaped or not doesn't matter as none of the checked prefixes include a backslash.
local linkOptionForPrefix = string.gsub(string.sub(linkOption, linkOptionFirstNonWhitespace, -1), "\"", "");
-- ndk-build passes the flags to Clang++, not to LLD directly.
-- Therefore, most of linker options must be passed via -Wl, and for those that don't, the presence of -Wl doesn't matter.
-- Specifically, -l and -L can be passed to both Clang++ and LLD, but --library and --library-path can't (and require -Wl).
-- -l and -L can be either attached directly to the name or placed in a separate (whitespace-separated) argument.
-- --library and --library-path can be either attached with a = or placed in a separate argument.
-- Since --library and --library-path require -Wl, arguments are comma-separate rather than whitespace-separated.
local wlPrefix = "-Wl,";
local wlPrefixLength = string.len(wlPrefix);
local hasWl = string.sub(linkOption, 1, string.len(wlPrefixLength)) == wlPrefix;
if hasWl then
linkOptionForPrefix = string.sub(linkOptionForPrefix, wlPrefixLength + 1, -1);
end
local linkOptionSingleCharacterPrefix = string.sub(linkOptionForPrefix, 1, 2);
if linkOptionSingleCharacterPrefix == "-u" then
linkOptionDestination = ldFlagsUndefined;
elseif linkOptionSingleCharacterPrefix == "-l" then
linkOptionDestination = ldLibsLibFlags;
elseif linkOptionSingleCharacterPrefix == "-L" then
linkOptionDestination = ldLibsDirFlags;
else
if hasWl then
-- Check if --Wl,--option=value or --Wl,--option,value is used.
for i2, longLinkOption in ipairs(longLinkOptions) do
local longLinkOptionPrefixSub = string.sub(linkOptionForPrefix, 1, string.len(longLinkOption.name));
if longLinkOption.name == (longLinkOptionPrefixSub .. "=") or longLinkOption.name == (longLinkOptionPrefixSub .. ",") then
linkOptionDestination = longLinkOption.destination;
break;
end
end
end
end
end
end
-- Add the flag to the needed table if adding to one was requested at all.
-- Quoting, or escaping of quotes, must be done by the project instead, as a single link option may contain multiple arguments.
-- Link options are platform-dependent anyway - the module is free to establish any rules.
if linkOptionDestination ~= nil then
table.insertkeyed(linkOptionDestination, linkOption);
end
end
-- Local search paths (`libdirs` and `links`).
if ldLibsDirFlags ~= nil then
for i, libDir in ipairs(p.config.getlinks(config, "system", "directory")) do
local libDirRelativePath = androidndk.getEscapedProjectRelativePath(config.project, libDir, true);
table.insertkeyed(
ldLibsDirFlags,
androidndk.getSingleArgumentPrefixedFlagPostValueEsc(libDirRelativePath, "-L", temporaryVariables));
end
end
-- System search paths.
if ldLibsSysDirFlags ~= nil then
for i, sysLibDir in ipairs(config.syslibdirs) do
local sysLibDirRelativePath = androidndk.getEscapedProjectRelativePath(config.project, sysLibDir, true);
table.insertkeyed(
ldLibsSysDirFlags,
androidndk.getSingleArgumentPrefixedFlagPostValueEsc(sysLibDirRelativePath, "-L", temporaryVariables));
end
end
-- Local links.
-- Specifying the : prefix directly in `links` is allowed to force treatment of the name as a full file name instead of a short name.
-- However, just specifying the full file name is also allowed for simplicity of the usage (especially of the usage of full paths).
-- libname.so will be treated as libname.so, not as liblibname.so.a or liblibname.so.so.
-- However, something like name.thumb will be treated as libname.thumb.a/libname.thumb.so still.
-- Making no special assumptions about GNU make references (such as environment variables).
-- The intended usage of LOCAL_LDLIBS is purely for linking to the libraries provided by the Android NDK via their short names anyway.
-- To use, for instance, a full path from an environment variable (or a different kind of a GNU make reference), specify:
-- links({ "$(dir $(VARIABLE))/:$(notdir $(VARIABLE))" })
if ldLibsLibFlags ~= nil then
for i, libName in ipairs(p.config.getlinks(config, "system", "name")) do
local libNamePrefix = "";
if string.sub(libName, 1, 1) ~= ":" then
-- Full name not forced.
-- Check if using the full name anyway.
local libExtension = path.getextension(libName);
if libExtension == ".a" or libExtension == ".so" then
libNamePrefix = ":";
end
end
table.insertkeyed(
ldLibsLibFlags,
androidndk.getSingleArgumentPrefixedFlagPostValueEsc(p.esc(libNamePrefix .. libName), "-l", temporaryVariables));
end
end
return flto;
end
function androidndk.generateProjectConfig(config)
local temporaryVariables = {};
local configAbi = androidndk.getConfigAbi(config);
assert(configAbi ~= nil, "Configurations with invalid ABIs must be skipped in isConfigSupported");
local configUsesA32 = androidndk.configUsesA32(config);
local configUsesNeon = androidndk.configUsesNeon(config);
-- Get the precompiler header path.
-- Handling of the ARM instruction set and NEON is done by ndk-build implicitly, not possible and not needed to specify suffixes.
-- All the inclusion of the built header is done by ndk-build itself implicitly.
-- At this point, it's needed for getting the file configuration for it so, if needed, C++-specific options can be extracted from it.
local pch = nil;
if not config.flags.NoPCH and config.pchheader ~= nil then
pch = androidndk.getEscapedProjectRelativePath(config.project, config.pchheader, false);
-- LOCAL_PCH is involved a value that goes to LOCAL_SRC_FILES internally in ndk-build, so the rules are the same.
-- However, = is also not allowed.
if androidndk.staticallyHasPatternPostEsc(pch, "[%s\"#%$&'%(%),;<=>`|]") then
p.warn(
"Skipping workspace '%s' project '%s' configuration '%s' precompiled header '%s' " ..
"with path containing whitespaces or disallowed characters \"#$&'(),;<=>`|",
config.workspace.name, config.project.name, config.name, pch);
pch = nil;
end
end
local pchFileConfig = nil;
-- Gather source files not excluded from build.
local sourceTree = p.project.getsourcetree(config.project);
local configAbiSupportsYasm = configAbi == "x86" or configAbi == "x86_64" or configAbi == androidndk.ABI_ALL;
-- External Android.mk files and prebuilt libraries.
local sourcePrecreatedFiles = {};
-- Keys - sequential indexes, paths without .arm and .neon suffixes.
-- Values - paths with .arm and .neon suffixes.
local sourceFiles = {};
local sourceFilesYasmConditional = {};
-- includeDirs[variable] and compilerFlags[variable] may be nil if no source files contributing to them have been found yet.
-- Each includeDirs element optionally contains includedirs = {}, sysincludedirs = {}.
local includeDirs = {};
local renderScriptIncludeDirsVariable = iif(config.renderscriptincludedirsoverride == true, "RENDERSCRIPT_INCLUDES_OVERRIDE", "RENDERSCRIPT_INCLUDES");
-- Each compilerFlags element optionally contains defines = {}, undefines = {}, buildoptions (used for the rest of flags) = {}, flto = "...".
-- flto, if present, contains the last -flto flag encountered for this extension.
local compilerFlags = {};
-- For simplicity, for project-defined flags, using separate CONLYFLAGS and CPPFLAGS.
-- Using LOCAL_CFLAGS is also undesirable because they go not only to C and C++, but to GNU assembly as well.
-- See the definition of ev-compile-s-source in ndk-build.
local configIncludeDirsAdded = {};