The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1254 lines
52KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2022 - Raw Material Software Limited
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. By using JUCE, you agree to the terms of both the JUCE 7 End-User License
  8. Agreement and JUCE Privacy Policy.
  9. End User License Agreement: www.juce.com/juce-7-licence
  10. Privacy Policy: www.juce.com/juce-privacy-policy
  11. Or: You may also use this code under the terms of the GPL v3 (see
  12. www.gnu.org/licenses).
  13. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  14. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  15. DISCLAIMED.
  16. ==============================================================================
  17. */
  18. #pragma once
  19. //==============================================================================
  20. class MakefileProjectExporter : public ProjectExporter
  21. {
  22. protected:
  23. //==============================================================================
  24. class MakeBuildConfiguration : public BuildConfiguration
  25. {
  26. public:
  27. MakeBuildConfiguration (Project& p, const ValueTree& settings, const ProjectExporter& e)
  28. : BuildConfiguration (p, settings, e),
  29. architectureTypeValue (config, Ids::linuxArchitecture, getUndoManager(), String()),
  30. pluginBinaryCopyStepValue (config, Ids::enablePluginBinaryCopyStep, getUndoManager(), true),
  31. vstBinaryLocation (config, Ids::vstBinaryLocation, getUndoManager(), "$(HOME)/.vst"),
  32. vst3BinaryLocation (config, Ids::vst3BinaryLocation, getUndoManager(), "$(HOME)/.vst3"),
  33. lv2BinaryLocation (config, Ids::lv2BinaryLocation, getUndoManager(), "$(HOME)/.lv2"),
  34. unityPluginBinaryLocation (config, Ids::unityPluginBinaryLocation, getUndoManager(), "$(HOME)/UnityPlugins")
  35. {
  36. linkTimeOptimisationValue.setDefault (false);
  37. optimisationLevelValue.setDefault (isDebug() ? gccO0 : gccO3);
  38. }
  39. void createConfigProperties (PropertyListBuilder& props) override
  40. {
  41. addRecommendedLinuxCompilerWarningsProperty (props);
  42. addGCCOptimisationProperty (props);
  43. props.add (new ChoicePropertyComponent (architectureTypeValue, "Architecture",
  44. { "<None>", "Native", "32-bit (-m32)", "64-bit (-m64)", "ARM v6", "ARM v7", "ARM v8-a" },
  45. { { String() }, "-march=native", "-m32", "-m64", "-march=armv6", "-march=armv7", "-march=armv8-a" }),
  46. "Specifies the 32/64-bit architecture to use. If you don't see the required architecture in this list, you can also specify the desired "
  47. "flag on the command-line when invoking make by passing \"TARGET_ARCH=-march=<arch to use>\"");
  48. auto isBuildingAnyPlugins = (project.shouldBuildVST() || project.shouldBuildVST3() || project.shouldBuildUnityPlugin() || project.shouldBuildLV2());
  49. if (isBuildingAnyPlugins)
  50. {
  51. props.add (new ChoicePropertyComponent (pluginBinaryCopyStepValue, "Enable Plugin Copy Step"),
  52. "Enable this to copy plugin binaries to a specified folder after building.");
  53. if (project.shouldBuildVST3())
  54. props.add (new TextPropertyComponentWithEnablement (vst3BinaryLocation, pluginBinaryCopyStepValue, "VST3 Binary Location",
  55. 1024, false),
  56. "The folder in which the compiled VST3 binary should be placed.");
  57. if (project.shouldBuildLV2())
  58. props.add (new TextPropertyComponentWithEnablement (lv2BinaryLocation, pluginBinaryCopyStepValue, "LV2 Binary Location",
  59. 1024, false),
  60. "The folder in which the compiled LV2 binary should be placed.");
  61. if (project.shouldBuildUnityPlugin())
  62. props.add (new TextPropertyComponentWithEnablement (unityPluginBinaryLocation, pluginBinaryCopyStepValue, "Unity Binary Location",
  63. 1024, false),
  64. "The folder in which the compiled Unity plugin binary and associated C# GUI script should be placed.");
  65. if (project.shouldBuildVST())
  66. props.add (new TextPropertyComponentWithEnablement (vstBinaryLocation, pluginBinaryCopyStepValue, "VST (Legacy) Binary Location",
  67. 1024, false),
  68. "The folder in which the compiled legacy VST binary should be placed.");
  69. }
  70. }
  71. String getModuleLibraryArchName() const override
  72. {
  73. auto archFlag = getArchitectureTypeString();
  74. String prefix ("-march=");
  75. if (archFlag.startsWith (prefix))
  76. return archFlag.substring (prefix.length());
  77. if (archFlag == "-m64")
  78. return "x86_64";
  79. if (archFlag == "-m32")
  80. return "i386";
  81. return "${JUCE_ARCH_LABEL}";
  82. }
  83. String getArchitectureTypeString() const { return architectureTypeValue.get(); }
  84. bool isPluginBinaryCopyStepEnabled() const { return pluginBinaryCopyStepValue.get(); }
  85. String getVSTBinaryLocationString() const { return vstBinaryLocation.get(); }
  86. String getVST3BinaryLocationString() const { return vst3BinaryLocation.get(); }
  87. String getLV2BinaryLocationString() const { return lv2BinaryLocation.get(); }
  88. String getUnityPluginBinaryLocationString() const { return unityPluginBinaryLocation.get(); }
  89. private:
  90. //==============================================================================
  91. ValueTreePropertyWithDefault architectureTypeValue, pluginBinaryCopyStepValue,
  92. vstBinaryLocation, vst3BinaryLocation, lv2BinaryLocation, unityPluginBinaryLocation;
  93. };
  94. BuildConfiguration::Ptr createBuildConfig (const ValueTree& tree) const override
  95. {
  96. return *new MakeBuildConfiguration (project, tree, *this);
  97. }
  98. public:
  99. //==============================================================================
  100. class MakefileTarget : public build_tools::ProjectType::Target
  101. {
  102. public:
  103. MakefileTarget (build_tools::ProjectType::Target::Type targetType, const MakefileProjectExporter& exporter)
  104. : build_tools::ProjectType::Target (targetType), owner (exporter)
  105. {}
  106. StringArray getCompilerFlags() const
  107. {
  108. StringArray result;
  109. if (getTargetFileType() == sharedLibraryOrDLL || getTargetFileType() == pluginBundle)
  110. {
  111. result.add ("-fPIC");
  112. result.add ("-fvisibility=hidden");
  113. }
  114. return result;
  115. }
  116. StringArray getLinkerFlags() const
  117. {
  118. StringArray result;
  119. if (getTargetFileType() == sharedLibraryOrDLL || getTargetFileType() == pluginBundle)
  120. {
  121. result.add ("-shared");
  122. if (getTargetFileType() == pluginBundle)
  123. result.add ("-Wl,--no-undefined");
  124. }
  125. return result;
  126. }
  127. StringPairArray getDefines (const BuildConfiguration& config) const
  128. {
  129. StringPairArray result;
  130. auto commonOptionKeys = owner.getAllPreprocessorDefs (config, build_tools::ProjectType::Target::unspecified).getAllKeys();
  131. auto targetSpecific = owner.getAllPreprocessorDefs (config, type);
  132. for (auto& key : targetSpecific.getAllKeys())
  133. if (! commonOptionKeys.contains (key))
  134. result.set (key, targetSpecific[key]);
  135. return result;
  136. }
  137. StringArray getTargetSettings (const MakeBuildConfiguration& config) const
  138. {
  139. if (type == AggregateTarget) // the aggregate target should not specify any settings at all!
  140. return {}; // it just defines dependencies on the other targets.
  141. StringArray s;
  142. auto cppflagsVarName = "JUCE_CPPFLAGS_" + getTargetVarName();
  143. s.add (cppflagsVarName + " := " + createGCCPreprocessorFlags (getDefines (config)));
  144. auto cflags = getCompilerFlags();
  145. if (! cflags.isEmpty())
  146. s.add ("JUCE_CFLAGS_" + getTargetVarName() + " := " + cflags.joinIntoString (" "));
  147. auto ldflags = getLinkerFlags();
  148. if (! ldflags.isEmpty())
  149. s.add ("JUCE_LDFLAGS_" + getTargetVarName() + " := " + ldflags.joinIntoString (" "));
  150. auto targetName = owner.replacePreprocessorTokens (config, config.getTargetBinaryNameString (type == UnityPlugIn));
  151. if (owner.projectType.isStaticLibrary())
  152. targetName = getStaticLibbedFilename (targetName);
  153. else if (owner.projectType.isDynamicLibrary())
  154. targetName = getDynamicLibbedFilename (targetName);
  155. else
  156. targetName = targetName.upToLastOccurrenceOf (".", false, false) + getTargetFileSuffix();
  157. if (type == VST3PlugIn)
  158. {
  159. s.add ("JUCE_VST3DIR := " + escapeQuotesAndSpaces (targetName).upToLastOccurrenceOf (".", false, false) + ".vst3");
  160. s.add ("VST3_PLATFORM_ARCH := $(shell $(CXX) make_helpers/arch_detection.cpp 2>&1 | tr '\\n' ' ' | sed \"s/.*JUCE_ARCH \\([a-zA-Z0-9_-]*\\).*/\\1/\")");
  161. s.add ("JUCE_VST3SUBDIR := Contents/$(VST3_PLATFORM_ARCH)-linux");
  162. targetName = "$(JUCE_VST3DIR)/$(JUCE_VST3SUBDIR)/" + targetName;
  163. }
  164. else if (type == UnityPlugIn)
  165. {
  166. s.add ("JUCE_UNITYDIR := Unity");
  167. targetName = "$(JUCE_UNITYDIR)/" + targetName;
  168. }
  169. else if (type == LV2PlugIn)
  170. {
  171. s.add ("JUCE_LV2DIR := " + escapeQuotesAndSpaces (targetName) + ".lv2");
  172. targetName = "$(JUCE_LV2DIR)/" + targetName + ".so";
  173. }
  174. else if (type == LV2TurtleProgram)
  175. {
  176. targetName = Project::getLV2FileWriterName();
  177. }
  178. s.add ("JUCE_TARGET_" + getTargetVarName() + String (" := ") + escapeQuotesAndSpaces (targetName));
  179. if (type == LV2PlugIn)
  180. s.add ("JUCE_LV2_FULL_PATH := $(JUCE_OUTDIR)/$(JUCE_TARGET_LV2_PLUGIN)");
  181. if (config.isPluginBinaryCopyStepEnabled()
  182. && (type == VST3PlugIn || type == VSTPlugIn || type == UnityPlugIn || type == LV2PlugIn))
  183. {
  184. String copyCmd ("JUCE_COPYCMD_" + getTargetVarName() + String (" := $(JUCE_OUTDIR)/"));
  185. if (type == VST3PlugIn)
  186. {
  187. s.add ("JUCE_VST3DESTDIR := " + config.getVST3BinaryLocationString());
  188. s.add (copyCmd + "$(JUCE_VST3DIR) $(JUCE_VST3DESTDIR)");
  189. }
  190. else if (type == VSTPlugIn)
  191. {
  192. s.add ("JUCE_VSTDESTDIR := " + config.getVSTBinaryLocationString());
  193. s.add (copyCmd + escapeQuotesAndSpaces (targetName) + " $(JUCE_VSTDESTDIR)");
  194. }
  195. else if (type == UnityPlugIn)
  196. {
  197. s.add ("JUCE_UNITYDESTDIR := " + config.getUnityPluginBinaryLocationString());
  198. s.add (copyCmd + "$(JUCE_UNITYDIR)/. $(JUCE_UNITYDESTDIR)");
  199. }
  200. else if (type == LV2PlugIn)
  201. {
  202. s.add ("JUCE_LV2DESTDIR := " + config.getLV2BinaryLocationString());
  203. s.add (copyCmd + "$(JUCE_LV2DIR) $(JUCE_LV2DESTDIR)");
  204. }
  205. }
  206. return s;
  207. }
  208. String getTargetFileSuffix() const
  209. {
  210. if (type == VSTPlugIn || type == VST3PlugIn || type == UnityPlugIn || type == DynamicLibrary)
  211. return ".so";
  212. if (type == SharedCodeTarget || type == StaticLibrary)
  213. return ".a";
  214. return {};
  215. }
  216. String getTargetVarName() const
  217. {
  218. return String (getName()).toUpperCase().replaceCharacter (L' ', L'_');
  219. }
  220. void writeObjects (OutputStream& out, const std::vector<std::pair<build_tools::RelativePath, String>>& filesToCompile) const
  221. {
  222. out << "OBJECTS_" + getTargetVarName() + String (" := \\") << newLine;
  223. for (auto& f : filesToCompile)
  224. out << " $(JUCE_OBJDIR)/" << escapeQuotesAndSpaces (owner.getObjectFileFor (f.first))
  225. << " \\" << newLine;
  226. out << newLine;
  227. }
  228. void addFiles (OutputStream& out, const std::vector<std::pair<build_tools::RelativePath, String>>& filesToCompile)
  229. {
  230. auto cppflagsVarName = "JUCE_CPPFLAGS_" + getTargetVarName();
  231. auto cflagsVarName = "JUCE_CFLAGS_" + getTargetVarName();
  232. for (auto& [path, flags] : filesToCompile)
  233. {
  234. const auto additionalTargetDependencies = [&path = path, this]
  235. {
  236. if ( owner.linuxSubprocessHelperProperties.shouldUseLinuxSubprocessHelper()
  237. && path.getFileName().contains ("include_juce_gui_extra.cpp"))
  238. {
  239. return owner.linuxSubprocessHelperProperties
  240. .getLinuxSubprocessHelperBinaryDataSource()
  241. .toUnixStyle();
  242. }
  243. return String{};
  244. }();
  245. const auto prependedWithSpaceIfNotEmpty = [] (auto s)
  246. {
  247. return s.isEmpty() ? s : " " + s;
  248. };
  249. out << "$(JUCE_OBJDIR)/" << escapeQuotesAndSpaces (owner.getObjectFileFor (path)) << ": " << escapeQuotesAndSpaces (path.toUnixStyle())
  250. << prependedWithSpaceIfNotEmpty (additionalTargetDependencies) << newLine
  251. << "\t-$(V_AT)mkdir -p $(@D)" << newLine
  252. << "\t@echo \"Compiling " << path.getFileName() << "\"" << newLine
  253. << (path.hasFileExtension ("c;s;S") ? "\t$(V_AT)$(CC) $(JUCE_CFLAGS) " : "\t$(V_AT)$(CXX) $(JUCE_CXXFLAGS) ")
  254. << "$(" << cppflagsVarName << ") $(" << cflagsVarName << ")"
  255. << (flags.isNotEmpty() ? " $(" + owner.getCompilerFlagSchemeVariableName (flags) + ")" : "") << " -o \"$@\" -c \"$<\"" << newLine
  256. << newLine;
  257. }
  258. }
  259. String getBuildProduct() const
  260. {
  261. return "$(JUCE_OUTDIR)/$(JUCE_TARGET_" + getTargetVarName() + ")";
  262. }
  263. String getPhonyName() const
  264. {
  265. if (type == LV2TurtleProgram)
  266. return "LV2_MANIFEST_HELPER";
  267. return String (getName()).upToFirstOccurrenceOf (" ", false, false);
  268. }
  269. void writeTargetLine (OutputStream& out, const StringArray& packages)
  270. {
  271. jassert (type != AggregateTarget);
  272. out << getBuildProduct() << " : "
  273. << "$(OBJECTS_" << getTargetVarName() << ") $(JUCE_OBJDIR)/execinfo.cmd $(RESOURCES)";
  274. if (type != SharedCodeTarget && owner.shouldBuildTargetType (SharedCodeTarget))
  275. out << " $(JUCE_OUTDIR)/$(JUCE_TARGET_SHARED_CODE)";
  276. if (type == LV2PlugIn)
  277. out << " $(JUCE_OUTDIR)/$(JUCE_TARGET_LV2_MANIFEST_HELPER)";
  278. out << newLine;
  279. if (! packages.isEmpty())
  280. {
  281. out << "\t@command -v $(PKG_CONFIG) >/dev/null 2>&1 || { echo >&2 \"pkg-config not installed. Please, install it.\"; exit 1; }" << newLine
  282. << "\t@$(PKG_CONFIG) --print-errors";
  283. for (auto& pkg : packages)
  284. out << " " << pkg;
  285. out << newLine;
  286. }
  287. out << "\t@echo Linking \"" << owner.projectName << " - " << getName() << "\"" << newLine
  288. << "\t-$(V_AT)mkdir -p $(JUCE_BINDIR)" << newLine
  289. << "\t-$(V_AT)mkdir -p $(JUCE_LIBDIR)" << newLine
  290. << "\t-$(V_AT)mkdir -p $(JUCE_OUTDIR)" << newLine;
  291. if (type == VST3PlugIn)
  292. out << "\t-$(V_AT)mkdir -p $(JUCE_OUTDIR)/$(JUCE_VST3DIR)/$(JUCE_VST3SUBDIR)" << newLine;
  293. else if (type == UnityPlugIn)
  294. out << "\t-$(V_AT)mkdir -p $(JUCE_OUTDIR)/$(JUCE_UNITYDIR)" << newLine;
  295. else if (type == LV2PlugIn)
  296. out << "\t-$(V_AT)mkdir -p $(JUCE_OUTDIR)/$(JUCE_LV2DIR)" << newLine;
  297. if (owner.projectType.isStaticLibrary() || type == SharedCodeTarget)
  298. {
  299. out << "\t$(V_AT)$(AR) -rcs " << getBuildProduct()
  300. << " $(OBJECTS_" << getTargetVarName() << ")" << newLine;
  301. }
  302. else
  303. {
  304. out << "\t$(V_AT)$(CXX) -o " << getBuildProduct()
  305. << " $(OBJECTS_" << getTargetVarName() << ") ";
  306. if (owner.shouldBuildTargetType (SharedCodeTarget))
  307. out << "$(JUCE_OUTDIR)/$(JUCE_TARGET_SHARED_CODE) ";
  308. out << "$(JUCE_LDFLAGS) $(shell cat $(JUCE_OBJDIR)/execinfo.cmd) ";
  309. if (getTargetFileType() == sharedLibraryOrDLL || getTargetFileType() == pluginBundle
  310. || type == GUIApp || type == StandalonePlugIn)
  311. out << "$(JUCE_LDFLAGS_" << getTargetVarName() << ") ";
  312. out << "$(RESOURCES) $(TARGET_ARCH)" << newLine;
  313. }
  314. if (type == VST3PlugIn)
  315. {
  316. out << "\t-$(V_AT)[ ! \"$(JUCE_VST3DESTDIR)\" ] || (mkdir -p $(JUCE_VST3DESTDIR) && cp -R $(JUCE_COPYCMD_VST3))" << newLine;
  317. }
  318. else if (type == VSTPlugIn)
  319. {
  320. out << "\t-$(V_AT)[ ! \"$(JUCE_VSTDESTDIR)\" ] || (mkdir -p $(JUCE_VSTDESTDIR) && cp -R $(JUCE_COPYCMD_VST))" << newLine;
  321. }
  322. else if (type == UnityPlugIn)
  323. {
  324. auto scriptName = owner.getProject().getUnityScriptName();
  325. build_tools::RelativePath scriptPath (owner.getProject().getGeneratedCodeFolder().getChildFile (scriptName),
  326. owner.getTargetFolder(),
  327. build_tools::RelativePath::projectFolder);
  328. out << "\t-$(V_AT)cp " + scriptPath.toUnixStyle() + " $(JUCE_OUTDIR)/$(JUCE_UNITYDIR)" << newLine
  329. << "\t-$(V_AT)[ ! \"$(JUCE_UNITYDESTDIR)\" ] || (mkdir -p $(JUCE_UNITYDESTDIR) && cp -R $(JUCE_COPYCMD_UNITY_PLUGIN))" << newLine;
  330. }
  331. else if (type == LV2PlugIn)
  332. {
  333. out << "\t$(V_AT) $(JUCE_OUTDIR)/$(JUCE_TARGET_LV2_MANIFEST_HELPER) $(JUCE_LV2_FULL_PATH)" << newLine
  334. << "\t-$(V_AT)[ ! \"$(JUCE_LV2DESTDIR)\" ] || (mkdir -p $(JUCE_LV2DESTDIR) && cp -R $(JUCE_COPYCMD_LV2_PLUGIN))" << newLine;
  335. }
  336. out << newLine;
  337. }
  338. const MakefileProjectExporter& owner;
  339. };
  340. //==============================================================================
  341. static String getDisplayName() { return "Linux Makefile"; }
  342. static String getValueTreeTypeName() { return "LINUX_MAKE"; }
  343. static String getTargetFolderName() { return "LinuxMakefile"; }
  344. Identifier getExporterIdentifier() const override { return getValueTreeTypeName(); }
  345. static MakefileProjectExporter* createForSettings (Project& projectToUse, const ValueTree& settingsToUse)
  346. {
  347. if (settingsToUse.hasType (getValueTreeTypeName()))
  348. return new MakefileProjectExporter (projectToUse, settingsToUse);
  349. return nullptr;
  350. }
  351. //==============================================================================
  352. MakefileProjectExporter (Project& p, const ValueTree& t)
  353. : ProjectExporter (p, t),
  354. extraPkgConfigValue (settings, Ids::linuxExtraPkgConfig, getUndoManager())
  355. {
  356. name = getDisplayName();
  357. targetLocationValue.setDefault (getDefaultBuildsRootFolder() + getTargetFolderName());
  358. }
  359. //==============================================================================
  360. bool canLaunchProject() override { return false; }
  361. bool launchProject() override { return false; }
  362. bool usesMMFiles() const override { return false; }
  363. bool canCopeWithDuplicateFiles() override { return false; }
  364. bool supportsUserDefinedConfigurations() const override { return true; }
  365. bool isXcode() const override { return false; }
  366. bool isVisualStudio() const override { return false; }
  367. bool isCodeBlocks() const override { return false; }
  368. bool isMakefile() const override { return true; }
  369. bool isAndroidStudio() const override { return false; }
  370. bool isAndroid() const override { return false; }
  371. bool isWindows() const override { return false; }
  372. bool isLinux() const override { return true; }
  373. bool isOSX() const override { return false; }
  374. bool isiOS() const override { return false; }
  375. String getNewLineString() const override { return "\n"; }
  376. bool supportsTargetType (build_tools::ProjectType::Target::Type type) const override
  377. {
  378. using Target = build_tools::ProjectType::Target;
  379. switch (type)
  380. {
  381. case Target::GUIApp:
  382. case Target::ConsoleApp:
  383. case Target::StaticLibrary:
  384. case Target::SharedCodeTarget:
  385. case Target::AggregateTarget:
  386. case Target::VSTPlugIn:
  387. case Target::VST3PlugIn:
  388. case Target::StandalonePlugIn:
  389. case Target::DynamicLibrary:
  390. case Target::UnityPlugIn:
  391. case Target::LV2PlugIn:
  392. case Target::LV2TurtleProgram:
  393. return true;
  394. case Target::AAXPlugIn:
  395. case Target::AudioUnitPlugIn:
  396. case Target::AudioUnitv3PlugIn:
  397. case Target::unspecified:
  398. default:
  399. break;
  400. }
  401. return false;
  402. }
  403. void createExporterProperties (PropertyListBuilder& properties) override
  404. {
  405. properties.add (new TextPropertyComponent (extraPkgConfigValue, "pkg-config libraries", 8192, false),
  406. "Extra pkg-config libraries for you application. Each package should be space separated.");
  407. }
  408. void initialiseDependencyPathValues() override
  409. {
  410. vstLegacyPathValueWrapper.init ({ settings, Ids::vstLegacyFolder, nullptr },
  411. getAppSettings().getStoredPath (Ids::vstLegacyPath, TargetOS::linux), TargetOS::linux);
  412. araPathValueWrapper.init ({ settings, Ids::araFolder, nullptr },
  413. getAppSettings().getStoredPath (Ids::araPath, TargetOS::linux), TargetOS::linux);
  414. }
  415. //==============================================================================
  416. bool anyTargetIsSharedLibrary() const
  417. {
  418. for (auto* target : targets)
  419. {
  420. auto fileType = target->getTargetFileType();
  421. if (fileType == build_tools::ProjectType::Target::sharedLibraryOrDLL
  422. || fileType == build_tools::ProjectType::Target::pluginBundle)
  423. return true;
  424. }
  425. return false;
  426. }
  427. //==============================================================================
  428. void create (const OwnedArray<LibraryModule>&) const override
  429. {
  430. build_tools::writeStreamToFile (getTargetFolder().getChildFile ("Makefile"), [&] (MemoryOutputStream& mo)
  431. {
  432. mo.setNewLineString (getNewLineString());
  433. writeMakefile (mo);
  434. });
  435. if (project.shouldBuildVST3())
  436. {
  437. auto helperDir = getTargetFolder().getChildFile ("make_helpers");
  438. helperDir.createDirectory();
  439. build_tools::overwriteFileIfDifferentOrThrow (helperDir.getChildFile ("arch_detection.cpp"),
  440. BinaryData::juce_runtime_arch_detection_cpp);
  441. }
  442. linuxSubprocessHelperProperties.deployLinuxSubprocessHelperSourceFilesIfNecessary();
  443. }
  444. //==============================================================================
  445. void addPlatformSpecificSettingsForProjectType (const build_tools::ProjectType&) override
  446. {
  447. linuxSubprocessHelperProperties.addToExtraSearchPathsIfNecessary();
  448. callForAllSupportedTargets ([this] (build_tools::ProjectType::Target::Type targetType)
  449. {
  450. targets.insert (targetType == build_tools::ProjectType::Target::AggregateTarget ? 0 : -1,
  451. new MakefileTarget (targetType, *this));
  452. });
  453. // If you hit this assert, you tried to generate a project for an exporter
  454. // that does not support any of your targets!
  455. jassert (targets.size() > 0);
  456. }
  457. private:
  458. ValueTreePropertyWithDefault extraPkgConfigValue;
  459. //==============================================================================
  460. StringPairArray getDefines (const BuildConfiguration& config) const
  461. {
  462. StringPairArray result;
  463. result.set ("LINUX", "1");
  464. if (config.isDebug())
  465. {
  466. result.set ("DEBUG", "1");
  467. result.set ("_DEBUG", "1");
  468. }
  469. else
  470. {
  471. result.set ("NDEBUG", "1");
  472. }
  473. result = mergePreprocessorDefs (result, getAllPreprocessorDefs (config, build_tools::ProjectType::Target::unspecified));
  474. return result;
  475. }
  476. StringArray getExtraPkgConfigPackages() const
  477. {
  478. auto packages = StringArray::fromTokens (extraPkgConfigValue.get().toString(), " ", "\"'");
  479. packages.removeEmptyStrings();
  480. return packages;
  481. }
  482. StringArray getCompilePackages() const
  483. {
  484. auto packages = getLinuxPackages (PackageDependencyType::compile);
  485. packages.addArray (getExtraPkgConfigPackages());
  486. return packages;
  487. }
  488. StringArray getLinkPackages() const
  489. {
  490. auto packages = getLinuxPackages (PackageDependencyType::link);
  491. packages.addArray (getExtraPkgConfigPackages());
  492. return packages;
  493. }
  494. String getPreprocessorPkgConfigFlags() const
  495. {
  496. auto compilePackages = getCompilePackages();
  497. if (compilePackages.size() > 0)
  498. return "$(shell $(PKG_CONFIG) --cflags " + compilePackages.joinIntoString (" ") + ")";
  499. return {};
  500. }
  501. String getLinkerPkgConfigFlags() const
  502. {
  503. auto linkPackages = getLinkPackages();
  504. if (linkPackages.size() > 0)
  505. return "$(shell $(PKG_CONFIG) --libs " + linkPackages.joinIntoString (" ") + ")";
  506. return {};
  507. }
  508. StringArray getCPreprocessorFlags (const BuildConfiguration&) const
  509. {
  510. StringArray result;
  511. if (linuxLibs.contains ("pthread"))
  512. result.add ("-pthread");
  513. return result;
  514. }
  515. StringArray getCFlags (const BuildConfiguration& config) const
  516. {
  517. StringArray result;
  518. if (anyTargetIsSharedLibrary())
  519. result.add ("-fPIC");
  520. if (config.isDebug())
  521. {
  522. result.add ("-g");
  523. result.add ("-ggdb");
  524. }
  525. result.add ("-O" + config.getGCCOptimisationFlag());
  526. if (config.isLinkTimeOptimisationEnabled())
  527. result.add ("-flto");
  528. for (auto& recommended : config.getRecommendedCompilerWarningFlags().common)
  529. result.add (recommended);
  530. auto extra = replacePreprocessorTokens (config, config.getAllCompilerFlagsString()).trim();
  531. if (extra.isNotEmpty())
  532. result.add (extra);
  533. return result;
  534. }
  535. StringArray getCXXFlags (const BuildConfiguration& config) const
  536. {
  537. StringArray result;
  538. for (auto& recommended : config.getRecommendedCompilerWarningFlags().cpp)
  539. result.add (recommended);
  540. auto cppStandard = project.getCppStandardString();
  541. if (cppStandard == "latest")
  542. cppStandard = project.getLatestNumberedCppStandardString();
  543. result.add ("-std=" + String (shouldUseGNUExtensions() ? "gnu++" : "c++") + cppStandard);
  544. return result;
  545. }
  546. StringArray getHeaderSearchPaths (const BuildConfiguration& config) const
  547. {
  548. StringArray searchPaths (extraSearchPaths);
  549. searchPaths.addArray (config.getHeaderSearchPaths());
  550. searchPaths = getCleanedStringArray (searchPaths);
  551. StringArray result;
  552. for (auto& path : searchPaths)
  553. result.add (build_tools::unixStylePath (replacePreprocessorTokens (config, path)));
  554. return result;
  555. }
  556. StringArray getLibraryNames (const BuildConfiguration& config) const
  557. {
  558. StringArray result (linuxLibs);
  559. auto libraries = StringArray::fromTokens (getExternalLibrariesString(), ";", "\"'");
  560. libraries.removeEmptyStrings();
  561. for (auto& lib : libraries)
  562. result.add (replacePreprocessorTokens (config, lib).trim());
  563. return result;
  564. }
  565. StringArray getLibrarySearchPaths (const BuildConfiguration& config) const
  566. {
  567. auto result = getSearchPathsFromString (config.getLibrarySearchPathString());
  568. for (auto path : moduleLibSearchPaths)
  569. result.add (path + "/" + config.getModuleLibraryArchName());
  570. return result;
  571. }
  572. StringArray getLinkerFlags (const BuildConfiguration& config) const
  573. {
  574. auto result = makefileExtraLinkerFlags;
  575. result.add ("-fvisibility=hidden");
  576. if (config.isLinkTimeOptimisationEnabled())
  577. result.add ("-flto");
  578. const auto extraFlags = config.getAllLinkerFlagsString().trim();
  579. if (extraFlags.isNotEmpty())
  580. result.add (replacePreprocessorTokens (config, extraFlags));
  581. return result;
  582. }
  583. //==============================================================================
  584. void writeDefineFlags (OutputStream& out, const MakeBuildConfiguration& config) const
  585. {
  586. out << createGCCPreprocessorFlags (mergePreprocessorDefs (getDefines (config), getAllPreprocessorDefs (config, build_tools::ProjectType::Target::unspecified)));
  587. }
  588. void writePkgConfigFlags (OutputStream& out) const
  589. {
  590. auto flags = getPreprocessorPkgConfigFlags();
  591. if (flags.isNotEmpty())
  592. out << " " << flags;
  593. }
  594. void writeCPreprocessorFlags (OutputStream& out, const BuildConfiguration& config) const
  595. {
  596. auto flags = getCPreprocessorFlags (config);
  597. if (! flags.isEmpty())
  598. out << " " << flags.joinIntoString (" ");
  599. }
  600. void writeHeaderPathFlags (OutputStream& out, const BuildConfiguration& config) const
  601. {
  602. for (auto& path : getHeaderSearchPaths (config))
  603. out << " -I" << escapeQuotesAndSpaces (path).replace ("~", "$(HOME)");
  604. }
  605. void writeCppFlags (OutputStream& out, const MakeBuildConfiguration& config) const
  606. {
  607. out << " JUCE_CPPFLAGS := $(DEPFLAGS)";
  608. writeDefineFlags (out, config);
  609. writePkgConfigFlags (out);
  610. writeCPreprocessorFlags (out, config);
  611. writeHeaderPathFlags (out, config);
  612. out << " $(CPPFLAGS)" << newLine;
  613. }
  614. void writeLinkerFlags (OutputStream& out, const BuildConfiguration& config) const
  615. {
  616. out << " JUCE_LDFLAGS += $(TARGET_ARCH) -L$(JUCE_BINDIR) -L$(JUCE_LIBDIR)";
  617. for (auto path : getLibrarySearchPaths (config))
  618. out << " -L" << escapeQuotesAndSpaces (path).replace ("~", "$(HOME)");
  619. auto pkgConfigFlags = getLinkerPkgConfigFlags();
  620. if (pkgConfigFlags.isNotEmpty())
  621. out << " " << getLinkerPkgConfigFlags();
  622. auto linkerFlags = getLinkerFlags (config).joinIntoString (" ");
  623. if (linkerFlags.isNotEmpty())
  624. out << " " << linkerFlags;
  625. for (auto& libName : getLibraryNames (config))
  626. out << " -l" << libName;
  627. out << " $(LDFLAGS)" << newLine;
  628. }
  629. void writeTargetLines (OutputStream& out, const StringArray& packages) const
  630. {
  631. auto n = targets.size();
  632. for (int i = 0; i < n; ++i)
  633. {
  634. if (auto* target = targets.getUnchecked (i))
  635. {
  636. if (target->type == build_tools::ProjectType::Target::AggregateTarget)
  637. {
  638. StringArray dependencies;
  639. MemoryOutputStream subTargetLines;
  640. for (int j = 0; j < n; ++j)
  641. {
  642. if (i == j) continue;
  643. if (auto* dependency = targets.getUnchecked (j))
  644. {
  645. if (dependency->type != build_tools::ProjectType::Target::SharedCodeTarget)
  646. {
  647. auto phonyName = dependency->getPhonyName();
  648. subTargetLines << phonyName << " : " << dependency->getBuildProduct() << newLine;
  649. dependencies.add (phonyName);
  650. }
  651. }
  652. }
  653. out << "all : " << dependencies.joinIntoString (" ") << newLine << newLine;
  654. out << subTargetLines.toString() << newLine << newLine;
  655. }
  656. else
  657. {
  658. if (! getProject().isAudioPluginProject())
  659. out << "all : " << target->getBuildProduct() << newLine << newLine;
  660. target->writeTargetLine (out, packages);
  661. }
  662. }
  663. }
  664. }
  665. void writeConfig (OutputStream& out, const MakeBuildConfiguration& config) const
  666. {
  667. String buildDirName ("build");
  668. auto intermediatesDirName = buildDirName + "/intermediate/" + config.getName();
  669. auto outputDir = buildDirName;
  670. if (config.getTargetBinaryRelativePathString().isNotEmpty())
  671. {
  672. build_tools::RelativePath binaryPath (config.getTargetBinaryRelativePathString(), build_tools::RelativePath::projectFolder);
  673. outputDir = binaryPath.rebased (projectFolder, getTargetFolder(), build_tools::RelativePath::buildTargetFolder).toUnixStyle();
  674. }
  675. out << "ifeq ($(CONFIG)," << escapeQuotesAndSpaces (config.getName()) << ")" << newLine
  676. << " JUCE_BINDIR := " << escapeQuotesAndSpaces (buildDirName) << newLine
  677. << " JUCE_LIBDIR := " << escapeQuotesAndSpaces (buildDirName) << newLine
  678. << " JUCE_OBJDIR := " << escapeQuotesAndSpaces (intermediatesDirName) << newLine
  679. << " JUCE_OUTDIR := " << escapeQuotesAndSpaces (outputDir) << newLine
  680. << newLine
  681. << " ifeq ($(TARGET_ARCH),)" << newLine
  682. << " TARGET_ARCH := " << getArchFlags (config) << newLine
  683. << " endif" << newLine
  684. << newLine;
  685. writeCppFlags (out, config);
  686. for (auto target : targets)
  687. {
  688. auto lines = target->getTargetSettings (config);
  689. if (lines.size() > 0)
  690. out << " " << lines.joinIntoString ("\n ") << newLine;
  691. out << newLine;
  692. }
  693. out << " JUCE_CFLAGS += $(JUCE_CPPFLAGS) $(TARGET_ARCH)";
  694. auto cflags = getCFlags (config).joinIntoString (" ");
  695. if (cflags.isNotEmpty())
  696. out << " " << cflags;
  697. out << " $(CFLAGS)" << newLine;
  698. out << " JUCE_CXXFLAGS += $(JUCE_CFLAGS)";
  699. auto cxxflags = getCXXFlags (config).joinIntoString (" ");
  700. if (cxxflags.isNotEmpty())
  701. out << " " << cxxflags;
  702. out << " $(CXXFLAGS)" << newLine;
  703. writeLinkerFlags (out, config);
  704. out << newLine;
  705. const auto preBuildDirectory = [&]() -> String
  706. {
  707. if (linuxSubprocessHelperProperties.shouldUseLinuxSubprocessHelper())
  708. {
  709. using LSHP = LinuxSubprocessHelperProperties;
  710. const auto dataSource = linuxSubprocessHelperProperties.getLinuxSubprocessHelperBinaryDataSource();
  711. if (auto preBuildDir = LSHP::getParentDirectoryRelativeToBuildTargetFolder (dataSource))
  712. return " " + *preBuildDir;
  713. }
  714. return "";
  715. }();
  716. out << " CLEANCMD = rm -rf $(JUCE_OUTDIR)/$(TARGET) $(JUCE_OBJDIR)" << preBuildDirectory << newLine
  717. << "endif" << newLine
  718. << newLine;
  719. }
  720. void writeIncludeLines (OutputStream& out) const
  721. {
  722. auto n = targets.size();
  723. for (int i = 0; i < n; ++i)
  724. {
  725. if (auto* target = targets.getUnchecked (i))
  726. {
  727. if (target->type == build_tools::ProjectType::Target::AggregateTarget)
  728. continue;
  729. out << "-include $(OBJECTS_" << target->getTargetVarName()
  730. << ":%.o=%.d)" << newLine;
  731. }
  732. }
  733. }
  734. static String getCompilerFlagSchemeVariableName (const String& schemeName) { return "JUCE_COMPILERFLAGSCHEME_" + schemeName; }
  735. std::vector<std::pair<File, String>> findAllFilesToCompile (const Project::Item& projectItem) const
  736. {
  737. std::vector<std::pair<File, String>> results;
  738. if (projectItem.isGroup())
  739. {
  740. for (int i = 0; i < projectItem.getNumChildren(); ++i)
  741. {
  742. auto inner = findAllFilesToCompile (projectItem.getChild (i));
  743. results.insert (results.end(),
  744. std::make_move_iterator (inner.cbegin()),
  745. std::make_move_iterator (inner.cend()));
  746. }
  747. }
  748. else
  749. {
  750. if (projectItem.shouldBeCompiled())
  751. {
  752. auto f = projectItem.getFile();
  753. if (shouldFileBeCompiledByDefault (f))
  754. {
  755. auto scheme = projectItem.getCompilerFlagSchemeString();
  756. auto flags = getCompilerFlagsForProjectItem (projectItem);
  757. if (scheme.isNotEmpty() && flags.isNotEmpty())
  758. results.emplace_back (f, scheme);
  759. else
  760. results.emplace_back (f, String{});
  761. }
  762. }
  763. }
  764. return results;
  765. }
  766. void writeCompilerFlagSchemes (OutputStream& out, const std::vector<std::pair<File, String>>& filesToCompile) const
  767. {
  768. std::set<String> schemesToWrite;
  769. for (const auto& pair : filesToCompile)
  770. if (pair.second.isNotEmpty())
  771. schemesToWrite.insert (pair.second);
  772. if (schemesToWrite.empty())
  773. return;
  774. for (const auto& s : schemesToWrite)
  775. if (const auto flags = getCompilerFlagsForFileCompilerFlagScheme (s); flags.isNotEmpty())
  776. out << getCompilerFlagSchemeVariableName (s) << " := " << flags << newLine;
  777. out << newLine;
  778. }
  779. /* These targets are responsible for building the juce_linux_subprocess_helper, the
  780. juce_simple_binary_builder, and then using the binary builder to create embeddable .h and .cpp
  781. files from the linux subprocess helper.
  782. */
  783. void writeSubprocessHelperTargets (OutputStream& out) const
  784. {
  785. using LSHP = LinuxSubprocessHelperProperties;
  786. const auto ensureDirs = [] (auto& outStream, std::vector<String> dirs)
  787. {
  788. for (const auto& dir : dirs)
  789. outStream << "\t-$(V_AT)mkdir -p " << dir << newLine;
  790. };
  791. const auto makeTarget = [&ensureDirs] (auto& outStream, String input, String output)
  792. {
  793. const auto isObjectTarget = output.endsWith (".o");
  794. const auto isSourceInput = input.endsWith (".cpp");
  795. const auto targetOutput = isObjectTarget ? "$(JUCE_OBJDIR)/" + output : output;
  796. outStream << (isObjectTarget ? "$(JUCE_OBJDIR)/" : "") << output << ": " << input << newLine;
  797. const auto createBuildTargetRelative = [] (auto path)
  798. {
  799. return build_tools::RelativePath { path, build_tools::RelativePath::buildTargetFolder };
  800. };
  801. if (isObjectTarget)
  802. ensureDirs (outStream, { "$(JUCE_OBJDIR)" });
  803. else if (auto outputParentFolder = LSHP::getParentDirectoryRelativeToBuildTargetFolder (createBuildTargetRelative (output)))
  804. ensureDirs (outStream, { *outputParentFolder });
  805. outStream << (isObjectTarget ? "\t@echo \"Compiling " : "\t@echo \"Linking ")
  806. << (isObjectTarget ? input : output) << "\"" << newLine
  807. << "\t$(V_AT)$(CXX) $(JUCE_CXXFLAGS) -o " << targetOutput.quoted()
  808. << " " << (isSourceInput ? "-c \"$<\"" : input.quoted());
  809. if (! isObjectTarget)
  810. outStream << " $(JUCE_LDFLAGS)";
  811. outStream << " $(TARGET_ARCH)" << newLine << newLine;
  812. return targetOutput;
  813. };
  814. const auto subprocessHelperSource = linuxSubprocessHelperProperties.getLinuxSubprocessHelperSource();
  815. const auto subprocessHelperObj = makeTarget (out,
  816. subprocessHelperSource.toUnixStyle(),
  817. getObjectFileFor (subprocessHelperSource));
  818. const auto subprocessHelperPath = makeTarget (out,
  819. subprocessHelperObj,
  820. "$(JUCE_BINDIR)/" + LSHP::getBinaryNameFromSource (subprocessHelperSource));
  821. const auto binaryBuilderSource = linuxSubprocessHelperProperties.getSimpleBinaryBuilderSource();
  822. const auto binaryBuilderObj = makeTarget (out,
  823. binaryBuilderSource.toUnixStyle(),
  824. getObjectFileFor (binaryBuilderSource));
  825. const auto binaryBuilderPath = makeTarget (out,
  826. binaryBuilderObj,
  827. "$(JUCE_BINDIR)/" + LSHP::getBinaryNameFromSource (binaryBuilderSource));
  828. const auto binaryDataSource = linuxSubprocessHelperProperties.getLinuxSubprocessHelperBinaryDataSource();
  829. jassert (binaryDataSource.getRoot() == build_tools::RelativePath::buildTargetFolder);
  830. out << binaryDataSource.toUnixStyle() << ": " << subprocessHelperPath
  831. << " " << binaryBuilderPath
  832. << newLine;
  833. const auto binarySourceDir = [&]() -> String
  834. {
  835. if (const auto p = LSHP::getParentDirectoryRelativeToBuildTargetFolder (binaryDataSource))
  836. return *p;
  837. return ".";
  838. }();
  839. out << "\t$(V_AT)" << binaryBuilderPath.quoted() << " " << subprocessHelperPath.quoted()
  840. << " " << binarySourceDir.quoted() << " " << binaryDataSource.getFileNameWithoutExtension().quoted()
  841. << " LinuxSubprocessHelperBinaryData" << newLine;
  842. out << newLine;
  843. }
  844. void writeMakefile (OutputStream& out) const
  845. {
  846. out << "# Automatically generated makefile, created by the Projucer" << newLine
  847. << "# Don't edit this file! Your changes will be overwritten when you re-save the Projucer project!" << newLine
  848. << newLine;
  849. out << "# build with \"V=1\" for verbose builds" << newLine
  850. << "ifeq ($(V), 1)" << newLine
  851. << "V_AT =" << newLine
  852. << "else" << newLine
  853. << "V_AT = @" << newLine
  854. << "endif" << newLine
  855. << newLine;
  856. out << "# (this disables dependency generation if multiple architectures are set)" << newLine
  857. << "DEPFLAGS := $(if $(word 2, $(TARGET_ARCH)), , -MMD)" << newLine
  858. << newLine;
  859. out << "ifndef PKG_CONFIG" << newLine
  860. << " PKG_CONFIG=pkg-config" << newLine
  861. << "endif" << newLine
  862. << newLine;
  863. out << "ifndef STRIP" << newLine
  864. << " STRIP=strip" << newLine
  865. << "endif" << newLine
  866. << newLine;
  867. out << "ifndef AR" << newLine
  868. << " AR=ar" << newLine
  869. << "endif" << newLine
  870. << newLine;
  871. out << "ifndef CONFIG" << newLine
  872. << " CONFIG=" << escapeQuotesAndSpaces (getConfiguration(0)->getName()) << newLine
  873. << "endif" << newLine
  874. << newLine;
  875. out << "JUCE_ARCH_LABEL := $(shell uname -m)" << newLine
  876. << newLine;
  877. for (ConstConfigIterator config (*this); config.next();)
  878. writeConfig (out, dynamic_cast<const MakeBuildConfiguration&> (*config));
  879. std::vector<std::pair<File, String>> filesToCompile;
  880. for (int i = 0; i < getAllGroups().size(); ++i)
  881. {
  882. auto group = findAllFilesToCompile (getAllGroups().getReference (i));
  883. filesToCompile.insert (filesToCompile.end(),
  884. std::make_move_iterator (group.cbegin()),
  885. std::make_move_iterator (group.cend()));
  886. }
  887. writeCompilerFlagSchemes (out, filesToCompile);
  888. const auto getFilesForTarget = [this] (const std::vector<std::pair<File, String>>& files,
  889. MakefileTarget* target,
  890. const Project& p)
  891. {
  892. std::vector<std::pair<build_tools::RelativePath, String>> targetFiles;
  893. auto targetType = (p.isAudioPluginProject() ? target->type : MakefileTarget::SharedCodeTarget);
  894. for (auto& [path, flags] : files)
  895. {
  896. if (p.getTargetTypeFromFilePath (path, true) == targetType)
  897. {
  898. targetFiles.emplace_back (build_tools::RelativePath { path,
  899. getTargetFolder(),
  900. build_tools::RelativePath::buildTargetFolder },
  901. flags);
  902. }
  903. }
  904. if (( targetType == MakefileTarget::SharedCodeTarget
  905. || targetType == MakefileTarget::StaticLibrary
  906. || targetType == MakefileTarget::DynamicLibrary)
  907. && linuxSubprocessHelperProperties.shouldUseLinuxSubprocessHelper())
  908. {
  909. targetFiles.emplace_back (linuxSubprocessHelperProperties.getLinuxSubprocessHelperBinaryDataSource(), "");
  910. }
  911. if (targetType == MakefileTarget::LV2TurtleProgram)
  912. {
  913. targetFiles.emplace_back (getLV2TurtleDumpProgramSource().rebased (projectFolder,
  914. getTargetFolder(),
  915. build_tools::RelativePath::buildTargetFolder),
  916. String{});
  917. }
  918. return targetFiles;
  919. };
  920. for (auto target : targets)
  921. target->writeObjects (out, getFilesForTarget (filesToCompile, target, project));
  922. out << getPhonyTargetLine() << newLine << newLine;
  923. writeTargetLines (out, getLinkPackages());
  924. for (auto target : targets)
  925. target->addFiles (out, getFilesForTarget (filesToCompile, target, project));
  926. // libexecinfo is a separate library on BSD
  927. out << "$(JUCE_OBJDIR)/execinfo.cmd:" << newLine
  928. << "\t-$(V_AT)mkdir -p $(@D)" << newLine
  929. << "\t-@if [ -z \"$(V_AT)\" ]; then echo \"Checking if we need to link libexecinfo\"; fi" << newLine
  930. << "\t$(V_AT)printf \"int main() { return 0; }\" | $(CXX) -x c++ -o $(@D)/execinfo.x -lexecinfo - >/dev/null 2>&1 && printf -- \"-lexecinfo\" > \"$@\" || touch \"$@\"" << newLine
  931. << newLine;
  932. if (linuxSubprocessHelperProperties.shouldUseLinuxSubprocessHelper())
  933. writeSubprocessHelperTargets (out);
  934. out << "clean:" << newLine
  935. << "\t@echo Cleaning " << projectName << newLine
  936. << "\t$(V_AT)$(CLEANCMD)" << newLine
  937. << newLine;
  938. out << "strip:" << newLine
  939. << "\t@echo Stripping " << projectName << newLine
  940. << "\t-$(V_AT)$(STRIP) --strip-unneeded $(JUCE_OUTDIR)/$(TARGET)" << newLine
  941. << newLine;
  942. writeIncludeLines (out);
  943. }
  944. String getArchFlags (const BuildConfiguration& config) const
  945. {
  946. if (auto* makeConfig = dynamic_cast<const MakeBuildConfiguration*> (&config))
  947. return makeConfig->getArchitectureTypeString();
  948. return "-march=native";
  949. }
  950. String getObjectFileFor (const build_tools::RelativePath& file) const
  951. {
  952. return file.getFileNameWithoutExtension()
  953. + "_" + String::toHexString (file.toUnixStyle().hashCode()) + ".o";
  954. }
  955. String getPhonyTargetLine() const
  956. {
  957. MemoryOutputStream phonyTargetLine;
  958. phonyTargetLine << ".PHONY: clean all strip";
  959. if (! getProject().isAudioPluginProject())
  960. return phonyTargetLine.toString();
  961. for (auto target : targets)
  962. if (target->type != build_tools::ProjectType::Target::SharedCodeTarget
  963. && target->type != build_tools::ProjectType::Target::AggregateTarget)
  964. phonyTargetLine << " " << target->getPhonyName();
  965. return phonyTargetLine.toString();
  966. }
  967. OwnedArray<MakefileTarget> targets;
  968. JUCE_DECLARE_NON_COPYABLE (MakefileProjectExporter)
  969. };