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.

1290 lines
54KB

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