private AndroidMk GetMk() { if (!_gotMk) { _cachedMk = androidMkProvider.GetFile(); _gotMk = true; } return(_cachedMk); }
public void SerializeFile(AndroidMk mk) { if (!File.Exists(path + ".backup")) { File.Copy(path, path + ".backup"); } var sb = new StringBuilder(); foreach (var l in mk.Prefix) { sb.AppendLine(l); } foreach (var m in mk.Modules) { foreach (var p in m.PrefixLines) { sb.AppendLine(p); } sb.AppendLine("LOCAL_MODULE := " + m.Id); if (!string.IsNullOrEmpty(m.ExportIncludes)) { sb.AppendLine("LOCAL_EXPORT_C_INCLUDES := " + m.ExportIncludes); } if (m.ExportCFlags.Any()) { sb.AppendLine("LOCAL_EXPORT_C_FLAGS := " + string.Join(' ', m.CppFeatures)); } if (m.Src.Count == 1) { sb.AppendLine("LOCAL_SRC_FILES := " + m.Src.First()); } else { foreach (var src in m.Src) { sb.AppendLine("LOCAL_SRC_FILES += " + src); } } if (m.SharedLibs.Any()) { foreach (var lib in m.SharedLibs) { sb.AppendLine("LOCAL_SHARED_LIBRARIES += " + lib); } } if (m.LdLibs.Any()) { sb.AppendLine("LOCAL_LDLIBS += " + string.Join(' ', m.LdLibs)); } if (m.CFlags.Any()) { sb.AppendLine("LOCAL_CFLAGS += " + string.Join(' ', m.CFlags)); } if (m.CppFlags.Any()) { sb.AppendLine("LOCAL_CPPFLAGS += " + string.Join(' ', m.CppFlags)); } if (m.CIncludes.Any()) { sb.AppendLine("LOCAL_C_INCLUDES += " + string.Join(' ', m.CIncludes)); } if (m.CppFeatures.Any()) { sb.AppendLine("LOCAL_CPP_FEATURES += " + string.Join(' ', m.CppFeatures)); } // Suffix all unknown lines, hopefully this is good enough foreach (var e in m.ExtraLines) { sb.AppendLine(e); } sb.AppendLine(m.BuildLine); } foreach (var s in mk.Suffix) { sb.AppendLine(s); } // Throws File.WriteAllText(path, sb.ToString()); }
public AndroidMk GetFile() { var mk = new AndroidMk(); try { var lines = File.ReadAllLines(path); bool inModule = false; bool firstModuleFound = false; var module = new Module(); foreach (var line in lines) { if (!firstModuleFound) { mk.Prefix.Add(line); } else if (!inModule) { module.PrefixLines.Add(line); } else { // Check if mod end if (line.StartsWith("include $(")) { module.BuildLine = line; mk.Modules.Add(module); // Exit module with build statement inModule = false; // Create new module to populate prefix for module = new Module(); continue; } // Parse line var parsed = BreakString(line, out var type); if (parsed is null) { // If line can't be parsed, skip continue; } if (line.StartsWith("LOCAL_MODULE")) { module.Id = parsed; } else if (line.StartsWith("LOCAL_SRC_FILES")) { if (type == Concat.Set) { module.Src.Clear(); } module.Src.AddRange(ParseLine(parsed)); } else if (line.StartsWith("LOCAL_EXPORT_C_INCLUDES")) { if (type == Concat.Set) { module.ExportIncludes = string.Empty; } module.ExportIncludes += parsed; } else if (line.StartsWith("LOCAL_EXPORT_CFLAGS")) { if (type == Concat.Set) { module.ExportCFlags.Clear(); } module.ExportCFlags.AddRange(ParseLine(parsed)); } else if (line.StartsWith("LOCAL_SHARED_LIBRARIES")) { if (type == Concat.Set) { module.SharedLibs.Clear(); } module.SharedLibs.AddRange(ParseLine(parsed)); } else if (line.StartsWith("LOCAL_LDLIBS")) { if (type == Concat.Set) { module.LdLibs.Clear(); } module.LdLibs.AddRange(ParseLine(parsed)); } else if (line.StartsWith("LOCAL_CFLAGS")) { if (type == Concat.Set) { module.CFlags.Clear(); } module.CFlags.AddRange(ParseLine(parsed)); } else if (line.StartsWith("LOCAL_CPPFLAGS")) { if (type == Concat.Set) { module.CppFlags.Clear(); } module.CppFlags.AddRange(ParseLine(parsed)); } else if (line.StartsWith("LOCAL_C_INCLUDES")) { if (type == Concat.Set) { module.CIncludes.Clear(); } module.CIncludes.AddRange(ParseLine(parsed)); } else if (line.StartsWith("LOCAL_CPP_FEATURES")) { if (type == Concat.Set) { module.CppFeatures.Clear(); } module.CppFeatures.AddRange(ParseLine(parsed)); } else { module.ExtraLines.Add(line); } } if (line.StartsWith("include $(CLEAR_VARS)")) { // Enter module inModule = true; firstModuleFound = true; } } // Add last portion of module prefix to suffix of mk mk.Suffix.AddRange(module.PrefixLines); return(mk); } catch { return(null); } }