|  | 
| 7 | 7 | 
 | 
| 8 | 8 | #include <utility> | 
| 9 | 9 | #include <utils/MakefileUtils.h> | 
|  | 10 | +#include "utils/StringUtils.h" | 
| 10 | 11 | 
 | 
| 11 | 12 | namespace printer { | 
|  | 13 | +    using StringUtils::stringFormat; | 
|  | 14 | + | 
| 12 | 15 |     fs::path getMakefilePathForShared(fs::path path) { | 
| 13 | 16 |         return Paths::addSuffix(Paths::addPrefix(path, "__"), "_shared"); | 
| 14 | 17 |     } | 
| @@ -66,36 +69,52 @@ namespace printer { | 
| 66 | 69 |         fs::path sharedMakefilePath = getMakefilePathForShared(generalMakefilePath); | 
| 67 | 70 |         fs::path objMakefilePath = getMakefilePathForObject(generalMakefilePath); | 
| 68 | 71 | 
 | 
|  | 72 | +        generalMakefilePrinter.declareVariable("project_dir_relative_to_makefile", | 
|  | 73 | +                                               fs::relative(projectContext.projectPath, path)); | 
|  | 74 | +        generalMakefilePrinter.declareVariable("makefile_dir", "$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))"); | 
|  | 75 | +        generalMakefilePrinter.declareVariable("project_dir", | 
|  | 76 | +                                               stringFormat("%s/%s", "$(makefile_dir)", "$(project_dir_relative_to_makefile)")); | 
|  | 77 | +        generalMakefilePrinter.declareVariable("build_relative", objMakefilePrinter.buildDirectoryRelative); | 
|  | 78 | +        generalMakefilePrinter.declareVariable("build_dir", stringFormat("%s/%s", | 
|  | 79 | +                                                  objMakefilePrinter.pathToShellVariable.at(projectContext.projectPath), | 
|  | 80 | +                                                  objMakefilePrinter.pathToShellVariable.at(objMakefilePrinter.buildDirectoryRelative))); | 
|  | 81 | + | 
|  | 82 | + | 
| 69 | 83 |         generalMakefilePrinter.declareTarget(FORCE, {}, {}); | 
| 70 | 84 | 
 | 
|  | 85 | +        const std::string sharedMakefilePathRelative = | 
|  | 86 | +                sharedMakefilePrinter.getRelativePathWithShellVariableForProjectDirOrBuildDirOrRootDir(sharedMakefilePath); | 
|  | 87 | +        const std::string objMakefilePathRelative = | 
|  | 88 | +                objMakefilePrinter.getRelativePathWithShellVariableForProjectDirOrBuildDirOrRootDir(objMakefilePath); | 
| 71 | 89 |         generalMakefilePrinter.declareTarget("bin", {FORCE}, { | 
| 72 | 90 |                 StringUtils::joinWith( | 
| 73 |  | -                        MakefileUtils::getMakeCommand(sharedMakefilePath.string(), "bin", true), | 
|  | 91 | +                        MakefileUtils::getMakeCommand(sharedMakefilePathRelative, "bin", true), | 
| 74 | 92 |                         " ") | 
| 75 | 93 |         }); | 
| 76 | 94 |         generalMakefilePrinter.declareTarget("build", {FORCE}, { | 
| 77 | 95 |                 StringUtils::stringFormat("%s || %s", | 
| 78 | 96 |                                           StringUtils::joinWith(MakefileUtils::getMakeCommand( | 
| 79 |  | -                                                  sharedMakefilePath.string(), "build", true), " "), | 
|  | 97 | +                                                  sharedMakefilePathRelative, "build", true), " "), | 
| 80 | 98 |                                           StringUtils::joinWith(MakefileUtils::getMakeCommand( | 
| 81 |  | -                                                  objMakefilePath.string(), "build", true), " ")) | 
|  | 99 | +                                                  objMakefilePathRelative, "build", true), " ")) | 
| 82 | 100 |         }); | 
|  | 101 | + | 
| 83 | 102 |         generalMakefilePrinter.declareTarget("run", {FORCE}, { | 
| 84 | 103 |                 StringUtils::stringFormat("%s && { %s; exit $$?; } || { %s && { %s; exit $$?; } }", | 
| 85 | 104 |                                           StringUtils::joinWith(MakefileUtils::getMakeCommand( | 
| 86 |  | -                                                  sharedMakefilePath.string(), "build", true), " "), | 
|  | 105 | +                                                  sharedMakefilePathRelative, "build", true), " "), | 
| 87 | 106 |                                           StringUtils::joinWith(MakefileUtils::getMakeCommand( | 
| 88 |  | -                                                  sharedMakefilePath.string(), "run", true), " "), | 
|  | 107 | +                                                  sharedMakefilePathRelative, "run", true), " "), | 
| 89 | 108 |                                           StringUtils::joinWith(MakefileUtils::getMakeCommand( | 
| 90 |  | -                                                  objMakefilePath.string(), "build", true), " "), | 
|  | 109 | +                                                  objMakefilePathRelative, "build", true), " "), | 
| 91 | 110 |                                           StringUtils::joinWith(MakefileUtils::getMakeCommand( | 
| 92 |  | -                                                  objMakefilePath.string(), "run", true), " ")) | 
|  | 111 | +                                                  objMakefilePathRelative, "run", true), " ")) | 
| 93 | 112 |         }); | 
| 94 | 113 |         generalMakefilePrinter.declareTarget("clean", {FORCE}, { | 
| 95 | 114 |                 StringUtils::joinWith( | 
| 96 |  | -                        MakefileUtils::getMakeCommand(sharedMakefilePath.string(), "clean", true), " "), | 
|  | 115 | +                        MakefileUtils::getMakeCommand(sharedMakefilePathRelative, "clean", true), " "), | 
| 97 | 116 |                 StringUtils::joinWith( | 
| 98 |  | -                        MakefileUtils::getMakeCommand(objMakefilePath.string(), "clean", true), " ") | 
|  | 117 | +                        MakefileUtils::getMakeCommand(objMakefilePathRelative, "clean", true), " ") | 
| 99 | 118 |         }); | 
| 100 | 119 | 
 | 
| 101 | 120 |         return {generalMakefilePath, | 
|  | 
0 commit comments