├── .gitignore ├── .gitmodules ├── generate.bat ├── NOTICE ├── Marefile ├── Src ├── Mare.h ├── Main.cpp ├── Make.h ├── Make.cpp └── Mare.cpp └── LICENSE /.gitignore: -------------------------------------------------------------------------------- 1 | /Build 2 | /.vs 3 | *.vcxproj 4 | *.vcxproj.filters 5 | *.sdf 6 | *.opensdf 7 | *.sln 8 | *.suo -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "Ext/mare"] 2 | path = Ext/mare 3 | url = https://github.com/craflin/mare.git 4 | [submodule "Ext/libnstd"] 5 | path = Ext/libnstd 6 | url = https://github.com/craflin/libnstd.git 7 | -------------------------------------------------------------------------------- /generate.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | if not exist Build\Debug\.mare\mare.exe call Ext\mare\compile.bat --buildDir=Build/Debug/.mare --outputDir=Build/Debug/.mare --sourceDir=Ext/mare/src 4 | if not "%1"=="" (Build\Debug\.mare\mare.exe %*) else Build\Debug\.mare\mare.exe --vcxproj=2013 5 | -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | 2 | Copyright 2014 Colin Graf 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | -------------------------------------------------------------------------------- /Marefile: -------------------------------------------------------------------------------- 1 | 2 | buildDir = "Build/$(configuration)/.$(target)" 3 | 4 | targets = { 5 | 6 | make2mare = cppApplication + { 7 | dependencies = { "libnstd" } 8 | outputDir = "Build/$(configuration)" 9 | includePaths = { "Ext/libnstd/include" } 10 | libPaths = { "Build/$(configuration)/.libnstd" } 11 | libs = { "nstd" } 12 | root = "Src" 13 | files = { 14 | "Src/**.cpp" = cppSource 15 | "Src/**.h" 16 | } 17 | if tool == "vcxproj" { 18 | linkFlags += { "/SUBSYSTEM:CONSOLE" } 19 | } 20 | if platform == "Linux" { 21 | libs += { "pthread", "rt" } 22 | cppFlags += { "-Wno-delete-non-virtual-dtor" } 23 | } 24 | } 25 | 26 | include "Ext/libnstd/libnstd.mare" 27 | libnstd += { 28 | folder = "Ext" 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Src/Mare.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #include "Make.h" 9 | 10 | class Variant; 11 | 12 | class Mare 13 | { 14 | public: 15 | Mare(const String& configuration, const Make& make); 16 | 17 | void generateMare(const String& outputFile); 18 | 19 | private: 20 | class Configruation 21 | { 22 | public: 23 | }; 24 | 25 | class Target 26 | { 27 | public: 28 | class SourceFile 29 | { 30 | public: 31 | String type; 32 | HashSet cppFlags; 33 | HashSet includePaths; 34 | HashSet defines; 35 | String buildDir; 36 | }; 37 | 38 | public: 39 | String type; 40 | 41 | HashSet cppFlags; 42 | HashSet includePaths; 43 | HashSet defines; 44 | String buildDir; 45 | String outputDir; 46 | 47 | HashSet linkFlags; 48 | HashSet libPaths; 49 | HashSet libs; 50 | 51 | HashMap files; 52 | HashSet additionalInputs; 53 | }; 54 | 55 | private: 56 | HashMap targets; 57 | File file; 58 | 59 | private: 60 | void addTarget(const Make::Target& makeTarget); 61 | 62 | void fileOpen(const String& path); 63 | void fileWrite(const String& data); 64 | void fileWrite(const String& tabs, const Variant& data); 65 | 66 | void addHashSet(Variant& variant, const HashSet& set); 67 | }; 68 | -------------------------------------------------------------------------------- /Src/Main.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | 6 | #include "Make.h" 7 | #include "Mare.h" 8 | 9 | int main(int argc, char* argv[]) 10 | { 11 | // parse args 12 | HashMap configurations; 13 | for(int i = 1; i < argc; ++i) 14 | { 15 | String arg; 16 | arg.attach(argv[i], String::length(argv[i])); 17 | if(arg.startsWith("-")) 18 | { 19 | // ./make2mare Release Debug:DEBUG=yess 20 | Console::printf("Usage: %s [ [:] [ [:] ... ] ]\n", argv[0]); 21 | return -1; 22 | } 23 | else 24 | { 25 | String configName = arg; 26 | String makeArgs; 27 | const char* colon = configName.find(':'); 28 | if(colon) 29 | { 30 | size_t colonIndex = colon - (const char*)configName; 31 | configName = arg.substr(0, colonIndex); 32 | makeArgs = arg.substr(colonIndex + 1); 33 | } 34 | configurations.append(configName, makeArgs); 35 | } 36 | } 37 | if(configurations.isEmpty()) 38 | configurations.append("Release", String()); 39 | 40 | for(HashMap::Iterator i = configurations.begin(), end = configurations.end(); i != end; ++i) 41 | { 42 | Make make; 43 | if(!make.load(*i)) 44 | return -1; 45 | make.parse(); 46 | Mare mare(i.key(), make); 47 | mare.generateMare("Marefile"); 48 | break; // todo: support more than just the first configuration 49 | } 50 | 51 | return 0; 52 | } 53 | -------------------------------------------------------------------------------- /Src/Make.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | class Make 11 | { 12 | public: 13 | class SourceFile 14 | { 15 | public: 16 | String tool; 17 | String inputFile; 18 | HashSet cppFlags; 19 | HashSet includePaths; 20 | HashSet defines; 21 | }; 22 | 23 | class Target 24 | { 25 | public: 26 | String tool; 27 | String outputFile; 28 | HashSet linkFlags; 29 | HashSet libPaths; 30 | HashSet libs; 31 | HashSet inputFiles; 32 | HashMap files; 33 | }; 34 | 35 | public: 36 | List targets; 37 | 38 | public: 39 | bool load(const String& makeArgs); 40 | void parse(); 41 | 42 | /* 43 | 44 | void processData() 45 | { 46 | for(HashMap::Iterator i = targets.begin(), end = targets.end(); i != end; ++i) 47 | { 48 | Target& target = *i; 49 | processData(target); 50 | } 51 | } 52 | 53 | void processData(Target& target) 54 | { 55 | // removed object files that are not used as input files 56 | for(HashMap::Iterator i = target.files.begin(), end = target.files.end(); i != end;) 57 | { 58 | const String& objectFile = i.key(); 59 | HashSet::Iterator it = target.inputFiles.find(objectFile); 60 | if(it == target.inputFiles.end()) 61 | { 62 | // todo: print warning 63 | i = target.files.remove(i); 64 | } 65 | else 66 | { 67 | ++i; 68 | target.inputFiles.remove(it); 69 | } 70 | } 71 | 72 | // build global flag list 73 | HashSet cppFlags; 74 | HashSet includePaths; 75 | HashSet defines; 76 | for(HashMap::Iterator i = target.files.begin(), end = target.files.end(); i != end;) 77 | { 78 | const SourceFile& sourceFile = *i; 79 | cppFlags.append(sourceFile.cppFlags); 80 | includePaths.append(sourceFile.includePaths); 81 | defines.append(sourceFile.defines); 82 | } 83 | 84 | for(HashMap::Iterator j = target.files.begin(), end = target.files.end(); j != end;) 85 | { 86 | const SourceFile& sourceFile = *j; 87 | HashSet diffCppFlags(cppFlags); 88 | HashSet diffIncludePaths(includePaths); 89 | HashSet diffDefines(defines); 90 | diffCppFlags.remove(sourceFile.cppFlags); 91 | diffIncludePaths.remove(sourceFile.includePaths); 92 | diffDefines.remove(sourceFile.defines); 93 | cppFlags.remove(diffCppFlags); 94 | includePaths.remove(diffIncludePaths); 95 | defines.remove(diffDefines); 96 | } 97 | for(HashMap::Iterator j = target.files.begin(), end = target.files.end(); j != end;) 98 | { 99 | SourceFile& sourceFile = *j; 100 | sourceFile.cppFlags.remove(cppFlags); 101 | sourceFile.includePaths.remove(includePaths); 102 | sourceFile.defines.remove(defines); 103 | } 104 | target.cppFlags.swap(cppFlags); 105 | target.includePaths.swap(includePaths); 106 | target.defines.swap(defines); 107 | } 108 | 109 | void generateMare(Mare& mare, const String& outputFile) 110 | { 111 | fileOpen(outputFile); 112 | fileWrite("targets = {\n"); 113 | 114 | fileWrite("}\n"); 115 | } 116 | 117 | */ 118 | 119 | private: 120 | List lines; 121 | 122 | private: 123 | static String buildFilePath(const String& rootDir, const String& cwd, const String& inputPath); 124 | static void splitArgs(const String& command, HashSet& args); 125 | }; 126 | -------------------------------------------------------------------------------- /Src/Make.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | 5 | #include "Make.h" 6 | 7 | bool Make::load(const String& makeArgs) 8 | { 9 | Process process; 10 | if(!process.open(String("make -B -n -w ") + makeArgs, Process::stdoutStream)) 11 | return false; 12 | Buffer buffer; 13 | buffer.resize(4098); 14 | size_t bufferSize = 0; 15 | size_t i; 16 | String line; 17 | while((i = process.read((byte*)buffer + bufferSize, buffer.size() - bufferSize)) > 0) 18 | { 19 | bufferSize += i; 20 | for(;;) 21 | { 22 | const char* start = (const char*)(const byte*)buffer; 23 | const char* end = String::find(start, '\n'); 24 | if(!end) 25 | { 26 | if(bufferSize == buffer.size()) 27 | buffer.resize(buffer.size() * 2); 28 | break; 29 | } 30 | *(char*)end = '\0'; 31 | size_t len = end - start; 32 | line.attach(start, len); 33 | lines.append(line); 34 | ++len; 35 | buffer.removeFront(len); 36 | buffer.resize(buffer.capacity()); 37 | } 38 | } 39 | return true; 40 | } 41 | 42 | void Make::parse() 43 | { 44 | HashMap files; 45 | HashSet args; 46 | String cwd; 47 | List cwdStack; 48 | String rootDir; 49 | for(List::Iterator i = lines.begin(), end = lines.end(); i != end; ++i) 50 | { 51 | const String& line = *i; 52 | splitArgs(line, args); 53 | if(args.isEmpty()) 54 | continue; 55 | const String& tool = args.front(); 56 | if(tool.startsWith("make[") || tool.startsWith("make:")) 57 | { 58 | const char* dir = tool.find("Entering directory"); 59 | if(dir) 60 | { 61 | dir += 18; 62 | while(String::find(" '\"`", *dir)) 63 | ++dir; 64 | const char* end = String::findOneOf(dir, dir[-1] == ' ' ? " '\"`" : "'\"`"); 65 | cwd = File::simplifyPath(String(dir, end ? end - dir : String::length(dir))); 66 | cwdStack.append(cwd); 67 | if(rootDir.isEmpty()) 68 | rootDir = cwd; 69 | } 70 | else if(tool.find("Leaving directory")) 71 | { 72 | cwdStack.removeBack(); 73 | cwd = cwdStack.isEmpty() ? String() : cwdStack.back(); 74 | } 75 | else 76 | { 77 | // todo: print warning 78 | } 79 | } 80 | else if(tool == "g++" || tool == "gcc") 81 | { 82 | if(args.find("-c") != args.end()) // source file 83 | { 84 | HashSet cppFlags; 85 | HashSet includePaths; 86 | HashSet defines; 87 | String outputFile; 88 | String inputFile; 89 | for(HashSet::Iterator i = ++args.begin(), end = args.end(); i != end; ++i) 90 | { 91 | const String& arg = *i; 92 | if(arg == "-o") // output file 93 | { 94 | HashSet::Iterator next = i; ++next; 95 | if(next != end) 96 | { 97 | outputFile = buildFilePath(rootDir, cwd, *next); 98 | i = next; 99 | } 100 | } 101 | else if(arg.startsWith("-I")) // include path 102 | includePaths.append(buildFilePath(rootDir, cwd, arg.substr(2))); 103 | else if(arg.startsWith("-D")) // define 104 | defines.append(arg.substr(2)); 105 | else if(arg.startsWith("-")) // cpp flag 106 | cppFlags.append(arg); 107 | else 108 | inputFile = arg; 109 | } 110 | if(!outputFile.isEmpty()) 111 | { 112 | SourceFile& sourceFile = files.append(outputFile, SourceFile()); 113 | sourceFile.tool = tool; 114 | sourceFile.inputFile = inputFile; 115 | sourceFile.cppFlags.swap(cppFlags); 116 | sourceFile.includePaths.swap(includePaths); 117 | sourceFile.defines.swap(defines); 118 | } 119 | else 120 | { 121 | // todo: print warnig 122 | } 123 | } 124 | else // target 125 | { 126 | HashSet linkFlags; 127 | HashSet libPaths; 128 | HashSet libs; 129 | String outputFile; 130 | HashSet inputFiles; 131 | for(HashSet::Iterator i = ++args.begin(), end = args.end(); i != end; ++i) 132 | { 133 | const String& arg = *i; 134 | if(arg == "-o") // output file 135 | { 136 | HashSet::Iterator next = i; ++next; 137 | if(next != end) 138 | { 139 | outputFile = buildFilePath(rootDir, cwd, *next); 140 | i = next; 141 | } 142 | } 143 | else if(arg.startsWith("-L")) // lib path 144 | libPaths.append(buildFilePath(rootDir, cwd, arg.substr(2))); 145 | else if(arg.startsWith("-l")) // lib 146 | libs.append(arg.substr(2)); 147 | else if(arg.startsWith("-")) // cpp flag 148 | linkFlags.append(arg); 149 | else 150 | inputFiles.append(arg); 151 | } 152 | if(!outputFile.isEmpty()) 153 | { 154 | Target& target = targets.append(Target()); 155 | target.tool = tool; 156 | target.outputFile = outputFile, 157 | target.linkFlags.swap(linkFlags); 158 | target.libPaths.swap(libPaths); 159 | target.libs.swap(libs); 160 | target.inputFiles.swap(inputFiles); 161 | target.files.swap(files); 162 | } 163 | else 164 | { 165 | // todo: print warnig 166 | } 167 | } 168 | } 169 | else if(tool == "echo" || tool == "mkdir") 170 | { 171 | // ignore 172 | } 173 | else 174 | { 175 | // todo: print warnig 176 | } 177 | } 178 | } 179 | 180 | String Make::buildFilePath(const String& rootDir, const String& cwd, const String& inputPath) 181 | { 182 | String path = File::isAbsolutePath(inputPath) ? inputPath : File::simplifyPath(cwd + "/" + inputPath); 183 | String relPath = File::getRelativePath(rootDir, path); 184 | return relPath.startsWith("..") ? path : relPath; 185 | } 186 | 187 | void Make::splitArgs(const String& command, HashSet& args) 188 | { 189 | args.clear(); 190 | const char* str = command; 191 | for(;;) 192 | { 193 | while(String::isSpace(*str)) 194 | ++str; 195 | String arg; 196 | if(*str == '"') 197 | { 198 | yeahQuote: 199 | ++str; 200 | while(*str) 201 | { 202 | if(*str == '"') 203 | break; 204 | else if(*str == '\\') 205 | { 206 | if(str[1] == '\\' || str[1] == '"') 207 | { 208 | arg.append(str[1]); 209 | str += 2; 210 | } 211 | else 212 | { 213 | arg.append(*str); 214 | ++str; 215 | } 216 | } 217 | else 218 | { 219 | arg.append(*str); 220 | ++str; 221 | } 222 | } 223 | args.append(arg); 224 | } 225 | else 226 | { 227 | while(*str && !String::isSpace(*str)) 228 | { 229 | if(*str == '"') 230 | goto yeahQuote; 231 | else 232 | { 233 | arg.append(*str); 234 | ++str; 235 | } 236 | } 237 | args.append(arg); 238 | } 239 | } 240 | } 241 | 242 | -------------------------------------------------------------------------------- /Src/Mare.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include "Mare.h" 8 | #include "Make.h" 9 | 10 | Mare::Mare(const String& configuration, const Make& make) 11 | { 12 | for(List::Iterator i = make.targets.begin(), end = make.targets.end(); i != end; ++i) 13 | { 14 | const Make::Target& makeTarget = *i; 15 | addTarget(makeTarget); 16 | } 17 | } 18 | 19 | void Mare::addTarget(const Make::Target& makeTarget) 20 | { 21 | String extension = File::extension(makeTarget.outputFile); 22 | String targetName = File::basename(makeTarget.outputFile, extension); 23 | Target& target = targets.append(targetName, Target()); 24 | 25 | HashSet inputFiles = makeTarget.inputFiles; 26 | for(HashMap::Iterator i = makeTarget.files.begin(), end = makeTarget.files.end(); i != end; ++i) 27 | { 28 | const Make::SourceFile& sourceFile = *i; 29 | const String& objectFile = i.key(); 30 | HashSet::Iterator it = inputFiles.find(objectFile); 31 | if(it == inputFiles.end()) 32 | { 33 | // todo: print warning 34 | } 35 | else 36 | { 37 | inputFiles.remove(it); 38 | Target::SourceFile& file = target.files.append(sourceFile.inputFile, Target::SourceFile()); 39 | file.cppFlags = sourceFile.cppFlags; 40 | file.defines = sourceFile.defines; 41 | file.includePaths = sourceFile.includePaths; 42 | file.buildDir = File::dirname(objectFile); 43 | 44 | if(sourceFile.tool == "g++") 45 | file.type = "cppSource"; 46 | else if(sourceFile.tool == "gcc") 47 | file.type = "cSource"; 48 | } 49 | } 50 | target.additionalInputs.swap(inputFiles); 51 | 52 | // build global flag list 53 | HashSet cppFlags; 54 | HashSet includePaths; 55 | HashSet defines; 56 | String buildDir; 57 | for(HashMap::Iterator i = target.files.begin(), end = target.files.end(); i != end;) 58 | { 59 | const Target::SourceFile& file = *i; 60 | cppFlags.append(file.cppFlags); 61 | includePaths.append(file.includePaths); 62 | defines.append(file.defines); 63 | 64 | if(buildDir.isEmpty()) 65 | buildDir = file.buildDir; 66 | else if(file.buildDir != buildDir && buildDir != ".") 67 | { 68 | String fileBuildDir = File::dirname(file.buildDir); 69 | for(;;) 70 | { 71 | if(fileBuildDir.length() > buildDir.length() && fileBuildDir.startsWith(buildDir)) 72 | { 73 | char lastChar = ((const char*)fileBuildDir)[buildDir.length()]; 74 | if(lastChar == '/' || lastChar == '\\') 75 | break; 76 | } 77 | else if(fileBuildDir == buildDir) 78 | break; 79 | buildDir = File::dirname(buildDir); 80 | if(buildDir == ".") 81 | break; 82 | } 83 | } 84 | } 85 | if(buildDir == ".") 86 | buildDir.clear(); 87 | 88 | for(HashMap::Iterator i = target.files.begin(), end = target.files.end(); i != end;) 89 | { 90 | const Target::SourceFile& file = *i; 91 | HashSet diffCppFlags(cppFlags); 92 | HashSet diffIncludePaths(includePaths); 93 | HashSet diffDefines(defines); 94 | diffCppFlags.remove(file.cppFlags); 95 | diffIncludePaths.remove(file.includePaths); 96 | diffDefines.remove(file.defines); 97 | cppFlags.remove(diffCppFlags); 98 | includePaths.remove(diffIncludePaths); 99 | defines.remove(diffDefines); 100 | } 101 | for(HashMap::Iterator j = target.files.begin(), end = target.files.end(); j != end;) 102 | { 103 | Target::SourceFile& file = *j; 104 | file.cppFlags.remove(cppFlags); 105 | file.includePaths.remove(includePaths); 106 | file.defines.remove(defines); 107 | if(file.buildDir == buildDir) 108 | file.buildDir.clear(); 109 | else if(file.buildDir.length() > buildDir.length() && file.buildDir.startsWith(buildDir)) 110 | { 111 | char lastChar = ((const char*)file.buildDir)[buildDir.length()]; 112 | if(lastChar == '/' || lastChar == '\\') 113 | file.buildDir = String("$(buildDir)") + file.buildDir.substr(buildDir.length()); 114 | } 115 | } 116 | target.cppFlags.swap(cppFlags); 117 | target.includePaths.swap(includePaths); 118 | target.defines.swap(defines); 119 | target.buildDir = buildDir; 120 | target.outputDir = File::dirname(makeTarget.outputFile); 121 | if(!buildDir.isEmpty() && target.outputDir == target.buildDir) 122 | target.outputDir = String(); 123 | 124 | // determine type 125 | if(makeTarget.tool == "gcc") 126 | { 127 | if(extension == "so") 128 | target.type = "cDynamicLibrary"; 129 | else 130 | target.type = "cApplication"; 131 | } 132 | else if(makeTarget.tool == "g++") 133 | { 134 | if(extension == "so") 135 | target.type = "cppDynamicLibrary"; 136 | else 137 | target.type = "cppApplication"; 138 | } 139 | else if(makeTarget.tool == "ar") 140 | { 141 | bool isC = true; 142 | for(HashMap::Iterator i = target.files.begin(), end = target.files.end(); i != end; ++i) 143 | { 144 | const Target::SourceFile& file = *i; 145 | if(file.type != "cSource") 146 | { 147 | isC = false; 148 | break; 149 | } 150 | } 151 | if(isC) 152 | target.type = "cStaticLibrary"; 153 | else 154 | target.type = "cppStaticLibrary"; 155 | } 156 | } 157 | 158 | void Mare::fileOpen(const String& path) 159 | { 160 | if(!file.open(path)) 161 | { 162 | Console::errorf("Could not open output file %s: %s\n", (const char*)path, (const char*)Error::getErrorString()); 163 | Process::exit(1); 164 | } 165 | } 166 | 167 | void Mare::fileWrite(const String& data) 168 | { 169 | if(!file.write(data)) 170 | { 171 | Console::errorf("Could not write to output file: %s\n", (const char*)Error::getErrorString()); 172 | Process::exit(1); 173 | } 174 | } 175 | 176 | void Mare::fileWrite(const String& tabs, const Variant& data) 177 | { 178 | const HashMap& dataVar = data.toMap(); 179 | for(HashMap::Iterator i = dataVar.begin(), end = dataVar.end(); i != end; ++i) 180 | { 181 | const String& key = i.key(); 182 | const Variant& var = *i; 183 | if(key == ".type") 184 | continue; 185 | if(var.getType() == Variant::mapType) 186 | { 187 | const HashMap& dataVar = data.toMap(); 188 | Variant& type = *dataVar.find(".type"); 189 | if(!type.isNull()) 190 | fileWrite(tabs + key + " = " + type.toString() + "{\n"); 191 | else 192 | fileWrite(tabs + key + " = {\n"); 193 | fileWrite(tabs + " ", var); 194 | fileWrite(tabs + "}\n"); 195 | } 196 | else if(var.getType() == Variant::listType) 197 | { 198 | const List& listVar = var.toList(); 199 | for(List::Iterator i = listVar.begin(), end = listVar.end(); i != end; ++i) 200 | fileWrite(tabs + "\"" + i->toString() + "\"\n"); 201 | } 202 | else 203 | fileWrite(tabs + key + " = \"" + var.toString() + "\"\n"); 204 | } 205 | } 206 | 207 | void Mare::addHashSet(Variant& variant, const HashSet& set) 208 | { 209 | List& listVar = variant.toList(); 210 | for(HashSet::Iterator i = set.begin(), end = set.end(); i != end; ++i) 211 | listVar.append(*i); 212 | } 213 | 214 | void Mare::generateMare(const String& outputFile) 215 | { 216 | Variant data; 217 | HashMap& targetsVar = data.toMap().append("targets", Variant()).toMap(); 218 | for(const HashMap::Iterator i = targets.begin(), end = targets.end(); i != end; ++i) 219 | { 220 | const String& targetName = i.key(); 221 | const Target& target = *i; 222 | HashMap& targetVar = targetsVar.append(targetName, Variant()).toMap(); 223 | 224 | if(!target.type.isEmpty()) 225 | targetVar.append(".type", target.type); 226 | if(!target.cppFlags.isEmpty()) 227 | addHashSet(targetVar.append("cppFlags", Variant()), target.cppFlags); 228 | if(!target.includePaths.isEmpty()) 229 | addHashSet(targetVar.append("includePaths", Variant()), target.includePaths); 230 | if(!target.defines.isEmpty()) 231 | addHashSet(targetVar.append("defines", Variant()), target.defines); 232 | if(!target.buildDir.isEmpty()) 233 | targetVar.append("buildDir", target.buildDir); 234 | if(!target.outputDir.isEmpty()) 235 | targetVar.append("outputDir", target.outputDir); 236 | if(!target.linkFlags.isEmpty()) 237 | addHashSet(targetVar.append("linkFlags", Variant()), target.linkFlags); 238 | if(!target.libPaths.isEmpty()) 239 | addHashSet(targetVar.append("libPaths", Variant()), target.libPaths); 240 | if(!target.libs.isEmpty()) 241 | addHashSet(targetVar.append("libs", Variant()), target.libs); 242 | 243 | HashMap& filesVar = targetVar.append("files", Variant()).toMap(); 244 | for(HashMap::Iterator i = target.files.begin(), end = target.files.end(); i != end; ++i) 245 | { 246 | const String& inputFile = i.key(); 247 | const Target::SourceFile& file = *i; 248 | if(!file.type.isEmpty()) 249 | targetVar.append(".type", file.type); 250 | if(!file.cppFlags.isEmpty()) 251 | addHashSet(targetVar.append("cppFlags", Variant()), target.cppFlags); 252 | if(!file.includePaths.isEmpty()) 253 | addHashSet(targetVar.append("includePaths", Variant()), target.includePaths); 254 | if(!file.defines.isEmpty()) 255 | addHashSet(targetVar.append("defines", Variant()), target.defines); 256 | if(!file.buildDir.isEmpty()) 257 | targetVar.append("buildDir", file.buildDir); 258 | } 259 | } 260 | 261 | fileOpen(outputFile); 262 | fileWrite("", data); 263 | } 264 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | --------------------------------------------------------------------------------