main.cpp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. 
  2. // Because it would be slow to check if the build system needs to be recompiled every time something uses it,
  3. // you must manually delete the build system's binary and try to build a project using it after making changes to the builder's source code.
  4. // Otherwise buildProject.sh will just see that an old version exists and use it.
  5. // TODO:
  6. // * Let the build script define a temporary folder path for lazy compilation with reused *.o files.
  7. // The /tmp folder is erased when shutting down the computer, which would force recompilation of each library after each time the computer has rebooted.
  8. // * 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.
  9. // This makes sure that including the same file twice using alternative ways of writing the path can be detected and trigger a warning.
  10. // 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?
  11. // * Implement more features for the machine, such as:
  12. // * Unary negation.
  13. // * else and elseif cases.
  14. // * Temporarily letting the theoretical path go into another folder within a scope, similar to if statements but only affecting the path.
  15. // Like writing (cd path; stmt;) in Bash but with fast parsed Basic-like syntax.
  16. // The same stack used to store theoretical paths might be useful for else if cases to remember when the scope has already passed a case when not jumping with gotos.
  17. // * Create portable scripted events for pre-build and post-build, translated into both Batch and Bash.
  18. // Pre-build can be used to generate and transpile code before compiling.
  19. // Post-build should be used to execute the resulting program.
  20. // Optionally with variables from the build script as input arguments.
  21. // * Should the build system detect the local system automatically, or support cross compilation using a MinGW extension?
  22. #include "../../DFPSR/api/fileAPI.h"
  23. #include "generator.h"
  24. using namespace dsr;
  25. // List dependencies for main.cpp on Linux: ./builder main.cpp --depend
  26. DSR_MAIN_CALLER(dsrMain)
  27. void dsrMain(List<String> args) {
  28. if (args.length() <= 2) {
  29. 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");
  30. } else {
  31. // Get the project file path from the first argument after the program name.
  32. String projectFilePath = args[1];
  33. String platform = args[2];
  34. Machine settings;
  35. // Begin reading input arguments after the project's path, as named integers assigned to ones.
  36. // Calling builder with the extra arguments "Graphics" and "Linux" will then create and assign both variables to 1.
  37. // Other values can be assigned using an equality sign.
  38. // Avoid spaces around the equality sign, because quotes are already used for string arguments in assignments.
  39. for (int a = 2; a < args.length(); a++) {
  40. String argument = args[a];
  41. int64_t assignmentIndex = string_findFirst(argument, U'=');
  42. if (assignmentIndex == -1) {
  43. assignValue(settings, argument, U"1");
  44. printText(U"Assigning ", argument, U" to 1 from input argument.\n");
  45. } else {
  46. String key = string_removeOuterWhiteSpace(string_before(argument, assignmentIndex));
  47. String value = string_removeOuterWhiteSpace(string_after(argument, assignmentIndex));
  48. assignValue(settings, key, value);
  49. printText(U"Assigning ", key, U" to ", value, U" from input argument.\n");
  50. }
  51. }
  52. // Evaluate compiler settings while searching for source code mentioned in the project and imported headers.
  53. printText(U"Executing project file from ", projectFilePath, U".\n");
  54. evaluateScript(settings, projectFilePath);
  55. // Once we are done finding all source files, we can resolve the dependencies to create a graph connected by indices.
  56. resolveDependencies();
  57. if (getFlagAsInteger(settings, U"ListDependencies")) {
  58. printDependencies();
  59. }
  60. generateCompilationScript(settings, file_getAbsoluteParentFolder(projectFilePath));
  61. }
  62. }