main.cpp 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. 
  2. // TODO:
  3. // * Let the build script define a temporary folder path for lazy compilation with reused *.o files.
  4. // The /tmp folder is erased when shutting down the computer, which would force recompilation of each library after each time the computer has rebooted.
  5. // * Find a way to check if a file is truly unique using a combination of pathless filenames, content checksums and visibility of surrounding files from the folder.
  6. // This makes sure that including the same file twice using alternative ways of writing the path can be detected and trigger a warning.
  7. // Can one convert the file ID from each platform into a string or 64-bit hash sum to quickly make sure that the file is unique?
  8. // * Create scripts compiling the build system when it does not exist and managing creation of a temporary folder, calling the generated script...
  9. // * Implement more features for the machine, such as:
  10. // * Unary negation.
  11. // * else and elseif cases.
  12. // * Temporarily letting the theoretical path go into another folder within a scope, similar to if statements but only affecting the path.
  13. // Like writing (cd path; stmt;) in Bash but with fast parsed Basic-like syntax.
  14. #include "../../DFPSR/api/fileAPI.h"
  15. #include "generator.h"
  16. using namespace dsr;
  17. // List dependencies for main.cpp on Linux: ./builder main.cpp --depend
  18. DSR_MAIN_CALLER(dsrMain)
  19. void dsrMain(List<String> args) {
  20. if (args.length() <= 2) {
  21. printText(U"To use the DFPSR build system, pass a path to the project file and the flags you want assigned before running the build script.\n");
  22. } else {
  23. // Get the project file path from the first argument after the program name.
  24. String projectFilePath = args[1];
  25. String platform = args[2];
  26. Machine settings;
  27. // Begin reading input arguments after the project's path, as named integers assigned to ones.
  28. // Calling builder with the extra arguments "Graphics" and "Linux" will then create and assign both variables to 1.
  29. // Other values can be assigned using an equality sign.
  30. // Avoid spaces around the equality sign, because quotes are already used for string arguments in assignments.
  31. for (int a = 2; a < args.length(); a++) {
  32. String argument = args[a];
  33. int64_t assignmentIndex = string_findFirst(argument, U'=');
  34. if (assignmentIndex == -1) {
  35. assignValue(settings, argument, U"1");
  36. } else {
  37. String key = string_removeOuterWhiteSpace(string_before(argument, assignmentIndex));
  38. String value = string_removeOuterWhiteSpace(string_after(argument, assignmentIndex));
  39. assignValue(settings, key, value);
  40. }
  41. }
  42. // Evaluate compiler settings while searching for source code mentioned in the project and imported headers.
  43. printText(U"Executing project file from ", projectFilePath, U".\n");
  44. evaluateScript(settings, projectFilePath);
  45. // Once we are done finding all source files, we can resolve the dependencies to create a graph connected by indices.
  46. resolveDependencies();
  47. if (getFlagAsInteger(settings, U"ListDependencies")) {
  48. printDependencies();
  49. }
  50. generateCompilationScript(settings, file_getAbsoluteParentFolder(projectFilePath));
  51. }
  52. }