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.

1319 lines
55KB

  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 (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, 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 writeLinesForAggregateTarget (OutputStream& out) const
  650. {
  651. const auto isPartOfAggregate = [&] (const MakefileTarget* x)
  652. {
  653. return x != nullptr
  654. && x->type != build_tools::ProjectType::Target::AggregateTarget
  655. && x->type != build_tools::ProjectType::Target::SharedCodeTarget;
  656. };
  657. std::vector<MakefileTarget*> dependencies;
  658. std::copy_if (targets.begin(), targets.end(), std::back_inserter (dependencies), isPartOfAggregate);
  659. out << "all :";
  660. for (const auto& d : dependencies)
  661. out << ' ' << d->getPhonyName();
  662. out << newLine << newLine;
  663. for (const auto& d : dependencies)
  664. out << d->getPhonyName() << " : " << d->getBuildProduct() << newLine;
  665. out << newLine << newLine;
  666. }
  667. void writeLinesForTarget (OutputStream& out, const StringArray& packages, MakefileTarget& target) const
  668. {
  669. if (target.type == build_tools::ProjectType::Target::AggregateTarget)
  670. {
  671. writeLinesForAggregateTarget (out);
  672. }
  673. else
  674. {
  675. if (! getProject().isAudioPluginProject())
  676. out << "all : " << target.getBuildProduct() << newLine << newLine;
  677. target.writeTargetLine (out, packages);
  678. }
  679. }
  680. void writeTargetLines (OutputStream& out, const StringArray& packages) const
  681. {
  682. for (const auto& target : targets)
  683. if (target != nullptr)
  684. writeLinesForTarget (out, packages, *target);
  685. }
  686. void writeConfig (OutputStream& out, const MakeBuildConfiguration& config) const
  687. {
  688. String buildDirName ("build");
  689. auto intermediatesDirName = buildDirName + "/intermediate/" + config.getName();
  690. auto outputDir = buildDirName;
  691. if (config.getTargetBinaryRelativePathString().isNotEmpty())
  692. {
  693. build_tools::RelativePath binaryPath (config.getTargetBinaryRelativePathString(), build_tools::RelativePath::projectFolder);
  694. outputDir = binaryPath.rebased (projectFolder, getTargetFolder(), build_tools::RelativePath::buildTargetFolder).toUnixStyle();
  695. }
  696. out << "ifeq ($(CONFIG)," << escapeQuotesAndSpaces (config.getName()) << ")" << newLine
  697. << " JUCE_BINDIR := " << escapeQuotesAndSpaces (buildDirName) << newLine
  698. << " JUCE_LIBDIR := " << escapeQuotesAndSpaces (buildDirName) << newLine
  699. << " JUCE_OBJDIR := " << escapeQuotesAndSpaces (intermediatesDirName) << newLine
  700. << " JUCE_OUTDIR := " << escapeQuotesAndSpaces (outputDir) << newLine
  701. << newLine
  702. << " ifeq ($(TARGET_ARCH),)" << newLine
  703. << " TARGET_ARCH := " << getArchFlags (config) << newLine
  704. << " endif" << newLine
  705. << newLine;
  706. writeCppFlags (out, config);
  707. for (auto target : targets)
  708. {
  709. auto lines = target->getTargetSettings (config);
  710. if (lines.size() > 0)
  711. out << " " << lines.joinIntoString ("\n ") << newLine;
  712. out << newLine;
  713. }
  714. out << " JUCE_CFLAGS += $(JUCE_CPPFLAGS) $(TARGET_ARCH)";
  715. auto cflags = getCFlags (config).joinIntoString (" ");
  716. if (cflags.isNotEmpty())
  717. out << " " << cflags;
  718. out << " $(CFLAGS)" << newLine;
  719. out << " JUCE_CXXFLAGS += $(JUCE_CFLAGS)";
  720. auto cxxflags = getCXXFlags (config).joinIntoString (" ");
  721. if (cxxflags.isNotEmpty())
  722. out << " " << cxxflags;
  723. out << " $(CXXFLAGS)" << newLine;
  724. writeLinkerFlags (out, config);
  725. out << newLine;
  726. const auto preBuildDirectory = [&]() -> String
  727. {
  728. if (linuxSubprocessHelperProperties.shouldUseLinuxSubprocessHelper())
  729. {
  730. using LSHP = LinuxSubprocessHelperProperties;
  731. const auto dataSource = linuxSubprocessHelperProperties.getLinuxSubprocessHelperBinaryDataSource();
  732. if (auto preBuildDir = LSHP::getParentDirectoryRelativeToBuildTargetFolder (dataSource))
  733. return " " + *preBuildDir;
  734. }
  735. return "";
  736. }();
  737. const auto targetsToClean = [&]
  738. {
  739. StringArray result;
  740. for (const auto& target : targets)
  741. if (target->type != build_tools::ProjectType::Target::AggregateTarget)
  742. result.add (target->getBuildProduct());
  743. return result;
  744. }();
  745. out << " CLEANCMD = rm -rf " << targetsToClean.joinIntoString (" ") << " $(JUCE_OBJDIR)" << preBuildDirectory << newLine
  746. << "endif" << newLine
  747. << newLine;
  748. }
  749. void writeIncludeLines (OutputStream& out) const
  750. {
  751. auto n = targets.size();
  752. for (int i = 0; i < n; ++i)
  753. {
  754. if (auto* target = targets.getUnchecked (i))
  755. {
  756. if (target->type == build_tools::ProjectType::Target::AggregateTarget)
  757. continue;
  758. out << "-include $(OBJECTS_" << target->getTargetVarName()
  759. << ":%.o=%.d)" << newLine;
  760. }
  761. }
  762. }
  763. static String getCompilerFlagSchemeVariableName (const String& schemeName) { return "JUCE_COMPILERFLAGSCHEME_" + schemeName; }
  764. std::vector<std::pair<File, String>> findAllFilesToCompile (const Project::Item& projectItem) const
  765. {
  766. std::vector<std::pair<File, String>> results;
  767. if (projectItem.isGroup())
  768. {
  769. for (int i = 0; i < projectItem.getNumChildren(); ++i)
  770. {
  771. auto inner = findAllFilesToCompile (projectItem.getChild (i));
  772. results.insert (results.end(),
  773. std::make_move_iterator (inner.cbegin()),
  774. std::make_move_iterator (inner.cend()));
  775. }
  776. }
  777. else
  778. {
  779. if (projectItem.shouldBeCompiled())
  780. {
  781. auto f = projectItem.getFile();
  782. if (shouldFileBeCompiledByDefault (f))
  783. {
  784. auto scheme = projectItem.getCompilerFlagSchemeString();
  785. auto flags = getCompilerFlagsForProjectItem (projectItem);
  786. if (scheme.isNotEmpty() && flags.isNotEmpty())
  787. results.emplace_back (f, scheme);
  788. else
  789. results.emplace_back (f, String{});
  790. }
  791. }
  792. }
  793. return results;
  794. }
  795. void writeCompilerFlagSchemes (OutputStream& out, const std::vector<std::pair<File, String>>& filesToCompile) const
  796. {
  797. std::set<String> schemesToWrite;
  798. for (const auto& pair : filesToCompile)
  799. if (pair.second.isNotEmpty())
  800. schemesToWrite.insert (pair.second);
  801. if (schemesToWrite.empty())
  802. return;
  803. for (const auto& s : schemesToWrite)
  804. if (const auto flags = getCompilerFlagsForFileCompilerFlagScheme (s); flags.isNotEmpty())
  805. out << getCompilerFlagSchemeVariableName (s) << " := " << flags << newLine;
  806. out << newLine;
  807. }
  808. /* These targets are responsible for building the juce_linux_subprocess_helper, the
  809. juce_simple_binary_builder, and then using the binary builder to create embeddable .h and .cpp
  810. files from the linux subprocess helper.
  811. */
  812. void writeSubprocessHelperTargets (OutputStream& out) const
  813. {
  814. using LSHP = LinuxSubprocessHelperProperties;
  815. const auto ensureDirs = [] (auto& outStream, std::vector<String> dirs)
  816. {
  817. for (const auto& dir : dirs)
  818. outStream << "\t-$(V_AT)mkdir -p " << dir << newLine;
  819. };
  820. const auto makeTarget = [&ensureDirs] (auto& outStream, String input, String output)
  821. {
  822. const auto isObjectTarget = output.endsWith (".o");
  823. const auto isSourceInput = input.endsWith (".cpp");
  824. const auto targetOutput = isObjectTarget ? "$(JUCE_OBJDIR)/" + output : output;
  825. outStream << (isObjectTarget ? "$(JUCE_OBJDIR)/" : "") << output << ": " << input << newLine;
  826. const auto createBuildTargetRelative = [] (auto path)
  827. {
  828. return build_tools::RelativePath { path, build_tools::RelativePath::buildTargetFolder };
  829. };
  830. if (isObjectTarget)
  831. ensureDirs (outStream, { "$(JUCE_OBJDIR)" });
  832. else if (auto outputParentFolder = LSHP::getParentDirectoryRelativeToBuildTargetFolder (createBuildTargetRelative (output)))
  833. ensureDirs (outStream, { *outputParentFolder });
  834. outStream << (isObjectTarget ? "\t@echo \"Compiling " : "\t@echo \"Linking ")
  835. << (isObjectTarget ? input : output) << "\"" << newLine
  836. << "\t$(V_AT)$(CXX) $(JUCE_CXXFLAGS) -o " << targetOutput.quoted()
  837. << " " << (isSourceInput ? "-c \"$<\"" : input.quoted());
  838. if (! isObjectTarget)
  839. outStream << " $(JUCE_LDFLAGS)";
  840. outStream << " $(TARGET_ARCH)" << newLine << newLine;
  841. return targetOutput;
  842. };
  843. const auto subprocessHelperSource = linuxSubprocessHelperProperties.getLinuxSubprocessHelperSource();
  844. const auto subprocessHelperObj = makeTarget (out,
  845. subprocessHelperSource.toUnixStyle(),
  846. getObjectFileFor (subprocessHelperSource));
  847. const auto subprocessHelperPath = makeTarget (out,
  848. subprocessHelperObj,
  849. "$(JUCE_BINDIR)/" + LSHP::getBinaryNameFromSource (subprocessHelperSource));
  850. const auto binaryBuilderSource = linuxSubprocessHelperProperties.getSimpleBinaryBuilderSource();
  851. const auto binaryBuilderObj = makeTarget (out,
  852. binaryBuilderSource.toUnixStyle(),
  853. getObjectFileFor (binaryBuilderSource));
  854. const auto binaryBuilderPath = makeTarget (out,
  855. binaryBuilderObj,
  856. "$(JUCE_BINDIR)/" + LSHP::getBinaryNameFromSource (binaryBuilderSource));
  857. const auto binaryDataSource = linuxSubprocessHelperProperties.getLinuxSubprocessHelperBinaryDataSource();
  858. jassert (binaryDataSource.getRoot() == build_tools::RelativePath::buildTargetFolder);
  859. out << binaryDataSource.toUnixStyle() << ": " << subprocessHelperPath
  860. << " " << binaryBuilderPath
  861. << newLine;
  862. const auto binarySourceDir = [&]() -> String
  863. {
  864. if (const auto p = LSHP::getParentDirectoryRelativeToBuildTargetFolder (binaryDataSource))
  865. return *p;
  866. return ".";
  867. }();
  868. out << "\t$(V_AT)" << binaryBuilderPath.quoted() << " " << subprocessHelperPath.quoted()
  869. << " " << binarySourceDir.quoted() << " " << binaryDataSource.getFileNameWithoutExtension().quoted()
  870. << " LinuxSubprocessHelperBinaryData" << newLine;
  871. out << newLine;
  872. }
  873. void writeMakefile (OutputStream& out) const
  874. {
  875. out << "# Automatically generated makefile, created by the Projucer" << newLine
  876. << "# Don't edit this file! Your changes will be overwritten when you re-save the Projucer project!" << newLine
  877. << newLine;
  878. out << "# build with \"V=1\" for verbose builds" << newLine
  879. << "ifeq ($(V), 1)" << newLine
  880. << "V_AT =" << newLine
  881. << "else" << newLine
  882. << "V_AT = @" << newLine
  883. << "endif" << newLine
  884. << newLine;
  885. out << "# (this disables dependency generation if multiple architectures are set)" << newLine
  886. << "DEPFLAGS := $(if $(word 2, $(TARGET_ARCH)), , -MMD)" << newLine
  887. << newLine;
  888. out << "ifndef PKG_CONFIG" << newLine
  889. << " PKG_CONFIG=pkg-config" << newLine
  890. << "endif" << newLine
  891. << newLine;
  892. out << "ifndef STRIP" << newLine
  893. << " STRIP=strip" << newLine
  894. << "endif" << newLine
  895. << newLine;
  896. out << "ifndef AR" << newLine
  897. << " AR=ar" << newLine
  898. << "endif" << newLine
  899. << newLine;
  900. out << "ifndef CONFIG" << newLine
  901. << " CONFIG=" << escapeQuotesAndSpaces (getConfiguration(0)->getName()) << newLine
  902. << "endif" << newLine
  903. << newLine;
  904. out << "JUCE_ARCH_LABEL := $(shell uname -m)" << newLine
  905. << newLine;
  906. for (ConstConfigIterator config (*this); config.next();)
  907. writeConfig (out, dynamic_cast<const MakeBuildConfiguration&> (*config));
  908. std::vector<std::pair<File, String>> filesToCompile;
  909. for (int i = 0; i < getAllGroups().size(); ++i)
  910. {
  911. auto group = findAllFilesToCompile (getAllGroups().getReference (i));
  912. filesToCompile.insert (filesToCompile.end(),
  913. std::make_move_iterator (group.cbegin()),
  914. std::make_move_iterator (group.cend()));
  915. }
  916. writeCompilerFlagSchemes (out, filesToCompile);
  917. const auto getFilesForTarget = [this] (const std::vector<std::pair<File, String>>& files,
  918. MakefileTarget* target,
  919. const Project& p)
  920. {
  921. std::vector<std::pair<build_tools::RelativePath, String>> targetFiles;
  922. auto targetType = (p.isAudioPluginProject() ? target->type : MakefileTarget::SharedCodeTarget);
  923. for (auto& [path, flags] : files)
  924. {
  925. if (p.getTargetTypeFromFilePath (path, true) == targetType)
  926. {
  927. targetFiles.emplace_back (build_tools::RelativePath { path,
  928. getTargetFolder(),
  929. build_tools::RelativePath::buildTargetFolder },
  930. flags);
  931. }
  932. }
  933. if (( targetType == MakefileTarget::SharedCodeTarget
  934. || targetType == MakefileTarget::StaticLibrary
  935. || targetType == MakefileTarget::DynamicLibrary)
  936. && linuxSubprocessHelperProperties.shouldUseLinuxSubprocessHelper())
  937. {
  938. targetFiles.emplace_back (linuxSubprocessHelperProperties.getLinuxSubprocessHelperBinaryDataSource(), "");
  939. }
  940. if (targetType == MakefileTarget::LV2Helper)
  941. {
  942. targetFiles.emplace_back (getLV2HelperProgramSource().rebased (projectFolder,
  943. getTargetFolder(),
  944. build_tools::RelativePath::buildTargetFolder),
  945. String{});
  946. }
  947. else if (targetType == MakefileTarget::VST3Helper)
  948. {
  949. targetFiles.emplace_back (getVST3HelperProgramSource().rebased (projectFolder,
  950. getTargetFolder(),
  951. build_tools::RelativePath::buildTargetFolder),
  952. String{});
  953. }
  954. return targetFiles;
  955. };
  956. for (auto target : targets)
  957. target->writeObjects (out, getFilesForTarget (filesToCompile, target, project));
  958. out << getPhonyTargetLine() << newLine << newLine;
  959. writeTargetLines (out, getLinkPackages());
  960. for (auto target : targets)
  961. target->addFiles (out, getFilesForTarget (filesToCompile, target, project));
  962. // libexecinfo is a separate library on BSD
  963. out << "$(JUCE_OBJDIR)/execinfo.cmd:" << newLine
  964. << "\t-$(V_AT)mkdir -p $(@D)" << newLine
  965. << "\t-@if [ -z \"$(V_AT)\" ]; then echo \"Checking if we need to link libexecinfo\"; fi" << newLine
  966. << "\t$(V_AT)printf \"int main() { return 0; }\" | $(CXX) -x c++ -o $(@D)/execinfo.x -lexecinfo - >/dev/null 2>&1 && printf -- \"-lexecinfo\" > \"$@\" || touch \"$@\"" << newLine
  967. << newLine;
  968. // stdc++fs is only needed for some compilers
  969. out << "$(JUCE_OBJDIR)/cxxfs.cmd:" << newLine
  970. << "\t-$(V_AT)mkdir -p $(@D)" << newLine
  971. << "\t-@if [ -z \"$(V_AT)\" ]; then echo \"Checking if we need to link stdc++fs\"; fi" << newLine
  972. << "\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
  973. << newLine;
  974. if (linuxSubprocessHelperProperties.shouldUseLinuxSubprocessHelper())
  975. writeSubprocessHelperTargets (out);
  976. out << "clean:" << newLine
  977. << "\t@echo Cleaning " << projectName << newLine
  978. << "\t$(V_AT)$(CLEANCMD)" << newLine
  979. << newLine;
  980. out << "strip:" << newLine
  981. << "\t@echo Stripping " << projectName << newLine;
  982. for (const auto& target : targets)
  983. {
  984. if (target->type != build_tools::ProjectType::Target::AggregateTarget
  985. && target->type != build_tools::ProjectType::Target::SharedCodeTarget)
  986. {
  987. out << "\t-$(V_AT)$(STRIP) --strip-unneeded " << target->getBuildProduct() << newLine;
  988. }
  989. }
  990. out << newLine;
  991. writeIncludeLines (out);
  992. }
  993. String getArchFlags (const BuildConfiguration& config) const
  994. {
  995. if (auto* makeConfig = dynamic_cast<const MakeBuildConfiguration*> (&config))
  996. return makeConfig->getArchitectureTypeString();
  997. return "-march=native";
  998. }
  999. String getObjectFileFor (const build_tools::RelativePath& file) const
  1000. {
  1001. return file.getFileNameWithoutExtension()
  1002. + "_" + String::toHexString (file.toUnixStyle().hashCode()) + ".o";
  1003. }
  1004. String getPhonyTargetLine() const
  1005. {
  1006. MemoryOutputStream phonyTargetLine;
  1007. phonyTargetLine.setNewLineString (getNewLineString());
  1008. phonyTargetLine << ".PHONY: clean all strip";
  1009. if (! getProject().isAudioPluginProject())
  1010. return phonyTargetLine.toString();
  1011. for (auto target : targets)
  1012. {
  1013. if (target->type != build_tools::ProjectType::Target::SharedCodeTarget
  1014. && target->type != build_tools::ProjectType::Target::AggregateTarget)
  1015. {
  1016. phonyTargetLine << " " << target->getPhonyName();
  1017. }
  1018. }
  1019. return phonyTargetLine.toString();
  1020. }
  1021. OwnedArray<MakefileTarget> targets;
  1022. JUCE_DECLARE_NON_COPYABLE (MakefileProjectExporter)
  1023. };