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.

1283 lines
53KB

  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 == LV2Helper)
  175. {
  176. targetName = Project::getLV2FileWriterName();
  177. }
  178. else if (type == VST3Helper)
  179. {
  180. targetName = Project::getVST3FileWriterName();
  181. }
  182. s.add ("JUCE_TARGET_" + getTargetVarName() + String (" := ") + escapeQuotesAndSpaces (targetName));
  183. if (type == LV2PlugIn)
  184. s.add ("JUCE_LV2_FULL_PATH := $(JUCE_OUTDIR)/$(JUCE_TARGET_LV2_PLUGIN)");
  185. if (config.isPluginBinaryCopyStepEnabled()
  186. && (type == VST3PlugIn || type == VSTPlugIn || type == UnityPlugIn || type == LV2PlugIn))
  187. {
  188. String copyCmd ("JUCE_COPYCMD_" + getTargetVarName() + String (" := $(JUCE_OUTDIR)/"));
  189. if (type == VST3PlugIn)
  190. {
  191. s.add ("JUCE_VST3DESTDIR := " + config.getVST3BinaryLocationString());
  192. s.add (copyCmd + "$(JUCE_VST3DIR) $(JUCE_VST3DESTDIR)");
  193. }
  194. else if (type == VSTPlugIn)
  195. {
  196. s.add ("JUCE_VSTDESTDIR := " + config.getVSTBinaryLocationString());
  197. s.add (copyCmd + escapeQuotesAndSpaces (targetName) + " $(JUCE_VSTDESTDIR)");
  198. }
  199. else if (type == UnityPlugIn)
  200. {
  201. s.add ("JUCE_UNITYDESTDIR := " + config.getUnityPluginBinaryLocationString());
  202. s.add (copyCmd + "$(JUCE_UNITYDIR)/. $(JUCE_UNITYDESTDIR)");
  203. }
  204. else if (type == LV2PlugIn)
  205. {
  206. s.add ("JUCE_LV2DESTDIR := " + config.getLV2BinaryLocationString());
  207. s.add (copyCmd + "$(JUCE_LV2DIR) $(JUCE_LV2DESTDIR)");
  208. }
  209. }
  210. return s;
  211. }
  212. String getTargetFileSuffix() const
  213. {
  214. if (type == VSTPlugIn || type == VST3PlugIn || type == UnityPlugIn || type == DynamicLibrary)
  215. return ".so";
  216. if (type == SharedCodeTarget || type == StaticLibrary)
  217. return ".a";
  218. return {};
  219. }
  220. String getTargetVarName() const
  221. {
  222. return String (getName()).toUpperCase().replaceCharacter (L' ', L'_');
  223. }
  224. void writeObjects (OutputStream& out, const std::vector<std::pair<build_tools::RelativePath, String>>& filesToCompile) const
  225. {
  226. out << "OBJECTS_" + getTargetVarName() + String (" := \\") << newLine;
  227. for (auto& f : filesToCompile)
  228. out << " $(JUCE_OBJDIR)/" << escapeQuotesAndSpaces (owner.getObjectFileFor (f.first))
  229. << " \\" << newLine;
  230. out << newLine;
  231. }
  232. void addFiles (OutputStream& out, const std::vector<std::pair<build_tools::RelativePath, String>>& filesToCompile)
  233. {
  234. auto cppflagsVarName = "JUCE_CPPFLAGS_" + getTargetVarName();
  235. auto cflagsVarName = "JUCE_CFLAGS_" + getTargetVarName();
  236. for (auto& [path, flags] : filesToCompile)
  237. {
  238. const auto additionalTargetDependencies = [&path = path, this]
  239. {
  240. if ( owner.linuxSubprocessHelperProperties.shouldUseLinuxSubprocessHelper()
  241. && path.getFileName().contains ("include_juce_gui_extra.cpp"))
  242. {
  243. return owner.linuxSubprocessHelperProperties
  244. .getLinuxSubprocessHelperBinaryDataSource()
  245. .toUnixStyle();
  246. }
  247. return String{};
  248. }();
  249. const auto prependedWithSpaceIfNotEmpty = [] (auto s)
  250. {
  251. return s.isEmpty() ? s : " " + s;
  252. };
  253. out << "$(JUCE_OBJDIR)/" << escapeQuotesAndSpaces (owner.getObjectFileFor (path)) << ": " << escapeQuotesAndSpaces (path.toUnixStyle())
  254. << prependedWithSpaceIfNotEmpty (additionalTargetDependencies) << newLine
  255. << "\t-$(V_AT)mkdir -p $(@D)" << newLine
  256. << "\t@echo \"Compiling " << path.getFileName() << "\"" << newLine
  257. << (path.hasFileExtension ("c;s;S") ? "\t$(V_AT)$(CC) $(JUCE_CFLAGS) " : "\t$(V_AT)$(CXX) $(JUCE_CXXFLAGS) ")
  258. << "$(" << cppflagsVarName << ") $(" << cflagsVarName << ")"
  259. << (flags.isNotEmpty() ? " $(" + owner.getCompilerFlagSchemeVariableName (flags) + ")" : "") << " -o \"$@\" -c \"$<\"" << newLine
  260. << newLine;
  261. }
  262. }
  263. String getBuildProduct() const
  264. {
  265. return "$(JUCE_OUTDIR)/$(JUCE_TARGET_" + getTargetVarName() + ")";
  266. }
  267. String getPhonyName() const
  268. {
  269. if (type == LV2Helper)
  270. return "LV2_MANIFEST_HELPER";
  271. if (type == VST3Helper)
  272. return "VST3_MANIFEST_HELPER";
  273. return String (getName()).upToFirstOccurrenceOf (" ", false, false);
  274. }
  275. void writeTargetLine (OutputStream& out, const StringArray& packages)
  276. {
  277. jassert (type != AggregateTarget);
  278. out << getBuildProduct() << " : "
  279. << "$(OBJECTS_" << getTargetVarName() << ") $(JUCE_OBJDIR)/execinfo.cmd $(RESOURCES)";
  280. if (type != SharedCodeTarget && owner.shouldBuildTargetType (SharedCodeTarget))
  281. out << " $(JUCE_OUTDIR)/$(JUCE_TARGET_SHARED_CODE)";
  282. if (type == LV2PlugIn)
  283. out << " $(JUCE_OUTDIR)/$(JUCE_TARGET_LV2_MANIFEST_HELPER)";
  284. else if (type == VST3PlugIn && owner.project.isVst3ManifestEnabled())
  285. out << " $(JUCE_OUTDIR)/$(JUCE_TARGET_VST3_MANIFEST_HELPER)";
  286. out << newLine;
  287. if (! packages.isEmpty())
  288. {
  289. out << "\t@command -v $(PKG_CONFIG) >/dev/null 2>&1 || { echo >&2 \"pkg-config not installed. Please, install it.\"; exit 1; }" << newLine
  290. << "\t@$(PKG_CONFIG) --print-errors";
  291. for (auto& pkg : packages)
  292. out << " " << pkg;
  293. out << newLine;
  294. }
  295. out << "\t@echo Linking \"" << owner.projectName << " - " << getName() << "\"" << newLine
  296. << "\t-$(V_AT)mkdir -p $(JUCE_BINDIR)" << newLine
  297. << "\t-$(V_AT)mkdir -p $(JUCE_LIBDIR)" << newLine
  298. << "\t-$(V_AT)mkdir -p $(JUCE_OUTDIR)" << newLine;
  299. if (type == VST3PlugIn)
  300. out << "\t-$(V_AT)mkdir -p $(JUCE_OUTDIR)/$(JUCE_VST3DIR)/$(JUCE_VST3SUBDIR)" << newLine;
  301. else if (type == UnityPlugIn)
  302. out << "\t-$(V_AT)mkdir -p $(JUCE_OUTDIR)/$(JUCE_UNITYDIR)" << newLine;
  303. else if (type == LV2PlugIn)
  304. out << "\t-$(V_AT)mkdir -p $(JUCE_OUTDIR)/$(JUCE_LV2DIR)" << newLine;
  305. if (owner.projectType.isStaticLibrary() || type == SharedCodeTarget)
  306. {
  307. out << "\t$(V_AT)$(AR) -rcs " << getBuildProduct()
  308. << " $(OBJECTS_" << getTargetVarName() << ")" << newLine;
  309. }
  310. else
  311. {
  312. out << "\t$(V_AT)$(CXX) -o " << getBuildProduct()
  313. << " $(OBJECTS_" << getTargetVarName() << ") ";
  314. if (owner.shouldBuildTargetType (SharedCodeTarget))
  315. out << "$(JUCE_OUTDIR)/$(JUCE_TARGET_SHARED_CODE) ";
  316. out << "$(JUCE_LDFLAGS) $(shell cat $(JUCE_OBJDIR)/execinfo.cmd) ";
  317. if (getTargetFileType() == sharedLibraryOrDLL || getTargetFileType() == pluginBundle
  318. || type == GUIApp || type == StandalonePlugIn)
  319. out << "$(JUCE_LDFLAGS_" << getTargetVarName() << ") ";
  320. out << "$(RESOURCES) $(TARGET_ARCH)" << newLine;
  321. }
  322. if (type == VST3PlugIn)
  323. {
  324. if (owner.project.isVst3ManifestEnabled())
  325. {
  326. out << "\t$(V_AT) $(JUCE_OUTDIR)/$(JUCE_TARGET_VST3_MANIFEST_HELPER) "
  327. "-create "
  328. "-version " << owner.project.getVersionString().quoted() << " "
  329. "-path \"$(JUCE_OUTDIR)/$(JUCE_VST3DIR)\" "
  330. "-output \"$(JUCE_OUTDIR)/$(JUCE_VST3DIR)/Contents/moduleinfo.json\" " << newLine;
  331. }
  332. out << "\t-$(V_AT)[ ! \"$(JUCE_VST3DESTDIR)\" ] || (mkdir -p $(JUCE_VST3DESTDIR) && cp -R $(JUCE_COPYCMD_VST3))" << newLine;
  333. }
  334. else if (type == VSTPlugIn)
  335. {
  336. out << "\t-$(V_AT)[ ! \"$(JUCE_VSTDESTDIR)\" ] || (mkdir -p $(JUCE_VSTDESTDIR) && cp -R $(JUCE_COPYCMD_VST))" << newLine;
  337. }
  338. else if (type == UnityPlugIn)
  339. {
  340. auto scriptName = owner.getProject().getUnityScriptName();
  341. build_tools::RelativePath scriptPath (owner.getProject().getGeneratedCodeFolder().getChildFile (scriptName),
  342. owner.getTargetFolder(),
  343. build_tools::RelativePath::projectFolder);
  344. out << "\t-$(V_AT)cp " + scriptPath.toUnixStyle() + " $(JUCE_OUTDIR)/$(JUCE_UNITYDIR)" << newLine
  345. << "\t-$(V_AT)[ ! \"$(JUCE_UNITYDESTDIR)\" ] || (mkdir -p $(JUCE_UNITYDESTDIR) && cp -R $(JUCE_COPYCMD_UNITY_PLUGIN))" << newLine;
  346. }
  347. else if (type == LV2PlugIn)
  348. {
  349. out << "\t$(V_AT) $(JUCE_OUTDIR)/$(JUCE_TARGET_LV2_MANIFEST_HELPER) $(JUCE_LV2_FULL_PATH)" << newLine
  350. << "\t-$(V_AT)[ ! \"$(JUCE_LV2DESTDIR)\" ] || (mkdir -p $(JUCE_LV2DESTDIR) && cp -R $(JUCE_COPYCMD_LV2_PLUGIN))" << newLine;
  351. }
  352. out << newLine;
  353. }
  354. const MakefileProjectExporter& owner;
  355. };
  356. //==============================================================================
  357. static String getDisplayName() { return "Linux Makefile"; }
  358. static String getValueTreeTypeName() { return "LINUX_MAKE"; }
  359. static String getTargetFolderName() { return "LinuxMakefile"; }
  360. Identifier getExporterIdentifier() const override { return getValueTreeTypeName(); }
  361. static MakefileProjectExporter* createForSettings (Project& projectToUse, const ValueTree& settingsToUse)
  362. {
  363. if (settingsToUse.hasType (getValueTreeTypeName()))
  364. return new MakefileProjectExporter (projectToUse, settingsToUse);
  365. return nullptr;
  366. }
  367. //==============================================================================
  368. MakefileProjectExporter (Project& p, const ValueTree& t)
  369. : ProjectExporter (p, t),
  370. extraPkgConfigValue (settings, Ids::linuxExtraPkgConfig, getUndoManager())
  371. {
  372. name = getDisplayName();
  373. targetLocationValue.setDefault (getDefaultBuildsRootFolder() + getTargetFolderName());
  374. }
  375. //==============================================================================
  376. bool canLaunchProject() override { return false; }
  377. bool launchProject() override { return false; }
  378. bool usesMMFiles() const override { return false; }
  379. bool canCopeWithDuplicateFiles() override { return false; }
  380. bool supportsUserDefinedConfigurations() const override { return true; }
  381. bool isXcode() const override { return false; }
  382. bool isVisualStudio() const override { return false; }
  383. bool isCodeBlocks() const override { return false; }
  384. bool isMakefile() const override { return true; }
  385. bool isAndroidStudio() const override { return false; }
  386. bool isAndroid() const override { return false; }
  387. bool isWindows() const override { return false; }
  388. bool isLinux() const override { return true; }
  389. bool isOSX() const override { return false; }
  390. bool isiOS() const override { return false; }
  391. String getNewLineString() const override { return "\n"; }
  392. bool supportsTargetType (build_tools::ProjectType::Target::Type type) const override
  393. {
  394. using Target = build_tools::ProjectType::Target;
  395. switch (type)
  396. {
  397. case Target::GUIApp:
  398. case Target::ConsoleApp:
  399. case Target::StaticLibrary:
  400. case Target::SharedCodeTarget:
  401. case Target::AggregateTarget:
  402. case Target::VSTPlugIn:
  403. case Target::VST3PlugIn:
  404. case Target::VST3Helper:
  405. case Target::StandalonePlugIn:
  406. case Target::DynamicLibrary:
  407. case Target::UnityPlugIn:
  408. case Target::LV2PlugIn:
  409. case Target::LV2Helper:
  410. return true;
  411. case Target::AAXPlugIn:
  412. case Target::AudioUnitPlugIn:
  413. case Target::AudioUnitv3PlugIn:
  414. case Target::unspecified:
  415. default:
  416. break;
  417. }
  418. return false;
  419. }
  420. void createExporterProperties (PropertyListBuilder& properties) override
  421. {
  422. properties.add (new TextPropertyComponent (extraPkgConfigValue, "pkg-config libraries", 8192, false),
  423. "Extra pkg-config libraries for you application. Each package should be space separated.");
  424. }
  425. void initialiseDependencyPathValues() override
  426. {
  427. vstLegacyPathValueWrapper.init ({ settings, Ids::vstLegacyFolder, nullptr },
  428. getAppSettings().getStoredPath (Ids::vstLegacyPath, TargetOS::linux), TargetOS::linux);
  429. araPathValueWrapper.init ({ settings, Ids::araFolder, nullptr },
  430. getAppSettings().getStoredPath (Ids::araPath, TargetOS::linux), TargetOS::linux);
  431. }
  432. //==============================================================================
  433. bool anyTargetIsSharedLibrary() const
  434. {
  435. for (auto* target : targets)
  436. {
  437. auto fileType = target->getTargetFileType();
  438. if (fileType == build_tools::ProjectType::Target::sharedLibraryOrDLL
  439. || fileType == build_tools::ProjectType::Target::pluginBundle)
  440. return true;
  441. }
  442. return false;
  443. }
  444. //==============================================================================
  445. void create (const OwnedArray<LibraryModule>&) const override
  446. {
  447. build_tools::writeStreamToFile (getTargetFolder().getChildFile ("Makefile"), [&] (MemoryOutputStream& mo)
  448. {
  449. mo.setNewLineString (getNewLineString());
  450. writeMakefile (mo);
  451. });
  452. if (project.shouldBuildVST3())
  453. {
  454. auto helperDir = getTargetFolder().getChildFile ("make_helpers");
  455. helperDir.createDirectory();
  456. build_tools::overwriteFileIfDifferentOrThrow (helperDir.getChildFile ("arch_detection.cpp"),
  457. BinaryData::juce_runtime_arch_detection_cpp);
  458. }
  459. linuxSubprocessHelperProperties.deployLinuxSubprocessHelperSourceFilesIfNecessary();
  460. }
  461. //==============================================================================
  462. void addPlatformSpecificSettingsForProjectType (const build_tools::ProjectType&) override
  463. {
  464. linuxSubprocessHelperProperties.addToExtraSearchPathsIfNecessary();
  465. callForAllSupportedTargets ([this] (build_tools::ProjectType::Target::Type targetType)
  466. {
  467. targets.insert (targetType == build_tools::ProjectType::Target::AggregateTarget ? 0 : -1,
  468. new MakefileTarget (targetType, *this));
  469. });
  470. // If you hit this assert, you tried to generate a project for an exporter
  471. // that does not support any of your targets!
  472. jassert (targets.size() > 0);
  473. }
  474. private:
  475. ValueTreePropertyWithDefault extraPkgConfigValue;
  476. //==============================================================================
  477. StringPairArray getDefines (const BuildConfiguration& config) const
  478. {
  479. StringPairArray result;
  480. result.set ("LINUX", "1");
  481. if (config.isDebug())
  482. {
  483. result.set ("DEBUG", "1");
  484. result.set ("_DEBUG", "1");
  485. }
  486. else
  487. {
  488. result.set ("NDEBUG", "1");
  489. }
  490. result = mergePreprocessorDefs (result, getAllPreprocessorDefs (config, build_tools::ProjectType::Target::unspecified));
  491. return result;
  492. }
  493. StringArray getExtraPkgConfigPackages() const
  494. {
  495. auto packages = StringArray::fromTokens (extraPkgConfigValue.get().toString(), " ", "\"'");
  496. packages.removeEmptyStrings();
  497. return packages;
  498. }
  499. StringArray getCompilePackages() const
  500. {
  501. auto packages = getLinuxPackages (PackageDependencyType::compile);
  502. packages.addArray (getExtraPkgConfigPackages());
  503. return packages;
  504. }
  505. StringArray getLinkPackages() const
  506. {
  507. auto packages = getLinuxPackages (PackageDependencyType::link);
  508. packages.addArray (getExtraPkgConfigPackages());
  509. return packages;
  510. }
  511. String getPreprocessorPkgConfigFlags() const
  512. {
  513. auto compilePackages = getCompilePackages();
  514. if (compilePackages.size() > 0)
  515. return "$(shell $(PKG_CONFIG) --cflags " + compilePackages.joinIntoString (" ") + ")";
  516. return {};
  517. }
  518. String getLinkerPkgConfigFlags() const
  519. {
  520. auto linkPackages = getLinkPackages();
  521. if (linkPackages.size() > 0)
  522. return "$(shell $(PKG_CONFIG) --libs " + linkPackages.joinIntoString (" ") + ")";
  523. return {};
  524. }
  525. StringArray getCPreprocessorFlags (const BuildConfiguration&) const
  526. {
  527. StringArray result;
  528. if (linuxLibs.contains ("pthread"))
  529. result.add ("-pthread");
  530. return result;
  531. }
  532. StringArray getCFlags (const BuildConfiguration& config) const
  533. {
  534. StringArray result;
  535. if (anyTargetIsSharedLibrary())
  536. result.add ("-fPIC");
  537. if (config.isDebug())
  538. {
  539. result.add ("-g");
  540. result.add ("-ggdb");
  541. }
  542. result.add ("-O" + config.getGCCOptimisationFlag());
  543. if (config.isLinkTimeOptimisationEnabled())
  544. result.add ("-flto");
  545. for (auto& recommended : config.getRecommendedCompilerWarningFlags().common)
  546. result.add (recommended);
  547. auto extra = replacePreprocessorTokens (config, config.getAllCompilerFlagsString()).trim();
  548. if (extra.isNotEmpty())
  549. result.add (extra);
  550. return result;
  551. }
  552. StringArray getCXXFlags (const BuildConfiguration& config) const
  553. {
  554. StringArray result;
  555. for (auto& recommended : config.getRecommendedCompilerWarningFlags().cpp)
  556. result.add (recommended);
  557. auto cppStandard = project.getCppStandardString();
  558. if (cppStandard == "latest")
  559. cppStandard = project.getLatestNumberedCppStandardString();
  560. result.add ("-std=" + String (shouldUseGNUExtensions() ? "gnu++" : "c++") + cppStandard);
  561. return result;
  562. }
  563. StringArray getHeaderSearchPaths (const BuildConfiguration& config) const
  564. {
  565. StringArray searchPaths (extraSearchPaths);
  566. searchPaths.addArray (config.getHeaderSearchPaths());
  567. searchPaths = getCleanedStringArray (searchPaths);
  568. StringArray result;
  569. for (auto& path : searchPaths)
  570. result.add (build_tools::unixStylePath (replacePreprocessorTokens (config, path)));
  571. return result;
  572. }
  573. StringArray getLibraryNames (const BuildConfiguration& config) const
  574. {
  575. StringArray result (linuxLibs);
  576. auto libraries = StringArray::fromTokens (getExternalLibrariesString(), ";", "\"'");
  577. libraries.removeEmptyStrings();
  578. for (auto& lib : libraries)
  579. result.add (replacePreprocessorTokens (config, lib).trim());
  580. return result;
  581. }
  582. StringArray getLibrarySearchPaths (const BuildConfiguration& config) const
  583. {
  584. auto result = getSearchPathsFromString (config.getLibrarySearchPathString());
  585. for (auto path : moduleLibSearchPaths)
  586. result.add (path + "/" + config.getModuleLibraryArchName());
  587. return result;
  588. }
  589. StringArray getLinkerFlags (const BuildConfiguration& config) const
  590. {
  591. auto result = makefileExtraLinkerFlags;
  592. result.add ("-fvisibility=hidden");
  593. if (config.isLinkTimeOptimisationEnabled())
  594. result.add ("-flto");
  595. const auto extraFlags = config.getAllLinkerFlagsString().trim();
  596. if (extraFlags.isNotEmpty())
  597. result.add (replacePreprocessorTokens (config, extraFlags));
  598. return result;
  599. }
  600. //==============================================================================
  601. void writeDefineFlags (OutputStream& out, const MakeBuildConfiguration& config) const
  602. {
  603. out << createGCCPreprocessorFlags (mergePreprocessorDefs (getDefines (config), getAllPreprocessorDefs (config, build_tools::ProjectType::Target::unspecified)));
  604. }
  605. void writePkgConfigFlags (OutputStream& out) const
  606. {
  607. auto flags = getPreprocessorPkgConfigFlags();
  608. if (flags.isNotEmpty())
  609. out << " " << flags;
  610. }
  611. void writeCPreprocessorFlags (OutputStream& out, const BuildConfiguration& config) const
  612. {
  613. auto flags = getCPreprocessorFlags (config);
  614. if (! flags.isEmpty())
  615. out << " " << flags.joinIntoString (" ");
  616. }
  617. void writeHeaderPathFlags (OutputStream& out, const BuildConfiguration& config) const
  618. {
  619. for (auto& path : getHeaderSearchPaths (config))
  620. out << " -I" << escapeQuotesAndSpaces (path).replace ("~", "$(HOME)");
  621. }
  622. void writeCppFlags (OutputStream& out, const MakeBuildConfiguration& config) const
  623. {
  624. out << " JUCE_CPPFLAGS := $(DEPFLAGS)";
  625. writeDefineFlags (out, config);
  626. writePkgConfigFlags (out);
  627. writeCPreprocessorFlags (out, config);
  628. writeHeaderPathFlags (out, config);
  629. out << " $(CPPFLAGS)" << newLine;
  630. }
  631. void writeLinkerFlags (OutputStream& out, const BuildConfiguration& config) const
  632. {
  633. out << " JUCE_LDFLAGS += $(TARGET_ARCH) -L$(JUCE_BINDIR) -L$(JUCE_LIBDIR)";
  634. for (auto path : getLibrarySearchPaths (config))
  635. out << " -L" << escapeQuotesAndSpaces (path).replace ("~", "$(HOME)");
  636. auto pkgConfigFlags = getLinkerPkgConfigFlags();
  637. if (pkgConfigFlags.isNotEmpty())
  638. out << " " << getLinkerPkgConfigFlags();
  639. auto linkerFlags = getLinkerFlags (config).joinIntoString (" ");
  640. if (linkerFlags.isNotEmpty())
  641. out << " " << linkerFlags;
  642. for (auto& libName : getLibraryNames (config))
  643. out << " -l" << libName;
  644. out << " $(LDFLAGS)" << newLine;
  645. }
  646. void writeTargetLines (OutputStream& out, const StringArray& packages) const
  647. {
  648. auto n = targets.size();
  649. for (int i = 0; i < n; ++i)
  650. {
  651. if (auto* target = targets.getUnchecked (i))
  652. {
  653. if (target->type == build_tools::ProjectType::Target::AggregateTarget)
  654. {
  655. StringArray dependencies;
  656. MemoryOutputStream subTargetLines;
  657. for (int j = 0; j < n; ++j)
  658. {
  659. if (i == j) continue;
  660. if (auto* dependency = targets.getUnchecked (j))
  661. {
  662. if (dependency->type != build_tools::ProjectType::Target::SharedCodeTarget)
  663. {
  664. auto phonyName = dependency->getPhonyName();
  665. subTargetLines << phonyName << " : " << dependency->getBuildProduct() << newLine;
  666. dependencies.add (phonyName);
  667. }
  668. }
  669. }
  670. out << "all : " << dependencies.joinIntoString (" ") << newLine << newLine;
  671. out << subTargetLines.toString() << newLine << newLine;
  672. }
  673. else
  674. {
  675. if (! getProject().isAudioPluginProject())
  676. out << "all : " << target->getBuildProduct() << newLine << newLine;
  677. target->writeTargetLine (out, packages);
  678. }
  679. }
  680. }
  681. }
  682. void writeConfig (OutputStream& out, const MakeBuildConfiguration& config) const
  683. {
  684. String buildDirName ("build");
  685. auto intermediatesDirName = buildDirName + "/intermediate/" + config.getName();
  686. auto outputDir = buildDirName;
  687. if (config.getTargetBinaryRelativePathString().isNotEmpty())
  688. {
  689. build_tools::RelativePath binaryPath (config.getTargetBinaryRelativePathString(), build_tools::RelativePath::projectFolder);
  690. outputDir = binaryPath.rebased (projectFolder, getTargetFolder(), build_tools::RelativePath::buildTargetFolder).toUnixStyle();
  691. }
  692. out << "ifeq ($(CONFIG)," << escapeQuotesAndSpaces (config.getName()) << ")" << newLine
  693. << " JUCE_BINDIR := " << escapeQuotesAndSpaces (buildDirName) << newLine
  694. << " JUCE_LIBDIR := " << escapeQuotesAndSpaces (buildDirName) << newLine
  695. << " JUCE_OBJDIR := " << escapeQuotesAndSpaces (intermediatesDirName) << newLine
  696. << " JUCE_OUTDIR := " << escapeQuotesAndSpaces (outputDir) << newLine
  697. << newLine
  698. << " ifeq ($(TARGET_ARCH),)" << newLine
  699. << " TARGET_ARCH := " << getArchFlags (config) << newLine
  700. << " endif" << newLine
  701. << newLine;
  702. writeCppFlags (out, config);
  703. for (auto target : targets)
  704. {
  705. auto lines = target->getTargetSettings (config);
  706. if (lines.size() > 0)
  707. out << " " << lines.joinIntoString ("\n ") << newLine;
  708. out << newLine;
  709. }
  710. out << " JUCE_CFLAGS += $(JUCE_CPPFLAGS) $(TARGET_ARCH)";
  711. auto cflags = getCFlags (config).joinIntoString (" ");
  712. if (cflags.isNotEmpty())
  713. out << " " << cflags;
  714. out << " $(CFLAGS)" << newLine;
  715. out << " JUCE_CXXFLAGS += $(JUCE_CFLAGS)";
  716. auto cxxflags = getCXXFlags (config).joinIntoString (" ");
  717. if (cxxflags.isNotEmpty())
  718. out << " " << cxxflags;
  719. out << " $(CXXFLAGS)" << newLine;
  720. writeLinkerFlags (out, config);
  721. out << newLine;
  722. const auto preBuildDirectory = [&]() -> String
  723. {
  724. if (linuxSubprocessHelperProperties.shouldUseLinuxSubprocessHelper())
  725. {
  726. using LSHP = LinuxSubprocessHelperProperties;
  727. const auto dataSource = linuxSubprocessHelperProperties.getLinuxSubprocessHelperBinaryDataSource();
  728. if (auto preBuildDir = LSHP::getParentDirectoryRelativeToBuildTargetFolder (dataSource))
  729. return " " + *preBuildDir;
  730. }
  731. return "";
  732. }();
  733. out << " CLEANCMD = rm -rf $(JUCE_OUTDIR)/$(TARGET) $(JUCE_OBJDIR)" << preBuildDirectory << newLine
  734. << "endif" << newLine
  735. << newLine;
  736. }
  737. void writeIncludeLines (OutputStream& out) const
  738. {
  739. auto n = targets.size();
  740. for (int i = 0; i < n; ++i)
  741. {
  742. if (auto* target = targets.getUnchecked (i))
  743. {
  744. if (target->type == build_tools::ProjectType::Target::AggregateTarget)
  745. continue;
  746. out << "-include $(OBJECTS_" << target->getTargetVarName()
  747. << ":%.o=%.d)" << newLine;
  748. }
  749. }
  750. }
  751. static String getCompilerFlagSchemeVariableName (const String& schemeName) { return "JUCE_COMPILERFLAGSCHEME_" + schemeName; }
  752. std::vector<std::pair<File, String>> findAllFilesToCompile (const Project::Item& projectItem) const
  753. {
  754. std::vector<std::pair<File, String>> results;
  755. if (projectItem.isGroup())
  756. {
  757. for (int i = 0; i < projectItem.getNumChildren(); ++i)
  758. {
  759. auto inner = findAllFilesToCompile (projectItem.getChild (i));
  760. results.insert (results.end(),
  761. std::make_move_iterator (inner.cbegin()),
  762. std::make_move_iterator (inner.cend()));
  763. }
  764. }
  765. else
  766. {
  767. if (projectItem.shouldBeCompiled())
  768. {
  769. auto f = projectItem.getFile();
  770. if (shouldFileBeCompiledByDefault (f))
  771. {
  772. auto scheme = projectItem.getCompilerFlagSchemeString();
  773. auto flags = getCompilerFlagsForProjectItem (projectItem);
  774. if (scheme.isNotEmpty() && flags.isNotEmpty())
  775. results.emplace_back (f, scheme);
  776. else
  777. results.emplace_back (f, String{});
  778. }
  779. }
  780. }
  781. return results;
  782. }
  783. void writeCompilerFlagSchemes (OutputStream& out, const std::vector<std::pair<File, String>>& filesToCompile) const
  784. {
  785. std::set<String> schemesToWrite;
  786. for (const auto& pair : filesToCompile)
  787. if (pair.second.isNotEmpty())
  788. schemesToWrite.insert (pair.second);
  789. if (schemesToWrite.empty())
  790. return;
  791. for (const auto& s : schemesToWrite)
  792. if (const auto flags = getCompilerFlagsForFileCompilerFlagScheme (s); flags.isNotEmpty())
  793. out << getCompilerFlagSchemeVariableName (s) << " := " << flags << newLine;
  794. out << newLine;
  795. }
  796. /* These targets are responsible for building the juce_linux_subprocess_helper, the
  797. juce_simple_binary_builder, and then using the binary builder to create embeddable .h and .cpp
  798. files from the linux subprocess helper.
  799. */
  800. void writeSubprocessHelperTargets (OutputStream& out) const
  801. {
  802. using LSHP = LinuxSubprocessHelperProperties;
  803. const auto ensureDirs = [] (auto& outStream, std::vector<String> dirs)
  804. {
  805. for (const auto& dir : dirs)
  806. outStream << "\t-$(V_AT)mkdir -p " << dir << newLine;
  807. };
  808. const auto makeTarget = [&ensureDirs] (auto& outStream, String input, String output)
  809. {
  810. const auto isObjectTarget = output.endsWith (".o");
  811. const auto isSourceInput = input.endsWith (".cpp");
  812. const auto targetOutput = isObjectTarget ? "$(JUCE_OBJDIR)/" + output : output;
  813. outStream << (isObjectTarget ? "$(JUCE_OBJDIR)/" : "") << output << ": " << input << newLine;
  814. const auto createBuildTargetRelative = [] (auto path)
  815. {
  816. return build_tools::RelativePath { path, build_tools::RelativePath::buildTargetFolder };
  817. };
  818. if (isObjectTarget)
  819. ensureDirs (outStream, { "$(JUCE_OBJDIR)" });
  820. else if (auto outputParentFolder = LSHP::getParentDirectoryRelativeToBuildTargetFolder (createBuildTargetRelative (output)))
  821. ensureDirs (outStream, { *outputParentFolder });
  822. outStream << (isObjectTarget ? "\t@echo \"Compiling " : "\t@echo \"Linking ")
  823. << (isObjectTarget ? input : output) << "\"" << newLine
  824. << "\t$(V_AT)$(CXX) $(JUCE_CXXFLAGS) -o " << targetOutput.quoted()
  825. << " " << (isSourceInput ? "-c \"$<\"" : input.quoted());
  826. if (! isObjectTarget)
  827. outStream << " $(JUCE_LDFLAGS)";
  828. outStream << " $(TARGET_ARCH)" << newLine << newLine;
  829. return targetOutput;
  830. };
  831. const auto subprocessHelperSource = linuxSubprocessHelperProperties.getLinuxSubprocessHelperSource();
  832. const auto subprocessHelperObj = makeTarget (out,
  833. subprocessHelperSource.toUnixStyle(),
  834. getObjectFileFor (subprocessHelperSource));
  835. const auto subprocessHelperPath = makeTarget (out,
  836. subprocessHelperObj,
  837. "$(JUCE_BINDIR)/" + LSHP::getBinaryNameFromSource (subprocessHelperSource));
  838. const auto binaryBuilderSource = linuxSubprocessHelperProperties.getSimpleBinaryBuilderSource();
  839. const auto binaryBuilderObj = makeTarget (out,
  840. binaryBuilderSource.toUnixStyle(),
  841. getObjectFileFor (binaryBuilderSource));
  842. const auto binaryBuilderPath = makeTarget (out,
  843. binaryBuilderObj,
  844. "$(JUCE_BINDIR)/" + LSHP::getBinaryNameFromSource (binaryBuilderSource));
  845. const auto binaryDataSource = linuxSubprocessHelperProperties.getLinuxSubprocessHelperBinaryDataSource();
  846. jassert (binaryDataSource.getRoot() == build_tools::RelativePath::buildTargetFolder);
  847. out << binaryDataSource.toUnixStyle() << ": " << subprocessHelperPath
  848. << " " << binaryBuilderPath
  849. << newLine;
  850. const auto binarySourceDir = [&]() -> String
  851. {
  852. if (const auto p = LSHP::getParentDirectoryRelativeToBuildTargetFolder (binaryDataSource))
  853. return *p;
  854. return ".";
  855. }();
  856. out << "\t$(V_AT)" << binaryBuilderPath.quoted() << " " << subprocessHelperPath.quoted()
  857. << " " << binarySourceDir.quoted() << " " << binaryDataSource.getFileNameWithoutExtension().quoted()
  858. << " LinuxSubprocessHelperBinaryData" << newLine;
  859. out << newLine;
  860. }
  861. void writeMakefile (OutputStream& out) const
  862. {
  863. out << "# Automatically generated makefile, created by the Projucer" << newLine
  864. << "# Don't edit this file! Your changes will be overwritten when you re-save the Projucer project!" << newLine
  865. << newLine;
  866. out << "# build with \"V=1\" for verbose builds" << newLine
  867. << "ifeq ($(V), 1)" << newLine
  868. << "V_AT =" << newLine
  869. << "else" << newLine
  870. << "V_AT = @" << newLine
  871. << "endif" << newLine
  872. << newLine;
  873. out << "# (this disables dependency generation if multiple architectures are set)" << newLine
  874. << "DEPFLAGS := $(if $(word 2, $(TARGET_ARCH)), , -MMD)" << newLine
  875. << newLine;
  876. out << "ifndef PKG_CONFIG" << newLine
  877. << " PKG_CONFIG=pkg-config" << newLine
  878. << "endif" << newLine
  879. << newLine;
  880. out << "ifndef STRIP" << newLine
  881. << " STRIP=strip" << newLine
  882. << "endif" << newLine
  883. << newLine;
  884. out << "ifndef AR" << newLine
  885. << " AR=ar" << newLine
  886. << "endif" << newLine
  887. << newLine;
  888. out << "ifndef CONFIG" << newLine
  889. << " CONFIG=" << escapeQuotesAndSpaces (getConfiguration(0)->getName()) << newLine
  890. << "endif" << newLine
  891. << newLine;
  892. out << "JUCE_ARCH_LABEL := $(shell uname -m)" << newLine
  893. << newLine;
  894. for (ConstConfigIterator config (*this); config.next();)
  895. writeConfig (out, dynamic_cast<const MakeBuildConfiguration&> (*config));
  896. std::vector<std::pair<File, String>> filesToCompile;
  897. for (int i = 0; i < getAllGroups().size(); ++i)
  898. {
  899. auto group = findAllFilesToCompile (getAllGroups().getReference (i));
  900. filesToCompile.insert (filesToCompile.end(),
  901. std::make_move_iterator (group.cbegin()),
  902. std::make_move_iterator (group.cend()));
  903. }
  904. writeCompilerFlagSchemes (out, filesToCompile);
  905. const auto getFilesForTarget = [this] (const std::vector<std::pair<File, String>>& files,
  906. MakefileTarget* target,
  907. const Project& p)
  908. {
  909. std::vector<std::pair<build_tools::RelativePath, String>> targetFiles;
  910. auto targetType = (p.isAudioPluginProject() ? target->type : MakefileTarget::SharedCodeTarget);
  911. for (auto& [path, flags] : files)
  912. {
  913. if (p.getTargetTypeFromFilePath (path, true) == targetType)
  914. {
  915. targetFiles.emplace_back (build_tools::RelativePath { path,
  916. getTargetFolder(),
  917. build_tools::RelativePath::buildTargetFolder },
  918. flags);
  919. }
  920. }
  921. if (( targetType == MakefileTarget::SharedCodeTarget
  922. || targetType == MakefileTarget::StaticLibrary
  923. || targetType == MakefileTarget::DynamicLibrary)
  924. && linuxSubprocessHelperProperties.shouldUseLinuxSubprocessHelper())
  925. {
  926. targetFiles.emplace_back (linuxSubprocessHelperProperties.getLinuxSubprocessHelperBinaryDataSource(), "");
  927. }
  928. if (targetType == MakefileTarget::LV2Helper)
  929. {
  930. targetFiles.emplace_back (getLV2HelperProgramSource().rebased (projectFolder,
  931. getTargetFolder(),
  932. build_tools::RelativePath::buildTargetFolder),
  933. String{});
  934. }
  935. else if (targetType == MakefileTarget::VST3Helper)
  936. {
  937. for (const auto& source : getVST3HelperProgramSources (*this))
  938. {
  939. targetFiles.emplace_back (source.rebased (projectFolder,
  940. getTargetFolder(),
  941. build_tools::RelativePath::buildTargetFolder),
  942. String{});
  943. }
  944. }
  945. return targetFiles;
  946. };
  947. for (auto target : targets)
  948. target->writeObjects (out, getFilesForTarget (filesToCompile, target, project));
  949. out << getPhonyTargetLine() << newLine << newLine;
  950. writeTargetLines (out, getLinkPackages());
  951. for (auto target : targets)
  952. target->addFiles (out, getFilesForTarget (filesToCompile, target, project));
  953. // libexecinfo is a separate library on BSD
  954. out << "$(JUCE_OBJDIR)/execinfo.cmd:" << newLine
  955. << "\t-$(V_AT)mkdir -p $(@D)" << newLine
  956. << "\t-@if [ -z \"$(V_AT)\" ]; then echo \"Checking if we need to link libexecinfo\"; fi" << newLine
  957. << "\t$(V_AT)printf \"int main() { return 0; }\" | $(CXX) -x c++ -o $(@D)/execinfo.x -lexecinfo - >/dev/null 2>&1 && printf -- \"-lexecinfo\" > \"$@\" || touch \"$@\"" << newLine
  958. << newLine;
  959. if (linuxSubprocessHelperProperties.shouldUseLinuxSubprocessHelper())
  960. writeSubprocessHelperTargets (out);
  961. out << "clean:" << newLine
  962. << "\t@echo Cleaning " << projectName << newLine
  963. << "\t$(V_AT)$(CLEANCMD)" << newLine
  964. << newLine;
  965. out << "strip:" << newLine
  966. << "\t@echo Stripping " << projectName << newLine
  967. << "\t-$(V_AT)$(STRIP) --strip-unneeded $(JUCE_OUTDIR)/$(TARGET)" << newLine
  968. << newLine;
  969. writeIncludeLines (out);
  970. }
  971. String getArchFlags (const BuildConfiguration& config) const
  972. {
  973. if (auto* makeConfig = dynamic_cast<const MakeBuildConfiguration*> (&config))
  974. return makeConfig->getArchitectureTypeString();
  975. return "-march=native";
  976. }
  977. String getObjectFileFor (const build_tools::RelativePath& file) const
  978. {
  979. return file.getFileNameWithoutExtension()
  980. + "_" + String::toHexString (file.toUnixStyle().hashCode()) + ".o";
  981. }
  982. String getPhonyTargetLine() const
  983. {
  984. MemoryOutputStream phonyTargetLine;
  985. phonyTargetLine << ".PHONY: clean all strip";
  986. if (! getProject().isAudioPluginProject())
  987. return phonyTargetLine.toString();
  988. for (auto target : targets)
  989. if (target->type != build_tools::ProjectType::Target::SharedCodeTarget
  990. && target->type != build_tools::ProjectType::Target::AggregateTarget)
  991. phonyTargetLine << " " << target->getPhonyName();
  992. return phonyTargetLine.toString();
  993. }
  994. OwnedArray<MakefileTarget> targets;
  995. JUCE_DECLARE_NON_COPYABLE (MakefileProjectExporter)
  996. };