<commit_before>
#include <cstdio>
#include <cassert>

#include "Builder.h"

#include "../libmare/Tools/Process.h"
#include "../libmare/Tools/File.h"
#include "../libmare/Tools/Directory.h"
#include "../libmare/Tools/Words.h"
#include "../libmare/Engine.h"

bool Builder::build(const Map<String, String>& userArgs)
{
  // add default rules and stuff
  engine.addDefaultKey("CC", "gcc");
  engine.addDefaultKey("CXX", "g++");
  engine.addDefaultKey("AR", "ar");
  engine.enterDefaultKey("configurations");
    engine.addResolvableKey("Debug");
    engine.addResolvableKey("Release");
  engine.leaveKey();
  engine.addDefaultKey("targets");
  engine.addDefaultKey("buildDir", "$(configuration)");
  engine.enterDefaultKey("cppApplication");
    engine.addResolvableKey("input", "$(foreach file,$(filter %.c%,$(files)),$(buildDir)/$(patsubst %.%,%.o,$(subst ../,,$(file))))");
    engine.addResolvableKey("output", "$(buildDir)/$(target)$(if $(windows),.exe)");
    engine.addResolvableKey("command", "$(CXX) -o $(output) $(input) $(linkFlags) $(LDFLAGS) $(patsubst %,-L%,$(libPaths)) $(patsubst %,-l%,$(libs))");
    engine.addResolvableKey("message", "Linking $(target)...");
  engine.leaveKey();
  engine.enterDefaultKey("cppDynamicLibrary");
    engine.addResolvableKey("input", "$(foreach file,$(filter %.c%,$(files)),$(buildDir)/$(patsubst %.%,%.o,$(subst ../,,$(file))))");
    engine.addResolvableKey("output", "$(buildDir)/$(if $(windows),,lib)$(target)$(if $(windows),.dll,.so)");
    engine.addResolvableKey("__soFlags", "-fpic");
    engine.addResolvableKey("command", "$(CXX) -shared $(__soFlags) -o $(output) $(input) $(linkFlags) $(LDFLAGS) $(patsubst %,-L%,$(libPaths)) $(patsubst %,-l%,$(libs))");
    engine.addResolvableKey("message", "Linking $(target)...");
  engine.leaveKey();
  engine.enterDefaultKey("cppStaticLibrary");
    engine.addResolvableKey("input", "$(foreach file,$(filter %.c%,$(files)),$(buildDir)/$(patsubst %.%,%.o,$(subst ../,,$(file))))");
    engine.addResolvableKey("output", "$(buildDir)/$(if $(windows),,lib)$(target)$(if $(windows),.lib,.a)");
    engine.addResolvableKey("command", "$(AR) rcs $(output) $(input)");
    engine.addResolvableKey("message", "Creating $(target)...");
  engine.leaveKey();
  engine.enterDefaultKey("cApplication");
    engine.addResolvableKey("input", "$(foreach file,$(filter %.c%,$(files)),$(buildDir)/$(patsubst %.%,%.o,$(subst ../,,$(file))))");
    engine.addResolvableKey("output", "$(buildDir)/$(target)$(if $(windows),.exe)");
    engine.addResolvableKey("command", "$(CC) -o $(output) $(input) $(linkFlags) $(LDFLAGS) $(patsubst %,-L%,$(libPaths)) $(patsubst %,-l%,$(libs))");
    engine.addResolvableKey("message", "Linking $(target)...");
  engine.leaveKey();
  engine.enterDefaultKey("cDynamicLibrary");
    engine.addResolvableKey("input", "$(foreach file,$(filter %.c%,$(files)),$(buildDir)/$(patsubst %.%,%.o,$(subst ../,,$(file))))");
    engine.addResolvableKey("output", "$(buildDir)/$(if $(windows),,lib)$(target)$(if $(windows),.dll,.so)");
    engine.addResolvableKey("__soFlags", "-fpic");
    engine.addResolvableKey("command", "$(CC) -shared $(__soFlags) -o $(output) $(input) $(linkFlags) $(LDFLAGS) $(patsubst %,-L%,$(libPaths)) $(patsubst %,-l%,$(libs))");
    engine.addResolvableKey("message", "Linking $(target)...");
  engine.leaveKey();
  engine.enterDefaultKey("cStaticLibrary");
    engine.addResolvableKey("input", "$(foreach file,$(filter %.c%,$(files)),$(buildDir)/$(patsubst %.%,%.o,$(subst ../,,$(file))))");
    engine.addResolvableKey("output", "$(buildDir)/$(if $(windows),,lib)$(target)$(if $(windows),.lib,.a)");
    engine.addResolvableKey("command", "$(AR) rcs $(output) $(input)");
    engine.addResolvableKey("message", "Creating $(target)...");
  engine.leaveKey();
  engine.enterDefaultKey("cppSource");
    engine.addResolvableKey("ofile", "$(buildDir)/$(patsubst %.%,%.o,$(subst ../,,$(file)))");
    engine.addResolvableKey("dfile", "$(patsubst %.o,%.d,$(ofile))");
    engine.addResolvableKey("input", "$(file) $(filter-out %.o: \\,$(readfile $(dfile)))");
    engine.addResolvableKey("output", "$(ofile) $(dfile)");
    engine.addResolvableKey("command", "$(CXX) -MMD $(__soFlags) -o $(ofile) -c $(file) $(cppFlags) $(CXXFLAGS) $(patsubst %,-D%,$(defines)) $(patsubst %,-I%,$(includePaths))");
    engine.addResolvableKey("message", "$(file)");
  engine.leaveKey();
  engine.enterDefaultKey("cSource");
    engine.addResolvableKey("ofile", "$(buildDir)/$(patsubst %.%,%.o,$(subst ../,,$(file)))");
    engine.addResolvableKey("dfile", "$(patsubst %.o,%.d,$(ofile))");
    engine.addResolvableKey("input", "$(file) $(filter-out %.o: \\,$(readfile $(dfile)))");
    engine.addResolvableKey("output", "$(ofile) $(dfile)");
    engine.addResolvableKey("command", "$(CC) -MMD $(__soFlags) -o $(ofile) -c $(file) $(cFlags) $(CFLAGS) $(patsubst %,-D%,$(defines)) $(patsubst %,-I%,$(includePaths))");
    engine.addResolvableKey("message", "$(file)");
  engine.leaveKey();
#if defined(_WIN32)
  engine.addDefaultKey("windows", "true");
#elif defined(__linux)
  engine.addDefaultKey("linux", "true");
#elif defined(__APPLE__) && defined(__MACH__)
  engine.addDefaultKey("macosx", "true");
#else<commit_msg>Make name of some internal variables less prone to conflicts with user defined variables<commit_after>
#include <cstdio>
#include <cassert>

#include "Builder.h"

#include "../libmare/Tools/Process.h"
#include "../libmare/Tools/File.h"
#include "../libmare/Tools/Directory.h"
#include "../libmare/Tools/Words.h"
#include "../libmare/Engine.h"

bool Builder::build(const Map<String, String>& userArgs)
{
  // add default rules and stuff
  engine.addDefaultKey("CC", "gcc");
  engine.addDefaultKey("CXX", "g++");
  engine.addDefaultKey("AR", "ar");
  engine.enterDefaultKey("configurations");
    engine.addResolvableKey("Debug");
    engine.addResolvableKey("Release");
  engine.leaveKey();
  engine.addDefaultKey("targets");
  engine.addDefaultKey("buildDir", "$(configuration)");
  engine.enterDefaultKey("cppApplication");
    engine.addResolvableKey("input", "$(foreach file,$(filter %.c%,$(files)),$(buildDir)/$(patsubst %.%,%.o,$(subst ../,,$(file))))");
    engine.addResolvableKey("output", "$(buildDir)/$(target)$(if $(windows),.exe)");
    engine.addResolvableKey("command", "$(CXX) -o $(output) $(input) $(linkFlags) $(LDFLAGS) $(patsubst %,-L%,$(libPaths)) $(patsubst %,-l%,$(libs))");
    engine.addResolvableKey("message", "Linking $(target)...");
  engine.leaveKey();
  engine.enterDefaultKey("cppDynamicLibrary");
    engine.addResolvableKey("input", "$(foreach file,$(filter %.c%,$(files)),$(buildDir)/$(patsubst %.%,%.o,$(subst ../,,$(file))))");
    engine.addResolvableKey("output", "$(buildDir)/$(if $(windows),,lib)$(target)$(if $(windows),.dll,.so)");
    engine.addResolvableKey("__soFlags", "-fpic");
    engine.addResolvableKey("command", "$(CXX) -shared $(__soFlags) -o $(output) $(input) $(linkFlags) $(LDFLAGS) $(patsubst %,-L%,$(libPaths)) $(patsubst %,-l%,$(libs))");
    engine.addResolvableKey("message", "Linking $(target)...");
  engine.leaveKey();
  engine.enterDefaultKey("cppStaticLibrary");
    engine.addResolvableKey("input", "$(foreach file,$(filter %.c%,$(files)),$(buildDir)/$(patsubst %.%,%.o,$(subst ../,,$(file))))");
    engine.addResolvableKey("output", "$(buildDir)/$(if $(windows),,lib)$(target)$(if $(windows),.lib,.a)");
    engine.addResolvableKey("command", "$(AR) rcs $(output) $(input)");
    engine.addResolvableKey("message", "Creating $(target)...");
  engine.leaveKey();
  engine.enterDefaultKey("cApplication");
    engine.addResolvableKey("input", "$(foreach file,$(filter %.c%,$(files)),$(buildDir)/$(patsubst %.%,%.o,$(subst ../,,$(file))))");
    engine.addResolvableKey("output", "$(buildDir)/$(target)$(if $(windows),.exe)");
    engine.addResolvableKey("command", "$(CC) -o $(output) $(input) $(linkFlags) $(LDFLAGS) $(patsubst %,-L%,$(libPaths)) $(patsubst %,-l%,$(libs))");
    engine.addResolvableKey("message", "Linking $(target)...");
  engine.leaveKey();
  engine.enterDefaultKey("cDynamicLibrary");
    engine.addResolvableKey("input", "$(foreach file,$(filter %.c%,$(files)),$(buildDir)/$(patsubst %.%,%.o,$(subst ../,,$(file))))");
    engine.addResolvableKey("output", "$(buildDir)/$(if $(windows),,lib)$(target)$(if $(windows),.dll,.so)");
    engine.addResolvableKey("__soFlags", "-fpic");
    engine.addResolvableKey("command", "$(CC) -shared $(__soFlags) -o $(output) $(input) $(linkFlags) $(LDFLAGS) $(patsubst %,-L%,$(libPaths)) $(patsubst %,-l%,$(libs))");
    engine.addResolvableKey("message", "Linking $(target)...");
  engine.leaveKey();
  engine.enterDefaultKey("cStaticLibrary");
    engine.addResolvableKey("input", "$(foreach file,$(filter %.c%,$(files)),$(buildDir)/$(patsubst %.%,%.o,$(subst ../,,$(file))))");
    engine.addResolvableKey("output", "$(buildDir)/$(if $(windows),,lib)$(target)$(if $(windows),.lib,.a)");
    engine.addResolvableKey("command", "$(AR) rcs $(output) $(input)");
    engine.addResolvableKey("message", "Creating $(target)...");
  engine.leaveKey();
  engine.enterDefaultKey("cppSource");
    engine.addResolvableKey("__ofile", "$(buildDir)/$(patsubst %.%,%.o,$(subst ../,,$(file)))");
    engine.addResolvableKey("__dfile", "$(patsubst %.o,%.d,$(__ofile))");
    engine.addResolvableKey("input", "$(file) $(filter-out %.o: \\,$(readfile $(__dfile)))");
    engine.addResolvableKey("output", "$(__ofile) $(__dfile)");
    engine.addResolvableKey("command", "$(CXX) -MMD $(__soFlags) -o $(__ofile) -c $(file) $(cppFlags) $(CXXFLAGS) $(patsubst %,-D%,$(defines)) $(patsubst %,-I%,$(includePaths))");
    engine.addResolvableKey("message", "$(file)");
  engine.leaveKey();
  engine.enterDefaultKey("cSource");
    engine.addResolvableKey("__ofile", "$(buildDir)/$(patsubst %.%,%.o,$(subst ../,,$(file)))");
    engine.addResolvableKey("__dfile", "$(patsubst %.o,%.d,$(__ofile))");
    engine.addResolvableKey("input", "$(file) $(filter-out %.o: \\,$(readfile $(__dfile)))");
    engine.addResolvableKey("output", "$(__ofile) $(__dfile)");
    engine.addResolvableKey("command", "$(CC) -MMD $(__soFlags) -o $(__ofile) -c $(file) $(cFlags) $(CFLAGS) $(patsubst %,-D%,$(defines)) $(patsubst %,-I%,$(includePaths))");
    engine.addResolvableKey("message", "$(file)");
  engine.leaveKey();
#if defined(_WIN32)
  engine.addDefaultKey("windows", "true");
#elif defined(__linux)
  engine.addDefaultKey("linux", "true");
#elif defined(__APPLE__) && defined(__MACH__)
  engine.addDefaultKey("macosx", "true");
#else
{'fraction_non_alphanumeric': 0.2658071855152147, 'fraction_numerical': 0.00037918286093468573, 'mean_word_length': 6.306094182825484, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5284760', 'n_tokens_mistral': 3697, 'n_tokens_neox': 3607, 'n_words': 556}